X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=sbr%2Fm_convert.c;h=2837e0f4db74960ffc0b4cd2cfc202dd31a23304;hb=0f56dec07e0eda5042276a5e65cb51ea95c23ff9;hp=ee9ba5b975af659c134c0bb07444251fecb5950e;hpb=a485ed478abbd599d8c9aab48934e7a26733ecb1;p=mmh diff --git a/sbr/m_convert.c b/sbr/m_convert.c index ee9ba5b..2837e0f 100644 --- a/sbr/m_convert.c +++ b/sbr/m_convert.c @@ -1,17 +1,17 @@ /* - * m_convert.c -- parse a message range or sequence and set SELECTED - * - * This code is Copyright (c) 2002, by the authors of nmh. See the - * COPYRIGHT file in the root directory of the nmh distribution for - * complete copyright information. - */ +** m_convert.c -- parse a message range or sequence and set SELECTED +** +** This code is Copyright (c) 2002, by the authors of nmh. See the +** COPYRIGHT file in the root directory of the nmh distribution for +** complete copyright information. +*/ #include /* - * error codes for sequence - * and message range processing - */ +** error codes for sequence +** and message range processing +*/ #define BADMSG (-2) #define BADRNG (-3) #define BADNEW (-4) @@ -21,27 +21,27 @@ #define FIRST 1 #define LAST 2 -#define getnew(mp) (mp->hghmsg + 1) +#define getbeyond(mp) ((mp)->hghmsg + 1) -static int convdir; /* convert direction */ -static char *delimp; +static int convdir; /* convert direction */ +static char *delimp; /* delimiter pointer */ /* - * static prototypes - */ -static int m_conv (struct msgs *, char *, int); -static int attr (struct msgs *, char *); +** static prototypes +*/ +static int m_conv(struct msgs *, char *, int); +static int attr(struct msgs *, char *); int -m_convert (struct msgs *mp, char *name) +m_convert(struct msgs *mp, char *name) { int first, last, found, range, err; unsigned char *bp; char *cp; /* check if user defined sequence */ - err = attr (mp, cp = name); + err = attr(mp, cp = name); if (err == -1) return 0; @@ -50,63 +50,66 @@ m_convert (struct msgs *mp, char *name) else if (err > 0) return 1; /* - * else err == 0, so continue - */ + ** else err == 0, so continue + */ found = 0; /* - * Check for special "new" sequence, which - * is valid only if ALLOW_NEW is set. - */ - if ((mp->msgflags & ALLOW_NEW) && !strcmp (cp, "new")) { - if ((err = first = getnew (mp)) <= 0) + ** Check for special beyond sequence, which + ** is valid only if ALLOW_BEYOND is set. + */ + if ((mp->msgflags & ALLOW_BEYOND) && !strcmp(cp, seq_beyond)) { + if ((err = first = getbeyond(mp)) <= 0) goto badmsg; else goto single; } - if (!strcmp (cp, "all")) - cp = "first-last"; + if (!strcmp(cp, seq_all)) + cp = concat(seq_first, "-", seq_last, NULL); - if ((err = first = m_conv (mp, cp, FIRST)) <= 0) + if ((err = first = m_conv(mp, cp, FIRST)) <= 0) goto badmsg; cp = delimp; if (*cp != '\0' && *cp != '-' && *cp != ':') { badelim: - advise (NULL, "illegal argument delimiter: `%c'(0%o)", *delimp, *delimp); + advise(NULL, "illegal argument delimiter: `%c'(0%o)", + *delimp, *delimp); return 0; } if (*cp == '-') { cp++; - if ((err = last = m_conv (mp, cp, LAST)) <= 0) { + if ((err = last = m_conv(mp, cp, LAST)) <= 0) { badmsg: switch (err) { case BADMSG: - advise (NULL, "no %s message", cp); + advise(NULL, "no %s message", cp); break; case BADNUM: - advise (NULL, "message %s doesn't exist", cp); + advise(NULL, "message %s doesn't exist", cp); break; case BADRNG: - advise (NULL, "message %s out of range 1-%d", cp, mp->hghmsg); + advise(NULL, "message %s out of range 1-%d", + cp, mp->hghmsg); break; case BADLST: badlist: - advise (NULL, "bad message list %s", name); + advise(NULL, "bad message list %s", name); break; case BADNEW: - advise (NULL, "folder full, no %s message", name); + advise(NULL, "folder full, no %s message", + name); break; default: - advise (NULL, "no messages match specification"); + advise(NULL, "no messages match specification"); } return 0; } @@ -117,7 +120,7 @@ badlist: goto badelim; if (first > mp->hghmsg || last < mp->lowmsg) { rangerr: - advise (NULL, "no messages in range %s", name); + advise(NULL, "no messages in range %s", name); return 0; } @@ -136,9 +139,9 @@ rangerr: convdir = 1; cp++; } - if ((range = atoi (bp = cp)) == 0) + if ((range = atoi(bp = cp)) == 0) goto badlist; - while (isdigit (*bp)) + while (isdigit(*bp)) bp++; if (*bp) goto badelim; @@ -154,7 +157,7 @@ rangerr: for (last = first; last >= mp->lowmsg && last <= mp->hghmsg; last += convdir) - if (does_exist (mp, last)) + if (does_exist(mp, last)) if (--range <= 0) break; if (last < mp->lowmsg) @@ -170,38 +173,36 @@ rangerr: single: /* - * Single Message - * - * If ALLOW_NEW is set, then allow selecting of an - * empty slot. If ALLOW_NEW is not set, then we - * check if message is in-range and exists. - */ - if (mp->msgflags & ALLOW_NEW) { - set_select_empty (mp, first); - } else { - if (first > mp->hghmsg - || first < mp->lowmsg - || !(does_exist (mp, first))) { - if (!strcmp (name, "cur") || !strcmp (name, ".")) - advise (NULL, "no %s message", name); - else - advise (NULL, "message %d doesn't exist", first); - return 0; - } + ** Single Message + ** + ** If ALLOW_BEYOND is set, then allow selecting of an + ** empty slot. If ALLOW_BEYOND is not set, then we + ** check if message is in-range and exists. + */ + if (mp->msgflags & ALLOW_BEYOND) { + set_select_empty(mp, first); + } else if (first > mp->hghmsg || first < mp->lowmsg + || !does_exist(mp, first)) { + if (!strcmp(name, seq_cur)) + advise(NULL, "no %s message", name); + else + advise(NULL, "message %d doesn't exist", + first); + return 0; } last = first; /* range of 1 */ } /* - * Cycle through the range and select the messages - * that exist. If ALLOW_NEW is set, then we also check - * if we are selecting an empty slot. - */ + ** Cycle through the range and select the messages + ** that exist. If ALLOW_BEYOND is set, then we also check + ** if we are selecting an empty slot. + */ for (; first <= last; first++) { - if (does_exist (mp, first) || - ((mp->msgflags & ALLOW_NEW) && is_select_empty (mp, first))) { - if (!is_selected (mp, first)) { - set_selected (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++; if (mp->lowsel == 0 || first < mp->lowsel) mp->lowsel = first; @@ -219,20 +220,19 @@ single: } /* - * Convert the various message names to - * their numeric values. - * - * n (integer) - * prev - * next - * first - * last - * cur - * . (same as cur) - */ - +** Convert the various message names to +** their numeric values. +** (`42' being an arbitrary number) +** +** 42 +** prev +** next +** first +** last +** cur +*/ static int -m_conv (struct msgs *mp, char *str, int call) +m_conv(struct msgs *mp, char *str, int call) { register int i; register unsigned char *cp, *bp; @@ -240,17 +240,17 @@ m_conv (struct msgs *mp, char *str, int call) convdir = 1; cp = bp = str; - if (isdigit (*cp)) { - while (isdigit (*bp)) + if (isdigit(*cp)) { + while (isdigit(*bp)) bp++; delimp = bp; - i = atoi (cp); + i = atoi(cp); if (i <= mp->hghmsg) return i; else if (*delimp || call == LAST) return mp->hghmsg + 1; - else if (mp->msgflags & ALLOW_NEW) + else if (mp->msgflags & ALLOW_BEYOND) return BADRNG; else return BADNUM; @@ -258,11 +258,9 @@ m_conv (struct msgs *mp, char *str, int call) #ifdef LOCALE /* doesn't enforce lower case */ - for (bp = buf; (isalpha(*cp) || *cp == '.') - && (bp - buf < sizeof(buf) - 1); ) + for (bp = buf; isalpha(*cp) && (bp - buf < sizeof(buf) - 1); ) #else - for (bp = buf; ((*cp >= 'a' && *cp <= 'z') || *cp == '.') - && (bp - buf < sizeof(buf) - 1); ) + for (bp = buf; islower(*cp) && (bp - buf < sizeof(buf) - 1); ) #endif /* LOCALE */ { *bp++ = *cp++; @@ -270,32 +268,32 @@ m_conv (struct msgs *mp, char *str, int call) *bp++ = '\0'; delimp = cp; - if (!strcmp (buf, "first")) - return (mp->hghmsg || !(mp->msgflags & ALLOW_NEW) + if (!strcmp(buf, seq_first)) + return (mp->hghmsg || !(mp->msgflags & ALLOW_BEYOND) ? mp->lowmsg : BADMSG); - if (!strcmp (buf, "last")) { + if (!strcmp(buf, seq_last)) { convdir = -1; - return (mp->hghmsg || !(mp->msgflags & ALLOW_NEW) ? mp->hghmsg : BADMSG); + return (mp->hghmsg || !(mp->msgflags & ALLOW_BEYOND) ? mp->hghmsg : BADMSG); } - if (!strcmp (buf, "cur") || !strcmp (buf, ".")) + if (!strcmp(buf, seq_cur)) return (mp->curmsg > 0 ? mp->curmsg : BADMSG); - if (!strcmp (buf, "prev")) { + if (!strcmp(buf, seq_prev)) { convdir = -1; for (i = (mp->curmsg <= mp->hghmsg) ? mp->curmsg - 1 : mp->hghmsg; i >= mp->lowmsg; i--) { - if (does_exist (mp, i)) + if (does_exist(mp, i)) return i; } return BADMSG; } - if (!strcmp (buf, "next")) { + if (!strcmp(buf, seq_next)) { for (i = (mp->curmsg >= mp->lowmsg) ? mp->curmsg + 1 : mp->lowmsg; i <= mp->hghmsg; i++) { - if (does_exist (mp, i)) + if (does_exist(mp, i)) return i; } return BADMSG; @@ -305,21 +303,21 @@ m_conv (struct msgs *mp, char *str, int call) } /* - * Handle user defined sequences. - * They can take the following forms: - * - * seq - * seq:prev - * seq:next - * seq:first - * seq:last - * seq:+n - * seq:-n - * seq:n - */ - +** 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:+42 +** seq:-42 +** seq:42 +*/ static int -attr (struct msgs *mp, char *cp) +attr(struct msgs *mp, char *cp) { register unsigned char *dp; char *bp = NULL; @@ -329,16 +327,22 @@ attr (struct msgs *mp, char *cp) int range = 0; /* no range */ int first = 0; - /* hack for "cur-name", "cur-n", etc. */ - if (!strcmp (cp, "cur")) + /* hack for "c-name", "c-42", etc. */ + if (!strcmp(cp, seq_cur)) return 0; - if (ssequal ("cur:", cp)) /* this code need to be rewritten... */ + /* "c:..." -- this code need to be rewritten... */ + if (strncmp(seq_cur, cp, strlen(seq_cur))==0 && + cp[strlen(seq_cur)] == ':') { return 0; + } /* Check for sequence negation */ - if ((dp = context_find (nsequence)) && *dp != '\0' && ssequal (dp, cp)) { + if (!(dp = context_find(nsequence))) { + dp = seq_neg; /* use default */ + } + if (dp && *dp && isprefix(dp, cp)) { inverted = 1; - cp += strlen (dp); + cp += strlen(dp); } convdir = 1; /* convert direction */ @@ -351,32 +355,32 @@ attr (struct msgs *mp, char *cp) range = 1; /* - * seq:prev (or) - * seq:next (or) - * seq:first (or) - * seq:last - */ - if (isalpha (*dp)) { - if (!strcmp (dp, "prev")) { + ** seq:prev (or) + ** seq:next (or) + ** seq:first (or) + ** seq:last + */ + if (isalpha(*dp)) { + if (!strcmp(dp, seq_prev)) { convdir = -1; first = (mp->curmsg > 0) && (mp->curmsg <= mp->hghmsg) ? mp->curmsg - 1 : mp->hghmsg; - } else if (!strcmp (dp, "next")) { + } else if (!strcmp(dp, seq_next)) { convdir = 1; first = (mp->curmsg >= mp->lowmsg) ? mp->curmsg + 1 : mp->lowmsg; - } else if (!strcmp (dp, "first")) { + } else if (!strcmp(dp, seq_first)) { convdir = 1; - } else if (!strcmp (dp, "last")) { + } else if (!strcmp(dp, seq_last)) { convdir = -1; } else return BADLST; } else { /* - * seq:n (or) - * seq:+n (or) - * seq:-n - */ + ** seq:42 (or) + ** seq:+42 (or) + ** seq:-42 + */ if (*dp == '+') dp++; else if (*dp == '-') { @@ -385,7 +389,7 @@ attr (struct msgs *mp, char *cp) } if ((range = atoi(dp)) == 0) return BADLST; - while (isdigit (*dp)) + while (isdigit(*dp)) dp++; if (*dp) return BADLST; @@ -394,7 +398,7 @@ attr (struct msgs *mp, char *cp) *bp = '\0'; /* temporarily terminate sequence name */ } - i = seq_getnum (mp, cp); /* get index of sequence */ + i = seq_getnum(mp, cp); /* get index of sequence */ if (bp) *bp = ':'; /* restore sequence name */ @@ -405,10 +409,10 @@ attr (struct msgs *mp, char *cp) for (j = first ? first : (convdir > 0) ? mp->lowmsg : mp->hghmsg; j >= mp->lowmsg && j <= mp->hghmsg; j += convdir) { - if (does_exist (mp, j) - && inverted ? !in_sequence (mp, i, j) : in_sequence (mp, i, j)) { - if (!is_selected (mp, j)) { - set_selected (mp, j); + if (does_exist(mp, j) + && inverted ? !in_sequence(mp, i, j) : in_sequence(mp, i, j)) { + if (!is_selected(mp, j)) { + set_selected(mp, j); mp->numsel++; if (mp->lowsel == 0 || j < mp->lowsel) mp->lowsel = j; @@ -418,9 +422,9 @@ attr (struct msgs *mp, char *cp) found++; /* - * If we have a range, then break out - * once we've found enough. - */ + ** If we have a range, then break out + ** once we've found enough. + */ if (range && found >= range) break; } @@ -431,6 +435,6 @@ attr (struct msgs *mp, char *cp) if (first) return BADMSG; - advise (NULL, "sequence %s %s", cp, inverted ? "full" : "empty"); + advise(NULL, "sequence %s %s", cp, inverted ? "full" : "empty"); return -1; }