]>
diplodocus.org Git - nmh/blob - sbr/seq_read.c
3 * seq_read.c -- read the .mh_sequence file and
4 * -- initialize sequence information
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.
17 static int seq_init (struct msgs
*, char *, char *);
18 static void seq_public (struct msgs
*, int);
19 static void seq_private (struct msgs
*);
23 * Get the sequence information for this folder from
24 * .mh_sequences (or equivalent specified in .mh_profile)
25 * or context file (for private sequences).
29 seq_read (struct msgs
*mp
, int lockflag
)
32 * Initialize the list of sequence names. Go ahead and
33 * add the "cur" sequence to the list of sequences.
35 svector_push_back (mp
->msgattrs
, getcpy (current
));
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 */
43 seq_public (mp
, lockflag
);
45 /* Initialize the private sequences */
51 * read folder's sequences file for public sequences
55 seq_public (struct msgs
*mp
, int lockflag
)
58 char *cp
, seqfile
[PATH_MAX
];
59 char name
[NAMESZ
], field
[BUFSIZ
];
61 m_getfld_state_t gstate
= 0;
64 * If mh_seq == NULL (such as if nmh been compiled with
65 * NOPUBLICSEQ), or if *mh_seq == '\0' (the user has defined
66 * the "mh-sequences" profile entry, but left it empty),
67 * then just return, and do not initialize any public sequences.
69 if (mh_seq
== NULL
|| *mh_seq
== '\0')
72 /* get filename of sequence file */
73 snprintf (seqfile
, sizeof(seqfile
), "%s/%s", mp
->foldpath
, mh_seq
);
75 if ((fp
= lkfopendata (seqfile
, lockflag
? "r+" : "r")) == NULL
)
78 /* Use m_getfld to scan sequence file */
80 int fieldsz
= sizeof field
;
81 switch (state
= m_getfld (&gstate
, name
, field
, &fieldsz
, fp
)) {
84 if (state
== FLDPLUS
) {
86 while (state
== FLDPLUS
) {
87 fieldsz
= sizeof field
;
88 state
= m_getfld (&gstate
, name
, field
, &fieldsz
, fp
);
91 seq_init (mp
, getcpy (name
), trimcpy (cp
));
94 seq_init (mp
, getcpy (name
), trimcpy (field
));
99 lkfclosedata (fp
, seqfile
);
100 adios (NULL
, "no blank lines are permitted in %s", seqfile
);
107 lkfclosedata (fp
, seqfile
);
108 adios (NULL
, "%s is poorly formatted", seqfile
);
110 break; /* break from for loop */
112 m_getfld_state_destroy (&gstate
);
116 mp
->seqname
= getcpy(seqfile
);
118 lkfclosedata (fp
, seqfile
);
124 * Scan profile/context list for private sequences.
126 * We search the context list for all keys that look like
127 * "atr-seqname-folderpath", and add them as private sequences.
131 seq_private (struct msgs
*mp
)
133 int i
, j
, alen
, plen
;
137 alen
= strlen ("atr-");
138 plen
= strlen (mp
->foldpath
) + 1;
140 for (np
= m_defs
; np
; np
= np
->n_next
) {
141 if (ssequal ("atr-", np
->n_name
)
142 && (j
= strlen (np
->n_name
) - plen
) > alen
143 && *(np
->n_name
+ j
) == '-'
144 && strcmp (mp
->foldpath
, np
->n_name
+ j
+ 1) == 0) {
145 cp
= getcpy (np
->n_name
+ alen
);
146 *(cp
+ j
- alen
) = '\0';
147 if ((i
= seq_init (mp
, cp
, getcpy (np
->n_field
))) != -1)
148 make_seq_private (mp
, i
);
155 * Add the name of sequence to the list of folder sequences.
156 * Then parse the list of message ranges for this
157 * sequence, and setup the various bit flags for each
158 * message in the sequence.
160 * Return internal index for the sequence if successful.
161 * Return -1 on error.
165 seq_init (struct msgs
*mp
, char *name
, char *field
)
168 int j
, k
, is_current
;
172 * Check if this is "cur" sequence,
173 * so we can do some special things.
175 is_current
= !strcmp (current
, name
);
178 * Search for this sequence name to see if we've seen
179 * it already. If we've seen this sequence before,
180 * then clear the bit for this sequence from all the
181 * mesages in this folder.
183 for (i
= 0; i
< svector_size (mp
->msgattrs
); i
++) {
184 if (!strcmp (svector_at (mp
->msgattrs
, i
), name
)) {
185 for (j
= mp
->lowmsg
; j
<= mp
->hghmsg
; j
++)
186 clear_sequence (mp
, i
, j
);
192 * If we've already seen this sequence name, just free the
193 * name string. Else add it to the list of sequence names.
195 if (svector_at (mp
->msgattrs
, i
)) {
198 svector_push_back (mp
->msgattrs
, name
);
202 * Split up the different message ranges at whitespace
204 for (ap
= brkstring (field
, " ", "\n"); *ap
; ap
++) {
205 if ((cp
= strchr(*ap
, '-')))
207 if ((j
= m_atoi (*ap
)) > 0) {
208 k
= cp
? m_atoi (cp
) : j
;
211 * Keep mp->curmsg and "cur" sequence in synch. Unlike
212 * other sequences, this message doesn't need to exist.
213 * Think about the series of command (rmm; next) to
214 * understand why this can be the case. But if it does
215 * exist, we will still set the bit flag for it like
221 * We iterate through messages in this range
222 * and flip on bit for this sequence.
224 for (; j
<= k
; j
++) {
225 if (j
>= mp
->lowmsg
&& j
<= mp
->hghmsg
&& does_exist(mp
, j
))
226 add_sequence (mp
, i
, j
);
231 free (field
); /* free string containing message ranges */