]> diplodocus.org Git - nmh/blobdiff - uip/new.c
m_getfld() now supports interleaving calls with
[nmh] / uip / new.c
index 4ff8c0496915af66a903418e614a1e6cb063c853..198207a86aef01bc467dbd328c2d12049a5a8a9d 100644 (file)
--- a/uip/new.c
+++ b/uip/new.c
@@ -4,8 +4,6 @@
  *       -- as fnext,  move to next folder with unseen messages
  *       -- as fprev,  move to previous folder with unseen messages
  *       -- as unseen, scan all unseen messages
  *       -- as fnext,  move to next folder with unseen messages
  *       -- as fprev,  move to previous folder with unseen messages
  *       -- as unseen, scan all unseen messages
- * $Id$
- *
  * This code is Copyright (c) 2008, 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) 2008, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
@@ -107,15 +105,16 @@ get_msgnums(char *folder, char *sequences[])
 
     /* copied from seq_read.c:seq_public */
     for (state = FLD;;) {
 
     /* copied from seq_read.c:seq_public */
     for (state = FLD;;) {
-        switch (state = m_getfld (state, name, field, sizeof(field), fp)) {
+       int fieldsz = sizeof field;
+       switch (state = m_getfld (state, name, field, &fieldsz, fp)) {
             case FLD:
             case FLDPLUS:
             case FLDEOF:
                 if (state == FLDPLUS) {
                     cp = getcpy (field);
                     while (state == FLDPLUS) {
             case FLD:
             case FLDPLUS:
             case FLDEOF:
                 if (state == FLDPLUS) {
                     cp = getcpy (field);
                     while (state == FLDPLUS) {
-                        state = m_getfld (state, name, field,
-                                          sizeof(field), fp);
+                       fieldsz = sizeof field;
+                       state = m_getfld (state, name, field, &fieldsz, fp);
                         cp = add (field, cp);
                     }
 
                         cp = add (field, cp);
                     }
 
@@ -220,6 +219,8 @@ crawl_callback(char *folder, void *baton)
  * `cur' points to the name of the current folder, `folders' points to the
  * name of a .folder (if NULL, crawl all folders), and `sequences' points to
  * the array of sequences for which to look.
  * `cur' points to the name of the current folder, `folders' points to the
  * name of a .folder (if NULL, crawl all folders), and `sequences' points to
  * the array of sequences for which to look.
+ *
+ * An empty list is returned as first=last=NULL.
  */
 static void
 check_folders(struct node **first, struct node **last,
  */
 static void
 check_folders(struct node **first, struct node **last,
@@ -231,7 +232,7 @@ check_folders(struct node **first, struct node **last,
     char *line;
     size_t len;
 
     char *line;
     size_t len;
 
-    *first = *cur_node = NULL;
+    *first = *last = *cur_node = NULL;
     *maxlen = 0;
 
     b.first = first;
     *maxlen = 0;
 
     b.first = first;
@@ -300,7 +301,7 @@ doit(char *cur, char *folders, char *sequences[])
     struct node *first, *cur_node, *node, *last, *prev;
     size_t folder_len;
     int count, total = 0;
     struct node *first, *cur_node, *node, *last, *prev;
     size_t folder_len;
     int count, total = 0;
-    char *command, *sequences_s;
+    char *command = NULL, *sequences_s = NULL;
 
     if (cur == NULL || cur[0] == '\0') {
         cur = "inbox";
 
     if (cur == NULL || cur[0] == '\0') {
         cur = "inbox";
@@ -310,7 +311,10 @@ doit(char *cur, char *folders, char *sequences[])
                  folders, sequences);
 
     if (run_mode == FNEXT || run_mode == FPREV) {
                  folders, sequences);
 
     if (run_mode == FNEXT || run_mode == FPREV) {
-       if (first->n_next == NULL) {
+       if (first == NULL) {
+           /* No folders at all... */
+           return NULL;
+       } else if (first->n_next == NULL) {
            /* We have only one node; any desired messages in it? */
            if (first->n_field == NULL) {
                return NULL;
            /* We have only one node; any desired messages in it? */
            if (first->n_field == NULL) {
                return NULL;
@@ -374,7 +378,7 @@ doit(char *cur, char *folders, char *sequences[])
             total += count;
 
             printf("%-*s %6d.%c %s\n",
             total += count;
 
             printf("%-*s %6d.%c %s\n",
-                   folder_len, node->n_name,
+                   (int) folder_len, node->n_name,
                    count,
                    (strcmp(node->n_name, cur) == 0 ? '*' : ' '),
                    node->n_field);
                    count,
                    (strcmp(node->n_name, cur) == 0 ? '*' : ' '),
                    node->n_field);
@@ -388,7 +392,7 @@ doit(char *cur, char *folders, char *sequences[])
     }
 
     if (run_mode == NEW) {
     }
 
     if (run_mode == NEW) {
-        printf("%-*s %6d.\n", folder_len, " total", total);
+        printf("%-*s %6d.\n", (int) folder_len, " total", total);
     }
 
     return cur_node;
     }
 
     return cur_node;
@@ -405,6 +409,9 @@ main(int argc, char **argv)
     char *unseen;
     struct node *folder;
 
     char *unseen;
     struct node *folder;
 
+    sequences[0] = NULL;
+    sequences[1] = NULL;
+
 #ifdef LOCALE
     setlocale(LC_ALL, "");
 #endif
 #ifdef LOCALE
     setlocale(LC_ALL, "");
 #endif
@@ -432,10 +439,10 @@ main(int argc, char **argv)
                snprintf (help, sizeof(help), "%s [switches] [sequences]",
                          invo_name);
                print_help (help, switches, 1);
                snprintf (help, sizeof(help), "%s [switches] [sequences]",
                          invo_name);
                print_help (help, switches, 1);
-               done (1);
+               done (0);
            case VERSIONSW:
                print_version(invo_name);
            case VERSIONSW:
                print_version(invo_name);
-               done (1);
+               done (0);
 
            case FOLDERSSW:
                if (!(folders = *argp++) || *folders == '-')
 
            case FOLDERSSW:
                if (!(folders = *argp++) || *folders == '-')
@@ -451,6 +458,7 @@ main(int argc, char **argv)
        /* have a sequence argument */
        if (!seq_in_list(cp, sequences)) {
            sequences[i++] = cp;
        /* have a sequence argument */
        if (!seq_in_list(cp, sequences)) {
            sequences[i++] = cp;
+           sequences[i] = NULL;
        }
     }
 
        }
     }