1 /* m_convert.c - parse a message sequence and set SELECTED */
3 static char ident[] = "@(#)$Id: m_convert.c,v 1.10 1992/12/15 00:20:22 jromine Exp $";
19 #define getnew(mp) (mp -> hghmsg + 1)
24 static m_conv(), attr();
28 register struct msgs *mp;
40 switch (err = attr (mp, cp = name)) {
54 flags = mp -> msgflags & MHPATH ? EXISTS | SELECT_EMPTY : EXISTS;
56 if ((mp -> msgflags & MHPATH) && strcmp (cp, "new") == 0)
57 if ((err = first = getnew (mp)) <= 0)
61 if (strcmp (cp, "all") == 0)
63 if ((err = first = m_conv (mp, cp, FIRST)) <= 0)
65 if (*(cp = delimp) && *cp != '-' && *cp != ':') {
67 advise (NULLCP, "illegal argument delimiter: `%c'(0%o)",
73 if ((err = last = m_conv (mp, cp, LAST)) <= 0) {
77 advise (NULLCP, "no %s message", cp);
81 advise (NULLCP, "message %s doesn't exist", cp);
85 advise (NULLCP, "message %s out of range 1-%d",
91 advise (NULLCP, "bad message list %s", name);
95 advise (NULLCP, "folder full, no %s message", name);
99 advise (NULLCP, "no messages match specification");
107 if (first > mp -> hghmsg || last < mp -> lowmsg) {
109 advise (NULLCP, "no messages in range %s", name);
112 if (last > mp -> hghmsg)
114 if (first < mp -> lowmsg)
115 first = mp -> lowmsg;
129 if ((range = atoi (bp = cp)) == 0)
131 while (isdigit (*bp))
135 if ((convdir > 0 && first > mp -> hghmsg)
136 || (convdir < 0 && first < mp -> lowmsg))
138 if (first < mp -> lowmsg)
139 first = mp -> lowmsg;
140 if (first > mp -> hghmsg)
141 first = mp -> hghmsg;
143 last >= mp -> lowmsg && last <= mp -> hghmsg;
145 if (mp -> msgstats[last] & EXISTS)
148 if (last < mp -> lowmsg)
150 if (last > mp -> hghmsg)
159 if (!(mp -> msgflags & MHPATH))
160 if (first > mp -> hghmsg
161 || first < mp -> lowmsg
162 || !(mp -> msgstats[first] & EXISTS)) {
163 if (strcmp (name, "cur") == 0 || strcmp (name, ".") == 0)
164 advise (NULLCP, "no %s message", name);
166 advise (NULLCP, "message %d doesn't exist", first);
171 if (mp -> msgflags & MHPATH)
172 mp -> msgstats[first] |= SELECT_EMPTY;
174 for (; first <= last; first++)
175 if (mp -> msgstats[first] & flags) {
176 if (!(mp -> msgstats[first] & SELECTED)) {
178 mp -> msgstats[first] |= SELECTED;
179 if (mp -> lowsel == 0 || first < mp -> lowsel)
180 mp -> lowsel = first;
181 if (first > mp -> hghsel)
182 mp -> hghsel = first;
194 static m_conv (mp, str, call)
195 register struct msgs *mp;
207 while (isdigit (*bp))
210 return ((i = atoi (cp)) <= mp -> hghmsg ? i
211 : *delimp || call == LAST ? mp -> hghmsg + 1
212 : mp -> msgflags & MHPATH ? BADRNG : BADNUM);
217 while ((*cp >= 'a' && *cp <= 'z') || *cp == '.')
219 while (isalpha(*cp) || *cp == '.') /* doesn't enforce lower case */
225 if (strcmp (buf, "first") == 0)
226 return (mp -> hghmsg || !(mp -> msgflags & MHPATH)
227 ? mp -> lowmsg : BADMSG);
229 if (strcmp (buf, "last") == 0) {
231 return (mp -> hghmsg || !(mp -> msgflags & MHPATH)
232 ? mp -> hghmsg : BADMSG);
235 if (strcmp (buf, "cur") == 0 || strcmp (buf, ".") == 0)
236 return (mp -> curmsg > 0 ? mp -> curmsg : BADMSG);
238 if (strcmp (buf, "prev") == 0) {
240 for (i = (mp -> curmsg <= mp -> hghmsg) ? mp -> curmsg - 1 : mp -> hghmsg;
241 i >= mp -> lowmsg; i--) {
242 if (mp -> msgstats[i] & EXISTS)
248 if (strcmp (buf, "next") == 0) {
249 for (i = (mp -> curmsg >= mp -> lowmsg) ? mp -> curmsg + 1 : mp -> lowmsg;
250 i <= mp -> hghmsg; i++) {
251 if (mp -> msgstats[i] & EXISTS)
263 register struct msgs *mp;
266 char *bp = (char *)NULL;
270 range = 0, /* no range */
276 if (strcmp (cp, "cur") == 0)/* hack for "cur-xyz", etc. */
278 if (ssequal ("cur:", cp)) /* this code need to be rewritten... */
281 if (inverted = (dp = m_find (nsequence)) && *dp && ssequal (dp, cp))
285 for (dp = cp; *dp && isalnum(*dp); dp++)
291 if (isalpha (*dp)) { /* optimize? */
292 if (strcmp (dp, "prev") == 0) {
294 first = (mp -> curmsg > 0) && (mp -> curmsg <= mp -> hghmsg)
298 else if (strcmp (dp, "next") == 0) {
300 first = (mp -> curmsg >= mp -> lowmsg)
304 else if (strcmp (dp, "first") == 0) {
307 else if (strcmp (dp, "last") == 0) {
313 else { /* a numeric range */
316 else if (*dp == '-') {
320 if ((range = atoi(dp)) == 0)
322 while (isdigit (*dp))
328 *bp = '\0'; /* terminate sequence name */
333 for (i = 0; mp -> msgattrs[i]; i++)
334 if (strcmp (mp -> msgattrs[i], cp) == 0)
337 *bp = ':'; /* restore sequence name */
338 if (mp -> msgattrs[i] == NULL)
342 for (j = first ? first : (convdir > 0) ? mp -> lowmsg : mp -> hghmsg;
343 j >= mp -> lowmsg && j <= mp -> hghmsg; j += convdir)
344 if ((mp -> msgstats[j] & EXISTS)
345 && inverted ? !(mp -> msgstats[j] & (1 << (bits + i)))
346 : mp -> msgstats[j] & (1 << (bits + i))) {
347 if (!(mp -> msgstats[j] & SELECTED)) {
349 mp -> msgstats[j] |= SELECTED;
350 if (mp -> lowsel == 0 || j < mp -> lowsel)
352 if (j > mp -> hghsel)
356 if (range && found >= range)
357 break; /* we've done enough */
364 advise (NULLCP, "sequence %s %s", cp, inverted ? "full" : "empty");