]> diplodocus.org Git - nmh/blobdiff - uip/whatnowsbr.c
Convert whatnow over to using the new Attach header.
[nmh] / uip / whatnowsbr.c
index 3010bff08d2ebc5bd5efc31ef4a4557c956341cd..e67ad53a97abe8fcfc91e1b5fd136a6d96b21be8 100644 (file)
@@ -53,8 +53,9 @@
     X("prompt string", 4, PRMPTSW) \
     X("version", 0, VERSIONSW) \
     X("help", 0, HELPSW) \
-    X("attach header-field-name", 0, ATTACHSW) \
-    X("noattach", 0, NOATTACHSW) \
+    X("attach header-field-name", -6, ATTACHSW) \
+    X("noattach", -8, NOATTACHSW) \
+
 
 #define X(sw, minchars, id) id,
 DEFINE_SWITCH_ENUM(WHATNOW);
@@ -122,7 +123,6 @@ WhatNow (int argc, char **argv)
     char buf[BUFSIZ], prompt[BUFSIZ];
     char **argp, **arguments;
     struct stat st;
-    char       *attach = NMH_ATTACH_HEADER;/* attachment header field name */
     char       cwd[PATH_MAX + 1];      /* current working directory */
     char       file[PATH_MAX + 1];     /* file name buffer */
     char       shell[PATH_MAX + 1];    /* shell response buffer */
@@ -197,12 +197,11 @@ WhatNow (int argc, char **argv)
                continue;
 
            case ATTACHSW:
-               if (!(attach = *argp++) || *attach == '-')
-                   adios (NULL, "missing argument to %s", argp[-2]);
+               advise(NULL, "The -attach switch is deprecated");
                continue;
 
            case NOATTACHSW:
-               attach = NULL;
+               advise(NULL, "The -noattach switch is deprecated");
                continue;
            }
        }
@@ -360,11 +359,6 @@ WhatNow (int argc, char **argv)
             *   -n     numbers listing
             */
 
-           if (attach == (char *)0) {
-               advise((char *)0, "can't list because no header field name was given.");
-               break;
-           }
-
            l = (char *)0;
            n = 0;
 
@@ -390,7 +384,7 @@ WhatNow (int argc, char **argv)
                advise((char *)0, "usage is alist [-ln].");
 
            else
-               annolist(drft, attach, l, n);
+               annolist(drft, ATTACH_FIELD, l, n);
 
            break;
 
@@ -402,11 +396,6 @@ WhatNow (int argc, char **argv)
             int verbose = 0;
             char **ap;
 
-           if (attach == (char *)0) {
-               advise((char *)0, "can't attach because no header field name was given.");
-               break;
-           }
-
            for (ap = argp+1; *ap; ++ap) {
                if (strcmp(*ap, "-v") == 0) {
                    ++argp;
@@ -437,28 +426,25 @@ WhatNow (int argc, char **argv)
 
            if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
                while (fgets(shell, sizeof (shell), f) != (char *)0) {
-                   char *build_directive;
+                   char *ctype;
 
                    *(strchr(shell, '\n')) = '\0';
 
                    if (*shell == '/') {
-                       (void)annotate(drft, attach, shell, 1, 0, -2, 1);
-                       if (verbose) {
-                           build_directive =
-                               construct_build_directive (shell, NULL, 1);
-                       }
+                       strncpy(file, shell, sizeof(file));
+                       file[sizeof(file) - 1] = '\0';
                    } else {
-                       (void)sprintf(file, "%s/%s", cwd, shell);
-                       (void)annotate(drft, attach, file, 1, 0, -2, 1);
-                       if (verbose) {
-                           build_directive =
-                               construct_build_directive (file, NULL, 1);
-                       }
+                       snprintf(file, sizeof(file), "%s/%s", cwd, shell);
+                   }
+
+                   annotate(drft, ATTACH_FIELD, file, 1, 0, -2, 1);
+                   if (verbose) {
+                       ctype = mime_type(file);
                    }
 
                    if (verbose) {
-                       printf ("%s", build_directive);
-                       free (build_directive);
+                       printf ("Attaching %s as a %s", file, ctype);
+                       free (ctype);
                    }
                }
 
@@ -475,11 +461,6 @@ WhatNow (int argc, char **argv)
             *  Detach files from current draft.
             */
 
-           if (attach == (char *)0) {
-               advise((char *)0, "can't detach because no header field name was given.");
-               break;
-           }
-
            /*
             *  Scan the arguments for a -n.  Mixed file names and numbers aren't allowed,
             *  so this catches a -n anywhere in the argument list.
@@ -506,7 +487,7 @@ WhatNow (int argc, char **argv)
 
                    if (**arguments != '\0') {
                        n = atoi(*arguments);
-                       (void)annotate(drft, attach, (char *)0, 1, 0, n, 1);
+                       annotate(drft, ATTACH_FIELD, (char *)0, 1, 0, n, 1);
 
                        for (argp = arguments + 1; *argp != (char *)0; argp++) {
                            if (atoi(*argp) > n) {
@@ -533,7 +514,7 @@ WhatNow (int argc, char **argv)
            if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
                while (fgets(shell, sizeof (shell), f) != (char *)0) {
                    *(strchr(shell, '\n')) = '\0';
-                   (void)annotate(drft, attach, shell, 1, 0, 0, 1);
+                   annotate(drft, ATTACH_FIELD, shell, 1, 0, 0, 1);
                }
                pclose(f);
            } else {