From afd666e21d9a1bd391f037c82b7c097d69e7b2f4 Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Wed, 4 Jan 2012 21:04:56 +0100 Subject: [PATCH] Various minor cleanups in sbr/m_convert.c. --- sbr/m_convert.c | 94 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 38 deletions(-) diff --git a/sbr/m_convert.c b/sbr/m_convert.c index 2837e0f..1350c37 100644 --- a/sbr/m_convert.c +++ b/sbr/m_convert.c @@ -6,6 +6,9 @@ ** complete copyright information. */ + +/* FIXME: This code needs rework! Rewrite as a parser? */ + #include /* @@ -42,15 +45,17 @@ m_convert(struct msgs *mp, char *name) /* 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; @@ -58,6 +63,7 @@ m_convert(struct msgs *mp, char *name) /* ** 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) @@ -66,6 +72,7 @@ m_convert(struct msgs *mp, char *name) goto single; } + /* replace `a' with `f-l' */ if (!strcmp(cp, seq_all)) cp = concat(seq_first, "-", seq_last, NULL); @@ -73,14 +80,9 @@ m_convert(struct msgs *mp, char *name) 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: @@ -129,8 +131,10 @@ rangerr: last = mp->hghmsg; if (first < mp->lowmsg) first = mp->lowmsg; + break; - } else if (*cp == ':') { + case ':': + /* anchored range */ cp++; if (*cp == '-') { convdir = -1; @@ -146,7 +150,7 @@ rangerr: 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 */ @@ -157,9 +161,8 @@ rangerr: 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) @@ -169,10 +172,17 @@ rangerr: 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 @@ -184,13 +194,21 @@ single: } 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; } /* @@ -199,8 +217,9 @@ single: ** 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++; @@ -220,16 +239,14 @@ single: } /* -** 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) @@ -305,16 +322,17 @@ 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) @@ -327,7 +345,7 @@ 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... */ @@ -355,10 +373,10 @@ attr(struct msgs *mp, char *cp) 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)) { -- 1.7.10.4