]> diplodocus.org Git - nmh/blobdiff - uip/burst.c
vector.c: Move interface to own file.
[nmh] / uip / burst.c
index 5375f8a17233775664b868c64060e9a6f7a5cac0..aab18141def0ad63b4ad250c4dd778a8ece9c3cd 100644 (file)
@@ -1,15 +1,21 @@
-
-/*
- * burst.c -- explode digests into individual messages
+/* burst.c -- explode digests into individual messages
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
  */
 
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/utils.h>
-#include <h/mhparse.h>
+#include "h/mh.h"
+#include "sbr/path.h"
+#include "sbr/print_version.h"
+#include "sbr/print_help.h"
+#include "sbr/error.h"
+#include "h/utils.h"
+#include "h/mhparse.h"
+#include "h/done.h"
+#include "sbr/m_maildir.h"
+#include "sbr/m_mktemp.h"
+#include "mhfree.h"
 
 #define BURST_SWITCHES \
     X("inplace", 0, INPLSW) \
 
 #define BURST_SWITCHES \
     X("inplace", 0, INPLSW) \
@@ -48,7 +54,7 @@ int debugsw = 0;
  */
 static int find_delim (int, struct smsg *, int *);
 static void find_mime_parts (CT, struct smsg *, int *);
  */
 static int find_delim (int, struct smsg *, int *);
 static void find_mime_parts (CT, struct smsg *, int *);
-static void burst (struct msgs **, int, struct smsg *, int, int, int,
+static void burst(struct msgs **, int, struct smsg *, int, bool, bool,
                   char *, int);
 static void cpybrst (FILE *, FILE *, char *, char *, int, int);
 
                   char *, int);
 static void cpybrst (FILE *, FILE *, char *, char *, int, int);
 
@@ -66,7 +72,10 @@ static void cpybrst (FILE *, FILE *, char *, char *, int, int);
 int
 main (int argc, char **argv)
 {
 int
 main (int argc, char **argv)
 {
-    int inplace = 0, quietsw = 0, verbosw = 0, mimesw = 1;
+    bool inplace = false;
+    bool quietsw = false;
+    bool verbosw = false;
+    int mimesw = 1;
     int hi, msgnum, numburst;
     char *cp, *maildir, *folder = NULL, buf[BUFSIZ];
     char **argp, **arguments;
     int hi, msgnum, numburst;
     char *cp, *maildir, *folder = NULL, buf[BUFSIZ];
     char **argp, **arguments;
@@ -74,7 +83,7 @@ main (int argc, char **argv)
     struct smsg *smsgs;
     struct msgs *mp;
 
     struct smsg *smsgs;
     struct msgs *mp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], true, true)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -86,7 +95,7 @@ main (int argc, char **argv)
                ambigsw (cp, switches);
                done (1);
            case UNKWNSW: 
                ambigsw (cp, switches);
                done (1);
            case UNKWNSW: 
-               adios (NULL, "-%s unknown\n", cp);
+               die("-%s unknown\n", cp);
 
            case HELPSW: 
                snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]",
 
            case HELPSW: 
                snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]",
@@ -98,10 +107,10 @@ main (int argc, char **argv)
                done (0);
 
            case INPLSW: 
                done (0);
 
            case INPLSW: 
-               inplace++;
+               inplace = true;
                continue;
            case NINPLSW: 
                continue;
            case NINPLSW: 
-               inplace = 0;
+               inplace = false;
                continue;
 
            case MIMESW:
                continue;
 
            case MIMESW:
@@ -115,25 +124,24 @@ main (int argc, char **argv)
                continue;
 
            case QIETSW: 
                continue;
 
            case QIETSW: 
-               quietsw++;
+               quietsw = true;
                continue;
            case NQIETSW: 
                continue;
            case NQIETSW: 
-               quietsw = 0;
+               quietsw = false;
                continue;
 
            case VERBSW: 
                continue;
 
            case VERBSW: 
-               verbosw++;
+               verbosw = true;
                continue;
            case NVERBSW: 
                continue;
            case NVERBSW: 
-               verbosw = 0;
+               verbosw = false;
                continue;
            }
        }
        if (*cp == '+' || *cp == '@') {
            if (folder)
                continue;
            }
        }
        if (*cp == '+' || *cp == '@') {
            if (folder)
-               adios (NULL, "only one folder at a time!");
-           else
-               folder = pluspath (cp);
+               die("only one folder at a time!");
+            folder = pluspath (cp);
        } else {
            app_msgarg(&msgs, cp);
        }
        } else {
            app_msgarg(&msgs, cp);
        }
@@ -152,11 +160,11 @@ main (int argc, char **argv)
 
     /* read folder and create message structure */
     if (!(mp = folder_read (folder, 1)))
 
     /* read folder and create message structure */
     if (!(mp = folder_read (folder, 1)))
-       adios (NULL, "unable to read folder %s", folder);
+       die("unable to read folder %s", folder);
 
     /* check for empty folder */
     if (mp->nummsg == 0)
 
     /* check for empty folder */
     if (mp->nummsg == 0)
-       adios (NULL, "no messages in %s", folder);
+       die("no messages in %s", folder);
 
     /* parse all the message ranges/sequences and set SELECTED */
     for (msgnum = 0; msgnum < msgs.size; msgnum++)
 
     /* parse all the message ranges/sequences and set SELECTED */
     for (msgnum = 0; msgnum < msgs.size; msgnum++)
@@ -164,10 +172,7 @@ main (int argc, char **argv)
            done (1);
     seq_setprev (mp);  /* set the previous-sequence */
 
            done (1);
     seq_setprev (mp);  /* set the previous-sequence */
 
-    smsgs = (struct smsg *)
-       mh_xcalloc ((size_t) (MAXFOLDER + 2), sizeof(*smsgs));
-    if (smsgs == NULL)
-       adios (NULL, "unable to allocate burst storage");
+    smsgs = mh_xcalloc(MAXFOLDER + 2, sizeof *smsgs);
 
     hi = mp->hghmsg + 1;
 
 
     hi = mp->hghmsg + 1;
 
@@ -177,22 +182,22 @@ main (int argc, char **argv)
            if ((numburst = find_delim (msgnum, smsgs, &mimesw)) >= 1) {
                if (verbosw)
                    printf ("%d message%s exploded from digest %d\n",
            if ((numburst = find_delim (msgnum, smsgs, &mimesw)) >= 1) {
                if (verbosw)
                    printf ("%d message%s exploded from digest %d\n",
-                           numburst, numburst > 1 ? "s" : "", msgnum);
+                           numburst, PLURALS(numburst), msgnum);
                burst (&mp, msgnum, smsgs, numburst, inplace, verbosw,
                       maildir, mimesw);
            } else {
                if (numburst == 0) {
                    if (!quietsw)
                burst (&mp, msgnum, smsgs, numburst, inplace, verbosw,
                       maildir, mimesw);
            } else {
                if (numburst == 0) {
                    if (!quietsw)
-                       admonish (NULL, "message %d not in digest format",
+                       inform("message %d not in digest format, continuing...",
                                  msgnum);
                }  /* this pair of braces was missing before 1999-07-15 */
                else
                                  msgnum);
                }  /* this pair of braces was missing before 1999-07-15 */
                else
-                   adios (NULL, "burst() botch -- you lose big");
+                   die("burst() botch -- you lose big");
            }
        }
     }
 
            }
        }
     }
 
-    free ((char *) smsgs);
+    free(smsgs);
     context_replace (pfolder, folder); /* update current folder */
 
     /*
     context_replace (pfolder, folder); /* update current folder */
 
     /*
@@ -245,17 +250,17 @@ find_delim (int msgnum, struct smsg *smsgs, int *mimesw)
        content = parse_mime(msgnam);
        if (! content && *mimesw == 2)
            return 0;
        content = parse_mime(msgnam);
        if (! content && *mimesw == 2)
            return 0;
-       else if (content) {
+       if (content) {
            smsgs[0].s_start = 0;
            smsgs[0].s_stop = content->c_begin - 1;
            msgp = 1;
            find_mime_parts(content, smsgs, &msgp);
            free_content(content);
            smsgs[0].s_start = 0;
            smsgs[0].s_stop = content->c_begin - 1;
            msgp = 1;
            find_mime_parts(content, smsgs, &msgp);
            free_content(content);
-           if (msgp == 1 && *mimesw == 2) {
+           if (msgp == 1 && *mimesw == 2)
                adios (msgnam, "does not have any message/rfc822 parts");
                adios (msgnam, "does not have any message/rfc822 parts");
-           } else if (msgp > 1) {
+           if (msgp > 1) {
                *mimesw = 1;
                *mimesw = 1;
-               return (msgp - 1);
+               return msgp - 1;
            }
        }
     }
            }
        }
     }
@@ -287,7 +292,7 @@ find_delim (int msgnum, struct smsg *smsgs, int *mimesw)
        /*
         * Read in lines until we get to a message delimiter.
         *
        /*
         * Read in lines until we get to a message delimiter.
         *
-        * Previously we checked to make sure the preceeding line and
+        * Previously we checked to make sure the preceding line and
         * next line was a newline.  That actually does not comply with
         * RFC 934, so make sure we break on a message delimiter even
         * if the previous character was NOT a newline.
         * next line was a newline.  That actually does not comply with
         * RFC 934, so make sure we break on a message delimiter even
         * if the previous character was NOT a newline.
@@ -295,8 +300,7 @@ find_delim (int msgnum, struct smsg *smsgs, int *mimesw)
        for (c = 0; fgets (buffer, sizeof(buffer), in); c = buffer[0]) {
            if ((wasdlm = CHECKDELIM(buffer)))
                break;
        for (c = 0; fgets (buffer, sizeof(buffer), in); c = buffer[0]) {
            if ((wasdlm = CHECKDELIM(buffer)))
                break;
-           else
-               pos += (long) strlen (buffer);
+            pos += (long) strlen (buffer);
        }
 
        /*
        }
 
        /*
@@ -319,7 +323,7 @@ find_delim (int msgnum, struct smsg *smsgs, int *mimesw)
     }
 
     fclose (in);
     }
 
     fclose (in);
-    return (msgp - 1);         /* return the number of messages burst */
+    return msgp - 1;           /* return the number of messages burst */
 }
 
 
 }
 
 
@@ -356,8 +360,6 @@ find_mime_parts (CT content, struct smsg *smsgs, int *msgp)
        for (part = m->mp_parts; part; part = part->mp_next)
            find_mime_parts(part->mp_part, smsgs, msgp);
     }
        for (part = m->mp_parts; part; part = part->mp_next)
            find_mime_parts(part->mp_part, smsgs, msgp);
     }
-
-    return;
 }
 
 
 }
 
 
@@ -367,7 +369,7 @@ find_mime_parts (CT content, struct smsg *smsgs, int *msgp)
 
 static void
 burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
 
 static void
 burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
-       int inplace, int verbosw, char *maildir, int mimesw)
+    bool inplace, bool verbosw, char *maildir, int mimesw)
 {
     int i, j, mode;
     char *msgnam;
 {
     int i, j, mode;
     char *msgnam;
@@ -389,7 +391,7 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
      */
     if ((mp->hghmsg + numburst > mp->hghoff) &&
        !(mp = folder_realloc (mp, mp->lowoff, mp->hghmsg + numburst)))
      */
     if ((mp->hghmsg + numburst > mp->hghoff) &&
        !(mp = folder_realloc (mp, mp->lowoff, mp->hghmsg + numburst)))
-       adios (NULL, "unable to allocate folder storage");
+       die("unable to allocate folder storage");
     *mpp = mp;
 
     j = mp->hghmsg;            /* old value */
     *mpp = mp;
 
     j = mp->hghmsg;            /* old value */
@@ -460,7 +462,7 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
         char *tempfile;
 
        if ((tempfile = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
         char *tempfile;
 
        if ((tempfile = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
+           die("unable to create temporary file in %s",
                  get_temp_dir());
        }
        strncpy (f2, tempfile, sizeof(f2));
                  get_temp_dir());
        }
        strncpy (f2, tempfile, sizeof(f2));
@@ -481,13 +483,13 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
                admonish (f3, "unable to rename %s to", f1);
 
            (void)snprintf(f3, sizeof (f3), "%s/%d", maildir, i);
                admonish (f3, "unable to rename %s to", f1);
 
            (void)snprintf(f3, sizeof (f3), "%s/%d", maildir, i);
-           ext_hook("del-hook", f3, (char *)0);
+           ext_hook("del-hook", f3, NULL);
        }
        if (rename (f2, f1) == NOTOK)
            admonish (f1, "unable to rename %s to", f2);
 
        (void)snprintf(f3, sizeof (f3), "%s/%d", maildir, i);
        }
        if (rename (f2, f1) == NOTOK)
            admonish (f1, "unable to rename %s to", f2);
 
        (void)snprintf(f3, sizeof (f3), "%s/%d", maildir, i);
-       ext_hook("add-hook", f3, (char *)0);
+       ext_hook("add-hook", f3, NULL);
 
        copy_msg_flags (mp, i, msgnum);
        mp->msgflags |= SEQMOD;
 
        copy_msg_flags (mp, i, msgnum);
        mp->msgflags |= SEQMOD;
@@ -503,14 +505,14 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
 #define S4  3
 
 /*
 #define S4  3
 
 /*
- * Copy a mesage which is being burst out of a digest.
+ * Copy a message which is being burst out of a digest.
  * It will remove any "dashstuffing" in the message.
  */
 
 static void
 cpybrst (FILE *in, FILE *out, char *ifile, char *ofile, int len, int mime)
 {
  * It will remove any "dashstuffing" in the message.
  */
 
 static void
 cpybrst (FILE *in, FILE *out, char *ifile, char *ofile, int len, int mime)
 {
-    register int c, state;
+    int c, state;
 
     for (state = mime ? S4 : S1; (c = fgetc (in)) != EOF && len > 0; len--) {
        if (c == 0)
 
     for (state = mime ? S4 : S1; (c = fgetc (in)) != EOF && len > 0; len--) {
        if (c == 0)
@@ -524,6 +526,7 @@ cpybrst (FILE *in, FILE *out, char *ifile, char *ofile, int len, int mime)
 
                    default: 
                        state = S2;
 
                    default: 
                        state = S2;
+                       /* FALLTHRU */
                    case '\n': 
                        fputc (c, out);
                        break;
                    case '\n': 
                        fputc (c, out);
                        break;
@@ -534,6 +537,7 @@ cpybrst (FILE *in, FILE *out, char *ifile, char *ofile, int len, int mime)
                switch (c) {
                    case '\n': 
                        state = S1;
                switch (c) {
                    case '\n': 
                        state = S1;
+                       /* FALLTHRU */
                    default: 
                        fputc (c, out);
                        break;
                    default: 
                        fputc (c, out);
                        break;