Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
gw-getopt.h File Reference

Go to the source code of this file.

Functions

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

Variables

int opterr
 
int optind
 
int optopt
 
char * optarg
 

Function Documentation

◆ getopt()

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

Definition at line 84 of file attgetopt.c.

References ERR, optarg, optind, and optopt.

Referenced by main(), and parse_options().

85 {
86  static int sp = 1;
87  register int c;
88  register char *cp;
89 
90  if(sp == 1) {
91  if(optind >= argc ||
92  argv[optind][0] != '-' || argv[optind][1] == '\0')
93  return(EOF);
94  else if(strcmp(argv[optind], "--") == 0) {
95  optind++;
96  return(EOF);
97  }
98  }
99  optopt = c = argv[optind][sp];
100  if(c == ':' || (cp=strchr(opts, c)) == NULL) {
101  ERR(": illegal option -- ", c);
102  if(argv[optind][++sp] == '\0') {
103  optind++;
104  sp = 1;
105  }
106  return('?');
107  }
108  if(*++cp == ':') {
109  if(argv[optind][sp+1] != '\0')
110  optarg = &argv[optind++][sp+1];
111  else if(++optind >= argc) {
112  ERR(": option requires an argument -- ", c);
113  sp = 1;
114  return('?');
115  } else
116  optarg = argv[optind++];
117  sp = 1;
118  } else {
119  if(argv[optind][++sp] == '\0') {
120  sp = 1;
121  optind++;
122  }
123  optarg = NULL;
124  }
125  return(c);
126 }
char * optarg
Definition: attgetopt.c:82
int optind
Definition: attgetopt.c:80
int optopt
Definition: attgetopt.c:81
#define ERR(s, c)
Definition: attgetopt.c:75

Variable Documentation

◆ optarg

char* optarg

Definition at line 82 of file attgetopt.c.

Referenced by getopt(), main(), and parse_options().

◆ opterr

int opterr

Definition at line 79 of file attgetopt.c.

◆ optind

int optind

Definition at line 80 of file attgetopt.c.

Referenced by getopt(), and main().

◆ optopt

int optopt

Definition at line 81 of file attgetopt.c.

Referenced by getopt().

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.