various cleanup

This commit is contained in:
rsc 2006-02-11 23:38:55 +00:00
parent e4d832222b
commit b5f65921f3
37 changed files with 223 additions and 248 deletions

View file

@ -585,15 +585,15 @@ matchpat(Pattern *p, char *message, Resub *m)
if(c1 == spat->c1)
if(memcmp(s, spat->string, spat->len) == 0)
if(!isalt(message, spat->alt)){
m->sp = s;
m->ep = s + spat->len;
m->s.sp = s;
m->e.ep = s + spat->len;
return 1;
}
}
}
return 0;
}
m->sp = m->ep = 0;
m->s.sp = m->e.ep = 0;
if(regexec(p->pat, message, m, 1) == 0)
return 0;
if(isalt(message, p->alt))
@ -608,23 +608,23 @@ xprint(int fd, char *type, Resub *m)
char *p, *q;
int i;
if(m->sp == 0 || m->ep == 0)
if(m->s.sp == 0 || m->e.ep == 0)
return;
/* back up approx 30 characters to whitespace */
for(p = m->sp, i = 0; *p && i < 30; i++, p--)
for(p = m->s.sp, i = 0; *p && i < 30; i++, p--)
;
while(*p && *p != ' ')
p--;
p++;
/* grab about 30 more chars beyond the end of the match */
for(q = m->ep, i = 0; *q && i < 30; i++, q++)
for(q = m->e.ep, i = 0; *q && i < 30; i++, q++)
;
while(*q && *q != ' ')
q++;
fprint(fd, "%s %.*s~%.*s~%.*s\n", type, (int)(m->sp-p), p, (int)(m->ep-m->sp), m->sp, (int)(q-m->ep), m->ep);
fprint(fd, "%s %.*s~%.*s~%.*s\n", type, (int)(m->s.sp-p), p, (int)(m->e.ep-m->s.sp), m->s.sp, (int)(q-m->e.ep), m->e.ep);
}
enum {

View file

@ -1,4 +1,4 @@
</$objtype/mkfile
<$PLAN9/src/mkhdr
TARG=scanmail\
testscan
@ -8,17 +8,11 @@ OFILES= common.$O
HFILES= spam.h\
../common/sys.h\
LIB= ../common/libcommon.a$O\
LIB= ../common/libcommon.a
BIN=/$objtype/bin/upas
UPDATE=\
mkfile\
$HFILES\
${OFILES:%.$O=%.c}\
${TARG:%=%.c}\
</sys/src/cmd/mkmany
BIN=$BIN/upas
<$PLAN9/src/mkmany
CFLAGS=$CFLAGS -I../common
scanmail.$O: scanmail.c
$CC $CFLAGS -D'SPOOL="/mail"' scanmail.c
$CC $CFLAGS -D'SPOOL="'$PLAN9'/mail"' scanmail.c

View file

@ -313,7 +313,7 @@ matcher(char *action, Pattern *p, char *message, Resub *m)
char *cp;
String *s;
for(cp = message; matchpat(p, cp, m); cp = m->ep){
for(cp = message; matchpat(p, cp, m); cp = m->e.ep){
switch(p->action){
case SaveLine:
if(vflag)
@ -340,12 +340,12 @@ matcher(char *action, Pattern *p, char *message, Resub *m)
case Dump:
if(vflag)
xprint(2, action, m);
*(m->ep) = 0;
*m->e.ep = 0;
if(!tflag){
s = s_new();
s_append(s, sender);
s = unescapespecial(s);
syslog(0, "smtpd", "Dumped %s [%s] to %s", s_to_c(s), m->sp,
syslog(0, "smtpd", "Dumped %s [%s] to %s", s_to_c(s), m->s.sp,
s_to_c(s_restart(recips)));
s_free(s);
}
@ -367,17 +367,17 @@ saveline(char *file, char *sender, Resub *rp)
int i, c;
Biobuf *bp;
if(rp->sp == 0 || rp->ep == 0)
if(rp->s.sp == 0 || rp->e.ep == 0)
return;
/* back up approx 20 characters to whitespace */
for(p = rp->sp, i = 0; *p && i < 20; i++, p--)
for(p = rp->s.sp, i = 0; *p && i < 20; i++, p--)
;
while(*p && *p != ' ')
p--;
p++;
/* grab about 20 more chars beyond the end of the match */
for(q = rp->ep, i = 0; *q && i < 20; i++, q++)
for(q = rp->e.ep, i = 0; *q && i < 20; i++, q++)
;
while(*q && *q != ' ')
q++;

View file

@ -191,11 +191,11 @@ matchaction(Patterns *pp, char *message)
p = pp->strings;
ret = 0;
if(p)
for(cp = message; matcher(name, p, cp, m); cp = m[0].ep)
for(cp = message; matcher(name, p, cp, m); cp = m[0].e.ep)
ret++;
for(p = pp->regexps; p; p = p->next)
for(cp = message; matcher(name, p, cp, m); cp = m[0].ep)
for(cp = message; matcher(name, p, cp, m); cp = m[0].e.ep)
ret++;
return ret;
}