}   restdir = firstdir = 0;  while ((c = getopt(argc, argv, "deEcCfFGgIinlLprR:s:uv:Vw:A:B:1T")) != EOF) switch (c) { case 'd': compare = C_DIFFERENCE; break;  case 'e': initdump |= 1; break;  case 'E': initdump |= 2; break;  case 'c': compare = C_COMMON; break;  case 'C': outform = F_TERMCAP; tversion = "BSD"; if (sortmode == S_DEFAULT) sortmode = S_TERMCAP; break;  case 'f': formatted = TRUE; break;  case 'G': numbers = 1; break;  case 'g': numbers = -1; break;  case 'F': filecompare = TRUE; break;  case 'I': outform = F_TERMINFO; if (sortmode == S_DEFAULT) sortmode = S_VARIABLE; tversion = 0; break;  case 'i': init_analyze = TRUE; break;  case 'l': outform = F_TERMINFO; break;  case 'L': outform = F_VARIABLE; if (sortmode == S_DEFAULT) sortmode = S_VARIABLE; break;  case 'n': compare = C_NAND; break;  case 'p': ignorepads = TRUE; break;  case 'r': tversion = 0; limited = FALSE; break;  case 'R': tversion = optarg; break;  case 's': if (*optarg == 'd') sortmode = S_NOSORT; else if (*optarg == 'i') sortmode = S_TERMINFO; else if (*optarg == 'l') sortmode = S_VARIABLE; else if (*optarg == 'c') sortmode = S_TERMCAP; else { (void) fprintf(stderr, "infocmp: unknown sort mode\n"); return EXIT_FAILURE; } break;  case 'u': compare = C_USEALL; break;  case 'v': itrace = atoi(optarg); _nc_tracing = (1 << itrace) - 1; break;  case 'V': (void) fputs(NCURSES_VERSION, stdout); putchar('\n'); ExitProgram(EXIT_SUCCESS);  case 'w': mwidth = atoi(optarg); break;  case 'A': firstdir = optarg; break;  case 'B': restdir = optarg; break;  case '1': mwidth = 0; break;  case 'T': limited = FALSE; break; default: usage();
} break;  case 'u': compare = C_USEALL; break;  case 'v': itrace = atoi(optarg); set_trace_level(itrace); break;  case 'V': (void) fputs(NCURSES_VERSION, stdout); putchar('\n'); ExitProgram(EXIT_SUCCESS);  case 'w': mwidth = atoi(optarg); break;  case 'A': firstdir = optarg; break;  case 'B': restdir = optarg; break;  case '1': mwidth = 0; break;  case 'T': limited = FALSE; break; default: usage(); }   if (sortmode == S_DEFAULT) sortmode = S_TERMINFO;   dump_init(tversion, outform, sortmode, mwidth, itrace, formatted);   if (optind >= argc) argv[argc++] = terminal;   if (compare != C_DEFAULT && optind >= argc - 1) argv[argc++] = terminal;   if (argc - optind == 2 && compare == C_DEFAULT) compare = C_DIFFERENCE;  if (!filecompare) {  termcount = 0; for (; optind < argc; optind++) { if (termcount >= MAXTERMS) { (void) fprintf(stderr, "infocmp: too many terminal type arguments\n"); return EXIT_FAILURE; } else { const char *directory = termcount ? restdir : firstdir; int status;  tname[termcount] = argv[optind];  if (directory) { (void) sprintf(tfile[termcount], "%s/%c/%s", directory, *argv[optind], argv[optind]); if (itrace) (void) fprintf(stderr, "infocmp: reading entry %s from file %s\n", argv[optind], tfile[termcount]);  status = _nc_read_file_entry(tfile[termcount], &term[termcount]); } else { if (itrace) (void) fprintf(stderr, "infocmp: reading entry %s from system directories %s\n", argv[optind], tname[termcount]);  status = _nc_read_entry(tname[termcount], tfile[termcount], &term[termcount]); directory = TERMINFO;
int main(int argc, char *argv[]){	char *terminal, *firstdir, *restdir;	/* Avoid "local data >32k" error with mwcc */	/* Also avoid overflowing smaller stacks on systems like AmigaOS */	path *tfile = malloc(sizeof(path)*MAXTERMS);	int c, i, len;	bool formatted = FALSE;	bool filecompare = FALSE;	int initdump = 0;	bool init_analyze = FALSE;	bool limited = TRUE;	if ((terminal = getenv("TERM")) == NULL)	{		(void) fprintf(stderr,			"infocmp: environment variable TERM not set\n");		return EXIT_FAILURE;	}	/* where is the terminfo database location going to default to? */	restdir = firstdir = 0;	while ((c = getopt(argc, argv, "deEcCfFGgIinlLprR:s:uv:Vw:A:B:1T")) != EOF)		switch (c)		{		case 'd':			compare = C_DIFFERENCE;			break;		case 'e':			initdump |= 1;			break;		case 'E':			initdump |= 2;			break;		case 'c':			compare = C_COMMON;			break;		case 'C':			outform = F_TERMCAP;			tversion = "BSD";			if (sortmode == S_DEFAULT)			    sortmode = S_TERMCAP;			break;		case 'f':			formatted = TRUE;			break;		case 'G':			numbers = 1;			break;		case 'g':			numbers = -1;			break;		case 'F':			filecompare = TRUE;			break;		case 'I':			outform = F_TERMINFO;			if (sortmode == S_DEFAULT)			    sortmode = S_VARIABLE;			tversion = 0;			break;		case 'i':			init_analyze = TRUE;			break;		case 'l':			outform = F_TERMINFO;			break;		case 'L':			outform = F_VARIABLE;			if (sortmode == S_DEFAULT)			    sortmode = S_VARIABLE;			break;		case 'n':			compare = C_NAND;			break;		case 'p':			ignorepads = TRUE;			break;		case 'r':			tversion = 0;			limited = FALSE;			break;		case 'R':			tversion = optarg;			break;		case 's':			if (*optarg == 'd')				sortmode = S_NOSORT;			else if (*optarg == 'i')				sortmode = S_TERMINFO;			else if (*optarg == 'l')				sortmode = S_VARIABLE;			else if (*optarg == 'c')				sortmode = S_TERMCAP;			else			{				(void) fprintf(stderr,					       "infocmp: unknown sort mode\n");				return EXIT_FAILURE;			}			break;		case 'u':			compare = C_USEALL;			break;		case 'v':			itrace = atoi(optarg);			_nc_tracing = (1 << itrace) - 1;			break;		case 'V':			(void) fputs(NCURSES_VERSION, stdout);			putchar('\n');			ExitProgram(EXIT_SUCCESS);		case 'w':			mwidth = atoi(optarg);			break;		case 'A':			firstdir = optarg;			break;		case 'B':			restdir = optarg;			break;		case '1':			mwidth = 0;			break;		case 'T':			limited = FALSE;			break;		default:			usage();		}	/* by default, sort by terminfo name */	if (sortmode == S_DEFAULT)		sortmode = S_TERMINFO;	/* set up for display */	dump_init(tversion, outform, sortmode, mwidth, itrace, formatted);	/* make sure we have at least one terminal name to work with */	if (optind >= argc)		argv[argc++] = terminal;	/* if user is after a comparison, make sure we have two entries */	if (compare != C_DEFAULT && optind >= argc - 1)		argv[argc++] = terminal;	/* exactly two terminal names with no options means do -d */	if (argc - optind == 2 && compare == C_DEFAULT)		compare = C_DIFFERENCE;	if (!filecompare)	{	    /* grab the entries */	    termcount = 0;	    for (; optind < argc; optind++)	    {		if (termcount >= MAXTERMS)		{		    (void) fprintf(stderr,			   "infocmp: too many terminal type arguments\n");		    return EXIT_FAILURE;		}		else		{		    const char	*directory = termcount ? restdir : firstdir;		    int		status;		    tname[termcount] = argv[optind];		    if (directory)		    {			(void) sprintf(tfile[termcount], "%s/%c/%s",				       directory,				       *argv[optind], argv[optind]);			if (itrace)			    (void) fprintf(stderr,					   "infocmp: reading entry %s from file %s\n",					   argv[optind], tfile[termcount]);			status = _nc_read_file_entry(tfile[termcount],						     &term[termcount]);		    }		    else		    {			if (itrace)			    (void) fprintf(stderr,					   "infocmp: reading entry %s from system directories %s\n",					   argv[optind], tname[termcount]);			status = _nc_read_entry(tname[termcount],						tfile[termcount],						&term[termcount]);			directory = TERMINFO;	/* for error message */		    }		    if (status <= 0)		    {			(void) fprintf(stderr,				       "infocmp: couldn't open terminfo file %s.\n",				       tfile[termcount]);			return EXIT_FAILURE;		    }		    termcount++;		}	    }#if NCURSES_XNAMES	    if (termcount > 1)		_nc_align_termtype(&term[0], &term[1]);#endif	    /* dump as C initializer for the terminal type */	    if (initdump)	    {		if (initdump & 1)		    dump_termtype();		if (initdump & 2)		    dump_initializers();		ExitProgram(EXIT_SUCCESS);	    }	    /* analyze the init strings */	    if (init_analyze)	    {#undef CUR#define CUR	term[0].		analyze_string("is1", init_1string, &term[0]);		analyze_string("is2", init_2string, &term[0]);		analyze_string("is3", init_3string, &term[0]);		analyze_string("rs1", reset_1string, &term[0]);		analyze_string("rs2", reset_2string, &term[0]);		analyze_string("rs3", reset_3string, &term[0]);		analyze_string("smcup", enter_ca_mode, &term[0]);		analyze_string("rmcup", exit_ca_mode, &term[0]);#undef CUR		ExitProgram(EXIT_SUCCESS);	    }	    /*	     * Here's where the real work gets done	     */	    switch (compare)	    {	    case C_DEFAULT:		if (itrace)		    (void) fprintf(stderr,				   "infocmp: about to dump %s\n",				   tname[0]);		(void) printf("#\tReconstructed via infocmp from file: %s\n",			      tfile[0]);		len = dump_entry(&term[0], limited, numbers, NULL);		putchar('\n');		if (itrace)		    (void)fprintf(stderr, "infocmp: length %d\n", len);		break;	    case C_DIFFERENCE:		if (itrace)		    (void)fprintf(stderr, "infocmp: dumping differences\n");		(void) printf("comparing %s to %s.\n", tname[0], tname[1]);		compare_entry(compare_predicate, term);		break;	    case C_COMMON:		if (itrace)		    (void) fprintf(stderr,				   "infocmp: dumping common capabilities\n");		(void) printf("comparing %s to %s.\n", tname[0], tname[1]);		compare_entry(compare_predicate, term);		break;	    case C_NAND:		if (itrace)		    (void) fprintf(stderr,				   "infocmp: dumping differences\n");		(void) printf("comparing %s to %s.\n", tname[0], tname[1]);		compare_entry(compare_predicate, term);		break;	    case C_USEALL:		if (itrace)		    (void) fprintf(stderr, "infocmp: dumping use entry\n");		len = dump_entry(&term[0], limited, numbers, use_predicate);		for (i = 1; i < termcount; i++)		    len += dump_uses(tname[i], !(outform==F_TERMCAP || outform==F_TCONVERR));		putchar('\n');		if (itrace)		    (void)fprintf(stderr, "infocmp: length %d\n", len);		break;	    }	}	else if (compare == C_USEALL)	    (void) fprintf(stderr, "Sorry, -u doesn't work with -F\n");	else if (compare == C_DEFAULT)	    (void) fprintf(stderr, "Use `tic -[CI] <file>' for this.\n");	else if (argc - optind != 2)	    (void) fprintf(stderr,		"File comparison needs exactly two file arguments.\n");	else	    file_comparison(argc-optind, argv+optind);	ExitProgram(EXIT_SUCCESS);}