]>
diplodocus.org Git - nmh/blob - sbr/seq_read.c
3cf8ad89ceed44715dadaac7e5f97f7d325d3024
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
*);
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
)
32 * Initialize the list of sequence names. Go ahead and
33 * add the "cur" sequence to the list of sequences.
35 mp
->msgattrs
[0] = getcpy (current
);
36 mp
->msgattrs
[1] = NULL
;
37 make_all_public (mp
); /* initially, make all public */
39 /* If folder is empty, don't scan for sequence information */
43 /* Initialize the public sequences */
46 /* Initialize the private sequences */
52 * read folder's sequences file for public sequences
56 seq_public (struct msgs
*mp
)
59 char *cp
, seqfile
[PATH_MAX
];
60 char name
[NAMESZ
], field
[BUFSIZ
];
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
= lkfopen (seqfile
, "r")) == NULL
)
78 /* Use m_getfld to scan sequence file */
80 int fieldsz
= sizeof field
;
81 switch (state
= m_getfld (state
, name
, field
, &fieldsz
, fp
)) {
85 if (state
== FLDPLUS
) {
87 while (state
== FLDPLUS
) {
88 fieldsz
= sizeof field
;
89 state
= m_getfld (state
, name
, field
, &fieldsz
, 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
)
164 int j
, k
, is_current
;
168 * Check if this is "cur" sequence,
169 * so we can do some special things.
171 is_current
= !strcmp (current
, name
);
174 * Search for this sequence name to see if we've seen
175 * it already. If we've seen this sequence before,
176 * then clear the bit for this sequence from all the
177 * mesages in this folder.
179 for (i
= 0; mp
->msgattrs
[i
]; i
++) {
180 if (!strcmp (mp
->msgattrs
[i
], name
)) {
181 for (j
= mp
->lowmsg
; j
<= mp
->hghmsg
; j
++)
182 clear_sequence (mp
, i
, j
);
187 /* Return error, if too many sequences */
195 * If we've already seen this sequence name, just free the
196 * name string. Else add it to the list of sequence names.
198 if (mp
->msgattrs
[i
]) {
201 mp
->msgattrs
[i
] = name
;
202 mp
->msgattrs
[i
+ 1] = NULL
;
206 * Split up the different message ranges at whitespace
208 for (ap
= brkstring (field
, " ", "\n"); *ap
; ap
++) {
209 if ((cp
= strchr(*ap
, '-')))
211 if ((j
= m_atoi (*ap
)) > 0) {
212 k
= cp
? m_atoi (cp
) : j
;
215 * Keep mp->curmsg and "cur" sequence in synch. Unlike
216 * other sequences, this message doesn't need to exist.
217 * Think about the series of command (rmm; next) to
218 * understand why this can be the case. But if it does
219 * exist, we will still set the bit flag for it like
225 * We iterate through messages in this range
226 * and flip on bit for this sequence.
228 for (; j
<= k
; j
++) {
229 if (j
>= mp
->lowmsg
&& j
<= mp
->hghmsg
&& does_exist(mp
, j
))
230 add_sequence (mp
, i
, j
);
235 free (field
); /* free string containing message ranges */