** ** Module Header ******************************************************* **
** **
** Modules Revision 3.0 **
** Providing a flexible user environment **
** **
** File: getopt.c **
** First Edition: 95/12/20 **
** **
** Authors: Jens Hamisch, jens@Strawberry.COM **
** **
** Description: getopt procedure for the Modules package **
** **
** Exports: getopt Recognition of commadn line options **
** **
** Notes: This is based on the 'Getopt for GNU' from the gcc-2.7.2 **
** compiler. It is preferred to the libc version, because it **
** provides 'long-options'. **
** **
** ************************************************************************ **
Included Files
- #include "modules_def.h"
- #include <stdio.h>
- #include <tcl.h>
- #include "config.h"
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <ctype.h>
- #include <sys/stat.h>
- #include <sys/termios.h>
- #include <fcntl.h>
- #include <sys/ioctl.h>
- #include <dirent.h>
- #include <errno.h>
Preprocessor definitions
#define _NO_PROTO
#define _( msgid )
#define my_index strchr
char* optarg
int optind
int opterr
int optopt
Local Variables
Id
static char Id[]
UseId
static void* UseId[]
module_name
static char module_name[]
nextchar
static char* nextchar
ordering
static enum {...} ordering
posixly_correct
static char* posixly_correct
first_nonopt
static int first_nonopt
last_nonopt
static int last_nonopt
** ** Function-Header ***************************************************** **
** **
** Function: getopt, getopt_long, getopt_long_only **
** **
** Description: Calls _getopt_internal in order to provide a normal **
** getopt call. **
** **
** First Edition: 95/12/20 **
** **
** Parameters: int argc, # of arguments **
** char **argv, ARGV array **
** char *optstring, String of valid short opt. **
** **
** Result: int '?' Parse error **
** 0 Long option w/o argument found **
** else short option that has been found **
** or the value of a long option **
** EOF no more arguments on ARGV **
** **
** Attached globals: optind Index of the current option in the **
** ARGV array **
** optarg Argument of an option with value **
** opterr Set in case of parse errors **
** **
** ************************************************************************ **
int getopt ( int argc, char* const* argv, const char* optstring )
int getopt_long ( int argc, char* const* argv, const char* optstring, const struct option* longopts, int* longind )
int getopt_long_only ( int argc, char* const* argv, const char* optstring, const struct option* longopts, int* longind )
** ** Function-Header ***************************************************** **
** **
** Function: _getopt_initialize **
** **
** Description: Initialize the internal data when the first call is **
** made **
** This defines how to proceed if options and non-op- **
** tions are mixed up. See definition of the enum **
** 'ordering' for further explanation. **
** **
** First Edition: 95/12/20 **
** **
** Parameters: char *optstring Options string **
** **
** Result: argv ARGV array with exchanged sequences **
** **
** Attached globals: first_nonopt, First an las position of **
** last_nonopt non-option arguments **
** optind Option scan index **
** nextchar Next character to scan **
** posixly_correct Value of the environment **
** variable 'POSIXLY_CORRECT' **
** ordering Ordering method ... **
** **
** ************************************************************************ **
static const char* _getopt_initialize ( const char* optstring )
static int _getopt_internal ( int argc, char* const* argv, const char* optstring, const struct option* longopts, int* longind, int long_only )
** ** Function-Header ***************************************************** **
** **
** Function: exchange **
** **
** Description: Exchange two adjacent subsequences of ARGV. **
** One subsequence is elements( first_nonopt, **
** last_nonopt) which contains all the non-options that **
** have been skipped so far. The other is elements **
** (last_nonopt,optind), which contains all the options **
** processed since those non-options were skipped. **
** **
** `first_nonopt' and `last_nonopt' are relocated so **
** that they describe the new indices of the non-options**
** in ARGV after they are moved. **
** **
** First Edition: 95/12/20 **
** **
** Parameters: char **argv Command line arguments **
** **
** Result: argv ARGV array with exchanged sequences **
** **
** Attached Globals: first_nonopt first and last non option argument **
** last_nonopt on the stream before and after the **
** change.( I/O parameter) **
** **
** ************************************************************************ **
static void exchange ( char** argv )