Hatch and Magic processing now use the regexp library

This commit is contained in:
Michiel Broek 2002-05-10 19:47:16 +00:00
parent cb7b34b7de
commit e83107196f
3 changed files with 161 additions and 209 deletions

View File

@ -4761,8 +4761,8 @@ v0.33.20 10-Feb-2002
Added more checks to processing of file_id.diz files. Also Added more checks to processing of file_id.diz files. Also
when it is illegal formatted the already processed lines are when it is illegal formatted the already processed lines are
cleared to prevent later malformatted descriptions. cleared to prevent later malformatted descriptions.
Added experimental debugging only code in magic and hatch The hatch and magic processors now scan the filenames to test
name testing. using the regexp library, this should be more reliable.
mbmsg: mbmsg:
When creating non-existend message bases, the path is created When creating non-existend message bases, the path is created

View File

@ -41,10 +41,10 @@
extern int do_quiet; extern int do_quiet;
int Days[] = {31,28,31,30,31,30,31,31,30,31,30,31}; int Days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
int Hatched = 0; int Hatched = 0;
int CheckHatch(char *); int CheckHatch(char *);
@ -57,7 +57,7 @@ void Hatch()
int LastDay; int LastDay;
int HatchToday; int HatchToday;
temp = calloc(128, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
Syslog('+', "Pass: hatch files"); Syslog('+', "Pass: hatch files");
Now = time(NULL); Now = time(NULL);
Tm = localtime(&Now); Tm = localtime(&Now);
@ -86,8 +86,7 @@ void Hatch()
HatchToday = FALSE; HatchToday = FALSE;
if (hatch.Days[Diw]) if (hatch.Days[Diw])
HatchToday = TRUE; HatchToday = TRUE;
if ((hatch.Month[Tm->tm_mday -1]) || if ((hatch.Month[Tm->tm_mday -1]) || (hatch.Month[31] && (LastDay == Tm->tm_mday)))
(hatch.Month[31] && (LastDay == Tm->tm_mday)))
HatchToday = TRUE; HatchToday = TRUE;
sprintf(temp, "%s", hatch.Spec); sprintf(temp, "%s", hatch.Spec);
@ -106,9 +105,9 @@ int CheckHatch(char *temp)
{ {
DIR *dp; DIR *dp;
struct dirent *de; struct dirent *de;
char *fn, tf[81], tmp[4], *temp2; char *fn, *tf, tmp[4], *temp2;
int i, Match, hatched = FALSE; int i, hatched = FALSE;
char *Temp, *p, *q, mask[256]; char *p, *q, mask[256];
FILE *Tf; FILE *Tf;
fn = xstrcpy(strrchr(temp, '/') + 1); fn = xstrcpy(strrchr(temp, '/') + 1);
@ -119,16 +118,18 @@ int CheckHatch(char *temp)
if (chdir(temp)) { if (chdir(temp)) {
WriteError("$Can't chdir(%s)", temp); WriteError("$Can't chdir(%s)", temp);
free(fn);
return FALSE; return FALSE;
} }
if ((dp = opendir(temp)) == NULL) { if ((dp = opendir(temp)) == NULL) {
WriteError("$Can't opendir(%s)", temp); WriteError("$Can't opendir(%s)", temp);
free(fn);
return FALSE; return FALSE;
} }
Temp = xstrcpy(fn); memset(&mask, 0, sizeof(mask));
p = tl(Temp); p = fn;
q = mask; q = mask;
*q++ = '^'; *q++ = '^';
while ((*p) && (q < (mask + sizeof(mask) - 4))) { while ((*p) && (q < (mask + sizeof(mask) - 4))) {
@ -146,43 +147,19 @@ int CheckHatch(char *temp)
} }
*q++ = '$'; *q++ = '$';
*q = '\0'; *q = '\0';
Syslog('f', "Hatch mask \"%s\" -> \"%s\"", MBSE_SS(Temp), MBSE_SS(mask)); Syslog('f', "Hatch mask \"%s\" -> \"%s\"", MBSE_SS(fn), MBSE_SS(mask));
if ((re_comp(mask)) == NULL)
Syslog('f', "re_comp() accepted");
else
Syslog('f', "re_comp() returned NULL");
if ((re_comp(mask)) == NULL) {
tf = calloc(PATH_MAX, sizeof(char));
while ((de = readdir(dp))) { while ((de = readdir(dp))) {
Match = FALSE; if (re_exec(de->d_name)) {
if (strlen(fn) == strlen(de->d_name)) {
Match = TRUE;
for (i = 0; i < strlen(fn); i++) {
switch(fn[i]) {
case '?' : break;
case '#' : if (!isdigit(de->d_name[i]))
Match = FALSE;
break;
case '@' : if (!isalpha(de->d_name[i]))
Match = FALSE;
break;
default : if (fn[i] != de->d_name[i])
Match = FALSE;
}
}
}
if (re_exec(de->d_name))
Syslog('f', "%s matched using regexp", de->d_name);
else
Syslog('f', "%s no match using regexp", de->d_name);
if (Match) {
hatched = TRUE; hatched = TRUE;
Syslog('+', "Hatch %s in area %s", de->d_name, hatch.Name); Syslog('+', "Hatch %s in area %s", de->d_name, hatch.Name);
sprintf(tf, "%s/%s", CFG.pinbound, MakeTicName()); sprintf(tf, "%s/%s", CFG.pinbound, MakeTicName());
if ((Tf = fopen(tf, "a+")) == NULL)
if ((Tf = fopen(tf, "a+")) == NULL) {
WriteError("Can't create %s", tf); WriteError("Can't create %s", tf);
else { } else {
fprintf(Tf, "Hatch\r\n"); fprintf(Tf, "Hatch\r\n");
fprintf(Tf, "Created MBSE BBS v%s, %s\r\n", VERSION, SHORTRIGHT); fprintf(Tf, "Created MBSE BBS v%s, %s\r\n", VERSION, SHORTRIGHT);
fprintf(Tf, "Area %s\r\n", hatch.Name); fprintf(Tf, "Area %s\r\n", hatch.Name);
@ -230,6 +207,11 @@ int CheckHatch(char *temp)
} }
} }
} }
free(tf);
} else {
WriteError("Could not create regexp from %s", fn);
}
closedir(dp); closedir(dp);
free(fn); free(fn);
return hatched; return hatched;

View File

@ -100,8 +100,7 @@ char *Magic_Macro(int C)
int GetMagicRec(int Typ, int First) int GetMagicRec(int Typ, int First)
{ {
int Eof = FALSE, DoMagic = TRUE; int Eof = FALSE;
int i;
char *temp, *p, *q, mask[256]; char *temp, *p, *q, mask[256];
FILE *FeM; FILE *FeM;
@ -154,45 +153,16 @@ int GetMagicRec(int Typ, int First)
*q++ = '$'; *q++ = '$';
*q = '\0'; *q = '\0';
Syslog('f', "Magic mask \"%s\" -> \"%s\"", MBSE_SS(magic.Mask), MBSE_SS(mask)); Syslog('f', "Magic mask \"%s\" -> \"%s\"", MBSE_SS(magic.Mask), MBSE_SS(mask));
if ((re_comp(mask)) == NULL) { if ((re_comp(mask)) == NULL) {
if (re_exec(TIC.NewName)) if (re_exec(TIC.NewName)) {
Syslog('f', "Should matched using regexp");
else
Syslog('f', "No match using regexp");
} else {
Syslog('f', "re_comp() failed");
}
/*
* Comparing of the filename must be done in
* two parts, before and after the dot.
*/
if (strlen(magic.Mask) == strlen(TIC.NewName)) {
for (i = 0; i < strlen(magic.Mask); i++) {
switch (magic.Mask[i]) {
case '?': break;
case '@': if (!isalpha(TIC.NewName[i]))
DoMagic = FALSE;
break;
case '#': if (!isdigit(TIC.NewName[i]))
DoMagic = FALSE;
break;
default: if (toupper(TIC.NewName[i]) != toupper(magic.Mask[i]))
DoMagic = FALSE;
}
}
} else {
DoMagic = FALSE;
}
Syslog('f', "Old test, found %s", DoMagic ? "True":"False");
if (DoMagic) {
fclose(FeM); fclose(FeM);
free(temp); free(temp);
return TRUE; return TRUE;
} }
} else {
WriteError("Magic: re_comp(%s) failed", mask);
}
} }
} else { } else {