indent(1): Use NULL instead of zero for pointers.
[freebsd-src.git] / usr.bin / getopt / getopt.c
blobd1671a71e5eeeab03017092a85c122d9af8f646d
1 #include <sys/cdefs.h>
2 __FBSDID("$FreeBSD$");
4 /*
5 * This material, written by Henry Spencer, was released by him
6 * into the public domain and is thus not subject to any copyright.
7 */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
13 int
14 main(int argc, char *argv[])
16 int c;
17 int status = 0;
19 optind = 2; /* Past the program name and the option letters. */
20 while ((c = getopt(argc, argv, argv[1])) != -1)
21 switch (c) {
22 case '?':
23 status = 1; /* getopt routine gave message */
24 break;
25 default:
26 if (optarg != NULL)
27 printf(" -%c %s", c, optarg);
28 else
29 printf(" -%c", c);
30 break;
32 printf(" --");
33 for (; optind < argc; optind++)
34 printf(" %s", argv[optind]);
35 printf("\n");
36 return status;