Index: configure.in =================================================================== RCS file: /cvsroot/python/python/dist/src/configure.in,v retrieving revision 1.174 diff -c -r1.174 configure.in *** configure.in 2000/10/26 17:09:35 1.174 --- configure.in 2000/10/30 17:57:14 *************** *** 1200,1221 **** AC_REPLACE_FUNCS(hypot) LIBS=$LIBS_SAVE - # check for getopt - AC_MSG_CHECKING(for genuine getopt) - AC_CACHE_VAL(ac_cv_func_getopt, - [AC_TRY_RUN([#include - extern int optind, opterr, getopt(); - extern char* optarg; - int main() { - char* av[] = { "testprog", "parameter", "-fFlag", NULL }; - opterr = 0; - if (getopt(3, av, "f:") == 'f') { exit(1); } - exit(0); - }], ac_cv_func_getopt=yes, ac_cv_func_getopt=no, ac_cv_func_getopt=no)])dnl - AC_MSG_RESULT($ac_cv_func_getopt) - test $ac_cv_func_getopt = no && LIBOBJS="$LIBOBJS getopt.o" - AC_SUBST(LIBOBJS)dnl - # check whether malloc(0) returns NULL or not AC_MSG_CHECKING(what malloc(0) returns) AC_CACHE_VAL(ac_cv_malloc_zero, --- 1200,1205 ---- Index: Demo/pysvr/pysvr.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Demo/pysvr/pysvr.c,v retrieving revision 1.8 diff -c -r1.8 pysvr.c *** Demo/pysvr/pysvr.c 2000/07/22 19:25:51 1.8 --- Demo/pysvr/pysvr.c 2000/10/30 17:57:14 *************** *** 26,41 **** #include extern int Py_VerboseFlag; #ifndef PORT #define PORT 4000 #endif - extern int optind; - extern char *optarg; - extern int getopt(int, char **, char *); - struct workorder { int conn; struct sockaddr_in addr; --- 26,39 ---- #include + #include + extern int Py_VerboseFlag; #ifndef PORT #define PORT 4000 #endif struct workorder { int conn; struct sockaddr_in addr; *************** *** 64,70 **** if (argc > 0 && argv[0] != NULL && argv[0][0] != '\0') progname = argv[0]; ! while ((c = getopt(argc, argv, "v")) != EOF) { switch (c) { case 'v': Py_VerboseFlag++; --- 62,68 ---- if (argc > 0 && argv[0] != NULL && argv[0][0] != '\0') progname = argv[0]; ! while ((c = Py_GetOpt(argc, argv, "v")) != EOF) { switch (c) { case 'v': Py_VerboseFlag++; *************** *** 74,88 **** } } ! if (optind < argc) { ! if (optind+1 < argc) { oprogname(); fprintf(stderr, "too many arguments\n"); usage(); } ! port = atoi(argv[optind]); if (port <= 0) { ! fprintf(stderr, "bad port (%s)\n", argv[optind]); usage(); } } --- 72,86 ---- } } ! if (Py_optind < argc) { ! if (Py_optind+1 < argc) { oprogname(); fprintf(stderr, "too many arguments\n"); usage(); } ! port = atoi(argv[Py_optind]); if (port <= 0) { ! fprintf(stderr, "bad port (%s)\n", argv[Py_optind]); usage(); } } Index: Include/pygetopt.h =================================================================== RCS file: pygetopt.h diff -N pygetopt.h *** /dev/null Tue May 5 13:32:27 1998 --- pygetopt.h Mon Oct 30 09:57:15 2000 *************** *** 0 **** --- 1,17 ---- + + #ifndef Py_PYGETOPT_H + #define Py_PYGETOPT_H + #ifdef __cplusplus + extern "C" { + #endif + + extern DL_IMPORT(int) Py_opterr; + extern DL_IMPORT(int) Py_optind; + extern DL_IMPORT(char *) Py_optarg; + + DL_IMPORT(int) Py_GetOpt(int argc, char **argv, char *optstring); + + #ifdef __cplusplus + } + #endif + #endif /* !Py_PYGETOPT_H */ Index: Modules/main.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/main.c,v retrieving revision 1.45 diff -c -r1.45 main.c *** Modules/main.c 2000/09/15 18:40:42 1.45 --- Modules/main.c 2000/10/30 17:57:16 *************** *** 17,31 **** #define PYTHONHOMEHELP "/python2.0" #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; static int orig_argc; --- 17,27 ---- #define PYTHONHOMEHELP "/python2.0" #endif + #include "pygetopt.h" + #define COPYRIGHT \ "Type \"copyright\", \"credits\" or \"license\" for more information." /* For Py_GetArgcArgv(); set by main() */ static char **orig_argv; static int orig_argc; *************** *** 105,120 **** if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0') 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; } --- 101,116 ---- if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0') unbuffered = 1; ! while ((c = Py_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(Py_optarg) + 2); if (command == NULL) Py_FatalError( "not enough memory to copy -c argument"); ! strcpy(command, Py_optarg); strcat(command, "\n"); break; } *************** *** 181,190 **** exit(0); } ! if (command == NULL && optind < argc && ! strcmp(argv[optind], "-") != 0) { ! filename = argv[optind]; if (filename != NULL) { if ((fp = fopen(filename, "r")) == NULL) { fprintf(stderr, "%s: can't open file '%s'\n", --- 177,186 ---- exit(0); } ! if (command == NULL && Py_optind < argc && ! strcmp(argv[Py_optind], "-") != 0) { ! filename = argv[Py_optind]; if (filename != NULL) { if ((fp = fopen(filename, "r")) == NULL) { fprintf(stderr, "%s: can't open file '%s'\n", *************** *** 253,264 **** 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)) && isatty(fileno(stdin))) { --- 249,260 ---- if (command != NULL) { ! /* Backup Py_optind and force sys.argv[0] = '-c' */ ! Py_optind--; ! argv[Py_optind] = "-c"; } ! PySys_SetArgv(argc-Py_optind, argv+Py_optind); if ((inspect || (command == NULL && filename == NULL)) && isatty(fileno(stdin))) { Index: Python/Makefile.in =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Makefile.in,v retrieving revision 2.26 diff -c -r2.26 Makefile.in *** Python/Makefile.in 2000/08/23 21:16:10 2.26 --- Python/Makefile.in 2000/10/30 17:57:16 *************** *** 46,52 **** marshal.o modsupport.o mystrtoul.o \ pyfpe.o pystate.o pythonrun.o \ structmember.o sysmodule.o \ ! traceback.o \ $(DYNLOADFILE) \ $(LIBOBJS) OBJS= $(AROBJS) sigcheck.o --- 46,52 ---- marshal.o modsupport.o mystrtoul.o \ pyfpe.o pystate.o pythonrun.o \ structmember.o sysmodule.o \ ! traceback.o getopt.o \ $(DYNLOADFILE) \ $(LIBOBJS) OBJS= $(AROBJS) sigcheck.o Index: Python/getopt.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/getopt.c,v retrieving revision 2.8 diff -c -r2.8 getopt.c *** Python/getopt.c 2000/07/22 18:47:25 2.8 --- Python/getopt.c 2000/10/30 17:57:16 *************** *** 27,74 **** #include #include ! #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); return '?'; --- 27,61 ---- #include #include ! int Py_opterr = 1; /* generate error messages */ ! int Py_optind = 1; /* index into argv array */ ! char *Py_optarg = NULL; /* optional argument */ ! ! int Py_GetOpt(int argc, char **argv, char *optstring) { ! static char *opt_ptr = ""; ! char *ptr; ! int option; if (*opt_ptr == '\0') { ! if (Py_optind >= argc || argv[Py_optind][0] != '-' || ! argv[Py_optind][1] == '\0' /* lone dash */ ) return -1; ! else if (strcmp(argv[Py_optind], "--") == 0) { ! ++Py_optind; return -1; } ! opt_ptr = &argv[Py_optind++][1]; } if ( (option = *opt_ptr++) == '\0') ! return -1; if ((ptr = strchr(optstring, option)) == NULL) { ! if (Py_opterr) fprintf(stderr, "Unknown option: -%c\n", option); return '?'; *************** *** 76,94 **** 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); return '?'; } ! optarg = argv[optind++]; } } --- 63,81 ---- if (*(ptr + 1) == ':') { if (*opt_ptr != '\0') { ! Py_optarg = opt_ptr; opt_ptr = ""; } else { ! if (Py_optind >= argc) { ! if (Py_opterr) fprintf(stderr, "Argument expected for the -%c option\n", option); return '?'; } ! Py_optarg = argv[Py_optind++]; } }