Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / usr.bin / getopt / getopt.c
1 /* $FreeBSD: src/usr.bin/getopt/getopt.c,v 1.4.2.2 2001/07/30 10:16:38 dd Exp $ */
2 /* $DragonFly: src/usr.bin/getopt/getopt.c,v 1.2 2003/06/17 04:29:27 dillon Exp $ */
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7
8 main(argc, argv)
9 int argc;
10 char *argv[];
11 {
12         int c;
13         int status = 0;
14
15         optind = 2;     /* Past the program name and the option letters. */
16         while ((c = getopt(argc, argv, argv[1])) != -1)
17                 switch (c) {
18                 case '?':
19                         status = 1;     /* getopt routine gave message */
20                         break;
21                 default:
22                         if (optarg != NULL)
23                                 printf(" -%c %s", c, optarg);
24                         else
25                                 printf(" -%c", c);
26                         break;
27                 }
28         printf(" --");
29         for (; optind < argc; optind++)
30                 printf(" %s", argv[optind]);
31         printf("\n");
32         exit(status);
33 }