Add %(unmailto) format function for List-Post headers
[mmh] / sbr / fmt_compile.c
index 173f12d..2b32e71 100644 (file)
 */
 
 #include <h/mh.h>
+#include <h/utils.h>
 #include <h/addrsbr.h>
 #include <h/tws.h>
 #include <h/fmt_scan.h>
 #include <h/fmt_compile.h>
+#include <ctype.h>
+#include <sysexits.h>
 
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
@@ -200,13 +203,14 @@ static struct ftable functable[] = {
        { "mymbox",     TF_COMP,    FT_LV_COMPFLAG, FT_MYMBOX, TFL_PUTN },
 
        { "unquote",    TF_EXPR,    FT_LS_UNQUOTE, 0, TFL_PUTS},
+       { "unmailto",   TF_EXPR,    FT_LS_UNMAILTO, 0, TFL_PUTS},
 
        { NULL,         0,          0, 0, 0 }
 };
 
 /* Add new component to the hash table */
 #define NEWCOMP(cm,name) do { \
-               cm = ((struct comp *) calloc(1, sizeof (struct comp)));\
+               cm = (mh_xcalloc(1, sizeof (struct comp)));\
                cm->c_name = name;\
                ncomp++;\
                i = CHASH(name);\
@@ -260,9 +264,9 @@ static char *do_if(char *);
 static struct ftable *
 lookup(char *name)
 {
-       register struct ftable *t = functable;
-       register char *nm;
-       register char c = *name;
+       struct ftable *t = functable;
+       char *nm;
+       char c = *name;
 
        while ((nm = t->name)) {
                if (*nm == c && strcmp(nm, name) == 0)
@@ -289,8 +293,8 @@ compile_error(char *str, char *cp)
        }
 
        advise(NULL, "\"%s\": format compile error - %s",
-                  &usr_fstring[errpos-errctx], str);
-       adios(NULL, "%*s", errctx+1, "^");
+                       &usr_fstring[errpos-errctx], str);
+       adios(EX_SOFTWARE, NULL, "%*s", errctx+1, "^");
 }
 
 /*
@@ -301,12 +305,12 @@ compile_error(char *str, char *cp)
 int
 fmt_compile(char *fstring, struct format **fmt)
 {
-       register char *cp;
+       char *cp;
        size_t i;
 
        if (format_string)
-               free(format_string);
-       format_string = getcpy(fstring);
+               mh_free0(&format_string);
+       format_string = mh_xstrdup(fstring);
        usr_fstring = fstring;
 
        /* init the component hash table. */
@@ -325,10 +329,9 @@ fmt_compile(char *fstring, struct format **fmt)
        i = strlen(fstring)/2 + 1;
        if (i == 1)
                i++;
-       next_fp = formatvec = (struct format *)calloc((size_t) i,
-               sizeof(struct format));
+       next_fp = formatvec = mh_xcalloc(i, sizeof(struct format));
        if (next_fp == NULL)
-               adios(NULL, "unable to allocate format storage");
+               adios(EX_OSERR, NULL, "unable to allocate format storage");
 
        ncomp = 0;
        infunction = 0;
@@ -346,8 +349,8 @@ fmt_compile(char *fstring, struct format **fmt)
 static char *
 compile(char *sp)
 {
-       register char *cp = sp;
-       register int  c;
+       char *cp = sp;
+       int  c;
 
        for (;;) {
                sp = cp;
@@ -407,11 +410,11 @@ compile(char *sp)
 static char *
 do_spec(char *sp)
 {
-       register char *cp = sp;
-       register int c;
-       register int ljust = 0;
-       register int wid = 0;
-       register char fill = ' ';
+       char *cp = sp;
+       int c;
+       int ljust = 0;
+       int wid = 0;
+       char fill = ' ';
 
        c = *cp++;
        if (c == '-') {
@@ -459,9 +462,9 @@ do_spec(char *sp)
 static char *
 do_name(char *sp, int preprocess)
 {
-       register char *cp = sp;
-       register int c;
-       register int i;
+       char *cp = sp;
+       int c;
+       int i;
        static int primed = 0;
 
        while (isalnum(c = *cp++) || c == '-' || c == '_')
@@ -477,8 +480,7 @@ do_name(char *sp, int preprocess)
                if (cm->c_type & CT_ADDR) {
                        CERROR("component used as both date and address");
                }
-               cm->c_tws = (struct tws *)
-                       calloc((size_t) 1, sizeof(*cm->c_tws));
+               cm->c_tws = mh_xcalloc(1, sizeof(*cm->c_tws));
                fp->f_type = preprocess;
                PUTCOMP(sp);
                cm->c_type |= CT_DATE;
@@ -518,10 +520,10 @@ do_name(char *sp, int preprocess)
 static char *
 do_func(char *sp)
 {
-       register char *cp = sp;
-       register int c;
-       register struct ftable *t;
-       register int n;
+       char *cp = sp;
+       int c;
+       struct ftable *t;
+       int n;
        int mflag;  /* minus sign in NUM */
 
        infunction++;
@@ -615,8 +617,8 @@ do_func(char *sp)
 static char *
 do_expr(char *sp, int preprocess)
 {
-       register char *cp = sp;
-       register int  c;
+       char *cp = sp;
+       int  c;
 
        if ((c = *cp++) == '{') {
                cp = do_name(cp, preprocess);
@@ -646,7 +648,7 @@ do_expr(char *sp, int preprocess)
 static char *
 do_loop(char *sp)
 {
-       register char *cp = sp;
+       char *cp = sp;
        struct format *floop;
 
        floop = next_fp;
@@ -671,9 +673,9 @@ do_loop(char *sp)
 static char *
 do_if(char *sp)
 {
-       register char *cp = sp;
-       register struct format *fexpr, *fif = (struct format *)NULL;
-       register int c = '<';
+       char *cp = sp;
+       struct format *fexpr, *fif = (struct format *)NULL;
+       int c = '<';
 
        for (;;) {
                if (c == '<') {  /* doing an IF */