/********************************************************************** * Copyright (c) Digital Equipment Corporation 1984, 1985, 1986. * * All Rights Reserved. * * Reference "/usr/src/COPYRIGHT" for applicable restrictions. * **********************************************************************/ static char Sccsid[] = "@(#)getopt.c 3.0 4/21/86"; /* System 5 versions */ /* @(#)getopt.c 1.4 */ /* 3.0 SID # 1.1 */ #include <stdio.h> char *strchr(); main(argc, argv) int argc; char **argv; { extern int optind; extern char *optarg; register int c; int errflg = 0; char tmpstr[4]; char outstr[5120]; char *goarg; if(argc < 2) { fputs("usage: getopt legal-args $*\n", stderr); exit(2); } goarg = argv[1]; argv[1] = argv[0]; argv++; argc--; while((c=getopt(argc, argv, goarg)) != EOF) { if(c=='?') { errflg++; continue; } tmpstr[0] = '-'; tmpstr[1] = c; tmpstr[2] = ' '; tmpstr[3] = '\0'; strcat(outstr, tmpstr); if(*(strchr(goarg, c)+1) == ':') { strcat(outstr, optarg); strcat(outstr, " "); } } if(errflg) { exit(2); } strcat(outstr, "-- "); while(optind < argc) { strcat(outstr, argv[optind++]); strcat(outstr, " "); } printf("%s\n", outstr); exit(0); }