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

@ -143,7 +143,7 @@ getstring(Node *p)
return s;
}
#if 0 /* jpc */
#if 0
static char *fieldname[] =
{
[WORD-WORD] "WORD",
@ -172,7 +172,7 @@ static char *fieldname[] =
[MAILER-WORD] "MAILER",
[BADTOKEN-WORD] "BADTOKEN",
};
#endif /* jpc */
#endif
/* fix 822 addresses */
static void

View file

@ -21,22 +21,13 @@ SMOBJ=main.$O\
gateway.$O\
cat_mail.$O\
LIB=../common/libcommon.av\
HFILES=send.h\
../common/common.h\
../common/sys.h\
LIB=../common/libcommon.a\
BIN=$PLAN9/bin/upas
UPDATE=\
mkfile\
$HFILES\
${UOFILES:%.$O=%.c}\
${SMOBJ:%.$O=%.c}\
${TARG:%=%.c}\
LIB=../common/libcommon.a
BIN=$BIN/upas
<$PLAN9/src/mkmany
CFLAGS=$CFLAGS -I../common
@ -46,7 +37,6 @@ $O.send: $SMOBJ $OFILES
message.$O: ../smtp/y.tab.h
../smtp/y.tab.h ../smtp/rfc822.tab.$O: ../smtp/rfc822.y
# @{
cd ../smtp
mk rfc822.tab.$O
# }
cd ../smtp
mk rfc822.tab.$O

View file

@ -131,7 +131,7 @@ getrules(void)
String *type;
String *file;
file = abspath("rewrite", unsharp(UPASLIB), (String *)0);
file = abspath("rewrite", UPASLIB, (String *)0);
rfp = sysopen(s_to_c(file), "r", 0);
if(rfp == 0) {
rulep = 0;
@ -168,7 +168,7 @@ findrule(String *addrp, int authorized)
continue;
memset(rp->subexp, 0, sizeof(rp->subexp));
if(debug)
print("matching %s aginst %s\n", s_to_c(addrp), rp->matchre->base);
fprint(2, "matching %s aginst %s\n", s_to_c(addrp), rp->matchre->base);
if(regexec(rp->program, s_to_c(addrp), rp->subexp, NSUBEXP))
if(s_to_c(addrp) == rp->subexp[0].s.sp)
if((s_to_c(addrp) + strlen(s_to_c(addrp))) == rp->subexp[0].e.ep)
@ -203,17 +203,45 @@ rewrite(dest *dp, message *mp)
dp->repl2 = substitute(rp->repl2, rp->subexp, mp);
dp->status = rp->type;
if(debug){
print("\t->");
fprint(2, "\t->");
if(dp->repl1)
print("%s", s_to_c(dp->repl1));
fprint(2, "%s", s_to_c(dp->repl1));
if(dp->repl2)
print("%s", s_to_c(dp->repl2));
print("\n");
fprint(2, "%s", s_to_c(dp->repl2));
fprint(2, "\n");
}
s_free(lower);
return 0;
}
/* stolen from rc/lex.c */
static int
idchr(int c)
{
return c>' ' && !strchr("!\"#$%&'()+,-./:;<=>?@[\\]^`{|}~", c);
}
static char*
getrcvar(char* p, char** rv)
{
char* p0;
char buf[128];
char* bufe;
*rv = 0;
p0=p;
bufe=buf+sizeof buf-1;
while(p<bufe && idchr(*p))
p++;
memcpy(buf, p0, p-p0);
buf[p-p0]=0;
*rv = getenv(buf);
if (debug)
fprint(2, "varsubst: %s → %s\n", buf, *rv);
return p;
}
static String *
substitute(String *source, Resub *subexp, message *mp)
{
@ -264,11 +292,15 @@ substitute(String *source, Resub *subexp, message *mp)
s_putc(stp, *sp);
break;
}
} else if(*sp == '&') {
} else if(*sp == '&') {
if(subexp[0].s.sp != 0)
for (s = subexp[0].s.sp;
s < subexp[0].e.ep; s++)
s_putc(stp, *s);
} else if(*sp == '$') {
sp = getrcvar(sp+1, &s);
s_append(stp, s);
free(s);
} else
s_putc(stp, *sp);
sp++;