]>
diplodocus.org Git - nmh/blob - sbr/seq_read.c
3 * seq_read.c -- read the .mh_sequence file and
4 * -- initialize sequence information
8 * This code is Copyright (c) 2002, by the authors of nmh. See the
9 * COPYRIGHT file in the root directory of the nmh distribution for
10 * complete copyright information.
19 static int seq_init (struct msgs
*, char *, char *);
20 static void seq_public (struct msgs
*);
21 static void seq_private (struct msgs
*);
25 * Get the sequence information for this folder from
26 * .mh_sequences (or equivalent specified in .mh_profile)
27 * or context file (for private sequences).
31 seq_read (struct msgs
*mp
)
34 * Initialize the list of sequence names. Go ahead and
35 * add the "cur" sequence to the list of sequences.
37 mp
->msgattrs
[0] = getcpy (current
);
38 mp
->msgattrs
[1] = NULL
;
39 make_all_public (mp
); /* initially, make all public */
41 /* If folder is empty, don't scan for sequence information */
45 /* Initialize the public sequences */
48 /* Initialize the private sequences */
54 * read folder's sequences file for public sequences
58 seq_public (struct msgs
*mp
)
61 char *cp
, seqfile
[PATH_MAX
];
62 char name
[NAMESZ
], field
[BUFSIZ
];
66 * If mh_seq == NULL (such as if nmh been compiled with
67 * NOPUBLICSEQ), or if *mh_seq == '\0' (the user has defined
68 * the "mh-sequences" profile entry, but left it empty),
69 * then just return, and do not initialize any public sequences.
71 if (mh_seq
== NULL
|| *mh_seq
== '\0')
74 /* get filename of sequence file */
75 snprintf (seqfile
, sizeof(seqfile
), "%s/%s", mp
->foldpath
, mh_seq
);
77 if ((fp
= lkfopen (seqfile
, "r")) == NULL
)
80 /* Use m_getfld to scan sequence file */
82 switch (state
= m_getfld (state
, name
, field
, sizeof(field
), fp
)) {
86 if (state
== FLDPLUS
) {
88 while (state
== FLDPLUS
) {
89 state
= m_getfld (state
, name
, field
, sizeof(field
), fp
);
92 seq_init (mp
, getcpy (name
), trimcpy (cp
));
95 seq_init (mp
, getcpy (name
), trimcpy (field
));
103 adios (NULL
, "no blank lines are permitted in %s", seqfile
);
110 adios (NULL
, "%s is poorly formatted", seqfile
);
112 break; /* break from for loop */
115 lkfclose (fp
, seqfile
);
120 * Scan profile/context list for private sequences.
122 * We search the context list for all keys that look like
123 * "atr-seqname-folderpath", and add them as private sequences.
127 seq_private (struct msgs
*mp
)
129 int i
, j
, alen
, plen
;
133 alen
= strlen ("atr-");
134 plen
= strlen (mp
->foldpath
) + 1;
136 for (np
= m_defs
; np
; np
= np
->n_next
) {
137 if (ssequal ("atr-", np
->n_name
)
138 && (j
= strlen (np
->n_name
) - plen
) > alen
139 && *(np
->n_name
+ j
) == '-'
140 && strcmp (mp
->foldpath
, np
->n_name
+ j
+ 1) == 0) {
141 cp
= getcpy (np
->n_name
+ alen
);
142 *(cp
+ j
- alen
) = '\0';
143 if ((i
= seq_init (mp
, cp
, getcpy (np
->n_field
))) != -1)
144 make_seq_private (mp
, i
);
151 * Add the name of sequence to the list of folder sequences.
152 * Then parse the list of message ranges for this
153 * sequence, and setup the various bit flags for each
154 * message in the sequence.
156 * Return internal index for the sequence if successful.
157 * Return -1 on error.
161 seq_init (struct msgs
*mp
, char *name
, char *field
)
163 int i
, j
, k
, is_current
;
167 * Check if this is "cur" sequence,
168 * so we can do some special things.
170 is_current
= !strcmp (current
, name
);
173 * Search for this sequence name to see if we've seen
174 * it already. If we've seen this sequence before,
175 * then clear the bit for this sequence from all the
176 * mesages in this folder.
178 for (i
= 0; mp
->msgattrs
[i
]; i
++) {
179 if (!strcmp (mp
->msgattrs
[i
], name
)) {
180 for (j
= mp
->lowmsg
; j
<= mp
->hghmsg
; j
++)
181 clear_sequence (mp
, i
, j
);
186 /* Return error, if too many sequences */
194 * If we've already seen this sequence name, just free the
195 * name string. Else add it to the list of sequence names.
197 if (mp
->msgattrs
[i
]) {
200 mp
->msgattrs
[i
] = name
;
201 mp
->msgattrs
[i
+ 1] = NULL
;
205 * Split up the different message ranges at whitespace
207 for (ap
= brkstring (field
, " ", "\n"); *ap
; ap
++) {
208 if ((cp
= strchr(*ap
, '-')))
210 if ((j
= m_atoi (*ap
)) > 0) {
211 k
= cp
? m_atoi (cp
) : j
;
214 * Keep mp->curmsg and "cur" sequence in synch. Unlike
215 * other sequences, this message doesn't need to exist.
216 * Think about the series of command (rmm; next) to
217 * understand why this can be the case. But if it does
218 * exist, we will still set the bit flag for it like
224 * We iterate through messages in this range
225 * and flip on bit for this sequence.
227 for (; j
<= k
; j
++) {
228 if (j
>= mp
->lowmsg
&& j
<= mp
->hghmsg
&& does_exist(mp
, j
))
229 add_sequence (mp
, i
, j
);
234 free (field
); /* free string containing message ranges */