]> diplodocus.org Git - nmh/blobdiff - sbr/seq_save.c
Reworded description of "mark -seq foo delete all" example
[nmh] / sbr / seq_save.c
index 6366e5ebb849892aed909f3492eb54052fe67f91..a431804e65374a6af0206a5b7bc4662b72680c2d 100644 (file)
@@ -3,8 +3,6 @@
  * seq_save.c -- 1) synchronize sequences
  *            -- 2) save public sequences
  *
  * seq_save.c -- 1) synchronize sequences
  *            -- 2) save public sequences
  *
- * $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.
  * 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.
@@ -31,13 +29,16 @@ seq_save (struct msgs *mp)
     FILE *fp;
     sigset_t set, oset;
 
     FILE *fp;
     sigset_t set, oset;
 
-    /* sanity check - check that context has been read */
-    if (defpath == NULL)
-       adios (NULL, "oops, context hasn't been read yet");
-
     /* check if sequence information has changed */
     /* check if sequence information has changed */
-    if (!(mp->msgflags & SEQMOD))
+    if (!(mp->msgflags & SEQMOD)) {
+       if (mp->seqhandle) {
+           lkfclosedata (mp->seqhandle, mp->seqname);
+           mp->seqhandle = NULL;
+           free(mp->seqname);
+           mp->seqname = NULL;
+       }
        return;
        return;
+    }
     mp->msgflags &= ~SEQMOD;
 
     fp = NULL;
     mp->msgflags &= ~SEQMOD;
 
     fp = NULL;
@@ -80,9 +81,17 @@ priv:
                 * If that fails (probably because folder is
                 * readonly), then make sequence private.
                 */
                 * If that fails (probably because folder is
                 * readonly), then make sequence private.
                 */
-               if ((fp = fopen (seqfile, "w")) == NULL
+
+               if (mp->seqhandle) {
+                   fp = mp->seqhandle;
+                   mp->seqhandle = NULL;
+                   free(mp->seqname);
+                   mp->seqname = NULL;
+                   rewind(fp);
+                   ftruncate(fileno(fp), 0);
+               } else if ((fp = lkfopendata (seqfile, "w")) == NULL
                        && (unlink (seqfile) == -1 ||
                        && (unlink (seqfile) == -1 ||
-                           (fp = fopen (seqfile, "w")) == NULL)) {
+                           (fp = lkfopendata (seqfile, "w")) == NULL)) {
                    admonish (attr, "unable to write");
                    goto priv;
                }
                    admonish (attr, "unable to write");
                    goto priv;
                }
@@ -93,15 +102,15 @@ priv:
                sigaddset(&set, SIGINT);
                sigaddset(&set, SIGQUIT);
                sigaddset(&set, SIGTERM);
                sigaddset(&set, SIGINT);
                sigaddset(&set, SIGQUIT);
                sigaddset(&set, SIGTERM);
-               SIGPROCMASK (SIG_BLOCK, &set, &oset);
+               sigprocmask (SIG_BLOCK, &set, &oset);
            }
            fprintf (fp, "%s: %s\n", mp->msgattrs[i], cp);
        }
     }
 
     if (fp) {
            }
            fprintf (fp, "%s: %s\n", mp->msgattrs[i], cp);
        }
     }
 
     if (fp) {
-       fclose (fp);
-       SIGPROCMASK (SIG_SETMASK, &oset, &set);  /* reset signal mask */
+       lkfclosedata (fp, seqfile);
+       sigprocmask (SIG_SETMASK, &oset, &set);  /* reset signal mask */
     } else {
        /*
         * If folder is not readonly, and we didn't save any
     } else {
        /*
         * If folder is not readonly, and we didn't save any