Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Functions | Variables
getopt.c File Reference
#include "rle_config.h"
#include <stdio.h>
Include dependency graph for getopt.c:

Go to the source code of this file.

Functions

char * strchr ()
 
int getopt (int argc, argv, char *optstring)
 

Variables

char * optarg
 
int optind = 0
 
static char * scan = ((void *)0)
 

Function Documentation

int getopt ( int  argc,
argv  ,
char *  optstring 
)

Definition at line 37 of file getopt.c.

41 {
42  register char c;
43  register char *place;
44 
45  optarg = NULL;
46 
47  if (scan == NULL || *scan == '\0') {
48  if (optind == 0)
49  optind++;
50 
51  if (optind >= argc || argv[optind][0] != '-' ||
52  argv[optind][1] == '\0')
53  return( EOF );
54 
55  if (strcmp(argv[optind], "--")==0) {
56  optind++;
57  return( EOF );
58  }
59 
60  scan = argv[optind]+1;
61  optind++;
62  }
63 
64  c = *scan++;
65  place = index(optstring, c);
66 
67  if (place == NULL || c == ':') {
68  fprintf(stderr, "%s: unknown option -%c\n", argv[0], c);
69  return( '?' );
70  }
71 
72  place++;
73  if (*place == ':') {
74  if (*scan != '\0') {
75  optarg = scan;
76  scan = NULL;
77  } else {
78  if (optind >= argc) {
79  fprintf(stderr,
80  "%s: missing argument after -%c\n",
81  argv[0], c);
82  return( '?' );
83  }
84  optarg = argv[optind];
85  optind++;
86  }
87  }
88 
89  return( c );
90 }
int optind
Definition: getopt.c:30
static char * scan
Definition: getopt.c:32
#define index
Definition: rle_config.h:96
char * optarg
Definition: getopt.c:29
char* strchr ( )

Variable Documentation

char* optarg

Definition at line 29 of file getopt.c.

Referenced by main().

int optind = 0

Definition at line 30 of file getopt.c.

Referenced by main().

char* scan = ((void *)0)
static

Definition at line 32 of file getopt.c.