X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=sbr%2Ffmt_scan.c;h=89023cbcee9adac862adf8cee67a96c4b52dfe6b;hb=5aab34095ffbff27be09091e703e61ddf352ad87;hp=8475d50e3bbebca160269a6a3478673c2dee9a09;hpb=c0591ef34ea123aa8c709bda122308256d2c84cd;p=mmh diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index 8475d50..89023cb 100644 --- a/sbr/fmt_scan.c +++ b/sbr/fmt_scan.c @@ -2,11 +2,12 @@ /* * fmt_scan.c -- format string interpretation * - * $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. + * + * This is the engine that processes the format instructions created by + * fmt_compile (found in fmt_compile.c). */ #include @@ -15,31 +16,25 @@ #include #include -#ifdef TIME_WITH_SYS_TIME +#ifdef HAVE_SYS_TIME_H # include -# include -#else -# ifdef TM_IN_SYS_TIME -# include -# else -# include -# endif #endif +#include #ifdef MULTIBYTE_SUPPORT # include # include #endif -#define NFMTS MAXARGS - extern char *formataddr (); /* hook for custom address formatting */ +extern char *concataddr (); /* address formatting but allowing duplicates */ #ifdef LBL struct msgs *fmt_current_folder; /* current folder (set by main program) */ #endif extern int fmt_norm; /* defined in sbr/fmt_def.c = AD_NAME */ -struct mailname fmt_mnull; +struct mailname fmt_mnull = { NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, + NULL, NULL }; /* * static prototypes @@ -128,10 +123,11 @@ cpnumber(char **dest, int num, unsigned int wid, char fill, size_t n) { static void cptrimmed(char **dest, char *str, unsigned int wid, char fill, size_t n) { int remaining; /* remaining output width available */ - int c, ljust, w; + int c, ljust; int end; /* number of input bytes remaining in str */ #ifdef MULTIBYTE_SUPPORT int char_len; /* bytes in current character */ + int w; wchar_t wide_char; #endif char *sp; /* current position in source string */ @@ -160,7 +156,10 @@ cptrimmed(char **dest, char *str, unsigned int wid, char fill, size_t n) { sp += char_len; #else end--; - if (iscntrl(*sp) || isspace(*sp)) { + /* isnctrl(), etc., take an int argument. Cygwin's ctype.h + intentionally warns if they are passed a char. */ + int c = *sp; + if (iscntrl(c) || isspace(c)) { sp++; #endif if (!prevCtrl) { @@ -288,15 +287,17 @@ get_x400_comp (char *mbox, char *key, char *buffer, int buffer_len) || !(cp = strchr(mbox += idx + strlen (key), '/'))) return 0; - snprintf (buffer, buffer_len, "%*.*s", cp - mbox, cp - mbox, mbox); + snprintf (buffer, buffer_len, "%*.*s", (int)(cp - mbox), (int)(cp - mbox), mbox); return 1; } struct format * fmt_scan (struct format *format, char *scanl, int width, int *dat) { - char *cp, *ep, *sp; - char *savestr, *str = NULL; + char *cp, *ep; + unsigned char *sp; + char *savestr = NULL; + unsigned char *str = NULL; char buffer[BUFSIZ], buffer2[BUFSIZ]; int i, c, ljust, n; int value = 0; @@ -354,16 +355,22 @@ fmt_scan (struct format *format, char *scanl, int width, int *dat) case FT_STRF: cptrimmed (&cp, str, fmt->f_width, fmt->f_fill, ep - cp); break; + case FT_STRLIT: + sp = str; + while ((c = *sp++) && cp < ep) + *cp++ = c; + break; case FT_STRFW: adios (NULL, "internal error (FT_STRFW)"); case FT_NUM: n = snprintf(cp, ep - cp + 1, "%d", value); - if (n >= 0) + if (n >= 0) { if (n >= ep - cp) { cp = ep; } else cp += n; + } break; case FT_NUMF: cpnumber (&cp, value, fmt->f_width, fmt->f_fill, ep - cp); @@ -492,7 +499,7 @@ fmt_scan (struct format *format, char *scanl, int width, int *dat) case FT_LS_TRIM: if (str) { - char *xp; + unsigned char *xp; strncpy(buffer, str, sizeof(buffer)); buffer[sizeof(buffer)-1] = '\0'; @@ -505,13 +512,13 @@ fmt_scan (struct format *format, char *scanl, int width, int *dat) ljust++; } - if (!ljust && i > 0 && strlen(str) > i) + if (!ljust && i > 0 && (int) strlen(str) > i) str[i] = '\0'; xp = str; xp += strlen(str) - 1; while (xp > str && isspace(*xp)) *xp-- = '\0'; - if (ljust && i > 0 && strlen(str) > i) + if (ljust && i > 0 && (int) strlen(str) > i) str += strlen(str) - i; } break; @@ -792,6 +799,11 @@ fmt_scan (struct format *format, char *scanl, int width, int *dat) str = formataddr (savestr, str); break; + case FT_CONCATADDR: + /* The same as formataddr, but doesn't do duplicate suppression */ + str = concataddr (savestr, str); + break; + case FT_PUTADDR: /* output the str register as an address component, * splitting it into multiple lines if necessary. The @@ -800,7 +812,8 @@ fmt_scan (struct format *format, char *scanl, int width, int *dat) * (e.g., "To: ") */ { - char *lp, *lastb; + unsigned char *lp; + char *lastb; int indent, wid, len; lp = str;