NetBSD/usr.bin/getopt/getopt.c

41 lines
780 B
C
Raw Normal View History

/* $NetBSD: getopt.c,v 1.5 1998/02/03 03:44:22 perry Exp $ */
1997-01-09 23:18:21 +03:00
1997-10-19 06:13:39 +04:00
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: getopt.c,v 1.5 1998/02/03 03:44:22 perry 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>
#include <unistd.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);
}