NetBSD/usr.bin/getopt/getopt.c

41 lines
780 B
C
Raw Normal View History

1997-10-19 06:13:39 +04:00
/* $NetBSD: getopt.c,v 1.4 1997/10/19 02:16:59 lukem Exp $ */
1997-01-09 23:18:21 +03:00
1997-10-19 06:13:39 +04:00
#include <sys/cdefs.h>
#ifndef lint
1997-10-19 06:13:39 +04:00
__RCSID("$NetBSD: getopt.c,v 1.4 1997/10/19 02:16:59 lukem Exp $");
#endif /* not lint */
1997-10-19 06:13:39 +04:00
#include <errno.h>
1993-06-21 16:43:56 +04:00
#include <stdio.h>
1997-10-19 06:13:39 +04:00
#include <stdlib.h>
1993-06-21 16:43:56 +04:00
1997-10-19 06:13:39 +04:00
int main __P((int, char **));
int
1993-06-21 16:43:56 +04:00
main(argc, argv)
1997-10-19 06:13:39 +04:00
int argc;
char *argv[];
1993-06-21 16:43:56 +04:00
{
int c;
int status = 0;
optind = 2; /* Past the program name and the option letters. */
1997-10-19 06:13:39 +04:00
while ((c = getopt(argc, argv, argv[1])) != -1)
1993-06-21 16:43:56 +04:00
switch (c) {
case '?':
status = 1; /* getopt routine gave message */
break;
default:
if (optarg != NULL)
printf(" -%c %s", c, optarg);
else
printf(" -%c", c);
break;
}
printf(" --");
for (; optind < argc; optind++)
printf(" %s", argv[optind]);
printf("\n");
exit(status);
}