]>
diplodocus.org Git - nmh/blob - sbr/seq_save.c
3c53e4bc1914678638db8e545acffe281981af9b
3 * seq_save.c -- 1) synchronize sequences
4 * -- 2) save public sequences
6 * This code is Copyright (c) 2002, by the authors of nmh. See the
7 * COPYRIGHT file in the root directory of the nmh distribution for
8 * complete copyright information.
12 #include <h/signals.h>
16 * 1. If sequence is public and folder is readonly,
17 * then change it to be private
18 * 2a. If sequence is public, then add it to the sequences file
19 * in folder (name specified by mh-sequences profile entry).
20 * 2b. If sequence is private, then add it to the
25 seq_save (struct msgs
*mp
)
28 char flags
, *cp
, attr
[BUFSIZ
], seqfile
[PATH_MAX
];
32 /* check if sequence information has changed */
33 if (!(mp
->msgflags
& SEQMOD
)) {
35 lkfclosedata (mp
->seqhandle
, mp
->seqname
);
38 mp
->msgflags
&= ~SEQMOD
;
41 flags
= mp
->msgflags
; /* record folder flags */
44 * If no mh-sequences file is defined, or if a mh-sequences file
45 * is defined but empty (*mh_seq == '\0'), then pretend folder
46 * is readonly. This will force all sequences to be private.
48 if (mh_seq
== NULL
|| *mh_seq
== '\0')
51 snprintf (seqfile
, sizeof(seqfile
), "%s/%s", mp
->foldpath
, mh_seq
);
53 for (i
= 0; mp
->msgattrs
[i
]; i
++) {
54 snprintf (attr
, sizeof(attr
), "atr-%s-%s", mp
->msgattrs
[i
], mp
->foldpath
);
56 /* get space separated list of sequence ranges */
57 if (!(cp
= seq_list(mp
, mp
->msgattrs
[i
]))) {
58 context_del (attr
); /* delete sequence from context */
62 if (is_readonly(mp
) || is_seq_private(mp
, i
)) {
67 context_replace (attr
, cp
); /* update sequence in context */
72 context_del (attr
); /* delete sequence from context */
76 * Attempt to open file for public sequences.
77 * If that fails (probably because folder is
78 * readonly), then make sequence private.
87 ftruncate(fileno(fp
), 0);
88 } else if ((fp
= lkfopendata (seqfile
, "w")) == NULL
89 && (unlink (seqfile
) == -1 ||
90 (fp
= lkfopendata (seqfile
, "w")) == NULL
)) {
91 admonish (attr
, "unable to write");
95 /* block a few signals */
97 sigaddset(&set
, SIGHUP
);
98 sigaddset(&set
, SIGINT
);
99 sigaddset(&set
, SIGQUIT
);
100 sigaddset(&set
, SIGTERM
);
101 sigprocmask (SIG_BLOCK
, &set
, &oset
);
103 fprintf (fp
, "%s: %s\n", mp
->msgattrs
[i
], cp
);
108 lkfclosedata (fp
, seqfile
);
109 sigprocmask (SIG_SETMASK
, &oset
, &set
); /* reset signal mask */
112 * If folder is not readonly, and we didn't save any
113 * public sequences, then remove that file.
115 if (!is_readonly(mp
))
120 * Reset folder flag, since we may be
121 * pretending that folder is readonly.
123 mp
->msgflags
= flags
;