- allow scriptcontext objects to be dynamic
- enhancements in scriptcontext (error messages stored as properties)
This commit is contained in:
23
errormsg.c
23
errormsg.c
@@ -26,7 +26,7 @@ int ErrEqual(char *str1, char *str2)
|
||||
return 1;
|
||||
}
|
||||
|
||||
ErrMsg *ErrPutMsg(ErrMsg * dump, char *fmt, ...)
|
||||
void ErrPutMsg(ErrList *list, char *fmt, ...)
|
||||
{
|
||||
ErrMsg *m = NULL;
|
||||
ErrMsg **last = NULL;
|
||||
@@ -34,7 +34,8 @@ ErrMsg *ErrPutMsg(ErrMsg * dump, char *fmt, ...)
|
||||
char buf[256];
|
||||
char *text = NULL;
|
||||
int l;
|
||||
|
||||
static long id = 0;
|
||||
|
||||
va_start(ap, fmt);
|
||||
l = vsnprintf(buf, sizeof buf, fmt, ap);
|
||||
va_end(ap);
|
||||
@@ -43,12 +44,13 @@ ErrMsg *ErrPutMsg(ErrMsg * dump, char *fmt, ...)
|
||||
} else {
|
||||
/* assuming we have a C99 conforming snprintf and need a larger buffer */
|
||||
text = calloc(l, 1);
|
||||
if (!text) return;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(text, l, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
last = &dump;
|
||||
for (m = dump; m != NULL; m = m->next) {
|
||||
last = &list->current;
|
||||
for (m = list->current; m != NULL; m = m->next) {
|
||||
if (ErrEqual(text, m->text)) {
|
||||
*last = m->next; /* remove found item from list */
|
||||
break;
|
||||
@@ -61,12 +63,21 @@ ErrMsg *ErrPutMsg(ErrMsg * dump, char *fmt, ...)
|
||||
m = calloc(1, sizeof(*m));
|
||||
m->text = text;
|
||||
m->cnt = 1;
|
||||
m->dirty = 0;
|
||||
id++;
|
||||
m->id = id;
|
||||
} else {
|
||||
if (text != buf)
|
||||
free(text);
|
||||
m->cnt++;
|
||||
}
|
||||
m->next = dump;
|
||||
m->next = list->current;
|
||||
time(&m->last);
|
||||
return m;
|
||||
list->current = m;
|
||||
}
|
||||
|
||||
char *ErrGetLastMsg(ErrList *list) {
|
||||
if (list == NULL) return "";
|
||||
if (list->current == NULL) return "";
|
||||
return list->current->text;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user