- fixed bug in list

This commit is contained in:
zolliker
2008-06-05 13:34:29 +00:00
parent dc6225ecce
commit 3cb901b437
2 changed files with 10 additions and 9 deletions

View File

@ -18,9 +18,9 @@ int ErrEqual(char *str1, char *str2) {
if (str1 == NULL || str2 == NULL) { if (str1 == NULL || str2 == NULL) {
return str1 == str2; return str1 == str2;
} }
str1++;
str2++;
} }
str1++;
str2++;
} }
return 1; return 1;
} }
@ -45,23 +45,24 @@ ErrMsg *ErrPutMsg(ErrMsg *dump, char *fmt, ...) {
vsnprintf(text, l, fmt, ap); vsnprintf(text, l, fmt, ap);
va_end(ap); va_end(ap);
} }
for (last = &dump; *last != NULL; last = &m->next) { last = &dump;
m = *last; for (m = dump; m != NULL; m = m->next) {
if (ErrEqual(text, m->text)) { if (ErrEqual(text, m->text)) {
*last = m->next; *last = m->next; /* remove found item from the list */
break; break;
} }
last = &m->next;
} }
if (m == NULL) { if (m == NULL) { /* make a fresh list item m */
if (text == buf) text = strdup(buf); if (text == buf) text = strdup(buf);
m = calloc(1, sizeof(*m)); m = calloc(1, sizeof(*m));
m->text = text; m->text = text;
m->cnt = 1; m->cnt = 1;
} else { } else { /* take the found item m */
if (text != buf) free(text); if (text != buf) free(text);
m->cnt++; m->cnt++;
} }
m->next = dump; m->next = dump; /* add the new item to the head of the list */
time(&m->last); time(&m->last);
return m; return m;
} }

View File

@ -11,7 +11,6 @@
typedef struct ErrMsg { typedef struct ErrMsg {
struct ErrMsg *next; struct ErrMsg *next;
char *text; /**< the message text */ char *text; /**< the message text */
char *cmpr; /**< compressed message text */
int cnt; /**< count */ int cnt; /**< count */
time_t last; /**< time of last message */ time_t last; /**< time of last message */
} ErrMsg; } ErrMsg;
@ -22,6 +21,7 @@ typedef struct ErrMsg {
* with the same text, storing only the count and the last used time. * with the same text, storing only the count and the last used time.
* Characters within sqaure brackets are not taken into account * Characters within sqaure brackets are not taken into account
* when comparing messages. * when comparing messages.
* The newset message is always at the head of the list.
* *
* \param dump the error message list * \param dump the error message list
* \param fmt the format for the message * \param fmt the format for the message