#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;
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;
}
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",
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))) {
#include <stdio.h>
#include <string.h>
-#define bool int
-#ifndef TRUE
-#define TRUE 1
-#endif
-#ifndef FALSE
-#define FALSE 0
-#endif
+int _PyOS_opterr = 1; /* generate error messages */
+int _PyOS_optind = 1; /* index into argv array */
+char *_PyOS_optarg = NULL; /* optional argument */
-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
+int _PyOS_GetOpt(int argc, char **argv, char *optstring)
{
- static char *opt_ptr = "";
- register char *ptr;
- int option;
+ static char *opt_ptr = "";
+ char *ptr;
+ int option;
if (*opt_ptr == '\0') {
- if (optind >= argc || argv[optind][0] != '-' ||
- argv[optind][1] == '\0' /* lone dash */ )
+ if (_PyOS_optind >= argc || argv[_PyOS_optind][0] != '-' ||
+ argv[_PyOS_optind][1] == '\0' /* lone dash */ )
return -1;
- else if (strcmp(argv[optind], "--") == 0) {
- ++optind;
+ else if (strcmp(argv[_PyOS_optind], "--") == 0) {
+ ++_PyOS_optind;
return -1;
}
- opt_ptr = &argv[optind++][1];
+ opt_ptr = &argv[_PyOS_optind++][1];
}
if ( (option = *opt_ptr++) == '\0')
- return -1;
+ return -1;
if ((ptr = strchr(optstring, option)) == NULL) {
- if (opterr)
+ if (_PyOS_opterr)
fprintf(stderr, "Unknown option: -%c\n", option);
return '?';
if (*(ptr + 1) == ':') {
if (*opt_ptr != '\0') {
- optarg = opt_ptr;
+ _PyOS_optarg = opt_ptr;
opt_ptr = "";
}
else {
- if (optind >= argc) {
- if (opterr)
+ if (_PyOS_optind >= argc) {
+ if (_PyOS_opterr)
fprintf(stderr,
"Argument expected for the -%c option\n", option);
return '?';
}
- optarg = argv[optind++];
+ _PyOS_optarg = argv[_PyOS_optind++];
}
}
int main() {
/* Ultrix mips cc rejects this. */
-typedef int charset[2]; const charset x;
+typedef int charset[2]; const charset x = {0,0};
/* SunOS 4.1.1 cc rejects this. */
char const *const *ccp;
char **p;
#include "confdefs.h"
int main() {
-} $ac_kw foo() {
+} int $ac_kw foo() {
; return 0; }
EOF
if { (eval echo configure:4921: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
LIBS=$LIBS_SAVE
-# check for getopt
-echo $ac_n "checking for genuine getopt""... $ac_c" 1>&6
-echo "configure:5631: checking for genuine getopt" >&5
-if eval "test \"`echo '$''{'ac_cv_func_getopt'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- if test "$cross_compiling" = yes; then
- ac_cv_func_getopt=no
-else
- cat > conftest.$ac_ext <<EOF
-#line 5639 "configure"
-#include "confdefs.h"
-#include <stdio.h>
-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);
-}
-EOF
-if { (eval echo configure:5651: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
-then
- ac_cv_func_getopt=yes
-else
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -fr conftest*
- ac_cv_func_getopt=no
-fi
-rm -fr conftest*
-fi
-
-fi
-echo "$ac_t""$ac_cv_func_getopt" 1>&6
-test $ac_cv_func_getopt = no && LIBOBJS="$LIBOBJS getopt.o"
-
# check whether malloc(0) returns NULL or not
echo $ac_n "checking what malloc(0) returns""... $ac_c" 1>&6
-echo "configure:5669: checking what malloc(0) returns" >&5
+echo "configure:5631: checking what malloc(0) returns" >&5
if eval "test \"`echo '$''{'ac_cv_malloc_zero'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
{ echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
else
cat > conftest.$ac_ext <<EOF
-#line 5677 "configure"
+#line 5639 "configure"
#include "confdefs.h"
#include <stdio.h>
#ifdef HAVE_STDLIB
exit(0);
}
EOF
-if { (eval echo configure:5696: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:5658: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_malloc_zero=nonnull
else
# check for wchar.h
ac_safe=`echo "wchar.h" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for wchar.h""... $ac_c" 1>&6
-echo "configure:5722: checking for wchar.h" >&5
+echo "configure:5684: checking for wchar.h" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5727 "configure"
+#line 5689 "configure"
#include "confdefs.h"
#include <wchar.h>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:5732: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:5694: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
# check for usable wchar_t
usable_wchar_t="unkown"
echo $ac_n "checking for usable wchar_t""... $ac_c" 1>&6
-echo "configure:5762: checking for usable wchar_t" >&5
+echo "configure:5724: checking for usable wchar_t" >&5
if test "$cross_compiling" = yes; then
{ echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
else
cat > conftest.$ac_ext <<EOF
-#line 5767 "configure"
+#line 5729 "configure"
#include "confdefs.h"
#include "wchar.h"
}
EOF
-if { (eval echo configure:5781: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:5743: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
cat >> confdefs.h <<\EOF
#define HAVE_USABLE_WCHAR_T 1
# check for endianness
echo $ac_n "checking whether byte ordering is bigendian""... $ac_c" 1>&6
-echo "configure:5800: checking whether byte ordering is bigendian" >&5
+echo "configure:5762: checking whether byte ordering is bigendian" >&5
if eval "test \"`echo '$''{'ac_cv_c_bigendian'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
ac_cv_c_bigendian=unknown
# See if sys/param.h defines the BYTE_ORDER macro.
cat > conftest.$ac_ext <<EOF
-#line 5807 "configure"
+#line 5769 "configure"
#include "confdefs.h"
#include <sys/types.h>
#include <sys/param.h>
#endif
; return 0; }
EOF
-if { (eval echo configure:5818: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:5780: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
# It does; now see whether it defined to BIG_ENDIAN or not.
cat > conftest.$ac_ext <<EOF
-#line 5822 "configure"
+#line 5784 "configure"
#include "confdefs.h"
#include <sys/types.h>
#include <sys/param.h>
#endif
; return 0; }
EOF
-if { (eval echo configure:5833: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:5795: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
ac_cv_c_bigendian=yes
else
{ echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
else
cat > conftest.$ac_ext <<EOF
-#line 5853 "configure"
+#line 5815 "configure"
#include "confdefs.h"
main () {
/* Are we little or big endian? From Harbison&Steele. */
exit (u.c[sizeof (long) - 1] == 1);
}
EOF
-if { (eval echo configure:5866: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:5828: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_c_bigendian=no
else
# Check whether right shifting a negative integer extends the sign bit
# or fills with zeros (like the Cray J90, according to Tim Peters).
echo $ac_n "checking whether right shift extends the sign bit""... $ac_c" 1>&6
-echo "configure:5893: checking whether right shift extends the sign bit" >&5
+echo "configure:5855: checking whether right shift extends the sign bit" >&5
if eval "test \"`echo '$''{'ac_cv_rshift_extends_sign'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
{ echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
else
cat > conftest.$ac_ext <<EOF
-#line 5902 "configure"
+#line 5864 "configure"
#include "confdefs.h"
int main()
}
EOF
-if { (eval echo configure:5911: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:5873: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_rshift_extends_sign=yes
else
#endif
EOF
echo $ac_n "checking for socklen_t""... $ac_c" 1>&6
-echo "configure:5943: checking for socklen_t" >&5
+echo "configure:5905: checking for socklen_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_socklen_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 5948 "configure"
+#line 5910 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
echo $ac_n "checking for Modules/Setup""... $ac_c" 1>&6
-echo "configure:5977: checking for Modules/Setup" >&5
+echo "configure:5939: checking for Modules/Setup" >&5
if test ! -f Modules/Setup ; then
if test ! -d Modules ; then
mkdir Modules