]> diplodocus.org Git - nmh/blobdiff - sbr/m_convert.c
new.c: Order two return statements to match comment.
[nmh] / sbr / m_convert.c
index d7080065783b1ffa240cbb2f5188e2c8fd3f93cc..06e31afec898ef028dc114d455f4e75098f60cd3 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * m_convert.c -- parse a message range or sequence and set SELECTED
+/* 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
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -8,6 +6,7 @@
  */
 
 #include <h/mh.h>
  */
 
 #include <h/mh.h>
+#include <h/utils.h>
 
 /*
  * error codes for sequence
 
 /*
  * error codes for sequence
@@ -46,9 +45,9 @@ m_convert (struct msgs *mp, char *name)
 
     if (err == -1)
        return 0;
 
     if (err == -1)
        return 0;
-    else if (err < 0)
+    if (err < 0)
        goto badmsg;
        goto badmsg;
-    else if (err > 0)
+    if (err > 0)
        return 1;
     /*
      * else err == 0, so continue
        return 1;
     /*
      * else err == 0, so continue
@@ -64,8 +63,7 @@ m_convert (struct msgs *mp, char *name)
     if ((mp->msgflags & ALLOW_NEW) && !strcmp (cp, "new")) {
        if ((err = first = getnew (mp)) <= 0)
            goto badmsg;
     if ((mp->msgflags & ALLOW_NEW) && !strcmp (cp, "new")) {
        if ((err = first = getnew (mp)) <= 0)
            goto badmsg;
-       else
-           goto single;
+        goto single;
     }
 
     if (!strcmp (cp, "all"))
     }
 
     if (!strcmp (cp, "all"))
@@ -77,7 +75,7 @@ m_convert (struct msgs *mp, char *name)
     cp = delimp;
     if (*cp != '\0' && *cp != '-' && *cp != ':' && *cp != '=') {
 badelim:
     cp = delimp;
     if (*cp != '\0' && *cp != '-' && *cp != ':' && *cp != '=') {
 badelim:
-       advise (NULL, "illegal argument delimiter: `%c'(0%o)", *delimp, *delimp);
+       inform("illegal argument delimiter: `%c'(0%o)", *delimp, *delimp);
        return 0;
     }
 
        return 0;
     }
 
@@ -87,28 +85,28 @@ badelim:
 badmsg:
            switch (err) {
            case BADMSG: 
 badmsg:
            switch (err) {
            case BADMSG: 
-               advise (NULL, "no %s message", cp);
+               inform("no %s message", cp);
                break;
 
            case BADNUM: 
                break;
 
            case BADNUM: 
-               advise (NULL, "message %s doesn't exist", cp);
+               inform("message %s doesn't exist", cp);
                break;
 
            case BADRNG: 
                break;
 
            case BADRNG: 
-               advise (NULL, "message %s out of range 1-%d", cp, mp->hghmsg);
+               inform("message %s out of range 1-%d", cp, mp->hghmsg);
                break;
 
            case BADLST: 
 badlist:
                break;
 
            case BADLST: 
 badlist:
-               advise (NULL, "bad message list %s", name);
+               inform("bad message list %s", name);
                break;
 
            case BADNEW:
                break;
 
            case BADNEW:
-               advise (NULL, "folder full, no %s message", name);
+               inform("folder full, no %s message", name);
                break;
 
            default: 
                break;
 
            default: 
-               advise (NULL, "no messages match specification");
+               inform("no messages match specification");
            }
            return 0;
        }
            }
            return 0;
        }
@@ -119,7 +117,7 @@ badlist:
            goto badelim;
        if (first > mp->hghmsg || last < mp->lowmsg) {
 rangerr:
            goto badelim;
        if (first > mp->hghmsg || last < mp->lowmsg) {
 rangerr:
-           advise (NULL, "no messages in range %s", name);
+           inform("no messages in range %s", name);
            return 0;
        }
 
            return 0;
        }
 
@@ -179,7 +177,7 @@ rangerr:
            }
        } else { /* looking for the nth message.  if not enough, fail. */
            if (last < mp->lowmsg || last > mp->hghmsg) {
            }
        } else { /* looking for the nth message.  if not enough, fail. */
            if (last < mp->lowmsg || last > mp->hghmsg) {
-               advise (NULL, "no such message");
+               inform("no such message");
                return 0;
            }
            first = last;
                return 0;
            }
            first = last;
@@ -204,8 +202,8 @@ single:
             * limits simply reallocate the folder so it's within range.
             */
            if (first < mp->lowoff || first > mp->hghoff)
             * limits simply reallocate the folder so it's within range.
             */
            if (first < mp->lowoff || first > mp->hghoff)
-               mp = folder_realloc(mp, first < mp->lowoff ? first : mp->lowoff,
-                                   first > mp->hghoff ? first : mp->hghoff);
+                mp = folder_realloc(mp, min(first, mp->lowoff),
+                                    max(first, mp->hghoff));
 
            set_select_empty (mp, first);
        } else {
 
            set_select_empty (mp, first);
        } else {
@@ -213,9 +211,9 @@ single:
                || first < mp->lowmsg
                || !(does_exist (mp, first))) {
                if (!strcmp (name, "cur") || !strcmp (name, "."))
                || first < mp->lowmsg
                || !(does_exist (mp, first))) {
                if (!strcmp (name, "cur") || !strcmp (name, "."))
-                   advise (NULL, "no %s message", name);
+                   inform("no %s message", name);
                else
                else
-                   advise (NULL, "message %d doesn't exist", first);
+                   inform("message %d doesn't exist", first);
                return 0;
            }
        }
                return 0;
            }
        }
@@ -278,12 +276,11 @@ m_conv (struct msgs *mp, char *str, int call)
 
        if (i <= mp->hghmsg)
            return i;
 
        if (i <= mp->hghmsg)
            return i;
-       else if (*delimp || call == LAST)
+       if (*delimp || call == LAST)
            return mp->hghmsg + 1;
            return mp->hghmsg + 1;
-       else if (mp->msgflags & ALLOW_NEW)
+       if (mp->msgflags & ALLOW_NEW)
            return BADRNG;
            return BADRNG;
-       else
-           return BADNUM;
+        return BADNUM;
     }
 
     /* doesn't enforce lower case */
     }
 
     /* doesn't enforce lower case */
@@ -296,16 +293,16 @@ m_conv (struct msgs *mp, char *str, int call)
     delimp = cp;
 
     if (!strcmp (buf, "first"))
     delimp = cp;
 
     if (!strcmp (buf, "first"))
-       return (mp->hghmsg || !(mp->msgflags & ALLOW_NEW)
-               ? mp->lowmsg : BADMSG);
+       return mp->hghmsg || !(mp->msgflags & ALLOW_NEW) ?
+            mp->lowmsg : BADMSG;
 
     if (!strcmp (buf, "last")) {
        convdir = -1;
 
     if (!strcmp (buf, "last")) {
        convdir = -1;
-       return (mp->hghmsg || !(mp->msgflags & ALLOW_NEW) ? mp->hghmsg : BADMSG);
+       return mp->hghmsg || !(mp->msgflags & ALLOW_NEW) ? mp->hghmsg : BADMSG;
     }
 
     if (!strcmp (buf, "cur") || !strcmp (buf, "."))
     }
 
     if (!strcmp (buf, "cur") || !strcmp (buf, "."))
-       return (mp->curmsg > 0 ? mp->curmsg : BADMSG);
+       return mp->curmsg > 0 ? mp->curmsg : BADMSG;
 
     if (!strcmp (buf, "prev")) {
        convdir = -1;
 
     if (!strcmp (buf, "prev")) {
        convdir = -1;
@@ -361,7 +358,7 @@ attr (struct msgs *mp, char *cp)
     /* hack for "cur-name", "cur-n", etc. */
     if (!strcmp (cp, "cur"))
        return 0;
     /* hack for "cur-name", "cur-n", etc. */
     if (!strcmp (cp, "cur"))
        return 0;
-    if (strncmp ("cur", cp, 3) == 0) {
+    if (has_prefix(cp, "cur")) {
        if (cp[3] == ':' || cp[3] == '=')
            return 0;
     }
        if (cp[3] == ':' || cp[3] == '=')
            return 0;
     }
@@ -374,7 +371,7 @@ attr (struct msgs *mp, char *cp)
 
     convdir = 1;       /* convert direction */
 
 
     convdir = 1;       /* convert direction */
 
-    for (dp = cp; *dp && isalnum((unsigned char) *dp); dp++)
+    for (dp = cp; isalnum((unsigned char)*dp); dp++)
        continue;
 
     if (*dp == ':') {
        continue;
 
     if (*dp == ':') {
@@ -506,6 +503,6 @@ attr (struct msgs *mp, char *cp)
 
     if (first || just_one)
        return BADMSG;
 
     if (first || just_one)
        return BADMSG;
-    advise (NULL, "sequence %s %s", cp, inverted ? "full" : "empty");
+    inform("sequence %s %s", cp, inverted ? "full" : "empty");
     return -1;
 }
     return -1;
 }