]> diplodocus.org Git - nmh/blobdiff - uip/mhparse.c
Don't `else' after return. Simplify control flow.
[nmh] / uip / mhparse.c
index 7ec030badd20f0e5c745e300a47662e9f3d84838..69ed3bd416afd8924012f4431bef9aa6935a1e56 100644 (file)
@@ -151,7 +151,6 @@ static int openURL (CT, char **);
 static int parse_header_attrs (const char *, const char *, char **, PM *,
                               PM *, char **);
 static size_t param_len(PM, int, size_t, int *, int *, size_t *);
 static int parse_header_attrs (const char *, const char *, char **, PM *,
                               PM *, char **);
 static size_t param_len(PM, int, size_t, int *, int *, size_t *);
-static size_t encode_param(PM, char *, size_t, size_t, size_t, int);
 static size_t normal_param(PM, char *, size_t, size_t, size_t);
 static int get_dispo (char *, CT, int);
 
 static size_t normal_param(PM, char *, size_t, size_t, size_t);
 static int get_dispo (char *, CT, int);
 
@@ -295,9 +294,7 @@ get_content (FILE *in, char *file, int toplevel)
     m_getfld_state_t gstate = 0;
 
     /* allocate the content structure */
     m_getfld_state_t gstate = 0;
 
     /* allocate the content structure */
-    if (!(ct = (CT) mh_xcalloc (1, sizeof(*ct))))
-       adios (NULL, "out of memory");
-
+    NEW0(ct);
     ct->c_fp = in;
     ct->c_file = add (file, NULL);
     ct->c_begin = ftell (ct->c_fp) + 1;
     ct->c_fp = in;
     ct->c_file = add (file, NULL);
     ct->c_begin = ftell (ct->c_fp) + 1;
@@ -584,7 +581,7 @@ add_header (CT ct, char *name, char *value)
     HF hp;
 
     /* allocate header field structure */
     HF hp;
 
     /* allocate header field structure */
-    hp = mh_xmalloc (sizeof(*hp));
+    NEW(hp);
 
     /* link data into header structure */
     hp->name = name;
 
     /* link data into header structure */
     hp->name = name;
@@ -1030,8 +1027,7 @@ InitText (CT ct)
     ct->c_subtype = ct_str_subtype (CT_TEXT, ci->ci_subtype);
 
     /* allocate text character set structure */
     ct->c_subtype = ct_str_subtype (CT_TEXT, ci->ci_subtype);
 
     /* allocate text character set structure */
-    if ((t = (struct text *) mh_xcalloc (1, sizeof(*t))) == NULL)
-       adios (NULL, "out of memory");
+    NEW0(t);
     ct->c_ctparams = (void *) t;
 
     /* scan for charset parameter */
     ct->c_ctparams = (void *) t;
 
     /* scan for charset parameter */
@@ -1057,7 +1053,7 @@ InitText (CT ct)
     if (chset != NULL && !check_charset (chset, strlen (chset))) {
        snprintf (buffer, sizeof(buffer), "%s-charset-%s", invo_name, chset);
        if ((cp = context_find (buffer)))
     if (chset != NULL && !check_charset (chset, strlen (chset))) {
        snprintf (buffer, sizeof(buffer), "%s-charset-%s", invo_name, chset);
        if ((cp = context_find (buffer)))
-           ct->c_termproc = getcpy (cp);
+           ct->c_termproc = mh_xstrdup(cp);
     }
 
     return OK;
     }
 
     return OK;
@@ -1135,8 +1131,7 @@ InitMultiPart (CT ct)
     }
 
     /* allocate primary structure for multipart info */
     }
 
     /* allocate primary structure for multipart info */
-    if ((m = (struct multipart *) mh_xcalloc (1, sizeof(*m))) == NULL)
-       adios (NULL, "out of memory");
+    NEW0(m);
     ct->c_ctparams = (void *) m;
 
     /* check if boundary parameter contains only whitespace characters */
     ct->c_ctparams = (void *) m;
 
     /* check if boundary parameter contains only whitespace characters */
@@ -1180,8 +1175,7 @@ InitMultiPart (CT ct)
            if (strcmp (bufp + 2, m->mp_start))
                continue;
 next_part:
            if (strcmp (bufp + 2, m->mp_start))
                continue;
 next_part:
-           if ((part = (struct part *) mh_xcalloc (1, sizeof(*part))) == NULL)
-               adios (NULL, "out of memory");
+           NEW0(part);
            *next = part;
            next = &part->mp_next;
 
            *next = part;
            next = &part->mp_next;
 
@@ -1420,8 +1414,7 @@ InitMessage (CT ct)
                PM pm;
                struct partial *p;
 
                PM pm;
                struct partial *p;
 
-               if ((p = (struct partial *) mh_xcalloc (1, sizeof(*p))) == NULL)
-                   adios (NULL, "out of memory");
+               NEW0(p);
                ct->c_ctparams = (void *) p;
 
                /* scan for parameters "id", "number", and "total" */
                ct->c_ctparams = (void *) p;
 
                /* scan for parameters "id", "number", and "total" */
@@ -1469,8 +1462,7 @@ invalid_param:
                CT p;
                FILE *fp;
 
                CT p;
                FILE *fp;
 
-               if ((e = (struct exbody *) mh_xcalloc (1, sizeof(*e))) == NULL)
-                   adios (NULL, "out of memory");
+               NEW0(e);
                ct->c_ctparams = (void *) e;
 
                if (!ct->c_fp
                ct->c_ctparams = (void *) e;
 
                if (!ct->c_fp
@@ -2330,7 +2322,7 @@ openExternal (CT ct, CT cb, CE ce, char **file, int *fd)
     if (find_cache (ct, rcachesw, (int *) 0, cb->c_id,
                cachefile, sizeof(cachefile)) != NOTOK) {
        if ((ce->ce_fp = fopen (cachefile, "r"))) {
     if (find_cache (ct, rcachesw, (int *) 0, cb->c_id,
                cachefile, sizeof(cachefile)) != NOTOK) {
        if ((ce->ce_fp = fopen (cachefile, "r"))) {
-           ce->ce_file = getcpy (cachefile);
+           ce->ce_file = mh_xstrdup(cachefile);
            ce->ce_unlink = 0;
            goto ready_already;
        } else {
            ce->ce_unlink = 0;
            goto ready_already;
        } else {
@@ -2382,7 +2374,7 @@ openFile (CT ct, char **file)
        return NOTOK;
     }
 
        return NOTOK;
     }
 
-    ce->ce_file = getcpy (e->eb_name);
+    ce->ce_file = mh_xstrdup(e->eb_name);
     ce->ce_unlink = 0;
 
     if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) {
     ce->ce_unlink = 0;
 
     if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) {
@@ -2523,7 +2515,7 @@ openFTP (CT ct, char **file)
                  LocalName (1));
        pass = buffer;
     } else {
                  LocalName (1));
        pass = buffer;
     } else {
-       ruserpass (e->eb_site, &username, &password);
+       ruserpass (e->eb_site, &username, &password, 0);
        user = username;
        pass = password;
     }
        user = username;
        pass = password;
     }
@@ -3545,8 +3537,7 @@ bad_quote:
            }
 
            if (pp == NULL) {
            }
 
            if (pp == NULL) {
-               pp = mh_xmalloc(sizeof(*pp));
-               memset(pp, 0, sizeof(*pp));
+               NEW0(pp);
                pp->name = nameptr;
                pp->next = phead;
                phead = pp;
                pp->name = nameptr;
                pp->next = phead;
                phead = pp;
@@ -3556,8 +3547,7 @@ bad_quote:
             * Insert this into the section linked list
             */
 
             * Insert this into the section linked list
             */
 
-           sp = mh_xmalloc(sizeof(*sp));
-           memset(sp, 0, sizeof(*sp));
+           NEW0(sp);
            sp->value = valptr;
            sp->index = index;
            sp->len = len;
            sp->value = valptr;
            sp->index = index;
            sp->len = len;
@@ -3673,7 +3663,7 @@ content_charset (CT ct) {
 
     ret_charset = get_param(ct->c_ctinfo.ci_first_pm, "charset", '?', 0);
 
 
     ret_charset = get_param(ct->c_ctinfo.ci_first_pm, "charset", '?', 0);
 
-    return ret_charset ? ret_charset : getcpy ("US-ASCII");
+    return ret_charset ? ret_charset : mh_xstrdup("US-ASCII");
 }
 
 
 }
 
 
@@ -3904,13 +3894,13 @@ param_len(PM pm, int index, size_t valueoff, int *encode, int *cont,
         */
 
        if (! pm->pm_charset) {
         */
 
        if (! pm->pm_charset) {
-           pm->pm_charset = getcpy(write_charset_8bit());
+           pm->pm_charset = mh_xstrdup(write_charset_8bit());
            if (strcasecmp(pm->pm_charset, "US-ASCII") == 0)
                adios(NULL, "8-bit characters in parameter \"%s\", but "
                      "local character set is US-ASCII", pm->pm_name);
        }
        if (! pm->pm_lang)
            if (strcasecmp(pm->pm_charset, "US-ASCII") == 0)
                adios(NULL, "8-bit characters in parameter \"%s\", but "
                      "local character set is US-ASCII", pm->pm_name);
        }
        if (! pm->pm_lang)
-           pm->pm_lang = getcpy(NULL); /* Default to a blank lang tag */
+           pm->pm_lang = mh_xstrdup("");       /* Default to a blank lang tag */
 
        len++;          /* For the encoding marker */
        maxfit--;
 
        len++;          /* For the encoding marker */
        maxfit--;
@@ -3981,7 +3971,7 @@ param_len(PM pm, int index, size_t valueoff, int *encode, int *cont,
  * Output an encoded parameter string.
  */
 
  * Output an encoded parameter string.
  */
 
-static size_t
+size_t
 encode_param(PM pm, char *output, size_t len, size_t valuelen,
              size_t valueoff, int index)
 {
 encode_param(PM pm, char *output, size_t len, size_t valuelen,
              size_t valueoff, int index)
 {
@@ -4090,10 +4080,9 @@ normal_param(PM pm, char *output, size_t len, size_t valuelen,
 PM
 add_param(PM *first, PM *last, char *name, char *value, int nocopy)
 {
 PM
 add_param(PM *first, PM *last, char *name, char *value, int nocopy)
 {
-    PM pm = mh_xmalloc(sizeof(*pm));
-
-    memset(pm, 0, sizeof(*pm));
+    PM pm;
 
 
+    NEW0(pm);
     pm->pm_name = nocopy ? name : getcpy(name);
     pm->pm_value = nocopy ? value : getcpy(value);
 
     pm->pm_name = nocopy ? name : getcpy(name);
     pm->pm_value = nocopy ? value : getcpy(value);