- Added a drivable adapter to scriptcontext nodes - Added subsampling to simulated histograms (and as a general option) in order to support Gumtree testing.
109 lines
2.1 KiB
C
109 lines
2.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
#include "errormsg.h"
|
|
|
|
/* 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++;
|
|
} else {
|
|
str1++;
|
|
str2++;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
ErrMsg *ErrFind(ErrMsg *dump, char *message){
|
|
ErrMsg *cur = dump;
|
|
while(cur != NULL){
|
|
if(ErrEqual(message,cur->text)){
|
|
break;
|
|
}
|
|
cur = cur->next;
|
|
}
|
|
return cur;
|
|
}
|
|
|
|
ErrMsg *ErrPutMsg(ErrMsg *dump, ErrMsg **current, char *fmt, ...){
|
|
ErrMsg *m = NULL;
|
|
va_list ap;
|
|
char buf[1024];
|
|
|
|
/* format message */
|
|
va_start(ap, fmt);
|
|
memset(buf,0,1024*sizeof(char));
|
|
vsnprintf(buf, sizeof buf, fmt, ap);
|
|
va_end(ap);
|
|
|
|
m = ErrFind(dump, buf);
|
|
if(m == NULL){
|
|
m = calloc(1, sizeof(*m));
|
|
m->text = strdup(buf);
|
|
m->cnt = 1;
|
|
m->next = dump;
|
|
*current = m;
|
|
return m;
|
|
} else {
|
|
*current = m;
|
|
return dump;
|
|
}
|
|
}
|
|
|
|
ErrMsg *ErrOldPutMsg(ErrMsg *dump, char *fmt, ...) {
|
|
ErrMsg *m = NULL;
|
|
ErrMsg **last = NULL;
|
|
va_list ap;
|
|
char buf[256];
|
|
char *text = NULL;
|
|
int l;
|
|
|
|
va_start(ap, fmt);
|
|
l = vsnprintf(buf, sizeof buf, fmt, ap);
|
|
va_end(ap);
|
|
if (l < sizeof buf) {
|
|
text = buf;
|
|
} else {
|
|
/* assuming we have a C99 conforming snprintf and need a larger buffer */
|
|
text = calloc(l, 1);
|
|
va_start(ap, fmt);
|
|
vsnprintf(text, l, fmt, ap);
|
|
va_end(ap);
|
|
}
|
|
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));
|
|
m->text = text;
|
|
m->cnt = 1;
|
|
} else {
|
|
if (text != buf) free(text);
|
|
m->cnt++;
|
|
}
|
|
if(m != dump){
|
|
m->next = dump;
|
|
}
|
|
time(&m->last);
|
|
return m;
|
|
}
|