** complete copyright information.
*/
+
+/* FIXME: This code needs rework! Rewrite as a parser? */
+
#include <h/mh.h>
/*
/* check if user defined sequence */
err = attr(mp, cp = name);
-
if (err == -1)
return 0;
else if (err < 0)
goto badmsg;
- else if (err > 0)
+ else if (err > 0) {
+ /* it had been a user-defined sequence: we're finished */
return 1;
+ }
/*
** else err == 0, so continue
+ ** (we know here: it is no user-defined seq)
*/
found = 0;
/*
** Check for special beyond sequence, which
** is valid only if ALLOW_BEYOND is set.
+ ** (It can appear only on its own.)
*/
if ((mp->msgflags & ALLOW_BEYOND) && !strcmp(cp, seq_beyond)) {
if ((err = first = getbeyond(mp)) <= 0)
goto single;
}
+ /* replace `a' with `f-l' */
if (!strcmp(cp, seq_all))
cp = concat(seq_first, "-", seq_last, NULL);
goto badmsg;
cp = delimp;
- if (*cp != '\0' && *cp != '-' && *cp != ':') {
-badelim:
- advise(NULL, "illegal argument delimiter: `%c'(0%o)",
- *delimp, *delimp);
- return 0;
- }
-
- if (*cp == '-') {
+ switch (*cp) {
+ case '-':
+ /* global range */
cp++;
if ((err = last = m_conv(mp, cp, LAST)) <= 0) {
badmsg:
last = mp->hghmsg;
if (first < mp->lowmsg)
first = mp->lowmsg;
+ break;
- } else if (*cp == ':') {
+ case ':':
+ /* anchored range */
cp++;
if (*cp == '-') {
convdir = -1;
if (*bp)
goto badelim;
if ((convdir > 0 && first > mp->hghmsg)
- || (convdir < 0 && first < mp->lowmsg))
+ || (convdir < 0 && first < mp->lowmsg))
goto rangerr;
/* tighten the range to search */
for (last = first; last >= mp->lowmsg && last <= mp->hghmsg;
last += convdir)
- if (does_exist(mp, last))
- if (--range <= 0)
- break;
+ if (does_exist(mp, last) && (--range <= 0))
+ break;
if (last < mp->lowmsg)
last = mp->lowmsg;
if (last > mp->hghmsg)
last = first;
first = range;
}
- } else {
+ break;
+ case '\0':
+ /* single name */
single:
/*
+ ** AFAICS, the only cases to reach here are:
+ ** f, l, p, n, c, b
+ ** But I'm not sure. --meillo
+ */
+ /*
** Single Message
**
** If ALLOW_BEYOND is set, then allow selecting of an
} else if (first > mp->hghmsg || first < mp->lowmsg
|| !does_exist(mp, first)) {
if (!strcmp(name, seq_cur))
- advise(NULL, "no %s message", name);
+ advise(NULL, "no current message");
else
advise(NULL, "message %d doesn't exist",
first);
return 0;
}
last = first; /* range of 1 */
+ break;
+
+ default:
+badelim:
+ advise(NULL, "illegal argument delimiter: `%c'(0%o)",
+ *delimp, *delimp);
+ return 0;
+ break;
}
/*
** if we are selecting an empty slot.
*/
for (; first <= last; first++) {
- if (does_exist(mp, first) ||
- ((mp->msgflags & ALLOW_BEYOND) && is_select_empty(mp, first))) {
+ if (does_exist(mp, first) || (
+ (mp->msgflags & ALLOW_BEYOND) &&
+ is_select_empty(mp, first))) {
if (!is_selected(mp, first)) {
set_selected(mp, first);
mp->numsel++;
}
/*
-** Convert the various message names to
-** their numeric values.
-** (`42' being an arbitrary number)
+** Convert the various message names to their numeric values.
**
-** 42
-** prev
-** next
-** first
-** last
-** cur
+** 42 (any integer)
+** p
+** n
+** f
+** l
+** c
*/
static int
m_conv(struct msgs *mp, char *str, int call)
/*
** Handle user defined sequences.
** They can take the following forms:
-** (`42' being an arbitrary number)
**
** seq
-** seq:prev
-** seq:next
-** seq:first
-** seq:last
+** seq:p
+** seq:n
+** seq:f
+** seq:l
** seq:+42
** seq:-42
** seq:42
+**
+** (`42' being an arbitrary integer)
*/
static int
attr(struct msgs *mp, char *cp)
int range = 0; /* no range */
int first = 0;
- /* hack for "c-name", "c-42", etc. */
+ /* hack for "c-..." */
if (!strcmp(cp, seq_cur))
return 0;
/* "c:..." -- this code need to be rewritten... */
range = 1;
/*
- ** seq:prev (or)
- ** seq:next (or)
- ** seq:first (or)
- ** seq:last
+ ** seq:p (or)
+ ** seq:n (or)
+ ** seq:f (or)
+ ** seq:l
*/
if (isalpha(*dp)) {
if (!strcmp(dp, seq_prev)) {