rem: char *cp, *s, *nargv[9]; int arg_need, popcount, i;
add: int ch, exitval, n; char *cptr, *p, *term, buf[1024], tbuf[1024];  term = NULL; while ((ch = getopt(argc, argv, "T:")) != -1) switch(ch) { case 'T': term = optarg; break; case '?': default: usage(); } argc -= optind; argv += optind;  if (!term && !(term = getenv("TERM"))) fprintf(stderr, "no terminal type specified and no TERM environmental variable."); if (tgetent(tbuf, term) != 1) fprintf(stderr, "tgetent failure"); setospeed(); for (exitval = 0; (p = *argv) != NULL; ++argv) { switch (*p) { case 'c': if (!strcmp(p, "clear")) p = "cl"; break; case 'i': if (!strcmp(p, "init")) p = "is"; break; case 'l': if (!strcmp(p, "longname")) { prlongname(tbuf); continue; } break; case 'r': if (!strcmp(p, "reset")) p = "rs"; break; } cptr = buf; if (tgetstr(p, &cptr)) argv = process(p, buf, argv); else if ((n = tgetnum(p)) != -1) (void)printf("%d\n", n); else exitval = !tgetflag(p);  if (argv == NULL) break; } exit(argv ? exitval : 2); }  static void prlongname(buf) char *buf; { int savech; char *p, *savep;  for (p = buf; *p && *p != ':'; ++p) continue; savech = *(savep = p); for (*p = '\0'; p >= buf && *p != '|'; --p) continue; (void)printf("%s\n", p + 1); *savep = savech; }  static char ** process(cap, str, argv) char *cap, *str, **argv; { static const char errfew[] = "not enough arguments (%d) for capability `%s'"; static const char errmany[] = "too many arguments (%d) for capability `%s'"; static const char erresc[] = "unknown %% escape `%c' for capability `%s'"; char *cp; int arg_need, arg_rows, arg_cols;
context: process(char *cap, char *str, char **argv){	char *cp, *s, *nargv[9];	int arg_need, popcount, i;	/* Count how many values we need for this capability. */	for (cp = str, arg_need = popcount = 0; *cp != '\0'; cp++) {		if (*cp == '%') {			switch (*++cp) {			case '%':			   	cp++;				break;			case 'i':				if (popcount < 2)					popcount = 2;				break;			case 'p':				cp++;				if (isdigit(cp[1]) && popcount < cp[1] - '0')					popcount = cp[1] - '0';				break;			case 'd':			case 's':			case '0':			case '1':			case '2':			case '3':			case '4':			case '5':			case '6':			case '7':			case '8':			case '9':			case '.':			case '+':				arg_need++;				break;			default:				break;			}		}	}	arg_need = MAX(arg_need, popcount);	if (arg_need > 9)		fprintf(stderr, "too many arguments (%d) for capability `%s'",		    arg_need, cap);		for (i = 0; i < arg_need; i++) {		long l;		if (argv[i] == NULL)			fprintf(stderr, "not enough arguments (%d) for capability `%s'",			    arg_need, cap);		/* convert ascii representation of numbers to longs */		if (isdigit(argv[i][0]) && (l = strtol(argv[i], &cp, 10)) >= 0		    && l < LONG_MAX && *cp == '\0')			nargv[i] = (char *)l;		else			nargv[i] = argv[i];	}	s = tparm(str, nargv[0], nargv[1], nargv[2], nargv[3],	    nargv[4], nargv[5], nargv[6], nargv[7], nargv[8]);	putp(s);	fflush(stdout);	return (argv + arg_need);}