]> diplodocus.org Git - nmh/blobdiff - sbr/mime_type.c
mhbuildsbr.c: Flip logic, moving goto to then-block; no need for else.
[nmh] / sbr / mime_type.c
index 23ccf0387fec78a7d11978522a00d80a21390efe..f1b96fe591c001ca6ac3885a11701ea4dec3c03a 100644 (file)
@@ -1,5 +1,4 @@
-/*
- * mime_type.c -- routine to determine the MIME Content-Type of a file
+/* mime_type.c -- routine to determine the MIME Content-Type of a file
  *
  * This code is Copyright (c) 2014, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -9,6 +8,7 @@
 #include <h/mh.h>
 #include <h/utils.h>
 #include <h/tws.h>
+#include "mime_type.h"
 
 #ifdef MIMETYPEPROC
 static char *get_file_info(const char *, const char *);
@@ -69,7 +69,7 @@ mime_type(const char *file_name) {
        if ((p = strrchr(file_name, '.')) != NULL) {
            for (np = m_defs; np; np = np->n_next) {
                if (strncasecmp(np->n_name, "mhshow-suffix-", 14) == 0 &&
-                   strcasecmp(p, np->n_field ? np->n_field : "") == 0) {
+                   strcasecmp(p, FENDNULL(np->n_field)) == 0) {
                    content_type = strdup(np->n_name + 14);
                    break;
                }
@@ -87,7 +87,7 @@ mime_type(const char *file_name) {
            int binary = 0, c;
 
            if (!(fp = fopen(file_name, "r"))) {
-               advise (NULL, "unable to access file \"%s\"", file_name);
+               inform("unable to access file \"%s\"", file_name);
                return NULL;
            }
 
@@ -121,19 +121,18 @@ get_file_info(const char *proc, const char *file_name) {
     if ((cp = strchr(file_name, '\''))) {
         /* file_name contains a single quote. */
         if (strchr(file_name, '"')) {
-            advise(NULL, "filenames containing both single and double quotes "
+            inform("filenames containing both single and double quotes "
                    "are unsupported for attachment");
             return NULL;
-        } else {
-            quotec = "\"";
         }
+        quotec = "\"";
     }
 
     if ((cmd = concat(proc, " ", quotec, file_name, quotec, NULL))) {
         FILE *fp;
 
         if ((fp = popen(cmd, "r")) != NULL) {
-            char buf[BUFSIZ >= 2048  ?  BUFSIZ  : 2048];
+            char buf[max(BUFSIZ, 2048)];
 
             buf[0] = '\0';
             if (fgets(buf, sizeof buf, fp)) {
@@ -163,12 +162,12 @@ get_file_info(const char *proc, const char *file_name) {
 
             (void) pclose(fp);
         } else {
-            advise(NULL, "no output from %s", cmd);
+            inform("no output from %s", cmd);
         }
 
         free(cmd);
     } else {
-        advise(NULL, "concat with \"%s\" failed, out of memory?", proc);
+        inform("concat with \"%s\" failed, out of memory?", proc);
     }
 
     return cp  ?  strdup(cp)  :  NULL;