]> diplodocus.org Git - nmh/blobdiff - sbr/seq_read.c
Added const qualifier to arguments of concat() and copy().
[nmh] / sbr / seq_read.c
index 649a360e41f8500da03777cadccf1969c903f84e..a807ef7d6169b0b000c57535c163590f8e190fd5 100644 (file)
@@ -3,10 +3,13 @@
  * seq_read.c -- read the .mh_sequence file and
  *            -- initialize sequence information
  *
  * seq_read.c -- read the .mh_sequence file and
  *            -- initialize sequence information
  *
- * $Id$
+ * 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/mh.h>
+#include <h/utils.h>
 
 /*
  * static prototypes
 
 /*
  * static prototypes
@@ -18,17 +21,13 @@ static void seq_private (struct msgs *);
 
 /*
  * Get the sequence information for this folder from
 
 /*
  * Get the sequence information for this folder from
- * .mh_sequence (or equivalent specified in .mh_profile)
+ * .mh_sequences (or equivalent specified in .mh_profile)
  * or context file (for private sequences).
  */
 
 void
 seq_read (struct msgs *mp)
 {
  * or context file (for private sequences).
  */
 
 void
 seq_read (struct msgs *mp)
 {
-    /* sanity check - check that context has been read */
-    if (defpath == NULL)
-       adios (NULL, "oops, context hasn't been read yet");
-
     /*
      * Initialize the list of sequence names.  Go ahead and
      * add the "cur" sequence to the list of sequences.
     /*
      * Initialize the list of sequence names.  Go ahead and
      * add the "cur" sequence to the list of sequences.
@@ -60,6 +59,7 @@ seq_public (struct msgs *mp)
     char *cp, seqfile[PATH_MAX];
     char name[NAMESZ], field[BUFSIZ];
     FILE *fp;
     char *cp, seqfile[PATH_MAX];
     char name[NAMESZ], field[BUFSIZ];
     FILE *fp;
+    m_getfld_state_t gstate = 0;
 
     /*
      * If mh_seq == NULL (such as if nmh been compiled with
 
     /*
      * If mh_seq == NULL (such as if nmh been compiled with
@@ -73,19 +73,20 @@ seq_public (struct msgs *mp)
     /* get filename of sequence file */
     snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq);
 
     /* get filename of sequence file */
     snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq);
 
-    if ((fp = fopen (seqfile, "r")) == NULL)
+    if ((fp = lkfopen (seqfile, "r")) == NULL)
        return;
 
     /* Use m_getfld to scan sequence file */
        return;
 
     /* Use m_getfld to scan sequence file */
-    for (state = FLD;;) {
-       switch (state = m_getfld (state, name, field, sizeof(field), fp)) {
+    for (;;) {
+       int fieldsz = sizeof field;
+       switch (state = m_getfld (&gstate, name, field, &fieldsz, fp)) {
            case FLD: 
            case FLDPLUS:
            case FLD: 
            case FLDPLUS:
-           case FLDEOF: 
                if (state == FLDPLUS) {
                    cp = getcpy (field);
                    while (state == FLDPLUS) {
                if (state == FLDPLUS) {
                    cp = getcpy (field);
                    while (state == FLDPLUS) {
-                       state = m_getfld (state, name, field, sizeof(field), fp);
+                       fieldsz = sizeof field;
+                       state = m_getfld (&gstate, name, field, &fieldsz, fp);
                        cp = add (field, cp);
                    }
                    seq_init (mp, getcpy (name), trimcpy (cp));
                        cp = add (field, cp);
                    }
                    seq_init (mp, getcpy (name), trimcpy (cp));
@@ -93,12 +94,9 @@ seq_public (struct msgs *mp)
                } else {
                    seq_init (mp, getcpy (name), trimcpy (field));
                }
                } else {
                    seq_init (mp, getcpy (name), trimcpy (field));
                }
-               if (state == FLDEOF)
-                   break;
                continue;
 
            case BODY: 
                continue;
 
            case BODY: 
-           case BODYEOF: 
                adios (NULL, "no blank lines are permitted in %s", seqfile);
                /* fall */
 
                adios (NULL, "no blank lines are permitted in %s", seqfile);
                /* fall */
 
@@ -110,8 +108,9 @@ seq_public (struct msgs *mp)
        }
        break;  /* break from for loop */
     }
        }
        break;  /* break from for loop */
     }
+    m_getfld_state_destroy (&gstate);
 
 
-    fclose (fp);
+    lkfclose (fp, seqfile);
 }
 
 
 }
 
 
@@ -159,7 +158,8 @@ seq_private (struct msgs *mp)
 static int
 seq_init (struct msgs *mp, char *name, char *field)
 {
 static int
 seq_init (struct msgs *mp, char *name, char *field)
 {
-    int i, j, k, is_current;
+    unsigned int i;
+    int j, k, is_current;
     char *cp, **ap;
 
     /*
     char *cp, **ap;
 
     /*