X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/0509728c8a506f287fa3483d8e8ffaf8fb66d41d..4829d096feb337a55e2b866adb19acab9617b071:/uip/burst.c diff --git a/uip/burst.c b/uip/burst.c index de762e99..b80d9ce9 100644 --- a/uip/burst.c +++ b/uip/burst.c @@ -5,11 +5,34 @@ * complete copyright information. */ -#include -#include -#include -#include "../sbr/m_maildir.h" -#include "../sbr/m_mktemp.h" +#include "h/mh.h" +#include "sbr/m_name.h" +#include "sbr/m_gmprot.h" +#include "sbr/getarguments.h" +#include "sbr/seq_setprev.h" +#include "sbr/seq_setcur.h" +#include "sbr/seq_save.h" +#include "sbr/smatch.h" +#include "sbr/m_convert.h" +#include "sbr/m_backup.h" +#include "sbr/getfolder.h" +#include "sbr/ext_hook.h" +#include "sbr/folder_read.h" +#include "sbr/folder_realloc.h" +#include "sbr/folder_free.h" +#include "sbr/context_save.h" +#include "sbr/context_replace.h" +#include "sbr/context_find.h" +#include "sbr/ambigsw.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 \ @@ -49,7 +72,7 @@ int debugsw = 0; */ 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); @@ -67,7 +90,10 @@ static void cpybrst (FILE *, FILE *, char *, char *, int, int); 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; @@ -75,7 +101,7 @@ main (int argc, char **argv) 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; @@ -87,7 +113,7 @@ main (int argc, char **argv) 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]", @@ -99,42 +125,41 @@ main (int argc, char **argv) done (0); case INPLSW: - inplace++; + inplace = true; continue; case NINPLSW: - inplace = 0; + inplace = false; continue; case MIMESW: - mimesw = 2; + mimesw = 2; continue; case NMIMESW: - mimesw = 0; + mimesw = 0; continue; case AUTOMIMESW: - mimesw = 1; + mimesw = 1; continue; case QIETSW: - quietsw++; + quietsw = true; continue; case NQIETSW: - quietsw = 0; + quietsw = false; continue; case VERBSW: - verbosw++; + verbosw = true; continue; case NVERBSW: - verbosw = 0; + verbosw = false; 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); } @@ -153,11 +178,11 @@ main (int argc, char **argv) /* 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) - 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++) @@ -185,7 +210,7 @@ main (int argc, char **argv) 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"); } } } @@ -240,7 +265,7 @@ find_delim (int msgnum, struct smsg *smsgs, int *mimesw) */ if (*mimesw > 0) { - content = parse_mime(msgnam); + content = parse_mime(msgnam); if (! content && *mimesw == 2) return 0; if (content) { @@ -249,11 +274,11 @@ find_delim (int msgnum, struct smsg *smsgs, int *mimesw) msgp = 1; find_mime_parts(content, smsgs, &msgp); free_content(content); - if (msgp == 1 && *mimesw == 2) { - adios (msgnam, "does not have any message/rfc822 parts"); - } else if (msgp > 1) { - *mimesw = 1; - return (msgp - 1); + if (msgp == 1 && *mimesw == 2) + adios (msgnam, "does not have any message/rfc822 parts"); + if (msgp > 1) { + *mimesw = 1; + return msgp - 1; } } } @@ -264,7 +289,7 @@ find_delim (int msgnum, struct smsg *smsgs, int *mimesw) adios (msgnam, "unable to read message"); for (msgp = 0, pos = 0L; msgp <= MAXFOLDER;) { - /* + /* * We're either at the beginning of the whole message, or * we're just past the delimiter of the last message. * Swallow lines until we get to something that's not a newline @@ -293,8 +318,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; - else - pos += (long) strlen (buffer); + pos += (long) strlen (buffer); } /* @@ -317,7 +341,7 @@ find_delim (int msgnum, struct smsg *smsgs, int *mimesw) } fclose (in); - return (msgp - 1); /* return the number of messages burst */ + return msgp - 1; /* return the number of messages burst */ } @@ -337,7 +361,7 @@ find_mime_parts (CT content, struct smsg *smsgs, int *msgp) */ if (content->c_type == CT_MESSAGE && - content->c_subtype == MESSAGE_RFC822) { + content->c_subtype == MESSAGE_RFC822) { smsgs[*msgp].s_start = content->c_begin; smsgs[*msgp].s_stop = content->c_end; (*msgp)++; @@ -349,7 +373,7 @@ find_mime_parts (CT content, struct smsg *smsgs, int *msgp) */ if (content->c_type == CT_MULTIPART) { - m = (struct multipart *) content->c_ctparams; + m = (struct multipart *) content->c_ctparams; for (part = m->mp_parts; part; part = part->mp_next) find_mime_parts(part->mp_part, smsgs, msgp); @@ -363,7 +387,7 @@ find_mime_parts (CT content, struct smsg *smsgs, int *msgp) 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; @@ -385,7 +409,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))) - adios (NULL, "unable to allocate folder storage"); + die("unable to allocate folder storage"); *mpp = mp; j = mp->hghmsg; /* old value */ @@ -410,8 +434,8 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst, */ if (inplace) { for (i = mp->hghmsg; j > msgnum; i--, j--) { - strncpy (f1, m_name (i), sizeof(f1)); - strncpy (f2, m_name (j), sizeof(f2)); + strncpy (f1, m_name (i), sizeof(f1) - 1); + strncpy (f2, m_name (j), sizeof(f2) - 1); if (does_exist (mp, j)) { if (verbosw) printf ("message %d becomes message %d\n", j, i); @@ -456,11 +480,11 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst, 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)); - strncpy (f1, m_name (i), sizeof(f1)); + strncpy (f2, tempfile, sizeof(f2) - 1); + strncpy (f1, m_name (i), sizeof(f1) - 1); if (verbosw && i != msgnum) printf ("message %d of digest %d becomes message %d\n", j, msgnum, i); @@ -472,7 +496,7 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst, fclose (out); if (i == msgnum) { - strncpy (f3, m_backup (f1), sizeof(f3)); + strncpy (f3, m_backup (f1), sizeof(f3) - 1); if (rename (f1, f3) == NOTOK) admonish (f3, "unable to rename %s to", f1); @@ -553,7 +577,7 @@ cpybrst (FILE *in, FILE *out, char *ifile, char *ofile, int len, int mime) break; case S4: - fputc (c, out); + fputc (c, out); break; } }