]> diplodocus.org Git - nmh/blobdiff - uip/mhparse.c
Replace strlen(foo) > 0 with *foo.
[nmh] / uip / mhparse.c
index 50bffcf6a2bacde389712125da66ece6eecf0e61..7e01b050807fe93b0538b73ca42c23c9cb367e3e 100644 (file)
@@ -330,7 +330,15 @@ get_content (FILE *in, char *file, int toplevel)
            continue;
 
        case BODY:
            continue;
 
        case BODY:
-           ct->c_begin = ftell (in) - strlen (buf);
+           if (name[0] == ':') {
+               /* Special case:  no blank line between header and body.  The
+                  file position indicator is on the newline at the end of the
+                  line, but it needs to be one prior to the beginning of the
+                  line.  So subtract the length of the line, bufsz, plus 1. */
+               ct->c_begin = ftell (in) - (bufsz + 1);
+           } else {
+               ct->c_begin = ftell (in) - (bufsz - 1);
+           }
            break;
 
        case FILEEOF:
            break;
 
        case FILEEOF:
@@ -649,11 +657,7 @@ get_ctinfo (char *cp, CT ct, int magic)
                TYPE_FIELD, ct->c_file);
        return NOTOK;
     }
                TYPE_FIELD, ct->c_file);
        return NOTOK;
     }
-
-    /* down case the content type string */
-    for (dp = ci->ci_type; *dp; dp++)
-       if (isalpha((unsigned char) *dp) && isupper ((unsigned char) *dp))
-           *dp = tolower ((unsigned char) *dp);
+    ToLower(ci->ci_type);
 
     while (isspace ((unsigned char) *cp))
        cp++;
 
     while (isspace ((unsigned char) *cp))
        cp++;
@@ -688,11 +692,7 @@ get_ctinfo (char *cp, CT ct, int magic)
                TYPE_FIELD, ct->c_file, ci->ci_type);
        return NOTOK;
     }
                TYPE_FIELD, ct->c_file, ci->ci_type);
        return NOTOK;
     }
-
-    /* down case the content subtype string */
-    for (dp = ci->ci_subtype; *dp; dp++)
-       if (isalpha((unsigned char) *dp) && isupper ((unsigned char) *dp))
-           *dp = tolower ((unsigned char) *dp);
+    ToLower(ci->ci_subtype);
 
 magic_skip:
     while (isspace ((unsigned char) *cp))
 
 magic_skip:
     while (isspace ((unsigned char) *cp))
@@ -712,10 +712,8 @@ magic_skip:
      * Get any <Content-Id> given in buffer
      */
     if (magic && *cp == '<') {
      * Get any <Content-Id> given in buffer
      */
     if (magic && *cp == '<') {
-       if (ct->c_id) {
-           free (ct->c_id);
-           ct->c_id = NULL;
-       }
+        mh_xfree(ct->c_id);
+        ct->c_id = NULL;
        if (!(dp = strchr(ct->c_id = ++cp, '>'))) {
            advise (NULL, "invalid ID in message %s", ct->c_file);
            return NOTOK;
        if (!(dp = strchr(ct->c_id = ++cp, '>'))) {
            advise (NULL, "invalid ID in message %s", ct->c_file);
            return NOTOK;
@@ -1201,10 +1199,9 @@ end_part:
                if (inout)
                    goto next_part;
                goto last_part;
                if (inout)
                    goto next_part;
                goto last_part;
-           } else {
-               if (strcmp (bufp + 2, m->mp_stop) == 0)
-                   goto end_part;
            }
            }
+            if (strcmp (bufp + 2, m->mp_stop) == 0)
+                goto end_part;
        }
     }
 
        }
     }
 
@@ -1223,7 +1220,7 @@ end_part:
                continue;
            *next = NULL;
            free_content (p);
                continue;
            *next = NULL;
            free_content (p);
-           free ((char *) part);
+           free(part);
        }
     }
 
        }
     }
 
@@ -1835,7 +1832,7 @@ openBase64 (CT ct, char **file)
         for (i = 0; i < decoded_len; ++i) {
             putc (*decoded_p++, ce->ce_fp);
         }
         for (i = 0; i < decoded_len; ++i) {
             putc (*decoded_p++, ce->ce_fp);
         }
-        free ((char *) decoded);
+        free(decoded);
         if (ferror (ce->ce_fp)) {
             content_error (ce->ce_file, ct, "error writing to");
             goto clean_up;
         if (ferror (ce->ce_fp)) {
             content_error (ce->ce_file, ct, "error writing to");
             goto clean_up;
@@ -2324,9 +2321,8 @@ openExternal (CT ct, CT cb, CE ce, char **file, int *fd)
            ce->ce_file = mh_xstrdup(cachefile);
            ce->ce_unlink = 0;
            goto ready_already;
            ce->ce_file = mh_xstrdup(cachefile);
            ce->ce_unlink = 0;
            goto ready_already;
-       } else {
-           admonish (cachefile, "unable to fopen for reading");
        }
        }
+        admonish (cachefile, "unable to fopen for reading");
     }
 
     *fd = fileno (ce->ce_fp);
     }
 
     *fd = fileno (ce->ce_fp);
@@ -2744,8 +2740,7 @@ openMail (CT ct, char **file)
 
     /* showproc is for mhshow and mhstore, though mhlist -debug
      * prints it, too. */
 
     /* showproc is for mhshow and mhstore, though mhlist -debug
      * prints it, too. */
-    if (ct->c_showproc)
-       free (ct->c_showproc);
+    mh_xfree(ct->c_showproc);
     ct->c_showproc = add ("true", NULL);
 
     fseek (ce->ce_fp, 0L, SEEK_SET);
     ct->c_showproc = add ("true", NULL);
 
     fseek (ce->ce_fp, 0L, SEEK_SET);
@@ -3293,8 +3288,7 @@ parse_header_attrs (const char *filename, const char *fieldname,
 
        /* down case the attribute name */
        for (dp = cp; istoken ((unsigned char) *dp); dp++)
 
        /* down case the attribute name */
        for (dp = cp; istoken ((unsigned char) *dp); dp++)
-           if (isalpha((unsigned char) *dp) && isupper ((unsigned char) *dp))
-               *dp = tolower ((unsigned char) *dp);
+            *dp = tolower ((unsigned char) *dp);
 
        for (up = dp; isspace ((unsigned char) *dp);)
            dp++;
 
        for (up = dp; isspace ((unsigned char) *dp);)
            dp++;
@@ -3403,8 +3397,7 @@ parse_header_attrs (const char *filename, const char *fieldname,
                           "field\n%*s(parameter %s)", filename, fieldname,
                           strlen(invo_name) + 2, "", nameptr);
                    free(nameptr);
                           "field\n%*s(parameter %s)", filename, fieldname,
                           strlen(invo_name) + 2, "", nameptr);
                    free(nameptr);
-                   if (charset)
-                       free(charset);
+                    mh_xfree(charset);
                    return NOTOK;
                }
 
                    return NOTOK;
                }
 
@@ -3429,10 +3422,8 @@ parse_header_attrs (const char *filename, const char *fieldname,
                               filename, fieldname, strlen(invo_name) + 2,
                               "", nameptr);
                        free(nameptr);
                               filename, fieldname, strlen(invo_name) + 2,
                               "", nameptr);
                        free(nameptr);
-                       if (charset)
-                           free(charset);
-                       if (lang)
-                           free(lang);
+                        mh_xfree(charset);
+                        mh_xfree(lang);
                        return NOTOK;
                    }
                    vp += 2;
                        return NOTOK;
                    }
                    vp += 2;
@@ -3475,10 +3466,8 @@ bad_quote:
                                filename, fieldname, strlen(invo_name) + 2, "",
                                nameptr);
                        free(nameptr);
                                filename, fieldname, strlen(invo_name) + 2, "",
                                nameptr);
                        free(nameptr);
-                       if (charset)
-                           free(charset);
-                       if (lang)
-                           free(lang);
+                        mh_xfree(charset);
+                        mh_xfree(lang);
                        return NOTOK;
                    case '"':
                        break;
                        return NOTOK;
                    case '"':
                        break;
@@ -3586,11 +3575,9 @@ bad_quote:
             */
 
            if (index == 0 && encoded) {
             */
 
            if (index == 0 && encoded) {
-               if (pp->charset)
-                   free(pp->charset);
+                mh_xfree(pp->charset);
                pp->charset = charset;
                pp->charset = charset;
-               if (pp->lang)
-                   free(pp->lang);
+                mh_xfree(pp->lang);
                pp->lang = lang;
            }
        } else {
                pp->lang = lang;
            }
        } else {
@@ -3690,8 +3677,7 @@ output_params(size_t initialwidth, PM params, int *offsetout, int external)
 
        if (strlen(params->pm_name) > CPERLIN) {
            advise(NULL, "Parameter name \"%s\" is too long", params->pm_name);
 
        if (strlen(params->pm_name) > CPERLIN) {
            advise(NULL, "Parameter name \"%s\" is too long", params->pm_name);
-           if (paramout)
-               free(paramout);
+            mh_xfree(paramout);
            return NULL;
        }
 
            return NULL;
        }
 
@@ -3728,8 +3714,7 @@ output_params(size_t initialwidth, PM params, int *offsetout, int external)
                                 numchars, valoff);
 
            if (i == 0) {
                                 numchars, valoff);
 
            if (i == 0) {
-               if (paramout)
-                   free(paramout);
+                mh_xfree(paramout);
                return NULL;
            }
 
                return NULL;
            }
 
@@ -3792,8 +3777,7 @@ output_params(size_t initialwidth, PM params, int *offsetout, int external)
                             strlen(params->pm_value + valoff), valoff);
 
        if (i == 0) {
                             strlen(params->pm_value + valoff), valoff);
 
        if (i == 0) {
-           if (paramout)
-               free(paramout);
+            mh_xfree(paramout);
            return NULL;
        }
 
            return NULL;
        }
 
@@ -4245,6 +4229,10 @@ noiconv:
     q = buffer;
     bufsize = sizeof(buffer);
     for (p = pm->pm_value; *p != '\0' && bufsize > 1; p++, q++, bufsize--) {
     q = buffer;
     bufsize = sizeof(buffer);
     for (p = pm->pm_value; *p != '\0' && bufsize > 1; p++, q++, bufsize--) {
+        /* FIXME: !iscntrl should perhaps be isprint as that allows all
+         * classes bar cntrl, whereas the cntrl class can include those
+         * in space and blank.
+         * http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html */
        if (isascii((unsigned char) *p) && !iscntrl((unsigned char) *p))
            *q = *p;
        else
        if (isascii((unsigned char) *p) && !iscntrl((unsigned char) *p))
            *q = *p;
        else