X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=sbr%2Ffmt_compile.c;h=797c192ad05fedfba1be8365d7b8da236d1b0ca0;hb=dee26acad9bca6aec7dca5c428b07a386909081b;hp=87e0769415afe6005983692a08ce914309c40fe3;hpb=a485ed478abbd599d8c9aab48934e7a26733ecb1;p=mmh diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index 87e0769..797c192 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -1,10 +1,10 @@ /* - * fmt_compile.c -- "compile" format strings for fmt_scan - * - * This code is Copyright (c) 2002, by the authors of nmh. See the - * COPYRIGHT file in the root directory of the nmh distribution for - * complete copyright information. - */ +** fmt_compile.c -- "compile" format strings for fmt_scan +** +** This code is Copyright (c) 2002, by the authors of nmh. See the +** COPYRIGHT file in the root directory of the nmh distribution for +** complete copyright information. +*/ #include #include @@ -24,8 +24,8 @@ #endif /* - * hash table for deciding if a component is "interesting" - */ +** hash table for deciding if a component is "interesting" +*/ struct comp *wantcomp[128]; static struct format *formatvec; /* array to hold formats */ @@ -50,9 +50,10 @@ extern struct mailname fmt_mnull; #define TF_NOP 8 /* like expr but no result */ /* ftable->flags */ -/* NB that TFL_PUTS is also used to decide whether the test - * in a "%<(function)..." should be a string or numeric one. - */ +/* +** NB that TFL_PUTS is also used to decide whether the test +** in a "%<(function)..." should be a string or numeric one. +*/ #define TFL_PUTS 1 /* implicit putstr if top level */ #define TFL_PUTN 2 /* implicit putnum if top level */ @@ -147,7 +148,6 @@ static struct ftable functable[] = { { "friendly", TF_COMP, FT_LS_FRIENDLY, FT_PARSEADDR, TFL_PUTS }, { "mymbox", TF_COMP, FT_LV_COMPFLAG, FT_MYMBOX, TFL_PUTN }, - { "addtoseq", TF_STR, FT_ADDTOSEQ, 0, 0 }, { "unquote", TF_EXPR, FT_LS_UNQUOTE, 0, TFL_PUTS}, @@ -188,23 +188,18 @@ static struct ftable functable[] = { static char *format_string; static unsigned char *usr_fstring; /* for CERROR */ -#define CERROR(str) compile_error (str, cp) - -/* - * external prototypes - */ -extern char *getusername(void); +#define CERROR(str) compile_error(str, cp) /* - * static prototypes - */ +** static prototypes +*/ static struct ftable *lookup(char *); static void compile_error(char *, char *); -static char *compile (char *); +static char *compile(char *); static char *do_spec(char *); static char *do_name(char *, int); static char *do_func(char *); -static char *do_expr (char *, int); +static char *do_expr(char *, int); static char *do_loop(char *); static char *do_if(char *); @@ -217,7 +212,7 @@ lookup(char *name) register char c = *name; while ((nm = t->name)) { - if (*nm == c && strcmp (nm, name) == 0) + if (*nm == c && strcmp(nm, name) == 0) return (ftbl = t); t++; @@ -236,24 +231,20 @@ compile_error(char *str, char *cp) usr_fstring[errpos] = '\0'; for (i = errpos-errctx; i < errpos; i++) { -#ifdef LOCALE if (iscntrl(usr_fstring[i])) -#else - if (usr_fstring[i] < 32) -#endif usr_fstring[i] = '_'; } advise(NULL, "\"%s\": format compile error - %s", &usr_fstring[errpos-errctx], str); - adios (NULL, "%*s", errctx+1, "^"); + adios(NULL, "%*s", errctx+1, "^"); } /* - * Compile format string "fstring" into format list "fmt". - * Return the number of header components found in the format - * string. - */ +** Compile format string "fstring" into format list "fmt". +** Return the number of header components found in the format +** string. +*/ int fmt_compile(char *fstring, struct format **fmt) @@ -262,8 +253,8 @@ fmt_compile(char *fstring, struct format **fmt) int i; if (format_string) - free (format_string); - format_string = getcpy (fstring); + free(format_string); + format_string = getcpy(fstring); usr_fstring = fstring; /* init the component hash table. */ @@ -272,19 +263,20 @@ fmt_compile(char *fstring, struct format **fmt) memset((char *) &fmt_mnull, 0, sizeof(fmt_mnull)); - /* it takes at least 4 char to generate one format so we - * allocate a worst-case format array using 1/4 the length - * of the format string. We actually need twice this much - * to handle both pre-processing (e.g., address parsing) and - * normal processing. - */ + /* + ** it takes at least 4 char to generate one format so we + ** allocate a worst-case format array using 1/4 the length + ** of the format string. We actually need twice this much + ** to handle both pre-processing (e.g., address parsing) and + ** normal processing. + */ i = strlen(fstring)/2 + 1; if (i == 1) i++; - next_fp = formatvec = (struct format *)calloc ((size_t) i, + next_fp = formatvec = (struct format *)calloc((size_t) i, sizeof(struct format)); if (next_fp == NULL) - adios (NULL, "unable to allocate format storage"); + adios(NULL, "unable to allocate format storage"); ncomp = 0; infunction = 0; @@ -300,7 +292,7 @@ fmt_compile(char *fstring, struct format **fmt) } static char * -compile (char *sp) +compile(char *sp) { register char *cp = sp; register int c; @@ -325,7 +317,7 @@ compile (char *sp) switch (c = *++cp) { case '%': - PUTC (*cp); + PUTC(*cp); cp++; break; @@ -435,7 +427,7 @@ do_name(char *sp, int preprocess) case FT_MYMBOX: if (!primed) { - ismymbox ((struct mailname *) 0); + ismymbox((struct mailname *) 0); primed++; } /* fall through */ @@ -476,7 +468,7 @@ do_func(char *sp) CERROR("'(', '{', ' ' or ')' expected"); } cp[-1] = '\0'; - if ((t = lookup (sp)) == 0) { + if ((t = lookup(sp)) == 0) { CERROR("unknown function"); } if (isspace(c)) @@ -552,22 +544,22 @@ do_func(char *sp) } static char * -do_expr (char *sp, int preprocess) +do_expr(char *sp, int preprocess) { register char *cp = sp; register int c; if ((c = *cp++) == '{') { - cp = do_name (cp, preprocess); + cp = do_name(cp, preprocess); fp->f_type = FT_LS_COMP; } else if (c == '(') { - cp = do_func (cp); + cp = do_func(cp); } else if (c == ')') { return (--cp); } else if (c == '%' && *cp == '<') { - cp = do_if (cp+1); + cp = do_if(cp+1); } else { - CERROR ("'(', '{', '%<' or ')' expected"); + CERROR("'(', '{', '%<' or ')' expected"); } return (cp); } @@ -579,9 +571,9 @@ do_loop(char *sp) struct format *floop; floop = next_fp; - cp = compile (cp); + cp = compile(cp); if (*cp++ != ']') - CERROR ("']' expected"); + CERROR("']' expected"); LV(FT_DONE, 1); /* not yet done */ LV(FT_GOTO, 0); @@ -602,21 +594,22 @@ do_if(char *sp) if ((c = *cp++) == '{') /*}*/{ cp = do_name(cp, 0); fp->f_type = FT_LS_COMP; - LV (FT_IF_S, 0); + LV(FT_IF_S, 0); } else if (c == '(') { cp = do_func(cp); /* see if we can merge the load and the "if" */ if (ftbl->f_type >= IF_FUNCS) fp->f_type = ftbl->extra; else { - /* Put out a string test or a value - * test depending on what this - * function 's return type is. - */ + /* + ** Put out a string test or a value + ** test depending on what this + ** function 's return type is. + */ if (ftbl->flags & TFL_PUTS) { - LV (FT_IF_S, 0); + LV(FT_IF_S, 0); } else { - LV (FT_IF_V_NE, 0); + LV(FT_IF_V_NE, 0); } } } else { @@ -625,7 +618,7 @@ do_if(char *sp) } fexpr = fp; /* loc of [ELS]IF */ - cp = compile (cp); /* compile IF TRUE stmts */ + cp = compile(cp); /* compile IF TRUE stmts */ if (fif) fif->f_skip = next_fp - fif; @@ -636,7 +629,7 @@ do_if(char *sp) fexpr = (struct format *)NULL;/* no extra ENDIF */ - cp = compile (cp); /* compile ELSE stmts */ + cp = compile(cp); /* compile ELSE stmts */ fif->f_skip = next_fp - fif; c = *cp++; } else if (c == '?') { /* another ELSIF */