annotate Mac/Python/macmain.c @ 3433:578ca302a598 legacy-trunk

Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd() after each chdir call.
author Jack Jansen <jack.jansen@cwi.nl>
date Wed, 06 Mar 1996 16:21:34 +0000
parents 67f5d29d405b
children 066a8ae4d406
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1811
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
2091
b4d982c648bb 1995 copyright
Guido van Rossum <guido@python.org>
parents: 2031
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
b4d982c648bb 1995 copyright
Guido van Rossum <guido@python.org>
parents: 2031
diff changeset
3 The Netherlands.
1811
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 documentation for any purpose and without fee is hereby granted,
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 both that copyright notice and this permission notice appear in
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 distribution of the software without specific, written prior permission.
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 ******************************************************************/
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
24
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
25 /* Python interpreter main program */
1811
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
27 #include "Python.h"
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
28 #include "pythonresources.h"
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
29 #include "import.h"
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
30 #include "marshal.h"
2144
0e60cd207adb must include rename2.h
Guido van Rossum <guido@python.org>
parents: 2091
diff changeset
31
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
32 #include <Memory.h>
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
33 #include <Resources.h>
1811
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #include <stdio.h>
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
35 #include <Events.h>
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
36 #include <Windows.h>
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
37 #include <Desk.h>
1811
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
2277
df7e26b5c918 Added stuff so CodeWarrior isn't so verbose about its stdio windows
Jack Jansen <jack.jansen@cwi.nl>
parents: 2226
diff changeset
39 #ifdef __MWERKS__
df7e26b5c918 Added stuff so CodeWarrior isn't so verbose about its stdio windows
Jack Jansen <jack.jansen@cwi.nl>
parents: 2226
diff changeset
40 #include <SIOUX.h>
3247
20d74fa3b50b For MW Python, update titlebar of window when python exits.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3236
diff changeset
41 #define USE_SIOUX
2277
df7e26b5c918 Added stuff so CodeWarrior isn't so verbose about its stdio windows
Jack Jansen <jack.jansen@cwi.nl>
parents: 2226
diff changeset
42 #endif
df7e26b5c918 Added stuff so CodeWarrior isn't so verbose about its stdio windows
Jack Jansen <jack.jansen@cwi.nl>
parents: 2226
diff changeset
43
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
44 #ifdef THINK_C
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
45 #include <console.h>
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
46 #endif
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
47
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
48 #define STARTUP "PythonStartup"
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
49
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
50 extern int Py_DebugFlag; /* For parser.c, declared in pythonrun.c */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
51 extern int Py_VerboseFlag; /* For import.c, declared in pythonrun.c */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
52 extern int Py_SuppressPrintingFlag; /* For ceval.c, declared in pythonrun.c */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
53
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
54
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
55 /* Subroutines that live in their own file */
3228
f4a59ffe1a5f Added prototypes.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3051
diff changeset
56 extern char *getversion Py_PROTO((void));
f4a59ffe1a5f Added prototypes.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3051
diff changeset
57 extern char *getcopyright Py_PROTO((void));
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
58
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
59
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
60 /* For getprogramname(); set by main() */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
61 static char *argv0;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
62
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
63 /* For getargcargv(); set by main() */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
64 static char **orig_argv;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
65 static int orig_argc;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
66
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
67 /* Flags indicating whether stdio window should stay open on termination */
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
68 static int keep_normal;
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
69 static int keep_error = 1;
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
70
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
71 /* Initialize the Mac toolbox world */
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
72
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
73 static void
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
74 init_mac_world()
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
75 {
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
76 #ifdef THINK_C
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
77 printf("\n");
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
78 #else
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
79 MaxApplZone();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
80 InitGraf(&qd.thePort);
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
81 InitFonts();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
82 InitWindows();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
83 TEInit();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
84 InitDialogs((long)0);
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
85 InitMenus();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
86 InitCursor();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
87 #endif
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
88 }
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
89
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
90 /* Initialization code shared by interpreter and applets */
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
91
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
92 static void
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
93 init_common()
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
94 {
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
95
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
96 /* Initialize toolboxes */
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
97 init_mac_world();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
98
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
99 #ifdef USE_MAC_SHARED_LIBRARY
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
100 /* Add the shared library to the stack of resource files */
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
101 PyMac_AddLibResources();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
102 #endif
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
103
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
104 #if defined(USE_GUSI)
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
105 /* Setup GUSI */
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
106 GUSIDefaultSetup();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
107 #endif
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
108
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
109 #ifdef USE_SIOUX
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
110 /* Set various SIOUX flags. Some are changed later based on options */
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
111 SIOUXSettings.asktosaveonclose = 0;
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
112 SIOUXSettings.showstatusline = 0;
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
113 SIOUXSettings.tabspaces = 4;
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
114 #endif
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
115
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
116 }
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
117
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
118
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
119 #ifdef USE_MAC_APPLET_SUPPORT
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
120 /* Applet support */
2031
1739f00ffc86 Enlarged version buffer (nobody expects the spanish inquisition:-)
Jack Jansen <jack.jansen@cwi.nl>
parents: 1821
diff changeset
121
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
122 /* Run a compiled Python Python script from 'PYC ' resource __main__ */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
123 static int
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
124 run_main_resource()
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
125 {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
126 Handle h;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
127 long size;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
128 PyObject *code;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
129 PyObject *result;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
130
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
131 h = GetNamedResource('PYC ', "\p__main__");
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
132 if (h == NULL) {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
133 Alert(NOPYC_ALERT, NULL);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
134 return 1;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
135 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
136 size = GetResourceSizeOnDisk(h);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
137 HLock(h);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
138 code = PyMarshal_ReadObjectFromString(*h + 8, (int)(size - 8));
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
139 HUnlock(h);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
140 ReleaseResource(h);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
141 if (code == NULL) {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
142 PyErr_Print();
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
143 return 1;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
144 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
145 result = PyImport_ExecCodeModule("__main__", code);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
146 Py_DECREF(code);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
147 if (result == NULL) {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
148 PyErr_Print();
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
149 return 1;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
150 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
151 Py_DECREF(result);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
152 return 0;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
153 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
154
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
155 /* Initialization sequence for applets */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
156 void
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
157 PyMac_InitApplet()
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
158 {
1811
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 int argc;
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 char **argv;
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
161 int err;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
162
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
163 init_common();
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
164 argc = PyMac_GetArgv(&argv);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
165 Py_Initialize();
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
166 PySys_SetArgv(argc, argv);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
167 err = run_main_resource();
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
168 fflush(stderr);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
169 fflush(stdout);
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
170 PyMac_Exit(err);
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
171 /* XXX Should we bother to Py_Exit(sts)? */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
172 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
173
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
174 #endif /* USE_MAC_APPLET_SUPPORT */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
175
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
176 /* For normal application */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
177 void
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
178 PyMac_InitApplication()
1811
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 {
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
180 int argc;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
181 char **argv;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
182
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
183 init_common();
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
184 argc = PyMac_GetArgv(&argv);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
185 if ( argc > 1 ) {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
186 /* We're running a script. Attempt to change current directory */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
187 char curwd[256], *endp;
2313
ff72a5f9a4ee Various changes wrt shared-library python:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2277
diff changeset
188
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
189 strcpy(curwd, argv[1]);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
190 endp = strrchr(curwd, ':');
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
191 if ( endp && endp > curwd ) {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
192 *endp = '\0';
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
193
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
194 chdir(curwd);
3433
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3422
diff changeset
195 #ifdef USE_GUSI
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3422
diff changeset
196 /* Change MacOS's idea of wd too */
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3422
diff changeset
197 PyMac_FixGUSIcd();
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3422
diff changeset
198 #endif
2313
ff72a5f9a4ee Various changes wrt shared-library python:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2277
diff changeset
199 }
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
200 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
201 Py_Main(argc, argv);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
202 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
203
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
204 /*
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
205 ** PyMac_InteractiveOptions - Allow user to set options if option key is pressed
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
206 */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
207 void
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
208 PyMac_InteractiveOptions(int *inspect, int *verbose, int *suppress_print,
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
209 int *unbuffered, int *debugging, int *keep_normal,
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
210 int *keep_error)
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
211 {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
212 KeyMap rmap;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
213 unsigned char *map;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
214 short item, type;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
215 ControlHandle handle;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
216 DialogPtr dialog;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
217 Rect rect;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
218
3411
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
219 /* Default-defaults: */
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
220 *keep_error = 1;
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
221 /* Get default settings from our preference file */
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
222 PyMac_PreferenceOptions(inspect, verbose, suppress_print,
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
223 unbuffered, debugging, keep_normal, keep_error);
3411
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
224 /* If option is pressed override these */
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
225 GetKeys(rmap);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
226 map = (unsigned char *)rmap;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
227 if ( ( map[0x3a>>3] & (1<<(0x3a&7)) ) == 0 ) /* option key is 3a */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
228 return;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
229
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
230 dialog = GetNewDialog(OPT_DIALOG, NULL, (WindowPtr)-1);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
231 if ( dialog == NULL ) {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
232 printf("Option dialog not found - cannot set options\n");
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
233 return;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
234 }
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
235
3411
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
236 /* Set default values */
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
237 #define SET_OPT_ITEM(num, var) \
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
238 GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
239 SetCtlValue(handle, (short)*(var));
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
240
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
241 SET_OPT_ITEM(OPT_INSPECT, inspect);
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
242 SET_OPT_ITEM(OPT_VERBOSE, verbose);
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
243 SET_OPT_ITEM(OPT_SUPPRESS, suppress_print);
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
244 SET_OPT_ITEM(OPT_UNBUFFERED, unbuffered);
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
245 SET_OPT_ITEM(OPT_DEBUGGING, debugging);
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
246 SET_OPT_ITEM(OPT_KEEPNORMAL, keep_normal);
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
247 SET_OPT_ITEM(OPT_KEEPERROR, keep_error);
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
248
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
249 #undef SET_OPT_ITEM
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
250
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
251 while (1) {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
252 handle = NULL;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
253 ModalDialog(NULL, &item);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
254 if ( item == OPT_OK )
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
255 break;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
256 if ( item == OPT_CANCEL ) {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
257 DisposDialog(dialog);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
258 exit(0);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
259 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
260 #define OPT_ITEM(num, var) \
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
261 if ( item == (num) ) { \
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
262 *(var) = !*(var); \
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
263 GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
264 SetCtlValue(handle, (short)*(var)); \
2313
ff72a5f9a4ee Various changes wrt shared-library python:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2277
diff changeset
265 }
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
266
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
267 OPT_ITEM(OPT_INSPECT, inspect);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
268 OPT_ITEM(OPT_VERBOSE, verbose);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
269 OPT_ITEM(OPT_SUPPRESS, suppress_print);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
270 OPT_ITEM(OPT_UNBUFFERED, unbuffered);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
271 OPT_ITEM(OPT_DEBUGGING, debugging);
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
272 OPT_ITEM(OPT_KEEPNORMAL, keep_normal);
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
273 OPT_ITEM(OPT_KEEPERROR, keep_error);
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
274
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
275 #undef OPT_ITEM
2313
ff72a5f9a4ee Various changes wrt shared-library python:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2277
diff changeset
276 }
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
277 DisposDialog(dialog);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
278 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
279 /* Main program */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
280
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
281 int
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
282 Py_Main(argc, argv)
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
283 int argc;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
284 char **argv;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
285 {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
286 int sts;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
287 char *command = NULL;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
288 char *filename = NULL;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
289 FILE *fp = stdin;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
290 int inspect = 0;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
291 int unbuffered = 0;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
292
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
293 orig_argc = argc; /* For getargcargv() */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
294 orig_argv = argv;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
295 argv0 = argv[0]; /* For getprogramname() */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
296
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
297 PyMac_InteractiveOptions(&inspect, &Py_VerboseFlag, &Py_SuppressPrintingFlag,
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
298 &unbuffered, &Py_DebugFlag, &keep_normal, &keep_error);
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
299
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
300 if (unbuffered) {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
301 #ifndef MPW
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
302 setbuf(stdout, (char *)NULL);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
303 setbuf(stderr, (char *)NULL);
2313
ff72a5f9a4ee Various changes wrt shared-library python:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2277
diff changeset
304 #else
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
305 /* On MPW (3.2) unbuffered seems to hang */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
306 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
307 setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
2313
ff72a5f9a4ee Various changes wrt shared-library python:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2277
diff changeset
308 #endif
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
309 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
310
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
311 filename = argv[1];
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
312
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
313 if (Py_VerboseFlag ||
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
314 command == NULL && filename == NULL && isatty((int)fileno(fp)))
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
315 fprintf(stderr, "Python %s\n%s\n",
1811
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 getversion(), getcopyright());
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
317
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
318 if (filename != NULL) {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
319 if ((fp = fopen(filename, "r")) == NULL) {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
320 fprintf(stderr, "%s: can't open file '%s'\n",
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
321 argv[0], filename);
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
322 PyMac_Exit(2);
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
323 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
324 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
325
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
326 Py_Initialize();
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
327
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
328 PySys_SetArgv(argc-1, argv+1);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
329
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
330 if (filename == NULL && isatty((int)fileno(fp))) {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
331 FILE *fp = fopen(STARTUP, "r");
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
332 if (fp != NULL) {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
333 (void) PyRun_SimpleFile(fp, STARTUP);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
334 PyErr_Clear();
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
335 fclose(fp);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
336 }
1811
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 }
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
338 sts = PyRun_AnyFile(
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
339 fp, filename == NULL ? "<stdin>" : filename) != 0;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
340 if (filename != NULL)
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
341 fclose(fp);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
342
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
343 if (inspect && isatty((int)fileno(stdin)) &&
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
344 (filename != NULL || command != NULL))
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
345 sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
346
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
347 Py_Exit(sts);
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
348 /*NOTREACHED*/
1811
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 }
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
350
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
351 /*
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
352 ** Terminate application
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
353 */
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
354 PyMac_Exit(status)
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
355 int status;
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
356 {
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
357 int keep;
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
358
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
359 if ( status )
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
360 keep = keep_error;
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
361 else
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
362 keep = keep_normal;
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
363
3247
20d74fa3b50b For MW Python, update titlebar of window when python exits.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3236
diff changeset
364 #ifdef USE_SIOUX
20d74fa3b50b For MW Python, update titlebar of window when python exits.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3236
diff changeset
365 if (keep) {
20d74fa3b50b For MW Python, update titlebar of window when python exits.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3236
diff changeset
366 SIOUXSettings.standalone = 1;
20d74fa3b50b For MW Python, update titlebar of window when python exits.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3236
diff changeset
367 SIOUXSettings.autocloseonquit = 0;
3411
14991c4331df Store default startup options in preference file or
Jack Jansen <jack.jansen@cwi.nl>
parents: 3247
diff changeset
368 SIOUXSetTitle("\p«terminated»");
3247
20d74fa3b50b For MW Python, update titlebar of window when python exits.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3236
diff changeset
369 }
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
370 else
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
371 SIOUXSettings.autocloseonquit = 1;
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
372 #endif
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
373 #ifdef THINK_C
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
374 console_options.pause_atexit = keep;
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
375 #endif
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
376
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
377 exit(status);
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
378 }
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
379
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
380 /* Return the program name -- some code out there needs this. */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
381
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
382 char *
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
383 getprogramname()
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
384 {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
385 return argv0;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
386 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
387
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
388
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
389 /* Make the *original* argc/argv available to other modules.
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
390 This is rare, but it is needed by the secureware extension. */
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
391
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
392 void
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
393 getargcargv(argc,argv)
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
394 int *argc;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
395 char ***argv;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
396 {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
397 *argc = orig_argc;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
398 *argv = orig_argv;
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
399 }