Annotation of 43BSDReno/contrib/jove/argcount.c, revision 1.1

1.1     ! root        1: /***************************************************************************
        !             2:  * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne.  JOVE *
        !             3:  * is provided to you without charge, and with no warranty.  You may give  *
        !             4:  * away copies of JOVE, including sources, provided that this notice is    *
        !             5:  * included in all the files.                                              *
        !             6:  ***************************************************************************/
        !             7: 
        !             8: #include "jove.h"
        !             9: #include <ctype.h>
        !            10: 
        !            11: private        void
        !            12:        gather_numeric_argument proto((int)),
        !            13:        quad_numeric_arg proto((void));
        !            14: 
        !            15: int    arg_supplied_p,
        !            16:        arg_count;
        !            17: 
        !            18: /* called by C-U to gather a numeric argument, either C-U's or digits,
        !            19:    but not both */
        !            20: 
        !            21: void
        !            22: TimesFour()
        !            23: {
        !            24:        quad_numeric_arg();
        !            25: }
        !            26: 
        !            27: /* This initializes the numeric argument to 1 and starts multiplying
        !            28:    by 4 (the magic number Stallman came up with).  It is an error to
        !            29:    invoke quad_numeric_arg() interactively (via TimesFour()), because
        !            30:    it uses the LastKeyStruck variable to know what character signals
        !            31:    to multiply again (in the loop). */
        !            32: private void
        !            33: quad_numeric_arg()
        !            34: {
        !            35:        int     oldc = LastKeyStruck,
        !            36:                newc,
        !            37:                narg_count,
        !            38:                slow;
        !            39: 
        !            40:        slow = NO;
        !            41:        arg_supplied_p = YES;
        !            42:        arg_count = 1;
        !            43:        this_cmd = ARG_CMD;
        !            44:        do {
        !            45:                if ((narg_count = arg_count * 4) != 0)
        !            46:                        arg_count = narg_count;
        !            47:                newc = waitchar(&slow);
        !            48:                if (isdigit(newc) || newc == '-') {
        !            49:                     arg_supplied_p = NO;
        !            50:                     gather_numeric_argument(newc);
        !            51:                     return;
        !            52:                }
        !            53:        } while (newc == oldc);
        !            54:        Ungetc(newc);
        !            55: }
        !            56: 
        !            57: private void
        !            58: gather_numeric_argument(c)
        !            59:        int     c;
        !            60: {
        !            61:        int     sign = 0;
        !            62:        static int      digited;
        !            63:        int     slow = NO;
        !            64: 
        !            65:        if (!isdigit(c) && c != '-')
        !            66:                complain((char *) 0);
        !            67:        if (arg_supplied_p == NO) {     /* if we just got here */
        !            68:                arg_count = 0;  /* start over */
        !            69:                digited = NO;
        !            70:        } else if (arg_supplied_p == YES_NODIGIT) {
        !            71:                sign = (arg_count < 0) ? -1 : 1;
        !            72:                arg_count = 0;
        !            73:        }
        !            74: 
        !            75:        if (!sign)
        !            76:                sign = (arg_count < 0) ? -1 : 1;
        !            77:        if (sign == -1)
        !            78:                arg_count = -arg_count;
        !            79:        if (c == '-') {
        !            80:                sign = -sign;
        !            81:                goto goread;
        !            82:        }
        !            83:        for (;;) {
        !            84:                if (isdigit(c)) {
        !            85:                        arg_count = (arg_count * 10) + (c - '0');
        !            86:                        digited = YES;
        !            87:                } else {
        !            88:                        if (digited)
        !            89:                                arg_supplied_p = YES;
        !            90:                        else {
        !            91:                                arg_count = 1;
        !            92:                                if (arg_supplied_p == NO)
        !            93:                                        arg_supplied_p = YES_NODIGIT;
        !            94:                        }
        !            95:                        arg_count *= sign;
        !            96:                        this_cmd = ARG_CMD;
        !            97:                        Ungetc(c);
        !            98:                        return;
        !            99:                }
        !           100: goread:                c = waitchar(&slow);
        !           101:        }
        !           102: }
        !           103: 
        !           104: void
        !           105: Digit()
        !           106: {
        !           107:        gather_numeric_argument(LastKeyStruck);
        !           108: }
        !           109: 
        !           110: void
        !           111: Digit0()
        !           112: {
        !           113:        gather_numeric_argument('0');
        !           114: }
        !           115: 
        !           116: void
        !           117: Digit1()
        !           118: {
        !           119:        gather_numeric_argument('1');
        !           120: }
        !           121: 
        !           122: void
        !           123: Digit2()
        !           124: {
        !           125:        gather_numeric_argument('2');
        !           126: }
        !           127: 
        !           128: void
        !           129: Digit3()
        !           130: {
        !           131:        gather_numeric_argument('3');
        !           132: }
        !           133: 
        !           134: void
        !           135: Digit4()
        !           136: {
        !           137:        gather_numeric_argument('4');
        !           138: }
        !           139: 
        !           140: void
        !           141: Digit5()
        !           142: {
        !           143:        gather_numeric_argument('5');
        !           144: }
        !           145: 
        !           146: void
        !           147: Digit6()
        !           148: {
        !           149:        gather_numeric_argument('6');
        !           150: }
        !           151: 
        !           152: void
        !           153: Digit7()
        !           154: {
        !           155:        gather_numeric_argument('7');
        !           156: }
        !           157: 
        !           158: void
        !           159: Digit8()
        !           160: {
        !           161:        gather_numeric_argument('8');
        !           162: }
        !           163: 
        !           164: void
        !           165: Digit9()
        !           166: {
        !           167:        gather_numeric_argument('9');
        !           168: }

unix.superglobalmegacorp.com

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