X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/0509728c8a506f287fa3483d8e8ffaf8fb66d41d..9291a5f82480f2458e04cb9ea7e6749bc952b308:/uip/new.c diff --git a/uip/new.c b/uip/new.c index 49aba332..f4e08e7f 100644 --- a/uip/new.c +++ b/uip/new.c @@ -11,11 +11,25 @@ #include -#include -#include -#include -#include "../sbr/lock_file.h" -#include "../sbr/m_maildir.h" +#include "h/mh.h" +#include "sbr/r1bindex.h" +#include "sbr/trimcpy.h" +#include "sbr/vfgets.h" +#include "sbr/getcpy.h" +#include "sbr/m_atoi.h" +#include "sbr/context_save.h" +#include "sbr/context_replace.h" +#include "sbr/context_find.h" +#include "sbr/brkstring.h" +#include "sbr/ambigsw.h" +#include "sbr/print_version.h" +#include "sbr/print_help.h" +#include "sbr/error.h" +#include "h/crawl_folders.h" +#include "h/done.h" +#include "h/utils.h" +#include "sbr/lock_file.h" +#include "sbr/m_maildir.h" #define NEW_SWITCHES \ X("mode", 1, MODESW) \ @@ -75,19 +89,19 @@ count_messages(char *field) return total; } -/* Return TRUE if the sequence 'name' is in 'sequences'. */ -static boolean +/* Return true if the sequence 'name' is in 'sequences'. */ +static bool seq_in_list(char *name, char *sequences[]) { int i; for (i = 0; sequences[i] != NULL; i++) { if (strcmp(name, sequences[i]) == 0) { - return TRUE; + return true; } } - return FALSE; + return false; } /* Return the string list of message numbers from the sequences file, or NULL @@ -102,7 +116,7 @@ get_msgnums(char *folder, char *sequences[]) char *cp; char *msgnums = NULL, *this_msgnums, *old_msgnums; int failed_to_lock = 0; - m_getfld_state_t gstate = 0; + m_getfld_state_t gstate; /* copied from seq_read.c:seq_public */ /* @@ -114,32 +128,30 @@ get_msgnums(char *folder, char *sequences[]) return NULL; /* get filename of sequence file */ - seqfile = concat(m_maildir(folder), "/", mh_seq, (void *)NULL); + seqfile = concat(m_maildir(folder), "/", mh_seq, NULL); if (seqfile == NULL) return NULL; if ((fp = lkfopendata (seqfile, "r", & failed_to_lock)) == NULL) { - - if (failed_to_lock) { + if (failed_to_lock) adios (seqfile, "failed to lock"); - } else { - free(seqfile); - return NULL; - } + free(seqfile); + return NULL; } - /* Use m_getfld to scan sequence file */ + /* Use m_getfld2 to scan sequence file */ + gstate = m_getfld_state_init(fp); for (;;) { int fieldsz = sizeof field; - switch (state = m_getfld (&gstate, name, field, &fieldsz, fp)) { + switch (state = m_getfld2(&gstate, name, field, &fieldsz)) { case FLD: case FLDPLUS: if (state == FLDPLUS) { cp = getcpy (field); while (state == FLDPLUS) { fieldsz = sizeof field; - state = m_getfld (&gstate, name, field, &fieldsz, fp); + state = m_getfld2(&gstate, name, field, &fieldsz); cp = add (field, cp); } @@ -152,7 +164,7 @@ get_msgnums(char *folder, char *sequences[]) } else { old_msgnums = msgnums; msgnums = concat(old_msgnums, " ", - this_msgnums, (void *)NULL); + this_msgnums, NULL); free(old_msgnums); free(this_msgnums); } @@ -167,7 +179,7 @@ get_msgnums(char *folder, char *sequences[]) } else { old_msgnums = msgnums; msgnums = concat(old_msgnums, " ", - this_msgnums, (void *)NULL); + this_msgnums, NULL); free(old_msgnums); free(this_msgnums); } @@ -177,14 +189,14 @@ get_msgnums(char *folder, char *sequences[]) continue; case BODY: - adios (NULL, "no blank lines are permitted in %s", seqfile); - /* FALLTHRU */ + die("no blank lines are permitted in %s", seqfile); + break; case FILEEOF: break; default: - adios (NULL, "%s is poorly formatted", seqfile); + die("%s is poorly formatted", seqfile); } break; /* break from for loop */ } @@ -227,11 +239,11 @@ check_folder(char *folder, size_t len, struct list_state *b) } } -static boolean +static bool crawl_callback(char *folder, void *baton) { check_folder(folder, strlen(folder), baton); - return TRUE; + return true; } /* Scan folders, returning: @@ -275,7 +287,7 @@ check_folders(struct node **first, struct node **last, } else { fp = fopen(folders, "r"); if (fp == NULL) { - adios(NULL, "failed to read %s", folders); + die("failed to read %s", folders); } while (vfgets(fp, &line) == OK) { len = strlen(line) - 1; @@ -372,10 +384,9 @@ doit(char *cur, char *folders, char *sequences[]) /* Found current folder in fprev mode; if we have a * previous node in the list, return it; else return * the last node. */ - if (prev == NULL) { - return last; - } - return prev; + if (prev) + return prev; + return last; } } else if (run_mode == RM_UNSEEN) { int status; @@ -397,7 +408,7 @@ doit(char *cur, char *folders, char *sequences[]) /* TODO: Split enough of scan.c out so that we can call it here. */ command = concat("scan +", node->n_name, " ", sequences_s, - (void *)NULL); + NULL); status = system(command); if (! WIFEXITED (status)) { adios (command, "system"); @@ -446,7 +457,7 @@ main(int argc, char **argv) char *unseen; struct node *folder; - 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; @@ -461,7 +472,7 @@ main(int argc, char **argv) ambigsw (cp, switches); done (1); case UNKWNSW: - adios (NULL, "-%s unknown", cp); + die("-%s unknown", cp); case HELPSW: snprintf (help, sizeof(help), "%s [switches] [sequences]", @@ -474,11 +485,11 @@ main(int argc, char **argv) case FOLDERSSW: if (!(folders = *argp++) || *folders == '-') - adios(NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); continue; case MODESW: if (!(invo_name = *argp++) || *invo_name == '-') - adios(NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); invo_name = r1bindex(invo_name, '/'); continue; } @@ -510,7 +521,7 @@ main(int argc, char **argv) /* no sequence arguments; use unseen */ unseen = context_find(usequence); if (unseen == NULL || unseen[0] == '\0') { - adios(NULL, "must specify sequences or set %s", usequence); + die("must specify sequences or set %s", usequence); } for (ap = brkstring(unseen, " ", "\n"); *ap; ap++) { svector_push_back (sequences, *ap);