Fix uip/whom.c for C89 compatibility
[mmh] / uip / mhmisc.c
index 869fe1c..8e20fa9 100644 (file)
@@ -11,6 +11,8 @@
 #include <h/mime.h>
 #include <h/mhparse.h>
 #include <h/utils.h>
+#include <stdarg.h>
+#include <sys/stat.h>
 
 extern int debugsw;
 
@@ -31,27 +33,29 @@ static char *errs = NULL;
 /*
 ** prototypes
 */
-int part_ok (CT, int);
-int type_ok (CT, int);
-void set_endian (void);
-int make_intermediates (char *);
-void content_error (char *, CT, char *, ...);
-void flush_errors (void);
+int part_ok(CT, int);
+int type_ok(CT, int);
+void set_endian(void);
+int make_intermediates(char *);
+void content_error(char *, CT, char *, ...);
+void flush_errors(void);
 
 
 int
-part_ok (CT ct, int sP)
+part_ok(CT ct, int sP)
 {
        char **ap;
        int len;
 
-       if (npart == 0 || (ct->c_type == CT_MULTIPART && (sP || ct->c_subtype)))
+       if (npart == 0 || (ct->c_type == CT_MULTIPART &&
+                       (sP || ct->c_subtype)))
                return 1;
 
        for (ap = parts; *ap; ap++) {
                len = strlen(*ap);
-               if (!strncmp (*ap, ct->c_partno, len) &&
-                               (!ct->c_partno[len] || ct->c_partno[len] == '.' ))
+               if (strncmp(*ap, ct->c_partno, len)==0 &&
+                               (!ct->c_partno[len] ||
+                               ct->c_partno[len] == '.' ))
                        return 1;
        }
 
@@ -60,18 +64,20 @@ part_ok (CT ct, int sP)
 
 
 int
-type_ok (CT ct, int sP)
+type_ok(CT ct, int sP)
 {
        char **ap;
        char buffer[BUFSIZ];
        CI ci = &ct->c_ctinfo;
 
-       if (ntype == 0 || (ct->c_type == CT_MULTIPART && (sP || ct->c_subtype)))
+       if (ntype == 0 || (ct->c_type == CT_MULTIPART &&
+                       (sP || ct->c_subtype)))
                return 1;
 
-       snprintf (buffer, sizeof(buffer), "%s/%s", ci->ci_type, ci->ci_subtype);
+       snprintf(buffer, sizeof(buffer), "%s/%s", ci->ci_type, ci->ci_subtype);
        for (ap = types; *ap; ap++)
-               if (!mh_strcasecmp (*ap, ci->ci_type) || !mh_strcasecmp (*ap, buffer))
+               if (!mh_strcasecmp(*ap, ci->ci_type) ||
+                               !mh_strcasecmp(*ap, buffer))
                        return 1;
 
        return 0;
@@ -79,7 +85,7 @@ type_ok (CT ct, int sP)
 
 
 void
-set_endian (void)
+set_endian(void)
 {
        union {
                long l;
@@ -89,13 +95,13 @@ set_endian (void)
        un.l = 1;
        endian = un.c[0] ? -1 : 1;
        if (debugsw)
-               fprintf (stderr, "%s endian architecture\n",
+               fprintf(stderr, "%s endian architecture\n",
                                endian > 0 ? "big" : "little");
 }
 
 
 int
-make_intermediates (char *file)
+make_intermediates(char *file)
 {
        char *cp;
 
@@ -103,24 +109,25 @@ make_intermediates (char *file)
                struct stat st;
 
                *cp = '\0';
-               if (stat (file, &st) == NOTOK) {
+               if (stat(file, &st) == NOTOK) {
                        int answer;
                        char *ep;
                        if (errno != ENOENT) {
-                               advise (file, "error on directory");
+                               advise(file, "error on directory");
 losing_directory:
                                *cp = '/';
                                return NOTOK;
                        }
 
-                       ep = concat ("Create directory \"", file, "\"? ", NULL);
-                       answer = getanswer (ep);
-                       free (ep);
+                       ep = concat("Create directory \"", file, "\"? ", NULL);
+                       answer = getanswer(ep);
+                       mh_free0(&ep);
 
                        if (!answer)
                                goto losing_directory;
-                       if (!makedir (file)) {
-                               advise (NULL, "unable to create directory %s", file);
+                       if (!makedir(file)) {
+                               advise(NULL, "unable to create directory %s",
+                                               file);
                                goto losing_directory;
                        }
                }
@@ -137,9 +144,8 @@ losing_directory:
 */
 
 void
-content_error (char *what, CT ct, char *fmt, ...)
+content_error(char *what, CT ct, char *fmt, ...)
 {
-       va_list arglist;
        int i, len, buflen;
        char *bp, buffer[BUFSIZ];
        CI ci;
@@ -148,16 +154,20 @@ content_error (char *what, CT ct, char *fmt, ...)
        buflen = sizeof(buffer);
 
        if (userrs && invo_name && *invo_name) {
-               snprintf (bp, buflen, "%s: ", invo_name);
-               len = strlen (bp);
+               snprintf(bp, buflen, "%s: ", invo_name);
+               len = strlen(bp);
                bp += len;
                buflen -= len;
        }
 
-       va_start (arglist, fmt);
+       {
+               va_list arglist;
 
-       vsnprintf (bp, buflen, fmt, arglist);
-       len = strlen (bp);
+               va_start(arglist, fmt);
+               vsnprintf(bp, buflen, fmt, arglist);
+               va_end(arglist);
+       }
+       len = strlen(bp);
        bp += len;
        buflen -= len;
 
@@ -167,48 +177,48 @@ content_error (char *what, CT ct, char *fmt, ...)
                char *s;
 
                if (*what) {
-                       snprintf (bp, buflen, " %s: ", what);
-                       len = strlen (bp);
+                       snprintf(bp, buflen, " %s: ", what);
+                       len = strlen(bp);
                        bp += len;
                        buflen -= len;
                }
 
-               if ((s = strerror (errno)))
-                       snprintf (bp, buflen, "%s", s);
+               if ((s = strerror(errno)))
+                       snprintf(bp, buflen, "%s", s);
                else
-                       snprintf (bp, buflen, "Error %d", errno);
+                       snprintf(bp, buflen, "Error %d", errno);
 
-               len = strlen (bp);
+               len = strlen(bp);
                bp += len;
                buflen -= len;
        }
 
-       i = strlen (invo_name) + 2;
+       i = strlen(invo_name) + 2;
 
        /* Now add content type and subtype */
-       snprintf (bp, buflen, "\n%*.*s(content %s/%s", i, i, "",
-               ci->ci_type, ci->ci_subtype);
-       len = strlen (bp);
+       snprintf(bp, buflen, "\n%*.*s(content %s/%s", i, i, "",
+                       ci->ci_type, ci->ci_subtype);
+       len = strlen(bp);
        bp += len;
        buflen -= len;
 
        /* Now add the message/part number */
        if (ct->c_file) {
-               snprintf (bp, buflen, " in message %s", ct->c_file);
-               len = strlen (bp);
+               snprintf(bp, buflen, " in message %s", ct->c_file);
+               len = strlen(bp);
                bp += len;
                buflen -= len;
 
                if (ct->c_partno) {
-                       snprintf (bp, buflen, ", part %s", ct->c_partno);
-                       len = strlen (bp);
+                       snprintf(bp, buflen, ", part %s", ct->c_partno);
+                       len = strlen(bp);
                        bp += len;
                        buflen -= len;
                }
        }
 
-       snprintf (bp, buflen, ")");
-       len = strlen (bp);
+       snprintf(bp, buflen, ")");
+       len = strlen(bp);
        bp += len;
        buflen -= len;
 
@@ -217,20 +227,19 @@ content_error (char *what, CT ct, char *fmt, ...)
                *bp = '\0';
                buflen--;
 
-               errs = add (buffer, errs);
+               errs = add(buffer, errs);
        } else {
-               advise (NULL, "%s", buffer);
+               advise(NULL, "%s", buffer);
        }
 }
 
 
 void
-flush_errors (void)
+flush_errors(void)
 {
        if (errs) {
-               fflush (stdout);
-               fprintf (stderr, "%s", errs);
-               free (errs);
-               errs = NULL;
+               fflush(stdout);
+               fprintf(stderr, "%s", errs);
+               mh_free0(&errs);
        }
 }