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: #ifdef MAC
  12: #	undef private
  13: #	define private
  14: #endif
  15: 
  16: #ifdef  LINT_ARGS
  17: private void
  18:     gather_numeric_argument(int),
  19:     quad_numeric_arg(void);
  20: #else
  21: private void
  22:     gather_numeric_argument(),
  23:     quad_numeric_arg();
  24: #endif
  25: 
  26: #ifdef MAC
  27: #	undef private
  28: #	define private static
  29: #endif
  30: 
  31: private int arg_supplied_p,
  32:         arg_count;
  33: 
  34: int
  35: arg_type()
  36: {
  37:     return arg_supplied_p;
  38: }
  39: 
  40: void
  41: set_is_an_arg(there_is)
  42: {
  43:     arg_supplied_p = there_is;
  44: }
  45: 
  46: void
  47: set_arg_value(n)
  48: {
  49:     arg_supplied_p = YES;
  50:     arg_count = n;
  51: }
  52: 
  53: void
  54: negate_arg_value()
  55: {
  56:     arg_count = -arg_count;
  57: }
  58: 
  59: void
  60: clr_arg_value()
  61: {
  62:     arg_supplied_p = NO;
  63:     arg_count = 1;
  64: }
  65: 
  66: /* return whether there is currently a numeric argument */
  67: 
  68: int
  69: is_an_arg()
  70: {
  71:     return (arg_supplied_p != NO);
  72: }
  73: 
  74: /* return the numeric argument */
  75: 
  76: int
  77: arg_value()
  78: {
  79:     return arg_count;
  80: }
  81: 
  82: /* called by C-U to gather a numeric argument, either C-U's or digits,
  83:    but not both */
  84: 
  85: void
  86: TimesFour()
  87: {
  88:     quad_numeric_arg();
  89: }
  90: 
  91: /* This initializes the numeric argument to 1 and starts multiplying
  92:    by 4 (the magic number Stallman came up with).  It is an error to
  93:    invoke quad_numeric_arg() interactively (via TimesFour()), because
  94:    it uses the LastKeyStruck variable to know what character signals
  95:    to multiply again (in the loop). */
  96: private void
  97: quad_numeric_arg()
  98: {
  99:     int oldc = LastKeyStruck,
 100:         newc,
 101:         narg_count,
 102:         slow;
 103: 
 104:     slow = 0;
 105:     arg_supplied_p = YES;
 106:     arg_count = 1;
 107:     this_cmd = ARG_CMD;
 108:     do {
 109:         if ((narg_count = arg_count * 4) != 0)
 110:             arg_count = narg_count;
 111:         if (!slow)
 112:             newc = waitchar(&slow);
 113:         else
 114:             newc = getch();
 115:         if (isdigit(newc) || newc == '-') {
 116:              arg_supplied_p = NO;
 117:              gather_numeric_argument(newc);
 118:              return;
 119:         }
 120:         if (slow)
 121:             message(key_strokes);
 122:     } while (newc == oldc);
 123:     Ungetc(newc);
 124: }
 125: 
 126: private void
 127: gather_numeric_argument(c)
 128: {
 129:     int sign = 0;
 130:     static int  digited;
 131:     int slow = 0;
 132: 
 133:     if (!isdigit(c) && c != '-')
 134:         complain((char *) 0);
 135:     if (arg_supplied_p == NO) { /* if we just got here */
 136:         arg_count = 0;  /* start over */
 137:         digited = NO;
 138:     } else if (arg_supplied_p == YES_NODIGIT) {
 139:         sign = (arg_count < 0) ? -1 : 1;
 140:         arg_count = 0;
 141:     }
 142: 
 143:     if (!sign)
 144:         sign = (arg_count < 0) ? -1 : 1;
 145:     if (sign == -1)
 146:         arg_count = -arg_count;
 147:     if (c == '-') {
 148:         sign = -sign;
 149:         goto goread;
 150:     }
 151:     for (;;) {
 152:         if (slow)
 153:             message(key_strokes);
 154:         if (isdigit(c)) {
 155:             arg_count = (arg_count * 10) + (c - '0');
 156:             digited = YES;
 157:         } else {
 158:             if (digited)
 159:                 arg_supplied_p = YES;
 160:             else {
 161:                 arg_count = 1;
 162:                 if (arg_supplied_p == NO)
 163:                     arg_supplied_p = YES_NODIGIT;
 164:             }
 165:             arg_count *= sign;
 166:             this_cmd = ARG_CMD;
 167:             Ungetc(c);
 168:             return;
 169:         }
 170: goread:     if (!slow)
 171:             c = waitchar(&slow);
 172:         else {
 173:             add_mess(NullStr);
 174:             c = getch();
 175:         }
 176:     }
 177: }
 178: 
 179: void
 180: Digit()
 181: {
 182:     gather_numeric_argument(LastKeyStruck);
 183: }
 184: 
 185: void
 186: Digit0()
 187: {
 188:     gather_numeric_argument('0');
 189: }
 190: 
 191: void
 192: Digit1()
 193: {
 194:     gather_numeric_argument('1');
 195: }
 196: 
 197: void
 198: Digit2()
 199: {
 200:     gather_numeric_argument('2');
 201: }
 202: 
 203: void
 204: Digit3()
 205: {
 206:     gather_numeric_argument('3');
 207: }
 208: 
 209: void
 210: Digit4()
 211: {
 212:     gather_numeric_argument('4');
 213: }
 214: 
 215: void
 216: Digit5()
 217: {
 218:     gather_numeric_argument('5');
 219: }
 220: 
 221: void
 222: Digit6()
 223: {
 224:     gather_numeric_argument('6');
 225: }
 226: 
 227: void
 228: Digit7()
 229: {
 230:     gather_numeric_argument('7');
 231: }
 232: 
 233: void
 234: Digit8()
 235: {
 236:     gather_numeric_argument('8');
 237: }
 238: 
 239: void
 240: Digit9()
 241: {
 242:     gather_numeric_argument('9');
 243: }

Defined functions

Digit defined in line 179; used 4 times
Digit0 defined in line 185; used 4 times
Digit1 defined in line 191; used 4 times
Digit2 defined in line 197; used 4 times
Digit3 defined in line 203; used 4 times
Digit4 defined in line 209; used 4 times
Digit5 defined in line 215; used 4 times
Digit6 defined in line 221; used 4 times
Digit7 defined in line 227; used 4 times
Digit8 defined in line 233; used 4 times
Digit9 defined in line 239; used 4 times
TimesFour defined in line 85; used 4 times
arg_type defined in line 34; used 4 times
gather_numeric_argument defined in line 126; used 14 times
quad_numeric_arg defined in line 96; used 3 times
set_is_an_arg defined in line 40; used 3 times

Defined variables

arg_count defined in line 32; used 18 times
arg_supplied_p defined in line 31; used 12 times
private defined in line 126; never used

Defined macros

private defined in line 28; used 5 times
Last modified: 1988-03-15
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 347
Valid CSS Valid XHTML 1.0 Strict