Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9dceedbb
Commit
9dceedbb
authored
Jul 12, 2006
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accept long options "--help" and "--version".
parent
76c5af62
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
7 deletions
+34
-7
Misc/NEWS
Misc/NEWS
+3
-0
Modules/main.c
Modules/main.c
+4
-3
Python/getopt.c
Python/getopt.c
+27
-4
No files found.
Misc/NEWS
View file @
9dceedbb
...
...
@@ -12,6 +12,9 @@ What's New in Python 2.5 release candidate 1?
Core and builtins
-----------------
- Patch #1521179: Python now accepts the standard options ``--help`` and
``--version`` as well as ``/?`` on Windows.
- Bug #1520864: unpacking singleton tuples in for loop (for x, in) work
again. Fixing this problem required changing the .pyc magic number.
This means that .pyc files generated before 2.5c1 will be regenerated.
...
...
Modules/main.c
View file @
9dceedbb
...
...
@@ -40,7 +40,7 @@ static char **orig_argv;
static
int
orig_argc
;
/* command line options */
#define BASE_OPTS "c:dEhim:OQ:StuUvVW:xX"
#define BASE_OPTS "c:dEhim:OQ:StuUvVW:xX
?
"
#ifndef RISCOS
#define PROGRAM_OPTS BASE_OPTS
...
...
@@ -62,7 +62,7 @@ Options and arguments (and corresponding environment variables):\n\
-c cmd : program passed in as string (terminates option list)
\n
\
-d : debug output from parser (also PYTHONDEBUG=x)
\n
\
-E : ignore environment variables (such as PYTHONPATH)
\n
\
-h : print this help message and exit
\n
\
-h : print this help message and exit
(also --help)
\n
\
-i : inspect interactively after running script, (also PYTHONINSPECT=x)
\n
\
and force prompts, even if stdin does not appear to be a terminal
\n
\
"
;
...
...
@@ -78,7 +78,7 @@ static char *usage_2 = "\
static
char
*
usage_3
=
"\
see man page for details on internal buffering relating to '-u'
\n
\
-v : verbose (trace import statements) (also PYTHONVERBOSE=x)
\n
\
-V : print the Python version number and exit
\n
\
-V : print the Python version number and exit
(also --version)
\n
\
-W arg : warning control (arg is action:message:category:module:lineno)
\n
\
-x : skip first line of source, allowing use of non-Unix forms of #!cmd
\n
\
file : program read from script file
\n
\
...
...
@@ -313,6 +313,7 @@ Py_Main(int argc, char **argv)
Py_UnicodeFlag
++
;
break
;
case
'h'
:
case
'?'
:
help
++
;
break
;
case
'V'
:
...
...
Python/getopt.c
View file @
9dceedbb
...
...
@@ -24,6 +24,9 @@
* davegottner@delphi.com.
*---------------------------------------------------------------------------*/
/* Modified to support --help and --version, as well as /? on Windows
* by Georg Brandl. */
#include <stdio.h>
#include <string.h>
...
...
@@ -43,8 +46,17 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring)
if
(
*
opt_ptr
==
'\0'
)
{
if
(
_PyOS_optind
>=
argc
||
argv
[
_PyOS_optind
][
0
]
!=
'-'
||
argv
[
_PyOS_optind
][
1
]
==
'\0'
/* lone dash */
)
if
(
_PyOS_optind
>=
argc
)
return
-
1
;
#ifdef MS_WINDOWS
else
if
(
strcmp
(
argv
[
_PyOS_optind
],
"/?"
)
==
0
)
{
++
_PyOS_optind
;
return
'h'
;
}
#endif
else
if
(
argv
[
_PyOS_optind
][
0
]
!=
'-'
||
argv
[
_PyOS_optind
][
1
]
==
'\0'
/* lone dash */
)
return
-
1
;
else
if
(
strcmp
(
argv
[
_PyOS_optind
],
"--"
)
==
0
)
{
...
...
@@ -52,6 +64,17 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring)
return
-
1
;
}
else
if
(
strcmp
(
argv
[
_PyOS_optind
],
"--help"
)
==
0
)
{
++
_PyOS_optind
;
return
'h'
;
}
else
if
(
strcmp
(
argv
[
_PyOS_optind
],
"--version"
)
==
0
)
{
++
_PyOS_optind
;
return
'V'
;
}
opt_ptr
=
&
argv
[
_PyOS_optind
++
][
1
];
}
...
...
@@ -62,7 +85,7 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring)
if
(
_PyOS_opterr
)
fprintf
(
stderr
,
"Unknown option: -%c
\n
"
,
option
);
return
'
?
'
;
return
'
_
'
;
}
if
(
*
(
ptr
+
1
)
==
':'
)
{
...
...
@@ -76,7 +99,7 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring)
if
(
_PyOS_opterr
)
fprintf
(
stderr
,
"Argument expected for the -%c option
\n
"
,
option
);
return
'
?
'
;
return
'
_
'
;
}
_PyOS_optarg
=
argv
[
_PyOS_optind
++
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment