]> diplodocus.org Git - nmh/blobdiff - uip/mhparse.c
Replace `if (p) free(p)' with `mh_xfree(p)'.
[nmh] / uip / mhparse.c
index 69ed3bd416afd8924012f4431bef9aa6935a1e56..0c2c17cd49b01e797c50ee3928192f76245ecc2f 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:
@@ -652,8 +660,7 @@ get_ctinfo (char *cp, CT ct, int magic)
 
     /* down case the content type string */
     for (dp = ci->ci_type; *dp; dp++)
 
     /* 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);
+        *dp = tolower ((unsigned char) *dp);
 
     while (isspace ((unsigned char) *cp))
        cp++;
 
     while (isspace ((unsigned char) *cp))
        cp++;
@@ -691,8 +698,7 @@ get_ctinfo (char *cp, CT ct, int magic)
 
     /* down case the content subtype string */
     for (dp = ci->ci_subtype; *dp; dp++)
 
     /* 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);
+        *dp = tolower ((unsigned char) *dp);
 
 magic_skip:
     while (isspace ((unsigned char) *cp))
 
 magic_skip:
     while (isspace ((unsigned char) *cp))
@@ -1201,10 +1207,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;
        }
     }
 
        }
     }
 
@@ -1702,8 +1707,7 @@ size_encoding (CT ct)
     if (ce->ce_file) {
        if (stat (ce->ce_file, &st) != NOTOK)
            return (long) st.st_size;
     if (ce->ce_file) {
        if (stat (ce->ce_file, &st) != NOTOK)
            return (long) st.st_size;
-       else
-           return 0L;
+        return 0L;
     }
 
     if (ct->c_encoding == CE_EXTERNAL)
     }
 
     if (ct->c_encoding == CE_EXTERNAL)
@@ -2325,9 +2329,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);
@@ -2919,17 +2922,16 @@ readDigest (CT ct, char *cp)
             }
 
             return OK;
             }
 
             return OK;
-        } else {
-            if (debugsw) {
-                fprintf (stderr, "invalid MD5 digest (got %d octets)\n",
-                         (int) strlen ((char *) digest));
-            }
-
-            return NOTOK;
         }
         }
-    } else {
+        if (debugsw) {
+            fprintf (stderr, "invalid MD5 digest (got %d octets)\n",
+                     (int) strlen ((char *) digest));
+        }
+
         return NOTOK;
     }
         return NOTOK;
     }
+
+    return NOTOK;
 }
 
 
 }
 
 
@@ -3295,8 +3297,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++;
@@ -4136,8 +4137,7 @@ get_param(PM first, const char *name, char replace, int fetchonly)
        if (strcasecmp(name, first->pm_name) == 0) {
            if (fetchonly)
                return first->pm_value;
        if (strcasecmp(name, first->pm_name) == 0) {
            if (fetchonly)
                return first->pm_value;
-           else
-               return getcpy(get_param_value(first, replace));
+            return getcpy(get_param_value(first, replace));
        }
        first = first->pm_next;
     }
        }
        first = first->pm_next;
     }
@@ -4248,6 +4248,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