[Python-checkins] CVS: python/dist/src/Python Makefile.in,2.26,2.27 getopt.c,2.8,2.9

Thomas Wouters python-dev@python.org
Fri, 3 Nov 2000 00:18:40 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory slayer.i.sourceforge.net:/tmp/cvs-serv27629/Python

Modified Files:
	Makefile.in getopt.c 
Log Message:

Move our own getopt() implementation to _PyOS_GetOpt(), and use it
regardless of whether the system getopt() does what we want. This avoids the
hassle with prototypes and externs, and the check to see if the system
getopt() does what we want. Prefix optind, optarg and opterr with _PyOS_ to
avoid name clashes. Add new include file to define the right symbols. Fix
Demo/pyserv/pyserv.c to include getopt.h itself, instead of relying on
Python to provide it.



Index: Makefile.in
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Makefile.in,v
retrieving revision 2.26
retrieving revision 2.27
diff -C2 -r2.26 -r2.27
*** Makefile.in	2000/08/23 21:16:10	2.26
--- Makefile.in	2000/11/03 08:18:37	2.27
***************
*** 47,51 ****
  		pyfpe.o pystate.o pythonrun.o \
  		structmember.o sysmodule.o \
! 		traceback.o \
  		$(DYNLOADFILE) \
  		$(LIBOBJS)
--- 47,51 ----
  		pyfpe.o pystate.o pythonrun.o \
  		structmember.o sysmodule.o \
! 		traceback.o getopt.o \
  		$(DYNLOADFILE) \
  		$(LIBOBJS)

Index: getopt.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/getopt.c,v
retrieving revision 2.8
retrieving revision 2.9
diff -C2 -r2.8 -r2.9
*** getopt.c	2000/07/22 18:47:25	2.8
--- getopt.c	2000/11/03 08:18:37	2.9
***************
*** 28,73 ****
  #include <string.h>
  
! #define bool	int
! #ifndef TRUE
! #define TRUE	1
! #endif
! #ifndef FALSE
! #define FALSE	0
! #endif
! 
! bool    opterr = TRUE;          /* generate error messages */
! int     optind = 1;             /* index into argv array   */
! char *  optarg = NULL;          /* optional argument       */
! 
! 
! #ifndef __BEOS__
! int getopt(int argc, char *argv[], char optstring[])
! #else
! int getopt(int argc, char *const *argv, const char *optstring)
! #endif
  {
! 	static   char *opt_ptr = "";
! 	register char *ptr;
! 			 int   option;
  
  	if (*opt_ptr == '\0') {
  
! 		if (optind >= argc || argv[optind][0] != '-' ||
! 		    argv[optind][1] == '\0' /* lone dash */ )
  			return -1;
  
! 		else if (strcmp(argv[optind], "--") == 0) {
! 			++optind;
  			return -1;
  		}
  
! 		opt_ptr = &argv[optind++][1]; 
  	}
  
  	if ( (option = *opt_ptr++) == '\0')
! 	  return -1;
  	
  	if ((ptr = strchr(optstring, option)) == NULL) {
! 		if (opterr)
  			fprintf(stderr, "Unknown option: -%c\n", option);
  
--- 28,60 ----
  #include <string.h>
  
! int _PyOS_opterr = 1;          /* generate error messages */
! int _PyOS_optind = 1;          /* index into argv array   */
! char *_PyOS_optarg = NULL;     /* optional argument       */
! 
! int _PyOS_GetOpt(int argc, char **argv, char *optstring)
  {
! 	static char *opt_ptr = "";
! 	char *ptr;
! 	int option;
  
  	if (*opt_ptr == '\0') {
  
! 		if (_PyOS_optind >= argc || argv[_PyOS_optind][0] != '-' ||
! 		    argv[_PyOS_optind][1] == '\0' /* lone dash */ )
  			return -1;
  
! 		else if (strcmp(argv[_PyOS_optind], "--") == 0) {
! 			++_PyOS_optind;
  			return -1;
  		}
  
! 		opt_ptr = &argv[_PyOS_optind++][1]; 
  	}
  
  	if ( (option = *opt_ptr++) == '\0')
! 		return -1;
  	
  	if ((ptr = strchr(optstring, option)) == NULL) {
! 		if (_PyOS_opterr)
  			fprintf(stderr, "Unknown option: -%c\n", option);
  
***************
*** 77,87 ****
  	if (*(ptr + 1) == ':') {
  		if (*opt_ptr != '\0') {
! 			optarg  = opt_ptr;
  			opt_ptr = "";
  		}
  
  		else {
! 			if (optind >= argc) {
! 				if (opterr)
  					fprintf(stderr,
  			    "Argument expected for the -%c option\n", option);
--- 64,74 ----
  	if (*(ptr + 1) == ':') {
  		if (*opt_ptr != '\0') {
! 			_PyOS_optarg  = opt_ptr;
  			opt_ptr = "";
  		}
  
  		else {
! 			if (_PyOS_optind >= argc) {
! 				if (_PyOS_opterr)
  					fprintf(stderr,
  			    "Argument expected for the -%c option\n", option);
***************
*** 89,93 ****
  			}
  
! 			optarg = argv[optind++];
  		}
  	}
--- 76,80 ----
  			}
  
! 			_PyOS_optarg = argv[_PyOS_optind++];
  		}
  	}