1 1.3 tls /* $NetBSD: getopt.c,v 1.3 1997/01/09 20:19:47 tls Exp $ */ 2 1.3 tls 3 1.2 mycroft #ifndef lint 4 1.3 tls static char rcsid[] = "$NetBSD: getopt.c,v 1.3 1997/01/09 20:19:47 tls Exp $"; 5 1.2 mycroft #endif /* not lint */ 6 1.2 mycroft 7 1.1 brezak #include <stdio.h> 8 1.1 brezak 9 1.1 brezak main(argc, argv) 10 1.1 brezak int argc; 11 1.1 brezak char *argv[]; 12 1.1 brezak { 13 1.1 brezak extern int optind; 14 1.1 brezak extern char *optarg; 15 1.1 brezak int c; 16 1.1 brezak int status = 0; 17 1.1 brezak 18 1.1 brezak optind = 2; /* Past the program name and the option letters. */ 19 1.1 brezak while ((c = getopt(argc, argv, argv[1])) != EOF) 20 1.1 brezak switch (c) { 21 1.1 brezak case '?': 22 1.1 brezak status = 1; /* getopt routine gave message */ 23 1.1 brezak break; 24 1.1 brezak default: 25 1.1 brezak if (optarg != NULL) 26 1.1 brezak printf(" -%c %s", c, optarg); 27 1.1 brezak else 28 1.1 brezak printf(" -%c", c); 29 1.1 brezak break; 30 1.1 brezak } 31 1.1 brezak printf(" --"); 32 1.1 brezak for (; optind < argc; optind++) 33 1.1 brezak printf(" %s", argv[optind]); 34 1.1 brezak printf("\n"); 35 1.1 brezak exit(status); 36 1.1 brezak } 37