From: markus schnalke Date: Thu, 5 Jan 2012 10:11:13 +0000 (+0100) Subject: Much more straight-forward handling of the beyond sequence. X-Git-Tag: mmh-thesis-end~424 X-Git-Url: http://git.marmaro.de/?p=mmh;a=commitdiff_plain;h=452df42b9645e99101184f28518652646ad75ba7 Much more straight-forward handling of the beyond sequence. Could remove the message flag SELECT_EMPTY in the same go. This frees one more space for a user-defined sequence. --- diff --git a/h/mh.h b/h/mh.h index 73845a4..fe99246 100644 --- a/h/mh.h +++ b/h/mh.h @@ -87,15 +87,14 @@ typedef unsigned int seqset_t; */ #define EXISTS (1<<0) /* exists */ #define SELECTED (1<<1) /* selected for use */ -#define SELECT_EMPTY (1<<2) /* "new" message */ -#define SELECT_UNSEEN (1<<3) /* inc/show "unseen" */ +#define SELECT_UNSEEN (1<<2) /* inc/show "unseen" */ -#define MBITS "\020\01EXISTS\02SELECTED\03NEW\04UNSEEN" +#define MBITS "\020\01EXISTS\02SELECTED\03UNSEEN" /* ** first free slot for user-defined sequences */ -#define FFATTRSLOT 4 +#define FFATTRSLOT 3 /* ** Determine the number of user defined sequences we @@ -174,9 +173,6 @@ struct msgs { #define unset_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECTED) #define set_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECTED) -#define is_select_empty(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_EMPTY) -#define set_select_empty(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_EMPTY) - #define is_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_UNSEEN) #define unset_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECT_UNSEEN) #define set_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_UNSEEN) diff --git a/sbr/m_convert.c b/sbr/m_convert.c index 1350c37..98c4733 100644 --- a/sbr/m_convert.c +++ b/sbr/m_convert.c @@ -36,6 +36,22 @@ static int m_conv(struct msgs *, char *, int); static int attr(struct msgs *, char *); +static void +addtosel(struct msgs *mp, int msg) +{ + if (is_selected(mp, msg)) { + return; /* dont select twice */ + } + set_selected(mp, msg); + mp->numsel++; + if (mp->lowsel == 0 || msg < mp->lowsel) { + mp->lowsel = msg; + } + if (msg > mp->hghsel) { + mp->hghsel = msg; + } +} + int m_convert(struct msgs *mp, char *name) { @@ -55,26 +71,25 @@ m_convert(struct msgs *mp, char *name) } /* ** else err == 0, so continue - ** (we know here: it is no user-defined seq) + ** here we know: 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.) + ** Handle the special beyond sequence, which is valid only if + ** ALLOW_BEYOND is set, and can appear only on its own. + ** Also, it is available in any folder. */ if ((mp->msgflags & ALLOW_BEYOND) && !strcmp(cp, seq_beyond)) { - if ((err = first = getbeyond(mp)) <= 0) - goto badmsg; - else - goto single; + addtosel(mp, getbeyond(mp)); + return 1; } - /* replace `a' with `f-l' */ - if (!strcmp(cp, seq_all)) + /* + ** Handle the special all sequence: replace `a' with `f-l' + */ + if (!strcmp(cp, seq_all)) { cp = concat(seq_first, "-", seq_last, NULL); + } if ((err = first = m_conv(mp, cp, FIRST)) <= 0) goto badmsg; @@ -160,7 +175,7 @@ rangerr: first = mp->hghmsg; for (last = first; last >= mp->lowmsg && last <= mp->hghmsg; - last += convdir) + last += convdir) if (does_exist(mp, last) && (--range <= 0)) break; if (last < mp->lowmsg) @@ -176,7 +191,6 @@ rangerr: case '\0': /* single name */ -single: /* ** AFAICS, the only cases to reach here are: ** f, l, p, n, c, b @@ -185,17 +199,14 @@ single: /* ** 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. + ** 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 (first > mp->hghmsg || first < mp->lowmsg || + !does_exist(mp, first)) { if (!strcmp(name, seq_cur)) advise(NULL, "no current message"); else + /* this case seems to never be reached */ advise(NULL, "message %d doesn't exist", first); return 0; @@ -211,27 +222,13 @@ badelim: break; } - /* - ** 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_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; - if (first > mp->hghsel) - mp->hghsel = first; - } + /* Cycle through the range and select the messages that exist. */ + for (found=0; first <= last; first++) { + if (does_exist(mp, first)) { + addtosel(mp, first); found++; } } - if (!found) goto rangerr; @@ -286,12 +283,13 @@ m_conv(struct msgs *mp, char *str, int call) delimp = cp; if (!strcmp(buf, seq_first)) - return (mp->hghmsg || !(mp->msgflags & ALLOW_BEYOND) - ? mp->lowmsg : BADMSG); + return (mp->hghmsg || !(mp->msgflags & ALLOW_BEYOND) ? + mp->lowmsg : BADMSG); if (!strcmp(buf, seq_last)) { convdir = -1; - return (mp->hghmsg || !(mp->msgflags & ALLOW_BEYOND) ? mp->hghmsg : BADMSG); + return (mp->hghmsg || !(mp->msgflags & ALLOW_BEYOND) ? + mp->hghmsg : BADMSG); } if (!strcmp(buf, seq_cur)) @@ -426,17 +424,11 @@ attr(struct msgs *mp, char *cp) found = 0; /* count the number we select for this argument */ for (j = first ? first : (convdir > 0) ? mp->lowmsg : mp->hghmsg; - j >= mp->lowmsg && j <= mp->hghmsg; j += convdir) { + 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); - mp->numsel++; - if (mp->lowsel == 0 || j < mp->lowsel) - mp->lowsel = j; - if (j > mp->hghsel) - mp->hghsel = j; - } + && inverted ? !in_sequence(mp, i, j) : + in_sequence(mp, i, j)) { + addtosel(mp, j); found++; /* @@ -448,7 +440,7 @@ attr(struct msgs *mp, char *cp) } } - if (found > 0) + if (found) return found; if (first)