NetBSD/usr.bin/getopt/getopt.c

42 lines
872 B
C
Raw Normal View History

/* $NetBSD: getopt.c,v 1.8 2006/07/09 21:39:48 wiz Exp $ */
/*
* This material, written by Henry Spencer, was released by him
* into the public domain and is thus not subject to any copyright.
*/
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.8 2006/07/09 21:39:48 wiz Exp $");
#endif /* not lint */
1993-06-21 16:43:56 +04:00
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
1993-06-21 16:43:56 +04:00
1997-10-19 06:13:39 +04:00
int
main(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);
}