X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/e491542da563673b49c6f6df9948ffaffbeed4fb..0b7286788a95dd854d1826b8493eda431d8e8aac:/uip/mark.c diff --git a/uip/mark.c b/uip/mark.c index f0f3d7a6..7ca41aae 100644 --- a/uip/mark.c +++ b/uip/mark.c @@ -1,6 +1,4 @@ - -/* - * mark.c -- add message(s) to sequences in given folder +/* mark.c -- add message(s) to sequences in given folder * -- delete messages (s) from sequences in given folder * -- list sequences in given folder * @@ -9,8 +7,24 @@ * complete copyright information. */ -#include -#include +#include "h/mh.h" +#include "sbr/folder_read.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/seq_bits.h" +#include "sbr/seq_del.h" +#include "sbr/seq_print.h" +#include "sbr/seq_add.h" +#include "sbr/error.h" +#include "h/done.h" +#include "h/utils.h" +#include "sbr/m_maildir.h" #define MARK_SWITCHES \ X("add", 0, ADDSW) \ @@ -43,8 +57,13 @@ static void seq_printdebug (struct msgs *); int main (int argc, char **argv) { - int addsw = 0, deletesw = 0, debugsw = 0; - int listsw = 0, publicsw = -1, zerosw = 0, msgnum; + bool addsw = false; + bool deletesw = false; + bool debugsw = false; + bool listsw = false; + int publicsw = -1; + bool zerosw = false; + int msgnum; unsigned int seqp = 0; char *cp, *maildir, *folder = NULL, buf[BUFSIZ]; char **argp, **arguments; @@ -52,13 +71,7 @@ main (int argc, char **argv) struct msgs_array msgs = { 0, 0, NULL }; struct msgs *mp; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], true, true)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; @@ -73,7 +86,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]", @@ -85,21 +98,24 @@ main (int argc, char **argv) done (0); case ADDSW: - addsw++; - deletesw = listsw = 0; + addsw = true; + deletesw = false; + listsw = false; continue; case DELSW: - deletesw++; - addsw = listsw = 0; + deletesw = true; + addsw = false; + listsw = false; continue; case LSTSW: - listsw++; - addsw = deletesw = 0; + listsw = true; + addsw = false; + deletesw = false; continue; case SEQSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); svector_push_back (seqs, cp); seqp++; @@ -113,24 +129,23 @@ main (int argc, char **argv) continue; case DEBUGSW: - debugsw++; + debugsw = true; continue; case ZEROSW: - zerosw++; + zerosw = true; continue; case NZEROSW: - zerosw = 0; + zerosw = 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); + app_msgarg(&msgs, cp); } /* @@ -140,9 +155,9 @@ main (int argc, char **argv) */ if (!addsw && !deletesw && !listsw) { if (seqp) - addsw++; + addsw = true; else - listsw++; + listsw = true; } if (!context_find ("path")) @@ -158,7 +173,7 @@ 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); /* print some general debugging info */ if (debugsw) @@ -166,7 +181,7 @@ main (int argc, char **argv) /* 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++) @@ -174,14 +189,14 @@ main (int argc, char **argv) done (1); if (publicsw == 1 && is_readonly(mp)) - adios (NULL, "folder %s is read-only, so -public not allowed", folder); + die("folder %s is read-only, so -public not allowed", folder); /* * Make sure at least one sequence has been * specified if we are adding or deleting. */ if (seqp == 0 && (addsw || deletesw)) - adios (NULL, "-%s requires at least one -sequence argument", + die("-%s requires at least one -sequence argument", addsw ? "add" : "delete"); /* Adding messages to sequences */ @@ -252,7 +267,7 @@ print_debug (struct msgs *mp) /* * Print debugging info about all the SELECTED * messages and the sequences they are in. - * Due limitattions of snprintb(), only a limited + * Due to limitations of snprintb(), only a limited * number of sequences will be printed. See the * comments in sbr/seq_bits.c. */ @@ -262,12 +277,12 @@ seq_printdebug (struct msgs *mp) int msgnum; char buf[BUFSIZ]; - printf ("\n"); + putchar('\n'); for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { if (is_selected (mp, msgnum)) printf ("%*d: %s\n", DMAXFOLDER, msgnum, snprintb (buf, sizeof buf, - (unsigned) *bvector_bits (msgstat (mp, msgnum)), + (unsigned) bvector_first_bits (msgstat (mp, msgnum)), seq_bits (mp))); } }