]> diplodocus.org Git - nmh/blobdiff - uip/dist.c
Alter HasSuffixC()'s char * to be const.
[nmh] / uip / dist.c
index 40732dceb0beac9cecd0680c3d6e10630e6fd5bc..f846b74da7f1b11c67f156b403c8f768de883481 100644 (file)
 #include <h/utils.h>
 #include <fcntl.h>
 
-static struct swit switches[] = {
-#define        ANNOSW  0
-    { "annotate", 0 },
-#define        NANNOSW 1
-    { "noannotate", 0 },
-#define        DFOLDSW 2
-    { "draftfolder +folder", 0 },
-#define        DMSGSW  3
-    { "draftmessage msg", 0 },
-#define        NDFLDSW 4
-    { "nodraftfolder", 0 },
-#define        EDITRSW 5
-    { "editor editor", 0 },
-#define        NEDITSW 6
-    { "noedit", 0 },
-#define        FORMSW  7
-    { "form formfile", 0 },
-#define        INPLSW  8
-    { "inplace", 0 },
-#define        NINPLSW 9
-    { "noinplace", 0 },
-#define        WHATSW  10
-    { "whatnowproc program", 0 },
-#define        NWHATSW 11
-    { "nowhatnowproc", 0 },
-#define VERSIONSW 12
-    { "version", 0 },
-#define        HELPSW  13
-    { "help", 0 },
-#define        FILESW  14
-    { "file file", -4 },       /* interface from msh */
-#define FROMSW  15
-    { "from address", 0 },
-#define TOSW    16
-    { "to address", 0 },
-#define CCSW    17
-    { "cc address", 0 },
-#define FCCSW   18
-    { "fcc mailbox", 0 },
-#define WIDTHSW 19
-    { "width columns", 0 },
-#define ATFILESW 20
-    { "atfile", 0 },
-#define NOATFILESW 21
-    { "noatfile", 0 },
-    { NULL, 0 }
-};
-
-static struct swit aqrnl[] = {
-#define        NOSW    0
-    { "quit", 0 },
-#define        YESW    1
-    { "replace", 0 },
-#define        LISTDSW 2
-    { "list", 0 },
-#define        REFILSW 3
-    { "refile +folder", 0 },
-#define NEWSW  4
-    { "new", 0 },
-    { NULL, 0 }
-};
+#define DIST_SWITCHES \
+    X("annotate", 0, ANNOSW) \
+    X("noannotate", 0, NANNOSW) \
+    X("draftfolder +folder", 0, DFOLDSW) \
+    X("draftmessage msg", 0, DMSGSW) \
+    X("nodraftfolder", 0, NDFLDSW) \
+    X("editor editor", 0, EDITRSW) \
+    X("noedit", 0, NEDITSW) \
+    X("form formfile", 0, FORMSW) \
+    X("inplace", 0, INPLSW) \
+    X("noinplace", 0, NINPLSW) \
+    X("whatnowproc program", 0, WHATSW) \
+    X("nowhatnowproc", 0, NWHATSW) \
+    X("version", 0, VERSIONSW) \
+    X("help", 0, HELPSW) \
+    X("file file", -4, FILESW) \
+    X("from address", 0, FROMSW) \
+    X("to address", 0, TOSW) \
+    X("cc address", 0, CCSW) \
+    X("fcc mailbox", 0, FCCSW) \
+    X("width columns", 0, WIDTHSW) \
+    X("atfile", 0, ATFILESW) \
+    X("noatfile", 0, NOATFILESW) \
+
+#define X(sw, minchars, id) id,
+DEFINE_SWITCH_ENUM(DIST);
+#undef X
+
+#define X(sw, minchars, id) { sw, minchars, id },
+DEFINE_SWITCH_ARRAY(DIST, switches);
+#undef X
+
+#define DISPO_SWITCHES \
+    X("quit", 0, NOSW) \
+    X("replace", 0, YESW) \
+    X("list", 0, LISTDSW) \
+    X("refile +folder", 0, REFILSW) \
+    X("new", 0, NEWSW) \
+
+#define X(sw, minchars, id) id,
+DEFINE_SWITCH_ENUM(DISPO);
+#undef X
+
+#define X(sw, minchars, id) { sw, minchars, id },
+DEFINE_SWITCH_ARRAY(DISPO, aqrnl);
+#undef X
 
 
 static struct swit aqrl[] = {
-    { "quit", 0 },
-    { "replace", 0 },
-    { "list", 0 },
-    { "refile +folder", 0 },
-    { NULL, 0 }
+    { "quit", 0, NOSW },
+    { "replace", 0, YESW },
+    { "list", 0, LISTDSW },
+    { "refile +folder", 0, REFILSW },
+    { NULL, 0, 0 }
 };
 
 
@@ -89,7 +74,7 @@ main (int argc, char **argv)
     int anot = 0, inplace = 1, nedit = 0;
     int nwhat = 0, i, in, isdf = 0, out;
     int outputlinelen = OUTPUTLINELEN;
-    int dat[5], atfile = 1;
+    int dat[5], atfile = 0;
     char *cp, *cwd, *maildir, *msgnam, *dfolder = NULL;
     char *dmsg = NULL, *ed = NULL, *file = NULL, *folder = NULL;
     char *form = NULL, *msg = NULL, buf[BUFSIZ], drft[BUFSIZ];
@@ -98,13 +83,7 @@ main (int argc, char **argv)
     struct msgs *mp = NULL;
     struct stat st;
 
-#ifdef LOCALE
-    setlocale(LC_ALL, "");
-#endif
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -239,7 +218,7 @@ main (int argc, char **argv)
        }
     }
 
-    cwd = getcpy (pwd ());
+    cwd = mh_xstrdup(pwd ());
 
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
@@ -253,7 +232,8 @@ try_it_again:
     if (stat (drft, &st) != NOTOK) {
        printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size);
        for (i = LISTDSW; i != YESW;) {
-           if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl)))
+           if (!(argp = read_switch_multiword ("\nDisposition? ",
+                                               isdf ? aqrnl : aqrl)))
                done (1);
            switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) {
                case NOSW: 
@@ -296,7 +276,7 @@ try_it_again:
            adios (maildir, "unable to change directory to");
 
        /* read folder and create message structure */
-       if (!(mp = folder_read (folder)))
+       if (!(mp = folder_read (folder, 1)))
            adios (NULL, "unable to read folder %s", folder);
 
        /* check for empty folder */
@@ -312,7 +292,7 @@ try_it_again:
            adios (NULL, "only one message at a time!");
     }
 
-    msgnam = file ? file : getcpy (m_name (mp->lowsel));
+    msgnam = file ? file : mh_xstrdup(m_name (mp->lowsel));
 
     dat[0] = mp ? mp->lowsel : 0;
     dat[1] = 0;