]> diplodocus.org Git - nmh/blobdiff - sbr/fmt_compile.c
Merge branch 'master' of ssh://git.sv.gnu.org/srv/git/nmh
[nmh] / sbr / fmt_compile.c
index 6583195866dc9a55f8149cae84c17a74663cadc1..23e0726382094e5603db0b41af451910e2386ff1 100644 (file)
@@ -212,7 +212,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},
 
@@ -264,14 +263,14 @@ static struct ftable functable[] = {
        } while (0)
 
 #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); fp->f_flags |= FF_STRALLOC; } while (0)
+#define LS(type, str)          do { NEW(type,0,0); fp->f_text = getcpy(str); fp->f_flags |= FF_STRALLOC; } while (0)
 
 #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 = getcpy(str); fp->f_flags |= FF_STRALLOC; } while (0)
 #define PUTC(c)                        do { NEW(FT_CHAR,0,0); fp->f_char = (c); } while (0)
 
 static char *format_string;
-static unsigned char *usr_fstring;     /* for CERROR */
+static char *usr_fstring;      /* for CERROR */
 
 #define CERROR(str) compile_error (str, cp)
 
@@ -322,7 +321,7 @@ compile_error(char *str, char *cp)
 
     for (i = errpos-errctx; i < errpos; i++) {
 #ifdef LOCALE
-       if (iscntrl(usr_fstring[i]))
+       if (iscntrl((unsigned char) usr_fstring[i]))
 #else
        if (usr_fstring[i] < 32)
 #endif
@@ -857,6 +856,24 @@ fmt_free(struct format *fmt, int reset_comptable)
        free_comptable();
 }
 
+/*
+ * Free just the text strings from all of the component hash table entries
+ */
+
+void
+fmt_freecomptext(void)
+{
+    unsigned int i;
+    struct comp *cm;
+
+    for (i = 0; i < sizeof(wantcomp)/sizeof(wantcomp[0]); i++)
+       for (cm = wantcomp[i]; cm; cm = cm->c_next)
+           if (cm->c_text) {
+               free(cm->c_text);
+               cm->c_text = NULL;
+           }
+}
+
 /*
  * Find a component in our hash table.  This is just a public interface to
  * the FINDCOMP macro, so we don't have to expose our hash table.
@@ -872,6 +889,53 @@ fmt_findcomp(char *component)
     return cm;
 }
 
+/*
+ * Like fmt_findcomp, but case-insensitive.
+ */
+
+struct comp *
+fmt_findcasecomp(char *component)
+{
+    struct comp *cm;
+
+    for (cm = wantcomp[CHASH(component)]; cm; cm = cm->c_next)
+       if (strcasecmp(component, cm->c_name ? cm->c_name : "") == 0)
+           break;
+
+    return cm;
+}
+
+/*
+ * Add an entry to the component hash table
+ *
+ * Returns true if the component was added, 0 if it already existed.
+ *
+ */
+
+int
+fmt_addcompentry(char *component)
+{
+    struct comp *cm;
+    int i;
+
+    FINDCOMP(cm, component);
+
+    if (cm)
+       return 0;
+
+    NEWCOMP(cm, component);
+
+    /*
+     * ncomp is really meant for fmt_compile() and this function is
+     * meant to be used outside of it.  So decrement it just to be safe
+     * (internal callers should be using NEWCOMP()).
+     */
+
+    ncomp--;
+
+    return 1;
+}
+
 /*
  * Add a string to a component hash table entry.
  *
@@ -880,25 +944,25 @@ fmt_findcomp(char *component)
  */
 
 int
-fmt_addcomp(char *component, char *text)
+fmt_addcomptext(char *component, char *text)
 {
     int i, found = 0, bucket = CHASH(component);
     struct comp *cptr = wantcomp[bucket];
     char *cp;
 
     while (cptr) {
-       if (mh_strcasecmp(component, cptr->c_name) == 0) {
+       if (strcasecmp(component, cptr->c_name ? cptr->c_name : "") == 0) {
            found++;
            if (! cptr->c_text) {
-               cptr->c_text = getcpy(text);
+               cptr->c_text = getcpy(text);
            } else {
-               i = strlen(cp = cptr->c_text) - 1;
+               i = strlen(cp = cptr->c_text) - 1;
                if (cp[i] == '\n') {
                    if (cptr->c_type & CT_ADDR) {
-                       cp[i] = '\0';
+                       cp[i] = '\0';
                        cp = add(",\n\t", cp);
                    } else {
-                       cp = add("\t", cp);
+                       cp = add("\t", cp);
                    }
                }
                cptr->c_text = add(text, cp);
@@ -922,7 +986,7 @@ fmt_appendcomp(int bucket, char *component, char *text)
 
     if (bucket != -1) {
        for (cptr = wantcomp[bucket]; cptr; cptr = cptr->c_next)
-           if (mh_strcasecmp(component, cptr->c_name) == 0)
+           if (strcasecmp(component, cptr->c_name ? cptr->c_name : "") == 0)
                cptr->c_text = add(text, cptr->c_text);
     }
 }
@@ -934,7 +998,7 @@ fmt_appendcomp(int bucket, char *component, char *text)
 static void
 free_comptable(void)
 {
-    int i;
+    unsigned int i;
     struct comp *cm, *cm2;
 
     for (i = 0; i < sizeof(wantcomp)/sizeof(wantcomp[0]); i++) {