]>
diplodocus.org Git - nmh/blob - sbr/m_convert.c
3 * m_convert.c -- parse a message range or sequence and set SELECTED
11 * error codes for sequence
12 * and message range processing
23 #define getnew(mp) (mp->hghmsg + 1)
25 static int convdir
; /* convert direction */
31 static int m_conv (struct msgs
*, char *, int);
32 static int attr (struct msgs
*, char *);
36 m_convert (struct msgs
*mp
, char *name
)
38 int first
, last
, found
, range
, err
;
41 /* check if user defined sequence */
42 err
= attr (mp
, cp
= name
);
51 * else err == 0, so continue
57 * Check for special "new" sequence, which
58 * is valid only if ALLOW_NEW is set.
60 if ((mp
->msgflags
& ALLOW_NEW
) && !strcmp (cp
, "new")) {
61 if ((err
= first
= getnew (mp
)) <= 0)
67 if (!strcmp (cp
, "all"))
70 if ((err
= first
= m_conv (mp
, cp
, FIRST
)) <= 0)
74 if (*cp
!= '\0' && *cp
!= '-' && *cp
!= ':') {
76 advise (NULL
, "illegal argument delimiter: `%c'(0%o)", *delimp
, *delimp
);
82 if ((err
= last
= m_conv (mp
, cp
, LAST
)) <= 0) {
86 advise (NULL
, "no %s message", cp
);
90 advise (NULL
, "message %s doesn't exist", cp
);
94 advise (NULL
, "message %s out of range 1-%d", cp
, mp
->hghmsg
);
99 advise (NULL
, "bad message list %s", name
);
103 advise (NULL
, "folder full, no %s message", name
);
107 advise (NULL
, "no messages match specification");
116 if (first
> mp
->hghmsg
|| last
< mp
->lowmsg
) {
118 advise (NULL
, "no messages in range %s", name
);
122 /* tighten the range to search */
123 if (last
> mp
->hghmsg
)
125 if (first
< mp
->lowmsg
)
128 } else if (*cp
== ':') {
139 if ((range
= atoi (bp
= cp
)) == 0)
141 while (isdigit (*bp
))
145 if ((convdir
> 0 && first
> mp
->hghmsg
)
146 || (convdir
< 0 && first
< mp
->lowmsg
))
149 /* tighten the range to search */
150 if (first
< mp
->lowmsg
)
152 if (first
> mp
->hghmsg
)
156 last
>= mp
->lowmsg
&& last
<= mp
->hghmsg
;
158 if (does_exist (mp
, last
))
161 if (last
< mp
->lowmsg
)
163 if (last
> mp
->hghmsg
)
176 * If ALLOW_NEW is set, then allow selecting of an
177 * empty slot. If ALLOW_NEW is not set, then we
178 * check if message is in-range and exists.
180 if (mp
->msgflags
& ALLOW_NEW
) {
181 set_select_empty (mp
, first
);
183 if (first
> mp
->hghmsg
184 || first
< mp
->lowmsg
185 || !(does_exist (mp
, first
))) {
186 if (!strcmp (name
, "cur") || !strcmp (name
, "."))
187 advise (NULL
, "no %s message", name
);
189 advise (NULL
, "message %d doesn't exist", first
);
193 last
= first
; /* range of 1 */
197 * Cycle through the range and select the messages
198 * that exist. If ALLOW_NEW is set, then we also check
199 * if we are selecting an empty slot.
201 for (; first
<= last
; first
++) {
202 if (does_exist (mp
, first
) ||
203 ((mp
->msgflags
& ALLOW_NEW
) && is_select_empty (mp
, first
))) {
204 if (!is_selected (mp
, first
)) {
205 set_selected (mp
, first
);
207 if (mp
->lowsel
== 0 || first
< mp
->lowsel
)
209 if (first
> mp
->hghsel
)
223 * Convert the various message names to
224 * there numeric value.
236 m_conv (struct msgs
*mp
, char *str
, int call
)
239 register char *cp
, *bp
;
245 while (isdigit (*bp
))
252 else if (*delimp
|| call
== LAST
)
253 return mp
->hghmsg
+ 1;
254 else if (mp
->msgflags
& ALLOW_NEW
)
261 /* doesn't enforce lower case */
262 for (bp
= buf
; (isalpha(*cp
) || *cp
== '.')
263 && (bp
- buf
< sizeof(buf
) - 1); )
265 for (bp
= buf
; ((*cp
>= 'a' && *cp
<= 'z') || *cp
== '.')
266 && (bp
- buf
< sizeof(buf
) - 1); )
274 if (!strcmp (buf
, "first"))
275 return (mp
->hghmsg
|| !(mp
->msgflags
& ALLOW_NEW
)
276 ? mp
->lowmsg
: BADMSG
);
278 if (!strcmp (buf
, "last")) {
280 return (mp
->hghmsg
|| !(mp
->msgflags
& ALLOW_NEW
) ? mp
->hghmsg
: BADMSG
);
283 if (!strcmp (buf
, "cur") || !strcmp (buf
, "."))
284 return (mp
->curmsg
> 0 ? mp
->curmsg
: BADMSG
);
286 if (!strcmp (buf
, "prev")) {
288 for (i
= (mp
->curmsg
<= mp
->hghmsg
) ? mp
->curmsg
- 1 : mp
->hghmsg
;
289 i
>= mp
->lowmsg
; i
--) {
290 if (does_exist (mp
, i
))
296 if (!strcmp (buf
, "next")) {
297 for (i
= (mp
->curmsg
>= mp
->lowmsg
) ? mp
->curmsg
+ 1 : mp
->lowmsg
;
298 i
<= mp
->hghmsg
; i
++) {
299 if (does_exist (mp
, i
))
309 * Handle user defined sequences.
310 * They can take the following forms:
323 attr (struct msgs
*mp
, char *cp
)
330 range
= 0, /* no range */
333 /* hack for "cur-name", "cur-n", etc. */
334 if (!strcmp (cp
, "cur"))
336 if (ssequal ("cur:", cp
)) /* this code need to be rewritten... */
339 /* Check for sequence negation */
340 if ((dp
= context_find (nsequence
)) && *dp
!= '\0' && ssequal (dp
, cp
)) {
345 convdir
= 1; /* convert direction */
347 for (dp
= cp
; *dp
&& isalnum(*dp
); dp
++)
361 if (!strcmp (dp
, "prev")) {
363 first
= (mp
->curmsg
> 0) && (mp
->curmsg
<= mp
->hghmsg
)
367 else if (!strcmp (dp
, "next")) {
369 first
= (mp
->curmsg
>= mp
->lowmsg
)
373 else if (!strcmp (dp
, "first")) {
376 else if (!strcmp (dp
, "last")) {
389 else if (*dp
== '-') {
393 if ((range
= atoi(dp
)) == 0)
395 while (isdigit (*dp
))
401 *bp
= '\0'; /* temporarily terminate sequence name */
404 i
= seq_getnum (mp
, cp
); /* get index of sequence */
407 *bp
= ':'; /* restore sequence name */
411 found
= 0; /* count the number we select for this argument */
413 for (j
= first
? first
: (convdir
> 0) ? mp
->lowmsg
: mp
->hghmsg
;
414 j
>= mp
->lowmsg
&& j
<= mp
->hghmsg
; j
+= convdir
) {
415 if (does_exist (mp
, j
)
416 && inverted
? !in_sequence (mp
, i
, j
) : in_sequence (mp
, i
, j
)) {
417 if (!is_selected (mp
, j
)) {
418 set_selected (mp
, j
);
420 if (mp
->lowsel
== 0 || j
< mp
->lowsel
)
428 * If we have a range, then break out
429 * once we've found enough.
431 if (range
&& found
>= range
)
441 advise (NULL
, "sequence %s %s", cp
, inverted
? "full" : "empty");