2 ** seq_read.c -- read the .mh_sequence file and
3 ** -- initialize sequence information
5 ** This code is Copyright (c) 2002, by the authors of nmh. See the
6 ** COPYRIGHT file in the root directory of the nmh distribution for
7 ** complete copyright information.
16 static int seq_init(struct msgs *, char *, char *);
17 static void seq_public(struct msgs *);
18 static void seq_private(struct msgs *);
22 ** Get the sequence information for this folder from
23 ** .mh_sequences (or equivalent specified in .mh_profile)
24 ** or context file (for private sequences).
28 seq_read(struct msgs *mp)
31 ** Initialize the list of sequence names. Go ahead and
32 ** add the "cur" sequence to the list of sequences.
34 mp->msgattrs[0] = getcpy(current);
35 mp->msgattrs[1] = NULL;
36 make_all_public(mp); /* initially, make all public */
38 /* If folder is empty, don't scan for sequence information */
42 /* Initialize the public sequences */
45 /* Initialize the private sequences */
51 ** read folder's sequences file for public sequences
55 seq_public(struct msgs *mp)
58 char *cp, seqfile[PATH_MAX];
59 char name[NAMESZ], field[BUFSIZ];
63 ** If public sequences are disabled (e.g. the user has defined
64 ** an empty `Mh-Sequences' profile entry), then just return.
66 if (mh_seq == NULL || *mh_seq == '\0')
69 /* get filename of sequence file */
70 snprintf(seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq);
72 if ((fp = lkfopen(seqfile, "r")) == NULL)
75 /* Use m_getfld to scan sequence file */
77 switch (state = m_getfld(state, name, field, sizeof(field), fp)) {
81 if (state == FLDPLUS) {
83 while (state == FLDPLUS) {
84 state = m_getfld(state, name, field, sizeof(field), fp);
87 seq_init(mp, getcpy(name), trimcpy(cp));
90 seq_init(mp, getcpy(name), trimcpy(field));
98 adios(NULL, "no blank lines are permitted in %s", seqfile);
105 adios(NULL, "%s is poorly formatted", seqfile);
107 break; /* break from for loop */
110 lkfclose(fp, seqfile);
115 ** Scan profile/context list for private sequences.
117 ** We search the context list for all keys that look like
118 ** "atr-seqname-folderpath", and add them as private sequences.
122 seq_private(struct msgs *mp)
124 int i, j, alen, plen;
128 alen = strlen("atr-");
129 plen = strlen(mp->foldpath) + 1;
131 for (np = m_defs; np; np = np->n_next) {
132 if (isprefix("atr-", np->n_name)
133 && (j = strlen(np->n_name) - plen) > alen
134 && *(np->n_name + j) == '-'
135 && strcmp(mp->foldpath, np->n_name + j + 1)
137 cp = getcpy(np->n_name + alen);
138 *(cp + j - alen) = '\0';
139 if ((i = seq_init(mp, cp, getcpy(np->n_field))) != -1)
140 make_seq_private(mp, i);
147 ** Add the name of sequence to the list of folder sequences.
148 ** Then parse the list of message ranges for this
149 ** sequence, and setup the various bit flags for each
150 ** message in the sequence.
152 ** Return internal index for the sequence if successful.
153 ** Return -1 on error.
157 seq_init(struct msgs *mp, char *name, char *field)
159 int i, j, k, is_current;
163 ** Check if this is "cur" sequence,
164 ** so we can do some special things.
166 is_current = !strcmp(current, name);
169 ** Search for this sequence name to see if we've seen
170 ** it already. If we've seen this sequence before,
171 ** then clear the bit for this sequence from all the
172 ** mesages in this folder.
174 for (i = 0; mp->msgattrs[i]; i++) {
175 if (!strcmp(mp->msgattrs[i], name)) {
176 for (j = mp->lowmsg; j <= mp->hghmsg; j++)
177 clear_sequence(mp, i, j);
182 /* Return error, if too many sequences */
190 ** If we've already seen this sequence name, just free the
191 ** name string. Else add it to the list of sequence names.
193 if (mp->msgattrs[i]) {
196 mp->msgattrs[i] = name;
197 mp->msgattrs[i + 1] = NULL;
201 ** Split up the different message ranges at whitespace
203 for (ap = brkstring(field, " ", "\n"); *ap; ap++) {
204 if ((cp = strchr(*ap, '-')))
206 if ((j = m_atoi(*ap)) > 0) {
207 k = cp ? m_atoi(cp) : j;
210 ** Keep mp->curmsg and "cur" sequence in synch. Unlike
211 ** other sequences, this message doesn't need to exist.
212 ** Think about the series of command (rmm; next) to
213 ** understand why this can be the case. But if it does
214 ** exist, we will still set the bit flag for it like
220 ** We iterate through messages in this range
221 ** and flip on bit for this sequence.
223 for (; j <= k; j++) {
224 if (j >= mp->lowmsg && j <= mp->hghmsg &&
226 add_sequence(mp, i, j);
231 free(field); /* free string containing message ranges */