summaryrefslogtreecommitdiffstats
path: root/Modules/main.c
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2000-11-03 08:18:37 (GMT)
committerThomas Wouters <thomas@python.org>2000-11-03 08:18:37 (GMT)
commit2cffc7d4202fc1197280a05d998075551b459283 (patch)
tree7c5d86617226e1517840a60c44bd21183160b3e0 /Modules/main.c
parent9dce7b3737c456f3c6f56f1f57c29b3c3b6b20aa (diff)
downloadcpython-2cffc7d4202fc1197280a05d998075551b459283.zip
cpython-2cffc7d4202fc1197280a05d998075551b459283.tar.gz
cpython-2cffc7d4202fc1197280a05d998075551b459283.tar.bz2
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.
Diffstat (limited to 'Modules/main.c')
-rw-r--r--Modules/main.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/Modules/main.c b/Modules/main.c
index b4d7cdf..c508eb6 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -17,15 +17,11 @@
#define PYTHONHOMEHELP "<prefix>/python2.0"
#endif
+#include "pygetopt.h"
+
#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;
@@ -105,16 +101,16 @@ Py_Main(int argc, char **argv)
if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
unbuffered = 1;
- while ((c = getopt(argc, argv, "c:diOStuUvxXhV")) != EOF) {
+ 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(optarg) + 2);
+ command = malloc(strlen(_PyOS_optarg) + 2);
if (command == NULL)
Py_FatalError(
"not enough memory to copy -c argument");
- strcpy(command, optarg);
+ strcpy(command, _PyOS_optarg);
strcat(command, "\n");
break;
}
@@ -181,10 +177,10 @@ Py_Main(int argc, char **argv)
exit(0);
}
- if (command == NULL && optind < argc &&
- strcmp(argv[optind], "-") != 0)
+ if (command == NULL && _PyOS_optind < argc &&
+ strcmp(argv[_PyOS_optind], "-") != 0)
{
- filename = argv[optind];
+ filename = argv[_PyOS_optind];
if (filename != NULL) {
if ((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr, "%s: can't open file '%s'\n",
@@ -253,12 +249,12 @@ Py_Main(int argc, char **argv)
if (command != NULL) {
- /* Backup optind and force sys.argv[0] = '-c' */
- optind--;
- argv[optind] = "-c";
+ /* Backup _PyOS_optind and force sys.argv[0] = '-c' */
+ _PyOS_optind--;
+ argv[_PyOS_optind] = "-c";
}
- PySys_SetArgv(argc-optind, argv+optind);
+ PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind);
if ((inspect || (command == NULL && filename == NULL)) &&
isatty(fileno(stdin))) {