X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Ffmt_compile.c;h=a180c561a403f0280d8b7eb8492912c10afdf32b;hp=339ac0a21b51fb54f936de173f087068e1dffe0d;hb=5dd6771b28c257af405d7248639ed0e3bcdce38b;hpb=1691e80890e5d8ba258c51c214a3e91880e1db2b diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index 339ac0a..a180c56 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -2,15 +2,28 @@ /* * fmt_compile.c -- "compile" format strings for fmt_scan * - * $Id$ + * 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 -#include +#include #include #include +#ifdef TIME_WITH_SYS_TIME +# include +# include +#else +# ifdef TM_IN_SYS_TIME +# include +# else +# include +# endif +#endif + /* * hash table for deciding if a component is "interesting" */ @@ -38,6 +51,9 @@ 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. + */ #define TFL_PUTS 1 /* implicit putstr if top level */ #define TFL_PUTN 2 /* implicit putnum if top level */ @@ -134,39 +150,44 @@ static struct ftable functable[] = { { "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}, + { NULL, 0, 0, 0, 0 } }; /* Add new component to the hash table */ -#define NEWCOMP(cm,name)\ +#define NEWCOMP(cm,name) do { \ cm = ((struct comp *) calloc(1, sizeof (struct comp)));\ cm->c_name = name;\ ncomp++;\ i = CHASH(name);\ cm->c_next = wantcomp[i];\ - wantcomp[i] = cm; + wantcomp[i] = cm; \ + } while (0) #define NEWFMT (next_fp++) -#define NEW(type,fill,wid)\ - fp=NEWFMT; fp->f_type=(type); fp->f_fill=(fill); fp->f_width=(wid); +#define NEW(type,fill,wid) do {\ + fp=NEWFMT; fp->f_type=(type); fp->f_fill=(fill); fp->f_width=(wid); \ + } while (0) /* Add (possibly new) component to the hash table */ -#define ADDC(name)\ +#define ADDC(name) do { \ FINDCOMP(cm, name);\ if (!cm) {\ NEWCOMP(cm,name);\ }\ - fp->f_comp = cm; + fp->f_comp = cm; \ + } while (0) -#define LV(type, value) NEW(type,0,0); fp->f_value = (value); -#define LS(type, str) NEW(type,0,0); fp->f_text = (str); +#define LV(type, value) do { NEW(type,0,0); fp->f_value = (value); } while (0) +#define LS(type, str) do { NEW(type,0,0); fp->f_text = (str); } while (0) -#define PUTCOMP(comp) NEW(FT_COMP,0,0); ADDC(comp); -#define PUTLIT(str) NEW(FT_LIT,0,0); fp->f_text = (str); -#define PUTC(c) NEW(FT_CHAR,0,0); fp->f_char = (c); +#define PUTCOMP(comp) do { NEW(FT_COMP,0,0); ADDC(comp); } while (0) +#define PUTLIT(str) do { NEW(FT_LIT,0,0); fp->f_text = (str); } while (0) +#define PUTC(c) do { NEW(FT_CHAR,0,0); fp->f_char = (c); } while (0) static char *format_string; -static char *usr_fstring; /* for CERROR */ +static unsigned char *usr_fstring; /* for CERROR */ #define CERROR(str) compile_error (str, cp) @@ -259,6 +280,7 @@ fmt_compile(char *fstring, struct format **fmt) * normal processing. */ i = strlen(fstring)/2 + 1; + if (i==1) i++; next_fp = formatvec = (struct format *)calloc ((size_t) i, sizeof(struct format)); if (next_fp == NULL) @@ -407,13 +429,11 @@ do_name(char *sp, int preprocess) if (cm->c_type & CT_ADDR) { CERROR("component used as both date and address"); } - if (! (cm->c_type & CT_DATE)) { - cm->c_tws = (struct tws *) - calloc((size_t) 1, sizeof(*cm->c_tws)); - fp->f_type = preprocess; - PUTCOMP(sp); - cm->c_type |= CT_DATE; - } + cm->c_tws = (struct tws *) + calloc((size_t) 1, sizeof(*cm->c_tws)); + fp->f_type = preprocess; + PUTCOMP(sp); + cm->c_type |= CT_DATE; break; case FT_MYMBOX: @@ -421,18 +441,15 @@ do_name(char *sp, int preprocess) ismymbox ((struct mailname *) 0); primed++; } - cm->c_type |= CT_MYMBOX; /* fall through */ case FT_PARSEADDR: if (cm->c_type & CT_DATE) { CERROR("component used as both date and address"); } - if (! (cm->c_type & CT_ADDRPARSE)) { - cm->c_mn = &fmt_mnull; - fp->f_type = preprocess; - PUTCOMP(sp); - cm->c_type |= (CT_ADDR | CT_ADDRPARSE); - } + cm->c_mn = &fmt_mnull; + fp->f_type = preprocess; + PUTCOMP(sp); + cm->c_type |= CT_ADDR; break; case FT_FORMATADDR: @@ -597,7 +614,14 @@ do_if(char *sp) if (ftbl->f_type >= IF_FUNCS) fp->f_type = ftbl->extra; else { - LV (FT_IF_V_NE, 0); + /* 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); + } else { + LV (FT_IF_V_NE, 0); + } } } else {