[Python-checkins] CVS: python/dist/src/Modules main.c,1.45,1.46

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


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

Modified Files:
	main.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: main.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/main.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -C2 -r1.45 -r1.46
*** main.c	2000/09/15 18:40:42	1.45
--- main.c	2000/11/03 08:18:37	1.46
***************
*** 18,30 ****
  #endif
  
  #define COPYRIGHT \
      "Type \"copyright\", \"credits\" or \"license\" for more information."
  
- /* Interface to getopt(): */
- extern int optind;
- extern char *optarg;
- extern int getopt(); /* PROTO((int, char **, char *)); -- not standardized */
- 
- 
  /* For Py_GetArgcArgv(); set by main() */
  static char **orig_argv;
--- 18,26 ----
  #endif
  
+ #include "pygetopt.h"
+ 
  #define COPYRIGHT \
      "Type \"copyright\", \"credits\" or \"license\" for more information."
  
  /* For Py_GetArgcArgv(); set by main() */
  static char **orig_argv;
***************
*** 106,119 ****
  		unbuffered = 1;
  
! 	while ((c = getopt(argc, argv, "c:diOStuUvxXhV")) != EOF) {
  		if (c == 'c') {
  			/* -c is the last option; following arguments
  			   that look like options are left for the
  			   the command to interpret. */
! 			command = malloc(strlen(optarg) + 2);
  			if (command == NULL)
  				Py_FatalError(
  				   "not enough memory to copy -c argument");
! 			strcpy(command, optarg);
  			strcat(command, "\n");
  			break;
--- 102,115 ----
  		unbuffered = 1;
  
! 	while ((c = _PyOS_GetOpt(argc, argv, "c:diOStuUvxXhV")) != EOF) {
  		if (c == 'c') {
  			/* -c is the last option; following arguments
  			   that look like options are left for the
  			   the command to interpret. */
! 			command = malloc(strlen(_PyOS_optarg) + 2);
  			if (command == NULL)
  				Py_FatalError(
  				   "not enough memory to copy -c argument");
! 			strcpy(command, _PyOS_optarg);
  			strcat(command, "\n");
  			break;
***************
*** 182,189 ****
  	}
  
! 	if (command == NULL && optind < argc &&
! 	    strcmp(argv[optind], "-") != 0)
  	{
! 		filename = argv[optind];
  		if (filename != NULL) {
  			if ((fp = fopen(filename, "r")) == NULL) {
--- 178,185 ----
  	}
  
! 	if (command == NULL && _PyOS_optind < argc &&
! 	    strcmp(argv[_PyOS_optind], "-") != 0)
  	{
! 		filename = argv[_PyOS_optind];
  		if (filename != NULL) {
  			if ((fp = fopen(filename, "r")) == NULL) {
***************
*** 254,263 ****
  	
  	if (command != NULL) {
! 		/* Backup optind and force sys.argv[0] = '-c' */
! 		optind--;
! 		argv[optind] = "-c";
  	}
  
! 	PySys_SetArgv(argc-optind, argv+optind);
  
  	if ((inspect || (command == NULL && filename == NULL)) &&
--- 250,259 ----
  	
  	if (command != NULL) {
! 		/* Backup _PyOS_optind and force sys.argv[0] = '-c' */
! 		_PyOS_optind--;
! 		argv[_PyOS_optind] = "-c";
  	}
  
! 	PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind);
  
  	if ((inspect || (command == NULL && filename == NULL)) &&