55 const char *logname,
const char *type,
56 int overwrite,
int maxLen)
67 for (i=0; i<
shipLog.nlogs; i++) {
68 if ((
shipLog.idstrList[i] != NULL)
69 && (strcmp(
shipLog.idstrList[i], idstr)==0)) {
77 for (i=0; i<
shipLog.nlogs; i++) {
78 if ((strcmp(type,
shipLog.typeList[i])==0)
79 && (strcmp(logname,
shipLog.nameList[i])==0)) {
98 }
else if (overwrite == 2) {
102 for ( i=0; i<
shipLog.nlogs; i++ ) {
103 if ( ( ( idstr != NULL ) && (
shipLog.idstrList[i] != NULL )
104 && ( strcmp(idstr,
shipLog.idstrList[i]) == 0 ) )
105 || ( ( idstr == NULL )
106 && ( strcmp(type,
shipLog.typeList[i]) == 0 ) ) ) {
109 if (e->id ==
shipLog.idList[i])
119 shipLog.nameList[i] = strdup(logname);
122 shipLog.idList[i] = LOG_ID_INVALID;
130 if ((indx ==
shipLog.nlogs) && (idstr != NULL)) {
132 for (i=0; i<
shipLog.nlogs; i++) {
133 if ((
shipLog.idstrList[i] != NULL)
134 && (strcmp( idstr,
shipLog.idstrList[i] ) == 0)) {
145 for (i=0; i<
shipLog.nlogs; i++) {
159 shipLog.nameList[indx] = strdup(logname);
160 shipLog.typeList[indx] = strdup(type);
162 shipLog.idstrList[indx]= (idstr==NULL) ? NULL : strdup(idstr);
177 for (i=0; i<
shipLog.nlogs; i++) {
178 if (((idstr == NULL) && (
shipLog.idstrList[i] == NULL) )
179 || ((idstr != NULL) && (
shipLog.idstrList[i] != NULL)
180 && (strcmp(idstr,
shipLog.idstrList[i]) == 0))) {
185 WARN(_(
"Warning - log not found: creating it"));
186 id =
shiplog_create( idstr, _(
"Please report this log as an error to github.com/naev" ),
187 idstr != NULL ? idstr :
"", 0, 0 );
215 if (e->time != now) {
218 if ((logid == e->id) && (strcmp(e->msg,msg) == 0)) {
225 WARN(_(
"Error creating new log entry - crash imminent!\n"));
235 e->msg = strdup(msg);
237 for (i=0; i<
shipLog.nlogs; i++) {
238 if (
shipLog.idList[i] == logid) {
248 if (e->id == logid) {
272 if ((logid < 0) && (logid != LOG_ID_ALL))
276 while ( e != NULL ) {
277 if ( logid == LOG_ID_ALL || logid == e->id ) {
278 if ( e->prev != NULL )
280 if ( e->next != NULL )
295 for ( i=0; i<
shipLog.nlogs; i++) {
296 if ( logid == LOG_ID_ALL || logid ==
shipLog.idList[i] ) {
297 shipLog.idList[i] = LOG_ID_INVALID;
325 for (i=0; i<
shipLog.nlogs; i++) {
326 if (
shipLog.idList[i] == logid) {
343 for (i=0; i<
shipLog.nlogs; i++) {
344 if ((
shipLog.idList[i] >= 0) &&
345 (strcmp(type,
shipLog.typeList[i])==0)) {
378int shiplog_save( xmlTextWriterPtr writer )
383 xmlw_startElem(writer,
"shiplog");
385 for (i=0; i<
shipLog.nlogs; i++) {
388 if (
shipLog.idList[i] >= 0 ) {
389 xmlw_startElem(writer,
"entry");
390 xmlw_attr(writer,
"id",
"%d",
shipLog.idList[i]);
391 xmlw_attr(writer,
"t",
"%s",
shipLog.typeList[i]);
392 if (
shipLog.removeAfter[i]!=0 )
393 xmlw_attr(writer,
"r",
"%"PRIu64,
shipLog.removeAfter[i]);
394 if (
shipLog.idstrList[i] != NULL )
395 xmlw_attr(writer,
"s",
"%s",
shipLog.idstrList[i]);
397 xmlw_attr(writer,
"m",
"%d",
shipLog.maxLen[i]);
398 xmlw_str(writer,
"%s",
shipLog.nameList[i]);
399 xmlw_endElem(writer);
403 while ( e != NULL ) {
405 xmlw_startElem(writer,
"log");
406 xmlw_attr(writer,
"id",
"%d",e->id);
407 xmlw_attr(writer,
"t",
"%"PRIu64,e->time);
408 xmlw_str(writer,
"%s",e->msg);
409 xmlw_endElem(writer);
413 xmlw_endElem(writer);
424 xmlNodePtr node, cur;
429 node = parent->xmlChildrenNode;
431 if (xml_isNode(node,
"shiplog")) {
432 cur = node->xmlChildrenNode;
434 if (xml_isNode(cur,
"entry")) {
435 xmlr_attr_int(cur,
"id",
id);
437 for ( i=0; i<
shipLog.nlogs; i++ ) {
456 WARN(_(
"No ID in shipLog entry"));
460 }
else if (xml_isNode(cur,
"log")) {
470 xmlr_attr_int( cur,
"id", e->id );
471 xmlr_attr_long( cur,
"t", e->time );
472 e->msg = strdup(xml_raw(cur));
474 }
while (xml_nextNode(cur));
476 }
while (xml_nextNode(node));
480void shiplog_listTypes(
int *ntypes,
char ***logTypes,
int includeAll )
487 types = malloc(
sizeof(
char * ) );
489 types[0] = strdup( _(
"All") );
491 for ( i=0; i<
shipLog.nlogs; i++ ) {
496 if (
shipLog.idList[i] >= 0 ) {
498 for ( j=0; j<n; j++ ) {
499 if ( strcmp(
shipLog.typeList[i], types[j]) == 0 )
504 types = realloc( types,
sizeof(
char * ) * n );
505 types[n-1] = strdup(
shipLog.typeList[i]);
523 int *nlogs,
char ***logsOut,
int **logIDs,
int includeAll )
531 logs = realloc(*logsOut,
sizeof(
char*) * n);
532 logid = realloc(*logIDs,
sizeof(
int) * n);
534 logs[0] = strdup( _(
"All") );
535 logid[0] = LOG_ID_ALL;
538 for ( i=
shipLog.nlogs-1; i>=0; i-- ) {
543 if ( (
shipLog.idList[i] >= 0 )
544 && ( (type == NULL) || ( strcmp(type,
shipLog.typeList[i]) == 0 ) ) ) {
546 logs = realloc( logs,
sizeof(
char * ) * n );
547 logs[n-1] = strdup(
shipLog.nameList[i]);
548 logid = realloc( logid,
sizeof(
int ) * n );
549 logid[n-1] =
shipLog.idList[i];
558int shiplog_getIdOfLogOfType(
const char *type,
int selectedLog )
563 for ( i=
shipLog.nlogs-1; i>=0; i-- ) {
564 if ( (
shipLog.removeAfter[i] > 0) && (
shipLog.removeAfter[i] < t) ) {
568 if ( (
shipLog.idList[i] >= 0 )
569 && ((type == NULL) || ( strcmp(type,
shipLog.typeList[i]) == 0 ) ) ) {
570 if ( n == selectedLog )
589 if ( e->prev != NULL)
591 if ( e->next != NULL )
608 const char *type,
int *nentries,
char ***logentries,
int incempty )
611 char **entries = NULL;
616 if ( logid == LOG_ID_ALL ) {
619 while ( e != NULL ) {
621 if ( logid == LOG_ID_ALL ) {
626 for ( i=0; i<
shipLog.nlogs; i++ ) {
627 if ( (
shipLog.idList[i] >= 0 )
628 && ( e->id ==
shipLog.idList[i] )
629 && ( strcmp(
shipLog.typeList[i], type) == 0 ) ) {
637 if ( e->id == logid ) {
643 entries = realloc(entries,
sizeof(
char*) * n);
646 pos +=
scnprintf(&buf[pos],
sizeof(buf)-pos,
": %s", use->msg);
647 entries[n-1] = strdup(buf);
653 if ( ( n == 0 ) && ( incempty != 0 ) ) {
656 entries = realloc(entries,
sizeof(
char*));
657 entries[0] = strdup(_(
"Empty"));
659 *logentries = entries;
672 for ( i=0; i<
shipLog.nlogs; i++ ) {
673 if ( ( (
shipLog.idstrList[i] == NULL ) && ( idstr == NULL) )
674 || ( (
shipLog.idstrList[i] != NULL ) && ( idstr != NULL )
675 && ( 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.