- allow scriptcontext objects to be dynamic

- enhancements in scriptcontext (error messages stored as properties)
This commit is contained in:
zolliker
2009-02-19 13:30:32 +00:00
parent 981534624f
commit 35f2b6b810
33 changed files with 753 additions and 310 deletions

View File

@@ -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;
}