]> git.saurik.com Git - apple/shell_cmds.git/blame - getopt/getopt.c
shell_cmds-17.1.tar.gz
[apple/shell_cmds.git] / getopt / getopt.c
CommitLineData
44bd5ea7
A
1/* $NetBSD: getopt.c,v 1.5 1998/02/03 03:44:22 perry Exp $ */
2
3#include <sys/cdefs.h>
4#ifndef lint
5__RCSID("$NetBSD: getopt.c,v 1.5 1998/02/03 03:44:22 perry Exp $");
6#endif /* not lint */
7
8#include <errno.h>
9#include <stdio.h>
10#include <unistd.h>
11
12int main __P((int, char **));
13
14int
15main(argc, argv)
16 int argc;
17 char *argv[];
18{
19 int c;
20 int status = 0;
21
22 optind = 2; /* Past the program name and the option letters. */
23 while ((c = getopt(argc, argv, argv[1])) != -1)
24 switch (c) {
25 case '?':
26 status = 1; /* getopt routine gave message */
27 break;
28 default:
29 if (optarg != NULL)
30 printf(" -%c %s", c, optarg);
31 else
32 printf(" -%c", c);
33 break;
34 }
35 printf(" --");
36 for (; optind < argc; optind++)
37 printf(" %s", argv[optind]);
38 printf("\n");
39 exit(status);
40}