void #line 504 "./cwebdir/comm-w2c.ch" scan_args P1H(void) #line 1257 "./cwebdir/common.w" { char*dot_pos; char*name_pos; register char*s; boolean found_web= 0,found_change= 0,found_out= 0; boolean flag_change; while(--argc> 0){ if((**(++argv)=='-'||**argv=='+')&&*(*argv+1))/*76:*/ #line 522 "./cwebdir/comm-w2c.ch" { if(strcmp("-help",*argv)==0||strcmp("--help",*argv)==0) /*84:*/ #line 599 "./cwebdir/comm-w2c.ch" usagehelp(program==ctangle?CTANGLEHELP:CWEAVEHELP); /*:84*/ #line 525 "./cwebdir/comm-w2c.ch" ; if(strcmp("-version",*argv)==0||strcmp("--version",*argv)==0) /*85:*/ #line 608 "./cwebdir/comm-w2c.ch" printversionandexit((program==ctangle?ctangle_banner:cweave_banner), "Silvio Levy and Donald E. Knuth",NULL); /*:85*/ #line 527 "./cwebdir/comm-w2c.ch" ; #line 1346 "./cwebdir/common.w" if(**argv=='-')flag_change= 0; #line 533 "./cwebdir/comm-w2c.ch" else flag_change= 1; if(*(*argv+1)=='d') if(sscanf(*argv+2,"%u",&kpathsea_debug)!=1)/*77:*/ #line 1352 "./cwebdir/common.w" { #line 556 "./cwebdir/comm-w2c.ch" if(program==ctangle){ fprintf(stderr,"ctangle: Need one to three file arguments.\n"); usage("ctangle"); }else{ fprintf(stderr,"cweave: Need one to three file arguments.\n"); usage("cweave"); } #line 1362 "./cwebdir/common.w" } /*:77*/ #line 535 "./cwebdir/comm-w2c.ch" ; #line 1348 "./cwebdir/common.w" for(dot_pos= *argv+1;*dot_pos> '\0';dot_pos++) #line 541 "./cwebdir/comm-w2c.ch" flags[(unsigned char)*dot_pos]= flag_change; #line 1350 "./cwebdir/common.w" } /*:76*/ #line 1266 "./cwebdir/common.w" else{ s= name_pos= *argv;dot_pos= NULL; while(*s){ if(*s=='.')dot_pos= s++; else if(*s=='/')dot_pos= NULL,name_pos= ++s; else s++; } if(!found_web)/*73:*/ #line 1292 "./cwebdir/common.w" { if(s-*argv> max_file_name_length-5) /*78:*/ #line 1364 "./cwebdir/common.w" fatal("! Filename too long\n",*argv); /*:78*/ #line 1295 "./cwebdir/common.w" ; if(dot_pos==NULL) sprintf(web_file_name,"%s.w",*argv); else{ strcpy(web_file_name,*argv); *dot_pos= 0; } #line 1303 "./cwebdir/common.w" sprintf(tex_file_name,"%s.tex",name_pos); sprintf(idx_file_name,"%s.idx",name_pos); sprintf(scn_file_name,"%s.scn",name_pos); sprintf(C_file_name,"%s.c",name_pos); found_web= 1; } /*:73*/ #line 1275 "./cwebdir/common.w" else if(!found_change)/*74:*/ #line 1310 "./cwebdir/common.w" { if(strcmp(*argv,"-")==0)found_change= -1; else{ if(s-*argv> max_file_name_length-4) /*78:*/ #line 1364 "./cwebdir/common.w" fatal("! Filename too long\n",*argv); /*:78*/ #line 1315 "./cwebdir/common.w" ; if(dot_pos==NULL) sprintf(change_file_name,"%s.ch",*argv); else strcpy(change_file_name,*argv); found_change= 1; } } /*:74*/ #line 1276 "./cwebdir/common.w" else if(!found_out)/*75:*/ #line 1323 "./cwebdir/common.w" { if(s-*argv> max_file_name_length-5) /*78:*/ #line 1364 "./cwebdir/common.w" fatal("! Filename too long\n",*argv); /*:78*/ #line 1326 "./cwebdir/common.w" ; if(dot_pos==NULL){ sprintf(tex_file_name,"%s.tex",*argv); sprintf(idx_file_name,"%s.idx",*argv); sprintf(scn_file_name,"%s.scn",*argv); sprintf(C_file_name,"%s.c",*argv); }else{ strcpy(tex_file_name,*argv); strcpy(C_file_name,*argv); if(flags['x']){ *dot_pos= 0; sprintf(idx_file_name,"%s.idx",*argv); sprintf(scn_file_name,"%s.scn",*argv); } } found_out= 1; } #line 522 "./cwebdir/comm-w2c.ch" /*:75*/ #line 1277 "./cwebdir/common.w" else/*77:*/ #line 1352 "./cwebdir/common.w" { #line 556 "./cwebdir/comm-w2c.ch" if(program==ctangle){ fprintf(stderr,"ctangle: Need one to three file arguments.\n"); usage("ctangle"); }else{ fprintf(stderr,"cweave: Need one to three file arguments.\n"); usage("cweave"); } #line 1362 "./cwebdir/common.w" } /*:77*/ #line 1278 "./cwebdir/common.w" ; } } if(!found_web)/*77:*/ #line 1352 "./cwebdir/common.w" { #line 556 "./cwebdir/comm-w2c.ch" if(program==ctangle){ fprintf(stderr,"ctangle: Need one to three file arguments.\n"); usage("ctangle"); }else{ fprintf(stderr,"cweave: Need one to three file arguments.\n"); usage("cweave"); } #line 1362 "./cwebdir/common.w" } /*:77*/ #line 1281 "./cwebdir/common.w" ; if(found_change<=0)strcpy(change_file_name,"/dev/null"); }
void parsearguments ( void ) { #define noptions ( 4 ) getoptstruct longoptions[noptions + 1] ; integer getoptreturnval ; cinttype optionindex ; integer currentoption ; currentoption = 0 ; longoptions [currentoption ].name = "help" ; longoptions [currentoption ].hasarg = 0 ; longoptions [currentoption ].flag = 0 ; longoptions [currentoption ].val = 0 ; currentoption = currentoption + 1 ; longoptions [currentoption ].name = "version" ; longoptions [currentoption ].hasarg = 0 ; longoptions [currentoption ].flag = 0 ; longoptions [currentoption ].val = 0 ; currentoption = currentoption + 1 ; longoptions [currentoption ].name = "mnemonics" ; longoptions [currentoption ].hasarg = 0 ; longoptions [currentoption ].flag = addressof ( wantsmnemonics ) ; longoptions [currentoption ].val = 1 ; currentoption = currentoption + 1 ; longoptions [currentoption ].name = "images" ; longoptions [currentoption ].hasarg = 0 ; longoptions [currentoption ].flag = addressof ( wantspixels ) ; longoptions [currentoption ].val = 1 ; currentoption = currentoption + 1 ; longoptions [currentoption ].name = 0 ; longoptions [currentoption ].hasarg = 0 ; longoptions [currentoption ].flag = 0 ; longoptions [currentoption ].val = 0 ; do { getoptreturnval = getoptlongonly ( argc , argv , "" , longoptions , addressof ( optionindex ) ) ; if ( getoptreturnval == -1 ) { ; } else if ( getoptreturnval == 63 ) { usage ( "gftype" ) ; } else if ( ( strcmp ( longoptions [optionindex ].name , "help" ) == 0 ) ) { usagehelp ( GFTYPEHELP , nil ) ; } else if ( ( strcmp ( longoptions [optionindex ].name , "version" ) == 0 ) ) { printversionandexit ( "This is GFtype, Version 3.1" , nil , "D.R. Fuchs" , nil ) ; } } while ( ! ( getoptreturnval == -1 ) ) ; if ( ( optind + 1 != argc ) ) { fprintf ( stderr , "%s%s\n", "gftype" , ": Need exactly one file argument." ) ; usage ( "gftype" ) ; } }
void parsearguments ( void ) { #define noptions ( 4 ) getoptstruct longoptions[noptions + 1] ; integer getoptreturnval ; cinttype optionindex ; integer currentoption ; verbose = false ; charcodeformat = charcodedefault ; currentoption = 0 ; longoptions [currentoption ].name = "help" ; longoptions [currentoption ].hasarg = 0 ; longoptions [currentoption ].flag = 0 ; longoptions [currentoption ].val = 0 ; currentoption = currentoption + 1 ; longoptions [currentoption ].name = "version" ; longoptions [currentoption ].hasarg = 0 ; longoptions [currentoption ].flag = 0 ; longoptions [currentoption ].val = 0 ; currentoption = currentoption + 1 ; longoptions [currentoption ].name = "verbose" ; longoptions [currentoption ].hasarg = 0 ; longoptions [currentoption ].flag = addressof ( verbose ) ; longoptions [currentoption ].val = 1 ; currentoption = currentoption + 1 ; longoptions [currentoption ].name = "charcode-format" ; longoptions [currentoption ].hasarg = 1 ; longoptions [currentoption ].flag = 0 ; longoptions [currentoption ].val = 0 ; currentoption = currentoption + 1 ; longoptions [currentoption ].name = 0 ; longoptions [currentoption ].hasarg = 0 ; longoptions [currentoption ].flag = 0 ; longoptions [currentoption ].val = 0 ; do { getoptreturnval = getoptlongonly ( argc , argv , "" , longoptions , addressof ( optionindex ) ) ; if ( getoptreturnval == -1 ) { ; } else if ( getoptreturnval == 63 ) { usage ( "tftopl" ) ; } else if ( ( strcmp ( longoptions [optionindex ].name , "help" ) == 0 ) ) { usagehelp ( TFTOPLHELP , nil ) ; } else if ( ( strcmp ( longoptions [optionindex ].name , "version" ) == 0 ) ) { printversionandexit ( "This is TFtoPL, Version 3.3" , nil , "D.E. Knuth" , nil ) ; } else if ( ( strcmp ( longoptions [optionindex ].name , "charcode-format" ) == 0 ) ) { if ( strcmp ( optarg , "ascii" ) == 0 ) charcodeformat = charcodeascii ; else if ( strcmp ( optarg , "octal" ) == 0 ) charcodeformat = charcodeoctal ; else fprintf ( stderr , "%s%s%c\n", "Bad character code format " , stringcast ( optarg ) , '.' ) ; } } while ( ! ( getoptreturnval == -1 ) ) ; if ( ( optind + 1 != argc ) && ( optind + 2 != argc ) ) { fprintf ( stderr , "%s%s\n", "tftopl" , ": Need one or two file arguments." ) ; usage ( "tftopl" ) ; } tfmname = cmdline ( optind ) ; }
int main (int argc, string *argv) { int getopt_return_val; int option_index = 0; name_program = xbasename(argv[0]); if (!strcmp(name_program, "ofm2opl") || !strcmp(name_program, "OFM2OPL.EXE")) { program = PROG_OFM2OPL; name_help = OFM2OPLHELP; name_program = "ofm2opl"; name_msg = "This is ofm2opl, Version 2.0"; no_files = 2; files[0] = &name_ofm; files[1] = &name_opl; suffixes[0] = "ofm"; suffixes[1] = "opl"; full_suffixes[0] = ".ofm"; full_suffixes[1] = ".opl"; } else if (!strcmp(name_program, "opl2ofm") || !strcmp(name_program, "OPL2OFM.EXE")) { program = PROG_OPL2OFM; name_help = OPL2OFMHELP; name_program = "opl2ofm"; name_msg = "This is opl2ofm, Version 2.0"; no_files = 2; files[0] = &name_opl; files[1] = &name_ofm; suffixes[0] = "opl"; suffixes[1] = "ofm"; full_suffixes[0] = ".opl"; full_suffixes[1] = ".ofm"; } else if (!strcmp(name_program, "ovp2ovf") || !strcmp(name_program, "OVP2OVF.EXE")) { program = PROG_OVP2OVF; name_help = OVP2OVFHELP; name_program = "ovp2ovf"; name_msg = "This is ovp2ovf, Version 2.0"; no_files = 3; files[0] = &name_ovp; files[1] = &name_ovf; files[2] = &name_ofm; suffixes[0] = "ovp"; suffixes[1] = "ovf"; suffixes[2] = "ofm"; full_suffixes[0] = ".ovp"; full_suffixes[1] = ".ovf"; full_suffixes[2] = ".ofm"; } else if (!strcmp(name_program, "ovf2ovp") || !strcmp(name_program, "OVF2OVP.EXE")) { program = PROG_OVF2OVP; name_help = OVF2OVPHELP; name_program = "ovf2ovp"; name_msg = "This is ovf2ovp, Version 2.0"; no_files = 3; files[0] = &name_ovf; files[1] = &name_ofm; files[2] = &name_ovp; suffixes[0] = "ovf"; suffixes[1] = "ofm"; suffixes[2] = "ovp"; full_suffixes[0] = ".ovf"; full_suffixes[1] = ".ofm"; full_suffixes[2] = ".ovp"; } else { fprintf(stderr , "Unrecognized program: %s\n", name_program); fprintf(stderr , "This binary supports ofm2opl, opl2ofm, ovf2ovp, and ovp2ovf\n"); exit(1); } kpse_set_program_name(name_program, NULL); kpse_init_prog(uppercasify(name_program), 0, nil, nil); do { getopt_return_val = getopt_long_only(argc, argv, "", long_options, &option_index) ; if (getopt_return_val == -1) { ; } else if ( getopt_return_val == 63 ) { usage (name_program); } else if (!strcmp(long_options[option_index].name, "help")) { usagehelp (name_help, NULL); } else if (!strcmp(long_options[option_index ].name, "version")) { printversionandexit(name_msg, nil, "J. Plaice, Y. Haralambous, D.E. Knuth", nil); } else if (!strcmp(long_options[option_index ].name, "char-format")) { if (!strcmp(optarg, "ascii")) char_format = CHAR_CODE_ASCII; else if (!strcmp(optarg, "num")) char_format = CHAR_CODE_NUM; else warning_s("Bad character code format (%s)", optarg); } else if (!strcmp(long_options[option_index ].name, "num-format")) { if (!strcmp(optarg, "hex")) num_format = NUM_CODE_HEX; else if (!strcmp(optarg, "octal")) num_format = NUM_CODE_OCTAL; else warning_s("Bad number code format (%s)", optarg); } else if (!strcmp(long_options[option_index ].name, "text-format")) { if (!strcmp(optarg, "upper")) text_format = TEXT_CODE_UPPER; else if (!strcmp(optarg, "mixed")) text_format = TEXT_CODE_MIXED; else warning_s("Bad text code format (%s)", optarg); } } while (getopt_return_val != -1); if (((argc-optind) > no_files) || ((argc-optind) < 1)) { fprintf(stderr , "%s: %s\n", name_program, no_files == 2 ? "Need one or two file arguments." : "Need one to three file arguments."); usage (name_program); } *(files[0]) = extend_filename(cmdline(optind) , suffixes[0]); if (optind+2 <= argc) { *(files[1]) = extend_filename(cmdline(optind+1) , suffixes[1]); if (no_files == 3) { if (optind+3 <= argc) { *(files[2]) = extend_filename(cmdline(optind+2) , suffixes[2]); } else if (program == PROG_OVP2OVF) { *(files[2]) = extend_filename(cmdline(optind+1), suffixes[2]); } } } else if (program != PROG_OFM2OPL) { *(files[1]) = basenamechangesuffix(*(files[0]), full_suffixes[0], full_suffixes[1]); if ((no_files == 3) && (program == PROG_OVP2OVF)) { *(files[2]) = basenamechangesuffix(*(files[0]), full_suffixes[0], full_suffixes[2]); } } switch(program) { case PROG_OFM2OPL: { file_ofm = kpse_open_file(name_ofm, kpse_ofm_format); read_in_whole(&ofm, &length_ofm, file_ofm, name_ofm); (void)fclose(file_ofm); if (name_opl==NULL) file_opl = stdout; else rewrite(file_opl, name_opl); file_output = file_opl; parse_ofm(FALSE); break; } case PROG_OVF2OVP: { file_ovf = kpse_open_file(name_ovf, kpse_ovf_format); read_in_whole(&ovf, &length_ovf, file_ovf, name_ovf); (void)fclose(file_ovf); file_ofm = kpse_open_file(name_ofm, kpse_ofm_format); read_in_whole(&ofm, &length_ofm, file_ofm, name_ofm); (void)fclose(file_ofm); if (name_ovp==NULL) file_ovp = stdout; else rewrite(file_ovp, name_ovp); file_output = file_ovp; parse_ofm(TRUE); break; } case PROG_OPL2OFM: { file_opl = kpse_open_file(name_opl, kpse_opl_format); rewritebin(file_ofm, name_ofm); init_tables(); yyin = file_opl; (void)yyparse(); output_ofm_file(); (void)fclose(file_ofm); break; } case PROG_OVP2OVF: { file_ovp = kpse_open_file(name_ovp, kpse_ovp_format); rewritebin(file_ovf, name_ovf); rewritebin(file_ofm, name_ofm); init_tables(); yyin = file_ovp; (void)yyparse(); output_ofm_file(); /*(void)fclose(file_ofm);*/ output_ovf_file(); (void)fclose(file_ovf); break; } default: {exit(1);} } exit(0); }