]> diplodocus.org Git - nmh/blobdiff - sbr/fmt_compile.c
Fixed dst format escape to return 1 instead of 16, to agree with its
[nmh] / sbr / fmt_compile.c
index 75adc08e2816f2286c41ebf6360ce025686304bc..9cec16a6031b784e6b1adbc66f4bbd1ed6c1101b 100644 (file)
@@ -159,6 +159,8 @@ static struct ftable functable[] = {
      { "decodecomp", TF_COMP,  FT_LS_DECODECOMP, 0,            TFL_PUTS },
      { "decode",     TF_EXPR,  FT_LS_DECODE,   0,              TFL_PUTS },
      { "trim",       TF_EXPR,  FT_LS_TRIM,     0,              0 },
+     { "kilo",       TF_EXPR,  FT_LS_KILO,     0,              TFL_PUTS },
+     { "kibi",       TF_EXPR,  FT_LS_KIBI,     0,              TFL_PUTS },
      { "compval",    TF_COMP,  FT_LV_COMP,     0,              TFL_PUTN },
      { "compflag",   TF_COMP,  FT_LV_COMPFLAG, 0,              TFL_PUTN },
      { "num",        TF_NUM,   FT_LV_LIT,      0,              TFL_PUTN },
@@ -282,7 +284,7 @@ static struct colormap colortable[] = {
 
 /* Add new component to the hash table */
 #define NEWCOMP(cm,name) do { \
-       cm = ((struct comp *) calloc(1, sizeof (struct comp)));\
+       cm = ((struct comp *) mh_xcalloc (1, sizeof (struct comp)));\
        cm->c_name = getcpy(name);\
        cm->c_refcount++;\
        ncomp++;\
@@ -364,11 +366,7 @@ compile_error(char *str, char *cp)
     usr_fstring[errpos] = '\0';
 
     for (i = errpos-errctx; i < errpos; i++) {
-#ifdef LOCALE
        if (iscntrl((unsigned char) usr_fstring[i]))
-#else
-       if (usr_fstring[i] < 32)
-#endif
            usr_fstring[i] = '_';
     }
 
@@ -408,7 +406,7 @@ fmt_compile(char *fstring, struct format **fmt, int reset_comptable)
      */
     i = strlen(fstring)/2 + 1;
                if (i==1) i++;
-    next_fp = formatvec = (struct format *)calloc ((size_t) i,
+    next_fp = formatvec = (struct format *)mh_xcalloc ((size_t) i,
                                                   sizeof(struct format));
     if (next_fp == NULL)
        adios (NULL, "unable to allocate format storage");
@@ -565,7 +563,7 @@ do_name(char *sp, int preprocess)
            CERROR("component used as both date and address");
        }
        cm->c_tws = (struct tws *)
-           calloc((size_t) 1, sizeof(*cm->c_tws));
+           mh_xcalloc ((size_t) 1, sizeof(*cm->c_tws));
        fp->f_type = preprocess;
        PUTCOMP(sp);
        cm->c_type |= CT_DATE;
@@ -1091,6 +1089,25 @@ fmt_appendcomp(int bucket, char *component, char *text)
     }
 }
 
+/*
+ * Iterate over our component hash table
+ */
+
+struct comp *
+fmt_nextcomp(struct comp *comp, unsigned int *bucket)
+{
+    if (comp == NULL)
+       *bucket = 0;
+    else
+       comp = comp->c_next;
+
+    while (comp == NULL && *bucket < sizeof(wantcomp)/sizeof(wantcomp[0])) {
+       comp = wantcomp[(*bucket)++];
+    }
+
+    return comp;
+}
+
 /*
  * Free and reset our component hash table
  */