File getopt.c

 ** ** 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'.					     **
 **									     **
 ** ************************************************************************ **
References Variables: Idgetopt.c

Included Files


Preprocessor definitions

#define _NO_PROTO

#define _( msgid )

#define my_index strchr


Global Variable optarg

char* optarg
Visible in:  getopt.c
   main.c
Used in: Check_Switches()main.c
  _getopt_internal()getopt.c

Global Variable optind

int optind
Visible in:  getopt.c
   main.c
Used in: Check_Switches()main.c
  _getopt_initialize()getopt.c
  _getopt_internal()getopt.c
  exchange()getopt.c

Global Variable opterr

int opterr
Visible in:  getopt.c
   main.c
Used in: _getopt_internal()getopt.c

Global Variable optopt

int optopt
Visible in:  getopt.c
   main.c
Used in: _getopt_internal()getopt.c

Local Variables

Id
static char Id[]
Used in:  getopt.c

UseId
static void* UseId[]

module_name
static char module_name[]
Used in: _getopt_internal()

nextchar
static char* nextchar
Used in: _getopt_initialize()
  _getopt_internal()

ordering
static enum {...} ordering
Used in: _getopt_initialize()
  _getopt_internal()

posixly_correct
static char* posixly_correct
Used in: _getopt_initialize()
  _getopt_internal()

first_nonopt
static int first_nonopt
Used in: _getopt_initialize()
  _getopt_internal()
  exchange()

last_nonopt
static int last_nonopt
Used in: _getopt_initialize()
  _getopt_internal()
  exchange()


Global Function getopt()

 ** ** 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 )
Prototyped in: getopt.h
Calls: _getopt_internal()getopt.c

Global Function getopt_long()

int getopt_long ( int argc, char* const* argv, const char* optstring, const struct option* longopts, int* longind )
Prototyped in: getopt.h
Calls: _getopt_internal()getopt.c
Called by: Check_Switches()main.c

Global Function getopt_long_only()

int getopt_long_only ( int argc, char* const* argv, const char* optstring, const struct option* longopts, int* longind )
Prototyped in: getopt.h
Calls: _getopt_internal()getopt.c

Local Function _getopt_initialize()

 ** ** 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 )
Prototyped in: getopt.c
Calls: getenv()
Called by: _getopt_internal()getopt.c
References Variables: first_nonoptgetopt.c
  last_nonoptgetopt.c
  nextchargetopt.c
  optindgetopt.c
  orderinggetopt.c
  posixly_correctgetopt.c

Local Function _getopt_internal()

static int _getopt_internal ( int argc, char* const* argv, const char* optstring, const struct option* longopts, int* longind, int long_only )
Prototyped in: getopt.c
Calls: Module_Error()error.c
  _getopt_initialize()getopt.c
  exchange()getopt.c
  sprintf(), strchr(), strcmp(), strlen(), strncmp()
Called by: getopt()getopt.c
  getopt_long()getopt.c
  getopt_long_only()getopt.c
References Variables: first_nonoptgetopt.c
  last_nonoptgetopt.c
  module_namegetopt.c
  nextchargetopt.c
  optarggetopt.c
  opterrgetopt.c
  optindgetopt.c
  optoptgetopt.c
  orderinggetopt.c
  posixly_correctgetopt.c

Local Function exchange()

 ** ** 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 )
Prototyped in: getopt.c
Called by: _getopt_internal()getopt.c
References Variables: first_nonoptgetopt.c
  last_nonoptgetopt.c
  optindgetopt.c