X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fm_convert.c;h=6e6acd7e8ce9bf27dd17381f7fc741c9d6ae4de3;hp=3065941ab76d24088911559d990961b07158b0be;hb=3cc8ed080f6e741b8df04a3ebe764c659e75cb38;hpb=a7771fd2e83d64228fb675749fc936151249dbd3 diff --git a/sbr/m_convert.c b/sbr/m_convert.c index 3065941..6e6acd7 100644 --- a/sbr/m_convert.c +++ b/sbr/m_convert.c @@ -21,10 +21,10 @@ #define FIRST 1 #define LAST 2 -#define getnew(mp) (mp->hghmsg + 1) +#define getnew(mp) ((mp)->hghmsg + 1) -static int convdir; /* convert direction */ -static char *delimp; +static int convdir; /* convert direction */ +static char *delimp; /* delimiter pointer */ /* ** static prototypes @@ -56,18 +56,18 @@ m_convert(struct msgs *mp, char *name) found = 0; /* - ** Check for special "new" sequence, which + ** Check for special beyond sequence, which ** is valid only if ALLOW_NEW is set. */ - if ((mp->msgflags & ALLOW_NEW) && !strcmp(cp, "new")) { + if ((mp->msgflags & ALLOW_NEW) && !strcmp(cp, seq_beyond)) { if ((err = first = getnew(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) goto badmsg; @@ -181,16 +181,14 @@ single: */ 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")) - advise(NULL, "no %s message", name); - else - advise(NULL, "message %d doesn't exist", first); - return 0; - } + } 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 */ } @@ -224,8 +222,9 @@ single: /* ** Convert the various message names to ** their numeric values. +** (`42' being an arbitrary number) ** -** n (integer) +** 42 ** prev ** next ** first @@ -269,19 +268,19 @@ m_conv(struct msgs *mp, char *str, int call) *bp++ = '\0'; delimp = cp; - if (!strcmp(buf, "first")) + if (!strcmp(buf, seq_first)) return (mp->hghmsg || !(mp->msgflags & ALLOW_NEW) ? mp->lowmsg : BADMSG); - if (!strcmp(buf, "last")) { + if (!strcmp(buf, seq_last)) { convdir = -1; return (mp->hghmsg || !(mp->msgflags & ALLOW_NEW) ? mp->hghmsg : BADMSG); } - if (!strcmp(buf, "cur")) + 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--) { @@ -291,7 +290,7 @@ m_conv(struct msgs *mp, char *str, int call) 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)) @@ -306,17 +305,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:+n -** seq:-n -** seq:n +** seq:+42 +** seq:-42 +** seq:42 */ - static int attr(struct msgs *mp, char *cp) { @@ -328,11 +327,14 @@ 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 (isprefix("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))) { @@ -359,25 +361,25 @@ attr(struct msgs *mp, char *cp) ** seq:last */ if (isalpha(*dp)) { - if (!strcmp(dp, "prev")) { + 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++;