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
when it is illegal formatted the already processed lines are
cleared to prevent later malformatted descriptions.
Added experimental debugging only code in magic and hatch
name testing.
The hatch and magic processors now scan the filenames to test
using the regexp library, this should be more reliable.
mbmsg:
When creating non-existend message bases, the path is created

View File

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

View File

@ -100,8 +100,7 @@ char *Magic_Macro(int C)
int GetMagicRec(int Typ, int First)
{
int Eof = FALSE, DoMagic = TRUE;
int i;
int Eof = FALSE;
char *temp, *p, *q, mask[256];
FILE *FeM;
@ -154,45 +153,16 @@ int GetMagicRec(int Typ, int First)
*q++ = '$';
*q = '\0';
Syslog('f', "Magic mask \"%s\" -> \"%s\"", MBSE_SS(magic.Mask), MBSE_SS(mask));
if ((re_comp(mask)) == NULL) {
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) {
if (re_exec(TIC.NewName)) {
fclose(FeM);
free(temp);
return TRUE;
}
} else {
WriteError("Magic: re_comp(%s) failed", mask);
}
}
} else {