source: trunk/essentials/dev-lang/python/Modules/main.c@ 3397

Last change on this file since 3397 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 13.7 KB
Line 
1/* Python interpreter main program */
2
3#include "Python.h"
4#include "osdefs.h"
5#include "code.h" /* For CO_FUTURE_DIVISION */
6#include "import.h"
7
8#ifdef __VMS
9#include <unixlib.h>
10#endif
11
12#if defined(MS_WINDOWS) || defined(__CYGWIN__)
13#ifdef HAVE_FCNTL_H
14#include <fcntl.h>
15#endif
16#endif
17
18#if (defined(PYOS_OS2) && !defined(PYCC_GCC)) || defined(MS_WINDOWS)
19#define PYTHONHOMEHELP "<prefix>\\lib"
20#else
21#if defined(PYOS_OS2) && defined(PYCC_GCC)
22#define PYTHONHOMEHELP "<prefix>/Lib"
23#else
24#define PYTHONHOMEHELP "<prefix>/pythonX.X"
25#endif
26#endif
27
28#include "pygetopt.h"
29
30#define COPYRIGHT \
31 "Type \"help\", \"copyright\", \"credits\" or \"license\" " \
32 "for more information."
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/* For Py_GetArgcArgv(); set by main() */
39static char **orig_argv;
40static int orig_argc;
41
42/* command line options */
43#define BASE_OPTS "c:dEhim:OQ:StuUvVW:xX?"
44
45#ifndef RISCOS
46#define PROGRAM_OPTS BASE_OPTS
47#else /*RISCOS*/
48/* extra option saying that we are running under a special task window
49 frontend; especially my_readline will behave different */
50#define PROGRAM_OPTS BASE_OPTS "w"
51/* corresponding flag */
52extern int Py_RISCOSWimpFlag;
53#endif /*RISCOS*/
54
55/* Short usage message (with %s for argv0) */
56static char *usage_line =
57"usage: %s [option] ... [-c cmd | -m mod | file | -] [arg] ...\n";
58
59/* Long usage message, split into parts < 512 bytes */
60static char *usage_1 = "\
61Options and arguments (and corresponding environment variables):\n\
62-c cmd : program passed in as string (terminates option list)\n\
63-d : debug output from parser (also PYTHONDEBUG=x)\n\
64-E : ignore environment variables (such as PYTHONPATH)\n\
65-h : print this help message and exit (also --help)\n\
66-i : inspect interactively after running script, (also PYTHONINSPECT=x)\n\
67 and force prompts, even if stdin does not appear to be a terminal\n\
68";
69static char *usage_2 = "\
70-m mod : run library module as a script (terminates option list)\n\
71-O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)\n\
72-OO : remove doc-strings in addition to the -O optimizations\n\
73-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew\n\
74-S : don't imply 'import site' on initialization\n\
75-t : issue warnings about inconsistent tab usage (-tt: issue errors)\n\
76-u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)\n\
77";
78static char *usage_3 = "\
79 see man page for details on internal buffering relating to '-u'\n\
80-v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
81-V : print the Python version number and exit (also --version)\n\
82-W arg : warning control (arg is action:message:category:module:lineno)\n\
83-x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
84file : program read from script file\n\
85- : program read from stdin (default; interactive mode if a tty)\n\
86";
87static char *usage_4 = "\
88arg ...: arguments passed to program in sys.argv[1:]\n\
89Other environment variables:\n\
90PYTHONSTARTUP: file executed on interactive startup (no default)\n\