|
|
1.1 ! root 1: #include <stdio.h> ! 2: char *strchr(); ! 3: ! 4: main(argc, argv) ! 5: int argc; ! 6: char **argv; ! 7: { ! 8: extern int optind; ! 9: extern char *optarg; ! 10: register int c; ! 11: int errflg = 0; ! 12: char tmpstr[4]; ! 13: char outstr[5120]; ! 14: char *goarg; ! 15: ! 16: if(argc < 2) { ! 17: fputs("usage: getopt legal-args $*\n", stderr); ! 18: exit(2); ! 19: } ! 20: ! 21: goarg = argv[1]; ! 22: argv[1] = argv[0]; ! 23: argv++; ! 24: argc--; ! 25: ! 26: while((c=getopt(argc, argv, goarg)) != EOF) { ! 27: if(c=='?') { ! 28: errflg++; ! 29: continue; ! 30: } ! 31: ! 32: tmpstr[0] = '-'; ! 33: tmpstr[1] = c; ! 34: tmpstr[2] = ' '; ! 35: tmpstr[3] = '\0'; ! 36: ! 37: strcat(outstr, tmpstr); ! 38: ! 39: if(*(strchr(goarg, c)+1) == ':') { ! 40: strcat(outstr, optarg); ! 41: strcat(outstr, " "); ! 42: } ! 43: } ! 44: ! 45: if(errflg) { ! 46: exit(2); ! 47: } ! 48: ! 49: strcat(outstr, "-- "); ! 50: while(optind < argc) { ! 51: strcat(outstr, argv[optind++]); ! 52: strcat(outstr, " "); ! 53: } ! 54: ! 55: printf("%s\n", outstr); ! 56: exit(0); ! 57: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.