Annotation of 3BSD/cmd/ucbmail/cmd1.c, revision 1.1

1.1     ! root        1: #
        !             2: #include "rcv.h"
        !             3: #include <sys/stat.h>
        !             4: 
        !             5: /*
        !             6:  * Mail -- a mail program
        !             7:  *
        !             8:  * User commands.
        !             9:  */
        !            10: 
        !            11: /*
        !            12:  * Print the current active headings.
        !            13:  */
        !            14: 
        !            15: static int screen;
        !            16: 
        !            17: headers(argv)
        !            18:        char **argv;
        !            19: {
        !            20:        register int mesg, flag;
        !            21:        register struct message *mp;
        !            22:        char c, *str;
        !            23: 
        !            24:        str = argv[0];
        !            25:        if (argcount(argv) == 0)
        !            26:                c = 0;
        !            27:        else
        !            28:                c = str[0];
        !            29:        if (c) {
        !            30:                if (numeric(str))
        !            31:                        screen = atoi(str) / SCREEN;
        !            32:                else
        !            33:                        switch (c) {
        !            34:                        case '0':
        !            35:                                /*
        !            36:                                 * Go back to top.
        !            37:                                 */
        !            38:                                screen = 0;
        !            39:                                break;
        !            40: 
        !            41:                        case '+':
        !            42:                                /*
        !            43:                                 * scroll down.
        !            44:                                 */
        !            45:                                screen++;
        !            46:                                break;
        !            47: 
        !            48:                        case '-':
        !            49:                                /*
        !            50:                                 * scroll up.
        !            51:                                 */
        !            52:                                screen--;
        !            53:                                break;
        !            54:                        }
        !            55:                if (screen < 0)
        !            56:                        screen = 0;
        !            57:        }
        !            58:        mp = &message[screen * SCREEN];
        !            59:        if (mp > &message[msgCount])
        !            60:                mp = &message[msgCount - SCREEN];
        !            61:        if (mp < &message[0])
        !            62:                mp = &message[0];
        !            63:        flag = 0;
        !            64:        mesg = mp - &message[0];
        !            65:        dot = mp;
        !            66:        for (; mp < &message[msgCount]; mp++) {
        !            67:                mesg++;
        !            68:                if (mp->m_flag & MDELETED)
        !            69:                        continue;
        !            70:                if (flag++ >= SCREEN)
        !            71:                        break;
        !            72:                printhead(mesg);
        !            73:                sreset();
        !            74:        }
        !            75:        if (flag == 0) {
        !            76:                printf("No more mail.\n");
        !            77:                return(1);
        !            78:        }
        !            79:        return(0);
        !            80: }
        !            81: 
        !            82: /*
        !            83:  * Print out the headlines for each message
        !            84:  * in the passed message list.
        !            85:  */
        !            86: 
        !            87: from(msgvec)
        !            88:        int *msgvec;
        !            89: {
        !            90:        register int *ip;
        !            91: 
        !            92:        for (ip = msgvec; *ip != NULL; ip++) {
        !            93:                printhead(*ip);
        !            94:                sreset();
        !            95:        }
        !            96:        if (--ip >= msgvec)
        !            97:                dot = &message[*ip - 1];
        !            98:        return(0);
        !            99: }
        !           100: 
        !           101: /*
        !           102:  * Print out the header of a specific message.
        !           103:  * This is a slight improvement to the standard one.
        !           104:  */
        !           105: 
        !           106: printhead(mesg)
        !           107: {
        !           108:        struct message *mp;
        !           109:        FILE *ibuf;
        !           110:        char headline[LINESIZE], wcount[10], *subjline, dispc;
        !           111:        char pbuf[BUFSIZ];
        !           112:        int s;
        !           113:        struct headline hl;
        !           114:        register char *cp;
        !           115: 
        !           116:        mp = &message[mesg-1];
        !           117:        ibuf = setinput(mp);
        !           118:        readline(ibuf, headline);
        !           119:        subjline = hfield("subject", mp);
        !           120:        if (subjline == NOSTR)
        !           121:                subjline = hfield("subj", mp);
        !           122: 
        !           123:        /*
        !           124:         * Bletch!
        !           125:         */
        !           126: 
        !           127:        if (subjline != NOSTR && strlen(subjline) > 28)
        !           128:                subjline[29] = '\0';
        !           129:        if (mp->m_flag & MSAVED)
        !           130:                dispc = '*';
        !           131:        else if (mp->m_flag & MPRESERVED)
        !           132:                dispc = 'P';
        !           133:        else
        !           134:                dispc = ' ';
        !           135:        parse(headline, &hl, pbuf);
        !           136:        sprintf(wcount, " %d/%d", mp->m_lines, mp->m_size);
        !           137:        s = strlen(wcount);
        !           138:        cp = wcount + s;
        !           139:        while (s < 7)
        !           140:                s++, *cp++ = ' ';
        !           141:        *cp = '\0';
        !           142:        if (subjline != NOSTR)
        !           143:                printf("%c%3d %-8s %16.16s %s \"%s\"\n", dispc, mesg,
        !           144:                    nameof(mp), hl.l_date, wcount, subjline);
        !           145:        else
        !           146:                printf("%c%3d %-8s %16.16s %s\n", dispc, mesg,
        !           147:                    nameof(mp), hl.l_date, wcount);
        !           148: }
        !           149: 
        !           150: /*
        !           151:  * Print out the value of dot.
        !           152:  */
        !           153: 
        !           154: pdot()
        !           155: {
        !           156:        printf("%d\n", dot - &message[0] + 1);
        !           157:        return(0);
        !           158: }
        !           159: 
        !           160: /*
        !           161:  * Print out all the possible commands.
        !           162:  */
        !           163: 
        !           164: pcmdlist()
        !           165: {
        !           166:        register struct cmd *cp;
        !           167:        register int cc;
        !           168:        extern struct cmd cmdtab[];
        !           169: 
        !           170:        printf("Commands are:\n");
        !           171:        for (cc = 0, cp = cmdtab; cp->c_name != NULL; cp++) {
        !           172:                cc += strlen(cp->c_name) + 2;
        !           173:                if (cc > 72) {
        !           174:                        printf("\n");
        !           175:                        cc = strlen(cp->c_name) + 2;
        !           176:                }
        !           177:                if ((cp+1)->c_name != NOSTR)
        !           178:                        printf("%s, ", cp->c_name);
        !           179:                else
        !           180:                        printf("%s\n", cp->c_name);
        !           181:        }
        !           182:        return(0);
        !           183: }
        !           184: 
        !           185: /*
        !           186:  * Go to the previous message and type it.
        !           187:  * If at the top, just bitch.
        !           188:  */
        !           189: 
        !           190: previous(argv)
        !           191:        char **argv;
        !           192: {
        !           193:        register struct message *mp;
        !           194:        register int c;
        !           195:        int list[2];
        !           196: 
        !           197:        c = 1;
        !           198:        if (argcount(argv) != 0)
        !           199:                c = atoi(argv[0]);
        !           200:        while (c--) {
        !           201:                mp = dot;
        !           202:                do {
        !           203:                        mp--;
        !           204:                        if (mp < &message[0]) {
        !           205:                                printf("Nonzero address required\n");
        !           206:                                return(0);
        !           207:                        }
        !           208:                } while (mp->m_flag & (MDELETED|MSAVED));
        !           209:                dot = mp;
        !           210:        }
        !           211:        list[0] = dot - &message[0] + 1;
        !           212:        list[1] = NULL;
        !           213:        return(type(list));
        !           214: }
        !           215: 
        !           216: /*
        !           217:  * Type out the messages requested.
        !           218:  */
        !           219: 
        !           220: type(msgvec)
        !           221:        int *msgvec;
        !           222: {
        !           223:        register *ip;
        !           224:        register struct message *mp;
        !           225:        register int mesg;
        !           226:        int c;
        !           227:        FILE *ibuf;
        !           228: 
        !           229:        for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
        !           230:                mesg = *ip;
        !           231:                touch(mesg);
        !           232:                mp = &message[mesg-1];
        !           233:                dot = mp;
        !           234:                print(mp);
        !           235:        }
        !           236:        return(0);
        !           237: }
        !           238: 
        !           239: /*
        !           240:  * Print the indicated message on standard output.
        !           241:  */
        !           242: 
        !           243: print(mp)
        !           244:        register struct message *mp;
        !           245: {
        !           246: 
        !           247:        if (value("quiet") == NOSTR)
        !           248:                printf("Message %2d:\n", mp - &message[0] + 1);
        !           249:        touch(mp - &message[0] + 1);
        !           250:        send(mp, stdout);
        !           251: }
        !           252: 
        !           253: /*
        !           254:  * Print the top so many lines of each desired message.
        !           255:  * The number of lines is taken from the variable "toplines"
        !           256:  * and defaults to 5.
        !           257:  */
        !           258: 
        !           259: top(msgvec)
        !           260:        int *msgvec;
        !           261: {
        !           262:        register int *ip;
        !           263:        register struct message *mp;
        !           264:        register int mesg;
        !           265:        int c, topl, lines, lineb;
        !           266:        char *valtop, linebuf[LINESIZE];
        !           267:        FILE *ibuf;
        !           268: 
        !           269:        topl = 5;
        !           270:        valtop = value("toplines");
        !           271:        if (valtop != NOSTR) {
        !           272:                topl = atoi(valtop);
        !           273:                if (topl < 0 || topl > 10000)
        !           274:                        topl = 5;
        !           275:        }
        !           276:        lineb = 1;
        !           277:        for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
        !           278:                mesg = *ip;
        !           279:                touch(mesg);
        !           280:                mp = &message[mesg-1];
        !           281:                dot = mp;
        !           282:                if (value("quiet") == NOSTR)
        !           283:                        printf("Message %2d:\n", mesg);
        !           284:                ibuf = setinput(mp);
        !           285:                c = mp->m_lines;
        !           286:                if (!lineb)
        !           287:                        printf("\n");
        !           288:                for (lines = 0; lines < c && lines <= topl; lines++) {
        !           289:                        if (readline(ibuf, linebuf) <= 0)
        !           290:                                break;
        !           291:                        puts(linebuf);
        !           292:                        lineb = blankline(linebuf);
        !           293:                }
        !           294:        }
        !           295:        return(0);
        !           296: }
        !           297: 
        !           298: /*
        !           299:  * Touch all the given messages so that they will
        !           300:  * get mboxed.
        !           301:  */
        !           302: 
        !           303: stouch(msgvec)
        !           304:        int msgvec[];
        !           305: {
        !           306:        register int *ip;
        !           307: 
        !           308:        for (ip = msgvec; *ip != 0; ip++) {
        !           309:                touch(*ip);
        !           310:                dot = &message[*ip-1];
        !           311:                dot->m_flag &= ~MPRESERVE;
        !           312:        }
        !           313:        return(0);
        !           314: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.