diff options
Diffstat (limited to 'event.c')
-rw-r--r-- | event.c | 106 |
1 files changed, 53 insertions, 53 deletions
@@ -10,94 +10,94 @@ #include <ctype.h> static char *duptolower(const char *s) { - char *c = strdup(s); - char *p = c; - for (; *p; ++p) - *p = tolower(*p); - return c; + char *c = strdup(s); + char *p = c; + for (; *p; ++p) + *p = tolower(*p); + return c; } cEventsBlock EventsBlock; cEventBlock::cEventBlock(void): - mRegularExp(false), - mIgnoreCase(false), - mCompiled(false) + mRegularExp(false), + mIgnoreCase(false), + mCompiled(false) { strncpy(mPattern, tr("New Entry"), sizeof(mPattern)); } cEventBlock::cEventBlock(const char *Pattern): - mRegularExp(false), - mIgnoreCase(false), - mCompiled(false) + mRegularExp(false), + mIgnoreCase(false), + mCompiled(false) { strncpy(mPattern, Pattern, sizeof(mPattern)); } cEventBlock::cEventBlock(const cEventBlock &Src) { - operator=(Src); + operator=(Src); } cEventBlock &cEventBlock::operator=(const cEventBlock &Src) { - printf("copy construct\n"); - strcpy(mPattern, Src.mPattern); - mRegularExp = Src.mRegularExp; - mIgnoreCase = Src.mIgnoreCase; - mCompiled = false; - Compile(); - return *this; + printf("copy construct\n"); + strcpy(mPattern, Src.mPattern); + mRegularExp = Src.mRegularExp; + mIgnoreCase = Src.mIgnoreCase; + mCompiled = false; + Compile(); + return *this; } cEventBlock::~cEventBlock() { - if (mRegularExp) - regfree(&mExpression); + if (mRegularExp) + regfree(&mExpression); } bool cEventBlock::Acceptable(const char *Event) const { - if (mRegularExp) - return regexec(&mExpression, Event, 0, NULL, 0) != 0; - else if (mIgnoreCase) { - char *ev = duptolower(Event); - char *pa = duptolower(mPattern); - printf("check for %s in %s\n", pa, ev); - bool res = strstr(ev, pa) == NULL; - free(ev); free(pa); - return res; - } else - return strstr(Event, mPattern) == NULL; + if (mRegularExp) + return regexec(&mExpression, Event, 0, NULL, 0) != 0; + else if (mIgnoreCase) { + char *ev = duptolower(Event); + char *pa = duptolower(mPattern); + printf("check for %s in %s\n", pa, ev); + bool res = strstr(ev, pa) == NULL; + free(ev); free(pa); + return res; + } else + return strstr(Event, mPattern) == NULL; } bool cEventBlock::Parse(char *s) { - char *patternbuf = NULL; - int fields = sscanf(s, "%d:%d:%a[^\n]", &mRegularExp, &mIgnoreCase, &patternbuf); - - if (fields == 3) { - strncpy(mPattern, skipspace(stripspace(patternbuf)), sizeof(mPattern)); - free(patternbuf); - } else { // backward compatibility - strncpy(mPattern, skipspace(stripspace(s)), sizeof(mPattern)); - mRegularExp = false; - mIgnoreCase = false; - } + char *patternbuf = NULL; + int fields = sscanf(s, "%d:%d:%a[^\n]", &mRegularExp, &mIgnoreCase, &patternbuf); + + if (fields == 3) { + strncpy(mPattern, skipspace(stripspace(patternbuf)), sizeof(mPattern)); + free(patternbuf); + } else { // backward compatibility + strncpy(mPattern, skipspace(stripspace(s)), sizeof(mPattern)); + mRegularExp = false; + mIgnoreCase = false; + } return Compile(); } bool cEventBlock::Compile(void) { - mCompiled = false; - if (mRegularExp) { - if (regcomp(&mExpression, mPattern, REG_EXTENDED | (mIgnoreCase ? REG_ICASE : 0)) != 0) { - esyslog("ERROR: malformed regular expression: %s", mPattern); - return false; - } else - mCompiled = true; - } - return true; + mCompiled = false; + if (mRegularExp) { + if (regcomp(&mExpression, mPattern, REG_EXTENDED | (mIgnoreCase ? REG_ICASE : 0)) != 0) { + esyslog("ERROR: malformed regular expression: %s", mPattern); + return false; + } else + mCompiled = true; + } + return true; } bool cEventBlock::Save(FILE *f) { @@ -116,7 +116,7 @@ bool cEventsBlock::Acceptable(const char *Event) { cEventsBlock &cEventsBlock::operator=(const cEventsBlock &Source) { cList<cEventBlock>::Clear(); - + const cEventBlock *event = Source.First(); while (event != NULL) { printf("transfering %p\n", event); |