src/util/getopt.c File Reference

#include <stdio.h>
#include "util.h"
Include dependency graph for getopt.c:

Go to the source code of this file.

Functions

void util_getopt_reset (void)
int util_getopt (int argc, char *const argv[], char const *optstring)

Variables

char * util_optarg
int util_optind = 0
static char * scan

Function Documentation

int util_getopt ( int  argc,
char *const   argv[],
char const *  optstring 
)

Definition at line 40 of file getopt.c.

00041 {
00042     register int c;
00043     register char *place;
00044 
00045     util_optarg = NIL(char);
00046 
00047     if (scan == NIL(char) || *scan == '\0') {
00048         if (util_optind == 0) util_optind++;
00049         if (util_optind >= argc) return EOF;
00050         place = argv[util_optind];
00051         if (place[0] != '-' || place[1] == '\0') return EOF;
00052         util_optind++;
00053         if (place[1] == '-' && place[2] == '\0') return EOF;
00054         scan = place+1;
00055     }
00056 
00057     c = *scan++;
00058     place = strchr(optstring, c);
00059     if (place == NIL(char) || c == ':') {
00060         (void) fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
00061         return '?';
00062     }
00063     if (*++place == ':') {
00064         if (*scan != '\0') {
00065             util_optarg = scan;
00066             scan = NIL(char);
00067         } else {
00068             if (util_optind >= argc) {
00069                 (void) fprintf(stderr, "%s: %c requires an argument\n", 
00070                     argv[0], c);
00071                 return '?';
00072             }
00073             util_optarg = argv[util_optind];
00074             util_optind++;
00075         }
00076     }
00077     return c;
00078 }

void util_getopt_reset ( void   ) 

Definition at line 30 of file getopt.c.

00031 {
00032     util_optarg = 0;
00033     util_optind = 0;
00034     scan = 0;
00035 }


Variable Documentation

char* scan [static]

Definition at line 26 of file getopt.c.

char* util_optarg

Definition at line 24 of file getopt.c.

int util_optind = 0

Definition at line 25 of file getopt.c.


Generated on Tue Jan 12 13:57:29 2010 for glu-2.2 by  doxygen 1.6.1