57 int overwrite,
int maxLen )
69 for (i = 0; i <
shipLog.nlogs; i++) {
70 if ((
shipLog.idstrList[i] != NULL ) &&
71 ( strcmp(
shipLog.idstrList[i], idstr ) == 0 )) {
79 for (i = 0; i <
shipLog.nlogs; i++) {
80 if (( strcmp( type,
shipLog.typeList[i] ) == 0 ) &&
81 ( strcmp( logname,
shipLog.nameList[i] ) == 0 )) {
101 }
else if (overwrite == 2) {
106 for (i = 0; i <
shipLog.nlogs; i++) {
107 if (( ( idstr != NULL ) && (
shipLog.idstrList[i] != NULL ) &&
108 ( strcmp( idstr,
shipLog.idstrList[i] ) == 0 ) ) ||
109 ( ( idstr == NULL ) &&
110 ( strcmp( type,
shipLog.typeList[i] ) == 0 ) )) {
113 if (e->id ==
shipLog.idList[i])
123 shipLog.nameList[i] = strdup( logname );
127 shipLog.idList[i] = LOG_ID_INVALID;
135 if (( indx ==
shipLog.nlogs ) && ( idstr != NULL )) {
137 for (i = 0; i <
shipLog.nlogs; i++) {
138 if ((
shipLog.idstrList[i] != NULL ) &&
139 ( strcmp( idstr,
shipLog.idstrList[i] ) == 0 )) {
150 for (i = 0; i <
shipLog.nlogs; i++) {
162 realloc(
shipLog.removeAfter,
sizeof( ntime_t ) *
shipLog.nlogs );
168 shipLog.nameList[indx] = strdup( logname );
169 shipLog.typeList[indx] = strdup( type );
171 shipLog.idstrList[indx] = ( idstr == NULL ) ? NULL : strdup( idstr );
186 for (i = 0; i <
shipLog.nlogs; i++) {
187 if (( ( idstr == NULL ) && (
shipLog.idstrList[i] == NULL ) ) ||
188 ( ( idstr != NULL ) && (
shipLog.idstrList[i] != NULL ) &&
189 ( strcmp( idstr,
shipLog.idstrList[i] ) == 0 ) )) {
194 WARN( _(
"Warning - log not found: creating it" ) );
196 idstr, _(
"Please report this log as an error to github.com/naev" ),
197 idstr != NULL ? idstr :
"", 0, 0 );
224 if (e->time != now) {
227 if (( logid == e->id ) && ( strcmp( e->msg, msg ) == 0 )) {
233 if (( e = calloc( 1,
sizeof(
ShipLogEntry ) ) ) == NULL) {
234 WARN( _(
"Error creating new log entry - crash imminent!\n" ) );
244 e->msg = strdup( msg );
246 for (i = 0; i <
shipLog.nlogs; i++) {
247 if (
shipLog.idList[i] == logid) {
257 if (e->id == logid) {
282 if (( logid < 0 ) && ( logid != LOG_ID_ALL ))
287 if (logid == LOG_ID_ALL || logid == e->id) {
305 for (i = 0; i <
shipLog.nlogs; i++) {
306 if (logid == LOG_ID_ALL || logid ==
shipLog.idList[i]) {
307 shipLog.idList[i] = LOG_ID_INVALID;
338 for (i = 0; i <
shipLog.nlogs; i++) {
339 if (
shipLog.idList[i] == logid) {
356 for (i = 0; i <
shipLog.nlogs; i++) {
357 if ((
shipLog.idList[i] >= 0 ) &&
358 ( strcmp( type,
shipLog.typeList[i] ) == 0 )) {
390int shiplog_save( xmlTextWriterPtr writer )
395 xmlw_startElem( writer,
"shiplog" );
397 for (i = 0; i <
shipLog.nlogs; i++) {
401 xmlw_startElem( writer,
"entry" );
402 xmlw_attr( writer,
"id",
"%d",
shipLog.idList[i] );
403 xmlw_attr( writer,
"t",
"%s",
shipLog.typeList[i] );
404 if (
shipLog.removeAfter[i] != 0)
405 xmlw_attr( writer,
"r",
"%" PRIu64,
shipLog.removeAfter[i] );
406 if (
shipLog.idstrList[i] != NULL)
407 xmlw_attr( writer,
"s",
"%s",
shipLog.idstrList[i] );
409 xmlw_attr( writer,
"m",
"%d",
shipLog.maxLen[i] );
410 xmlw_str( writer,
"%s",
shipLog.nameList[i] );
411 xmlw_endElem( writer );
417 xmlw_startElem( writer,
"log" );
418 xmlw_attr( writer,
"id",
"%d", e->id );
419 xmlw_attr( writer,
"t",
"%" PRIu64, e->time );
420 xmlw_str( writer,
"%s", e->msg );
421 xmlw_endElem( writer );
425 xmlw_endElem( writer );
436 xmlNodePtr node, cur;
441 node = parent->xmlChildrenNode;
443 if (xml_isNode( node,
"shiplog" )) {
444 cur = node->xmlChildrenNode;
446 if (xml_isNode( cur,
"entry" )) {
447 xmlr_attr_int( cur,
"id",
id );
449 for (i = 0; i <
shipLog.nlogs; i++) {
468 xmlr_attr_strd( cur,
"t",
470 xmlr_attr_long( cur,
"r",
472 xmlr_attr_strd( cur,
"s",
477 WARN( _(
"No ID in shipLog entry" ) );
480 strdup( xml_raw( cur ) );
482 }
else if (xml_isNode( cur,
"log" )) {
492 xmlr_attr_int( cur,
"id", e->id );
493 xmlr_attr_long( cur,
"t", e->time );
494 e->msg = strdup( xml_raw( cur ) );
496 }
while (xml_nextNode( cur ));
498 }
while (xml_nextNode( node ));
502void shiplog_listTypes(
int *ntypes,
char ***logTypes,
int includeAll )
509 types = malloc(
sizeof(
char * ) );
511 types[0] = strdup( _(
"All" ) );
513 for (i = 0; i <
shipLog.nlogs; i++) {
520 for (j = 0; j < n; j++) {
521 if (strcmp(
shipLog.typeList[i], types[j] ) == 0)
526 types = realloc( types,
sizeof(
char * ) * n );
527 types[n - 1] = strdup(
shipLog.typeList[i] );
548 int **logIDs,
int includeAll )
556 logs = realloc( *logsOut,
sizeof(
char * ) * n );
557 logid = realloc( *logIDs,
sizeof(
int ) * n );
559 logs[0] = strdup( _(
"All" ) );
560 logid[0] = LOG_ID_ALL;
563 for (i =
shipLog.nlogs - 1; i >= 0; i--) {
568 if ((
shipLog.idList[i] >= 0 ) &&
569 ( ( type == NULL ) ||
570 ( strcmp( type,
shipLog.typeList[i] ) == 0 ) )) {
572 logs = realloc( logs,
sizeof(
char * ) * n );
573 logs[n - 1] = strdup(
shipLog.nameList[i] );
574 logid = realloc( logid,
sizeof(
int ) * n );
575 logid[n - 1] =
shipLog.idList[i];
584int shiplog_getIdOfLogOfType(
const char *type,
int selectedLog )
589 for (i =
shipLog.nlogs - 1; i >= 0; i--) {
590 if ((
shipLog.removeAfter[i] > 0 ) && (
shipLog.removeAfter[i] < t )) {
594 if ((
shipLog.idList[i] >= 0 ) &&
595 ( ( type == NULL ) ||
596 ( strcmp( type,
shipLog.typeList[i] ) == 0 ) )) {
597 if (n == selectedLog)
636 char ***logentries,
int incempty )
638 int i, n = 0, all = 0;
639 char **entries = NULL;
644 if (logid == LOG_ID_ALL) {
649 if (logid == LOG_ID_ALL) {
654 for (i = 0; i <
shipLog.nlogs; i++) {
655 if ((
shipLog.idList[i] >= 0 ) &&
656 ( e->id ==
shipLog.idList[i] ) &&
657 ( strcmp(
shipLog.typeList[i], type ) == 0 )) {
665 if (e->id == logid) {
671 entries = realloc( entries,
sizeof(
char * ) * n );
674 pos +=
scnprintf( &buf[pos],
sizeof( buf ) - pos,
": %s", use->msg );
675 entries[n - 1] = strdup( buf );
681 if (( n == 0 ) && ( incempty != 0 )) {
684 entries = realloc( entries,
sizeof(
char * ) );
685 entries[0] = strdup( _(
"Empty" ) );
687 *logentries = entries;
700 for (i = 0; i <
shipLog.nlogs; i++) {
701 if (( (
shipLog.idstrList[i] == NULL ) && ( idstr == NULL ) ) ||
702 ( (
shipLog.idstrList[i] != NULL ) && ( idstr != NULL ) &&
703 ( strcmp( idstr,
shipLog.idstrList[i] ) == 0 ) )) {
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
ntime_t ntime_get(void)
Gets the current time.
void ntime_prettyBuf(char *str, int max, ntime_t t, int d)
Gets the time in a pretty human readable format filling a preset buffer.
void shiplog_new(void)
Set up the shiplog.
int shiplog_appendByID(int logid, const char *msg)
Adds to the log file.
static ShipLogEntry * shiplog_removeEntry(ShipLogEntry *e)
removes an entry from the log
int shiplog_load(xmlNodePtr parent)
Loads the logfiile.
void shiplog_listLog(int logid, const char *type, int *nentries, char ***logentries, int incempty)
Get all log entries matching logid, or if logid==LOG_ID_ALL, matching type, or if type==NULL,...
void shiplog_listLogsOfType(const char *type, int *nlogs, char ***logsOut, int **logIDs, int includeAll)
Lists matching logs (which haven't expired via "removeAfter") into the provided arrays.
void shiplog_clear(void)
Clear the shiplog.
void shiplog_delete(int logid)
Deletes a log (e.g. a cancelled mission may wish to do this, or the user might).
void shiplog_setRemove(int logid, ntime_t when)
Sets the remove flag for a log - it will be removed once time increases, eg after a player takes off.
int shiplog_append(const char *idstr, const char *msg)
Appends to the log file.
void shiplog_deleteType(const char *type)
Deletes all logs of given type.
int shiplog_create(const char *idstr, const char *logname, const char *type, int overwrite, int maxLen)
Creates a new log with given title of given type.
int shiplog_getID(const char *idstr)
Checks to see if the log family exists.