MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
getopt.c File Reference
#include "mbconfig.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
Include dependency graph for getopt.c:

Go to the source code of this file.

Functions

static void ERR (char *const argv[], const char *s, char c)
 
int getopt (int argc, char *const argv[], const char *opts)
 

Variables

int opterr = 1
 
int optind = 1
 
int optopt
 
char * optarg
 

Function Documentation

static void ERR ( char *const  argv[],
const char *  s,
char  c 
)
static

Definition at line 76 of file getopt.c.

References c.

Referenced by getopt().

77 {
78  char errbuf[2];
79 
80 #ifdef DF_TRACE_DEBUG
81 printf("DF_TRACE_DEBUG: static void ERR () in getopt.c\n");
82 #endif
83  if (opterr)
84  {
85  errbuf[0] = c;
86  errbuf[1] = '\n';
87  (void) write(STDERR_FILENO,argv[0],strlen(argv[0]));
88  (void) write(STDERR_FILENO,s,strlen(s));
89  (void) write(STDERR_FILENO,errbuf,sizeof errbuf);
90  }
91 }
int opterr
Definition: getopt.c:71
static std::stack< cleanup * > c
Definition: cleanup.cc:59
int getopt ( int  argc,
char *const  argv[],
const char *  opts 
)

Definition at line 93 of file getopt.c.

References c, ERR(), error(), optarg, and optind.

Referenced by main(), mbdyn_parse_arguments(), IO::Parse(), and test_init().

94 {
95  static int sp = 1, error = (int) '?';
96  static char sw = '-', eos = '\0', arg = ':';
97  register char c, * cp;
98 
99 #ifdef DF_TRACE_DEBUG
100 printf("DF_TRACE_DEBUG: int getopt () in getopt.c\n");
101 #endif
102  if (sp == 1)
103  {
104  if (optind >= argc || argv[optind][0] != sw
105  || argv[optind][1] == eos)
106  return EOF;
107  else if (strcmp(argv[optind],"--") == 0)
108  {
109  optind++;
110  return EOF;
111  }
112  }
113  c = argv[optind][sp];
114  optopt = (int) c;
115  if (c == arg || (cp = strchr(opts,c)) == NULL)
116  {
117  ERR(argv,": illegal option--",c);
118  if (argv[optind][++sp] == eos)
119  {
120  optind++;
121  sp = 1;
122  }
123  return error;
124  }
125  else if (*++cp == arg)
126  {
127  if (argv[optind][sp + 1] != eos)
128  optarg = &argv[optind++][sp + 1];
129  else if (++optind >= argc)
130  {
131  ERR(argv,": option requires an argument--",c);
132  sp = 1;
133  return error;
134  }
135  else
136  optarg = argv[optind++];
137  sp = 1;
138  }
139  else
140  {
141  if (argv[optind][++sp] == eos)
142  {
143  sp = 1;
144  optind++;
145  }
146  optarg = NULL;
147  }
148  return (int) c;
149 }
int optopt
Definition: getopt.c:73
int optind
Definition: getopt.c:72
int error(const char *test, int value)
static void ERR(char *const argv[], const char *s, char c)
Definition: getopt.c:76
static std::stack< cleanup * > c
Definition: cleanup.cc:59
char * optarg
Definition: getopt.c:74

Here is the call graph for this function:

Variable Documentation

char* optarg

Definition at line 74 of file getopt.c.

Referenced by getopt(), main(), mbdyn_parse_arguments(), IO::Parse(), and test_init().

int opterr = 1

Definition at line 71 of file getopt.c.

Referenced by mbdyn_parse_arguments().

int optind = 1

Definition at line 72 of file getopt.c.

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

int optopt

Definition at line 73 of file getopt.c.

Referenced by mbdyn_parse_arguments().