- unified the 2 script context commands
- minor changes in hipadaba and ascon/devser
This commit is contained in:
56
errormsg.c
56
errormsg.c
@@ -4,13 +4,30 @@
|
||||
#include <string.h>
|
||||
#include "errormsg.h"
|
||||
|
||||
/* ErrMsgList implementation */
|
||||
#define MC_NAME(T) ErrMsg##T
|
||||
#define MC_IMPLEMENTATION
|
||||
#include "mclist.c"
|
||||
/* compare two strings for euqality, ignoring text within square brackets */
|
||||
int ErrEqual(char *str1, char *str2) {
|
||||
char *p;
|
||||
|
||||
while (*str1 != '\0' || *str2 != '\0') {
|
||||
if (*str1 != *str2) {
|
||||
return 0;
|
||||
}
|
||||
if (*str1 == '[') {
|
||||
str1 = strchr(str1, ']');
|
||||
str2 = strchr(str2, ']');
|
||||
if (str1 == NULL || str2 == NULL) {
|
||||
return str1 == str2;
|
||||
}
|
||||
str1++;
|
||||
str2++;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ErrMsg *ErrPutMsg(ErrMsgList *dump, char *data, char *fmt, ...) {
|
||||
ErrMsg *m, *p;
|
||||
ErrMsg *ErrPutMsg(ErrMsg *dump, char *fmt, ...) {
|
||||
ErrMsg *m;
|
||||
ErrMsg **last;
|
||||
va_list ap;
|
||||
char buf[256];
|
||||
char *text;
|
||||
@@ -28,36 +45,23 @@ ErrMsg *ErrPutMsg(ErrMsgList *dump, char *data, char *fmt, ...) {
|
||||
vsnprintf(text, l, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
m = NULL;
|
||||
for (p = ErrMsgFirst(dump); p!= NULL; p = ErrMsgNext(dump)) {
|
||||
if (strcmp(text, p->text) == 0) {
|
||||
m = ErrMsgTake(dump);
|
||||
for (last = &dump; *last != NULL; last = &m->next) {
|
||||
m = *last;
|
||||
if (ErrEqual(text, m->text)) {
|
||||
*last = m->next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m == NULL) {
|
||||
if (text == buf) text = strdup(buf);
|
||||
m = calloc(1, sizeof(*m));
|
||||
if (text == buf) {
|
||||
m->text = strdup(text);
|
||||
} else {
|
||||
m->text = text;
|
||||
}
|
||||
m->data = NULL;
|
||||
m->text = text;
|
||||
m->cnt = 1;
|
||||
} else {
|
||||
if (text != buf) free(text);
|
||||
m->cnt++;
|
||||
}
|
||||
if (m->data) {
|
||||
free(m->data);
|
||||
m->data = NULL;
|
||||
}
|
||||
if (data) {
|
||||
m->data = strdup(data);
|
||||
}
|
||||
ErrMsgFirst(dump);
|
||||
ErrMsgInsert(dump, m);
|
||||
m->next = dump;
|
||||
time(&m->last);
|
||||
return m;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user