386BSD 0.1 development
[unix-history] / usr / src / usr.bin / mail / list.c
index a67fbbd..15ebf34 100644 (file)
@@ -2,21 +2,37 @@
  * Copyright (c) 1980 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1980 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)list.c     5.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)list.c     5.14 (Berkeley) 6/1/90";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -42,13 +58,17 @@ getmsglist(buf, vector, flags)
        register int *ip;
        register struct message *mp;
 
        register int *ip;
        register struct message *mp;
 
+       if (msgCount == 0) {
+               *vector = 0;
+               return 0;
+       }
        if (markall(buf, flags) < 0)
                return(-1);
        ip = vector;
        for (mp = &message[0]; mp < &message[msgCount]; mp++)
                if (mp->m_flag & MMARK)
                        *ip++ = mp - &message[0] + 1;
        if (markall(buf, flags) < 0)
                return(-1);
        ip = vector;
        for (mp = &message[0]; mp < &message[msgCount]; mp++)
                if (mp->m_flag & MMARK)
                        *ip++ = mp - &message[0] + 1;
-       *ip = NULL;
+       *ip = 0;
        return(ip - vector);
 }
 
        return(ip - vector);
 }
 
@@ -124,7 +144,7 @@ number:
                                if (check(lexnumber, f))
                                        return(-1);
                                for (i = beg; i <= lexnumber; i++)
                                if (check(lexnumber, f))
                                        return(-1);
                                for (i = beg; i <= lexnumber; i++)
-                                       if ((message[i - 1].m_flag & MDELETED) == f)
+                                       if (f == MDELETED || (message[i - 1].m_flag & MDELETED) == 0)
                                                mark(i);
                                beg = 0;
                                break;
                                                mark(i);
                                beg = 0;
                                break;
@@ -204,6 +224,9 @@ number:
                        }
                        star++;
                        break;
                        }
                        star++;
                        break;
+
+               case TERROR:
+                       return -1;
                }
                tok = scan(&bufp);
        }
                }
                tok = scan(&bufp);
        }
@@ -249,7 +272,7 @@ number:
                                        }
                                }
                                else {
                                        }
                                }
                                else {
-                                       if (sender(*np, i)) {
+                                       if (matchsender(*np, i)) {
                                                mc++;
                                                break;
                                        }
                                                mc++;
                                                break;
                                        }
@@ -330,8 +353,9 @@ evalcol(col)
 
 /*
  * Check the passed message number for legality and proper flags.
 
 /*
  * Check the passed message number for legality and proper flags.
+ * If f is MDELETED, then either kind will do.  Otherwise, the message
+ * has to be undeleted.
  */
  */
-
 check(mesg, f)
 {
        register struct message *mp;
 check(mesg, f)
 {
        register struct message *mp;
@@ -341,7 +365,7 @@ check(mesg, f)
                return(-1);
        }
        mp = &message[mesg-1];
                return(-1);
        }
        mp = &message[mesg-1];
-       if ((mp->m_flag & MDELETED) != f) {
+       if (f != MDELETED && (mp->m_flag & MDELETED) != 0) {
                printf("%d: Inappropriate message\n", mesg);
                return(-1);
        }
                printf("%d: Inappropriate message\n", mesg);
                return(-1);
        }
@@ -471,7 +495,7 @@ scan(sp)
        int quotec;
 
        if (regretp >= 0) {
        int quotec;
 
        if (regretp >= 0) {
-               strcpy(lexstring, stringstack[regretp]);
+               strcpy(lexstring, string_stack[regretp]);
                lexnumber = numberstack[regretp];
                return(regretstack[regretp--]);
        }
                lexnumber = numberstack[regretp];
                return(regretstack[regretp--]);
        }
@@ -541,16 +565,20 @@ scan(sp)
                c = *cp++;
        }
        while (c != '\0') {
                c = *cp++;
        }
        while (c != '\0') {
-               if (c == quotec)
+               if (c == quotec) {
+                       cp++;
                        break;
                        break;
+               }
                if (quotec == 0 && (c == ' ' || c == '\t'))
                        break;
                if (cp2 - lexstring < STRINGLEN-1)
                        *cp2++ = c;
                c = *cp++;
        }
                if (quotec == 0 && (c == ' ' || c == '\t'))
                        break;
                if (cp2 - lexstring < STRINGLEN-1)
                        *cp2++ = c;
                c = *cp++;
        }
-       if (quotec && c == 0)
+       if (quotec && c == 0) {
                fprintf(stderr, "Missing %c\n", quotec);
                fprintf(stderr, "Missing %c\n", quotec);
+               return TERROR;
+       }
        *sp = --cp;
        *cp2 = '\0';
        return(TSTRING);
        *sp = --cp;
        *cp2 = '\0';
        return(TSTRING);
@@ -566,7 +594,7 @@ regret(token)
                panic("Too many regrets");
        regretstack[regretp] = token;
        lexstring[STRINGLEN-1] = '\0';
                panic("Too many regrets");
        regretstack[regretp] = token;
        lexstring[STRINGLEN-1] = '\0';
-       stringstack[regretp] = savestr(lexstring);
+       string_stack[regretp] = savestr(lexstring);
        numberstack[regretp] = lexnumber;
 }
 
        numberstack[regretp] = lexnumber;
 }
 
@@ -586,24 +614,19 @@ scaninit()
 
 first(f, m)
 {
 
 first(f, m)
 {
-       register int mesg;
        register struct message *mp;
 
        register struct message *mp;
 
-       mesg = dot - &message[0] + 1;
+       if (msgCount == 0)
+               return 0;
        f &= MDELETED;
        m &= MDELETED;
        f &= MDELETED;
        m &= MDELETED;
-       for (mp = dot; mp < &message[msgCount]; mp++) {
+       for (mp = dot; mp < &message[msgCount]; mp++)
                if ((mp->m_flag & m) == f)
                if ((mp->m_flag & m) == f)
-                       return(mesg);
-               mesg++;
-       }
-       mesg = dot - &message[0];
-       for (mp = dot-1; mp >= &message[0]; mp--) {
+                       return mp - message + 1;
+       for (mp = dot-1; mp >= &message[0]; mp--)
                if ((mp->m_flag & m) == f)
                if ((mp->m_flag & m) == f)
-                       return(mesg);
-               mesg--;
-       }
-       return(NULL);
+                       return mp - message + 1;
+       return 0;
 }
 
 /*
 }
 
 /*
@@ -611,14 +634,14 @@ first(f, m)
  * if so.
  */
 
  * if so.
  */
 
-sender(str, mesg)
+matchsender(str, mesg)
        char *str;
 {
        char *str;
 {
-       register struct message *mp;
        register char *cp, *cp2, *backup;
 
        register char *cp, *cp2, *backup;
 
-       mp = &message[mesg-1];
-       backup = cp2 = nameof(mp, 0);
+       if (!*str)      /* null string matches nothing instead of everything */
+               return 0;
+       backup = cp2 = nameof(&message[mesg - 1], 0);
        cp = str;
        while (*cp2) {
                if (*cp == 0)
        cp = str;
        while (*cp2) {
                if (*cp == 0)