Added experimental hatch and magic regexp code

This commit is contained in:
Michiel Broek 2002-05-08 18:47:55 +00:00
parent 8d792f2e3b
commit b1ba68ebac
3 changed files with 64 additions and 1 deletions

View File

@ -4758,6 +4758,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
name testing.
mbmsg: mbmsg:
When creating non-existend message bases, the path is created When creating non-existend message bases, the path is created

View File

@ -108,6 +108,7 @@ int CheckHatch(char *temp)
struct dirent *de; struct dirent *de;
char *fn, tf[81], tmp[4], *temp2; char *fn, tf[81], tmp[4], *temp2;
int i, Match, hatched = FALSE; int i, Match, hatched = FALSE;
char *Temp, *p, *q, mask[256];
FILE *Tf; FILE *Tf;
fn = xstrcpy(strrchr(temp, '/') + 1); fn = xstrcpy(strrchr(temp, '/') + 1);
@ -126,6 +127,29 @@ int CheckHatch(char *temp)
return FALSE; return FALSE;
} }
Temp = xstrcpy(temp);
p = tl(Temp);
q = mask;
*q++ = '^';
while ((*p) && (q < (mask + sizeof(mask) - 4))) {
switch(*p) {
case '\\': *q++ = '\\'; *q++ = '\\'; break;
case '?': *q++ = '.'; break;
case '.': *q++ = '\\'; *q++ = '.'; break;
case '+': *q++ = '\\'; *q++ = '+'; break;
case '*': *q++ = '.'; *q++ = '*'; break;
default: *q++ = toupper(*p); break;
}
p++;
}
*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");
while ((de = readdir(dp))) { while ((de = readdir(dp))) {
Match = FALSE; Match = FALSE;
if (strlen(fn) == strlen(de->d_name)) { if (strlen(fn) == strlen(de->d_name)) {
@ -144,6 +168,12 @@ int CheckHatch(char *temp)
} }
} }
} }
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 (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);

View File

@ -102,7 +102,7 @@ int GetMagicRec(int Typ, int First)
{ {
int Eof = FALSE, DoMagic = TRUE; int Eof = FALSE, DoMagic = TRUE;
int i; int i;
char *temp; char *temp, *Magic, *p, *q, mask[256];
FILE *FeM; FILE *FeM;
if (First) if (First)
@ -132,6 +132,35 @@ int GetMagicRec(int Typ, int First)
if ((magic.Active) && (magic.Attrib == Typ) && (strcasecmp(magic.From, TIC.TicIn.Area) == 0)) { if ((magic.Active) && (magic.Attrib == Typ) && (strcasecmp(magic.From, TIC.TicIn.Area) == 0)) {
// p = tl(magic.Mask);
Magic = xstrcpy(magic.Mask);
p = tl(Magic);
q = mask;
*q++ = '^';
while ((*p) && (q < (mask + sizeof(mask) - 4))) {
switch(*p) {
case '\\': *q++ = '\\'; *q++ = '\\'; break;
case '?': *q++ = '.'; break;
case '.': *q++ = '\\'; *q++ = '.'; break;
case '+': *q++ = '\\'; *q++ = '+'; break;
case '*': *q++ = '.'; *q++ = '*'; break;
default: *q++ = toupper(*p); break;
}
p++;
}
*q++ = '$';
*q = '\0';
Syslog('f', "Magic mask \"%s\" -> \"%s\"", MBSE_SS(Magic), 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 returned NULL");
}
free(Magic);
/* /*
* Comparing of the filename must be done in * Comparing of the filename must be done in
* two parts, before and after the dot. * two parts, before and after the dot.
@ -155,6 +184,8 @@ int GetMagicRec(int Typ, int First)
DoMagic = FALSE; DoMagic = FALSE;
} }
Syslog('f', "Old test, found %s", DoMagic ? "True":"False");
if (DoMagic) { if (DoMagic) {
fclose(FeM); fclose(FeM);
free(temp); free(temp);