📄 argcount.c
字号:
/*************************************************************************** * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne. JOVE * * is provided to you without charge, and with no warranty. You may give * * away copies of JOVE, including sources, provided that this notice is * * included in all the files. * ***************************************************************************/#include "jove.h"#include "ctype.h"private void gather_numeric_argument proto((int)), quad_numeric_arg proto((void));int arg_supplied_p, /* NO, YES, or YES_NODIGIT */ arg_count;/* called by C-U to gather a numeric argument, either C-U's or digits, but not both */voidTimesFour(){ quad_numeric_arg();}/* This initializes the numeric argument to 1 and starts multiplying by 4 (the magic number Stallman came up with). It is an error to invoke quad_numeric_arg() interactively (via TimesFour()), because it uses the LastKeyStruck variable to know what character signals to multiply again (in the loop). */private voidquad_numeric_arg(){ int oldc = LastKeyStruck, newc, narg_count, slow; slow = NO; arg_supplied_p = YES; arg_count = 1; this_cmd = ARG_CMD; do { if ((narg_count = arg_count * 4) != 0) arg_count = narg_count; newc = waitchar(&slow); if (jisdigit(newc) || newc == '-') { arg_supplied_p = NO; gather_numeric_argument(newc); return; } } while (newc == oldc); Ungetc(newc);}private voidgather_numeric_argument(c) int c;{ int sign = 0; static bool digited; int slow = NO; if (!jisdigit(c) && c != '-') complain((char *)NULL); if (arg_supplied_p == NO) { /* if we just got here */ arg_count = 0; /* start over */ digited = NO; } else if (arg_supplied_p == YES_NODIGIT) { sign = (arg_count < 0) ? -1 : 1; arg_count = 0; } if (!sign) sign = (arg_count < 0) ? -1 : 1; if (sign == -1) arg_count = -arg_count; if (c == '-') { sign = -sign; c = waitchar(&slow); } for (;;) { if (jisdigit(c)) { arg_count = (arg_count * 10) + (c - '0'); digited = YES; } else { if (digited) arg_supplied_p = YES; else { arg_count = 1; if (arg_supplied_p == NO) arg_supplied_p = YES_NODIGIT; } arg_count *= sign; this_cmd = ARG_CMD; Ungetc(c); return; } c = waitchar(&slow); }}voidDigit(){ gather_numeric_argument(LastKeyStruck);}voidDigit0(){ gather_numeric_argument('0');}voidDigit1(){ gather_numeric_argument('1');}voidDigit2(){ gather_numeric_argument('2');}voidDigit3(){ gather_numeric_argument('3');}voidDigit4(){ gather_numeric_argument('4');}voidDigit5(){ gather_numeric_argument('5');}voidDigit6(){ gather_numeric_argument('6');}voidDigit7(){ gather_numeric_argument('7');}voidDigit8(){ gather_numeric_argument('8');}voidDigit9(){ gather_numeric_argument('9');}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -