annotate Mac/Python/macmain.c @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents fbe820e0c601
children a82ce198fe69 b9246f8fb8fd
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 /***********************************************************
5079
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4962
diff changeset
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
2091
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"
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4017
diff changeset
31 #include "macglue.h"
2144
0e60cd207adb must include rename2.h
Guido van Rossum <guido@python.org>
parents: 2091
diff changeset
32
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
33 #ifdef WITHOUT_FRAMEWORKS
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
34 #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
35 #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
36 #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
37 #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
38 #include <Windows.h>
3442
066a8ae4d406 Added missing include of Fonts.h
Jack Jansen <jack.jansen@cwi.nl>
parents: 3433
diff changeset
39 #include <Fonts.h>
6293
6c0a2658a156 Added old-exception and no-site-python options and balloon help
Jack Jansen <jack.jansen@cwi.nl>
parents: 6277
diff changeset
40 #include <Balloons.h>
20779
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
41 #if TARGET_API_MAC_CARBON
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
42 #include <CFBundle.h>
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
43 #include <CFURL.h>
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
44 #include <CFString.h>
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
45 #include <CFBase.h>
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
46 #include <CFArray.h>
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
47 #endif /* TARGET_API_MAC_CARBON */
11529
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
48 #ifdef USE_APPEARANCE
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
49 #include <Gestalt.h>
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
50 #include <Appearance.h>
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
51 #endif /* USE_APPEARANCE */
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
52 #else
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
53 #include <Carbon/Carbon.h>
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
54 #endif /* WITHOUT_FRAMEWORKS */
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
55
2277
df7e26b5c918 Added stuff so CodeWarrior isn't so verbose about its stdio windows
Jack Jansen <jack.jansen@cwi.nl>
parents: 2226
diff changeset
56 #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
57 #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
58 #define USE_SIOUX
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
59 extern int ccommand(char ***);
4911
21878c849626 Added profiler initialization/finalization code (if __profile__ is defined)
Jack Jansen <jack.jansen@cwi.nl>
parents: 4249
diff changeset
60 #if __profile__ == 1
21878c849626 Added profiler initialization/finalization code (if __profile__ is defined)
Jack Jansen <jack.jansen@cwi.nl>
parents: 4249
diff changeset
61 #include <profiler.h>
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
62 #endif /* __profile__ */
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
63 #endif /* __MWERKS__ */
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
64
12834
c2a0f2a81fa8 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12593
diff changeset
65 #include <unistd.h>
13702
f840bf6a3351 Added more prototypes.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13638
diff changeset
66 #ifdef USE_MAC_SHARED_LIBRARY
f840bf6a3351 Added more prototypes.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13638
diff changeset
67 extern PyMac_AddLibResources(void);
f840bf6a3351 Added more prototypes.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13638
diff changeset
68 #endif
2277
df7e26b5c918 Added stuff so CodeWarrior isn't so verbose about its stdio windows
Jack Jansen <jack.jansen@cwi.nl>
parents: 2226
diff changeset
69
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
70 #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
71
14464
17cec96f75bc Use same short banner message as unix/win Python.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14198
diff changeset
72 #define COPYRIGHT \
17cec96f75bc Use same short banner message as unix/win Python.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14198
diff changeset
73 "Type \"copyright\", \"credits\" or \"license\" for more information."
17cec96f75bc Use same short banner message as unix/win Python.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14198
diff changeset
74
4228
84444ea3f5f6 - Rationalized override preferences support, by remembering
Jack Jansen <jack.jansen@cwi.nl>
parents: 4215
diff changeset
75 short PyMac_AppRefNum; /* RefNum of application resource fork */
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
76
3930
52c19ee83a6b Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3750
diff changeset
77 /* For Py_GetArgcArgv(); set by main() */
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
78 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
79 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
80
16557
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
81 /* A flag which remembers whether the user has acknowledged all the console
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
82 ** output (by typing something)
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
83 */
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
84 #define STATE_UNKNOWN 0
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
85 #define STATE_LASTREAD 1
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
86 #define STATE_LASTWRITE 2
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
87 int console_output_state = STATE_UNKNOWN;
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
88
15192
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
89 PyMac_PrefRecord PyMac_options;
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
90
19855
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
91 static void Py_Main(int, char **, char *); /* Forward */
13542
ddd6138c9e6f ANSIfication step 1: get rid of Py_PROTO and Py_FPROTO.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12855
diff changeset
92 void PyMac_Exit(int); /* Forward */
4017
5dc8c042905b Guido: added some void's to declarations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3930
diff changeset
93
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
94 static void init_appearance(void)
11529
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
95 {
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
96 #ifdef USE_APPEARANCE
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
97 OSErr err;
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
98 SInt32 response;
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
99
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
100 err = Gestalt(gestaltAppearanceAttr,&response);
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
101 if ( err ) goto no_appearance;
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
102 if ( !(response&(1<<gestaltAppearanceExists)) ) goto no_appearance;
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
103 /* XXXX Should we check the version? Compat-mode? */
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
104 PyMac_AppearanceCompliant = 1;
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
105 no_appearance:
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
106 return;
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
107 #endif /* USE_APPEARANCE */
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
108 }
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
109 /* Initialize the Mac toolbox world */
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
110
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
111 static void
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
112 init_mac_world(void)
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
113 {
13608
a901c2c0166b Test for TARGET_API_MAC_CARBON with #if in stead of #ifdef.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13547
diff changeset
114 #if !TARGET_API_MAC_CARBON
12834
c2a0f2a81fa8 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12593
diff changeset
115 /* These aren't needed for carbon */
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
116 MaxApplZone();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
117 InitGraf(&qd.thePort);
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
118 InitFonts();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
119 InitWindows();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
120 TEInit();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
121 InitDialogs((long)0);
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
122 InitMenus();
12834
c2a0f2a81fa8 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12593
diff changeset
123 #endif
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
124 InitCursor();
11529
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 11350
diff changeset
125 init_appearance();
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
126 }
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
127
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
128 /*
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
129 ** PyMac_InteractiveOptions - Allow user to set options if option key is pressed
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
130 */
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
131 static void
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
132 PyMac_InteractiveOptions(PyMac_PrefRecord *p, int *argcp, char ***argvp)
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
133 {
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
134 KeyMap rmap;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
135 unsigned char *map;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
136 short item, type;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
137 ControlHandle handle;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
138 DialogPtr dialog;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
139 Rect rect;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
140
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
141 /*
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
142 ** If the preferences disallows interactive options we return,
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
143 ** similarly of <option> isn't pressed.
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
144 */
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
145 if (p->nointopt) return;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
146
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
147 GetKeys(rmap);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
148 map = (unsigned char *)rmap;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
149 if ( ( map[0x3a>>3] & (1<<(0x3a&7)) ) == 0 ) /* option key is 3a */
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
150 return;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
151
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
152 dialog = GetNewDialog(OPT_DIALOG, NULL, (WindowPtr)-1);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
153 if ( dialog == NULL ) {
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
154 printf("Option dialog not found - cannot set options\n");
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
155 return;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
156 }
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
157 SetDialogDefaultItem(dialog, OPT_OK);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
158 SetDialogCancelItem(dialog, OPT_CANCEL);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
159
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
160 /* Set default values */
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
161 #define SET_OPT_ITEM(num, var) \
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
162 GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \
5270
de9d0c5249b0 Changed the few old routine names still used to the new ones
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
163 SetControlValue(handle, (short)p->var);
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
164
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
165 SET_OPT_ITEM(OPT_INSPECT, inspect);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
166 SET_OPT_ITEM(OPT_VERBOSE, verbose);
19641
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
167 /* OPT_VERBOSEVERBOSE is default off */
6293
6c0a2658a156 Added old-exception and no-site-python options and balloon help
Jack Jansen <jack.jansen@cwi.nl>
parents: 6277
diff changeset
168 SET_OPT_ITEM(OPT_OPTIMIZE, optimize);
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
169 SET_OPT_ITEM(OPT_UNBUFFERED, unbuffered);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
170 SET_OPT_ITEM(OPT_DEBUGGING, debugging);
14773
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
171 GetDialogItem(dialog, OPT_KEEPALWAYS, &type, (Handle *)&handle, &rect);
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
172 SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ALWAYS));
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
173 GetDialogItem(dialog, OPT_KEEPOUTPUT, &type, (Handle *)&handle, &rect);
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
174 SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_OUTPUT));
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
175 GetDialogItem(dialog, OPT_KEEPERROR, &type, (Handle *)&handle, &rect);
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
176 SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ERROR));
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
177 GetDialogItem(dialog, OPT_KEEPNEVER, &type, (Handle *)&handle, &rect);
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
178 SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_NEVER));
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
179 /* SET_OPT_ITEM(OPT_KEEPCONSOLE, keep_console); */
12593
eaee924efb19 Removed string-exception preference, added tabcheck and NavService preference, upped version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
180 SET_OPT_ITEM(OPT_TABWARN, tabwarn);
6293
6c0a2658a156 Added old-exception and no-site-python options and balloon help
Jack Jansen <jack.jansen@cwi.nl>
parents: 6277
diff changeset
181 SET_OPT_ITEM(OPT_NOSITE, nosite);
19641
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
182 SET_OPT_ITEM(OPT_DIVISIONWARN, divisionwarn);
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
183 SET_OPT_ITEM(OPT_UNIXNEWLINES, unixnewlines);
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
184 /* The rest are not settable interactively */
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
185
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
186 #undef SET_OPT_ITEM
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
187
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
188 while (1) {
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
189 handle = NULL;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
190 ModalDialog(NULL, &item);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
191 if ( item == OPT_OK )
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
192 break;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
193 if ( item == OPT_CANCEL ) {
5270
de9d0c5249b0 Changed the few old routine names still used to the new ones
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
194 DisposeDialog(dialog);
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
195 exit(0);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
196 }
13608
a901c2c0166b Test for TARGET_API_MAC_CARBON with #if in stead of #ifdef.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13547
diff changeset
197 #if !TARGET_API_MAC_CARBON
6293
6c0a2658a156 Added old-exception and no-site-python options and balloon help
Jack Jansen <jack.jansen@cwi.nl>
parents: 6277
diff changeset
198 if ( item == OPT_HELP ) {
6c0a2658a156 Added old-exception and no-site-python options and balloon help
Jack Jansen <jack.jansen@cwi.nl>
parents: 6277
diff changeset
199 HMSetBalloons(!HMGetBalloons());
6c0a2658a156 Added old-exception and no-site-python options and balloon help
Jack Jansen <jack.jansen@cwi.nl>
parents: 6277
diff changeset
200 }
12834
c2a0f2a81fa8 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12593
diff changeset
201 #endif
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
202 #if !TARGET_API_MAC_OSX
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
203 if ( item == OPT_CMDLINE ) {
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
204 int old_argc = *argcp;
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
205 int i;
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
206 int new_argc, newer_argc;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
207 char **new_argv, **newer_argv;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
208
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
209 new_argc = ccommand(&new_argv);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
210 newer_argc = (new_argc-1) + old_argc;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
211 newer_argv = malloc((newer_argc+1)*sizeof(char *));
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
212 if( !newer_argv )
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
213 Py_FatalError("Cannot malloc argv\n");
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
214 for(i=0; i<old_argc; i++)
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
215 newer_argv[i] = (*argvp)[i];
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
216 for(i=old_argc; i<=newer_argc; i++) /* Copy the NULL too */
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
217 newer_argv[i] = new_argv[i-old_argc+1];
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
218 *argvp = newer_argv;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
219 *argcp = newer_argc;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
220
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
221 /* XXXX Is it not safe to use free() here, apparently */
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
222 }
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
223 #endif /* !TARGET_API_MAC_OSX */
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
224 #define OPT_ITEM(num, var) \
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
225 if ( item == (num) ) { \
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
226 p->var = !p->var; \
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
227 GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \
5270
de9d0c5249b0 Changed the few old routine names still used to the new ones
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
228 SetControlValue(handle, (short)p->var); \
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
229 }
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
230
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
231 OPT_ITEM(OPT_INSPECT, inspect);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
232 OPT_ITEM(OPT_VERBOSE, verbose);
19641
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
233 if ( item == OPT_VERBOSEVERBOSE ) {
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
234 if ( p->verbose == 2 )
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
235 p->verbose = 1;
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
236 else
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
237 p->verbose = 2;
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
238 GetDialogItem(dialog, OPT_VERBOSE, &type, (Handle *)&handle, &rect);
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
239 SetControlValue(handle, 1);
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
240 }
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
241 GetDialogItem(dialog, OPT_VERBOSEVERBOSE, &type, (Handle *)&handle, &rect);
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
242 SetControlValue(handle, p->verbose == 2);
6293
6c0a2658a156 Added old-exception and no-site-python options and balloon help
Jack Jansen <jack.jansen@cwi.nl>
parents: 6277
diff changeset
243 OPT_ITEM(OPT_OPTIMIZE, optimize);
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
244 OPT_ITEM(OPT_UNBUFFERED, unbuffered);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
245 OPT_ITEM(OPT_DEBUGGING, debugging);
14773
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
246 if ( item == OPT_KEEPALWAYS ) p->keep_console = POPT_KEEPCONSOLE_ALWAYS;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
247 if ( item == OPT_KEEPOUTPUT ) p->keep_console = POPT_KEEPCONSOLE_OUTPUT;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
248 if ( item == OPT_KEEPERROR ) p->keep_console = POPT_KEEPCONSOLE_ERROR;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
249 if ( item == OPT_KEEPNEVER ) p->keep_console = POPT_KEEPCONSOLE_NEVER;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
250 GetDialogItem(dialog, OPT_KEEPALWAYS, &type, (Handle *)&handle, &rect);
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
251 SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ALWAYS));
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
252 GetDialogItem(dialog, OPT_KEEPOUTPUT, &type, (Handle *)&handle, &rect);
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
253 SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_OUTPUT));
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
254 GetDialogItem(dialog, OPT_KEEPERROR, &type, (Handle *)&handle, &rect);
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
255 SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ERROR));
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
256 GetDialogItem(dialog, OPT_KEEPNEVER, &type, (Handle *)&handle, &rect);
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
257 SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_NEVER));
12593
eaee924efb19 Removed string-exception preference, added tabcheck and NavService preference, upped version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
258 OPT_ITEM(OPT_TABWARN, tabwarn);
6293
6c0a2658a156 Added old-exception and no-site-python options and balloon help
Jack Jansen <jack.jansen@cwi.nl>
parents: 6277
diff changeset
259 OPT_ITEM(OPT_NOSITE, nosite);
19641
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
260 OPT_ITEM(OPT_DIVISIONWARN, divisionwarn);
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
261 OPT_ITEM(OPT_UNIXNEWLINES, unixnewlines);
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
262
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
263 #undef OPT_ITEM
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
264 }
5270
de9d0c5249b0 Changed the few old routine names still used to the new ones
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
265 DisposeDialog(dialog);
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
266 }
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
267
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
268 /*
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
269 ** Initialization code, shared by interpreter and applets
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
270 */
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
271 static void
4962
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
272 init_common(int *argcp, char ***argvp, int embedded)
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
273 {
4228
84444ea3f5f6 - Rationalized override preferences support, by remembering
Jack Jansen <jack.jansen@cwi.nl>
parents: 4215
diff changeset
274 /* Remember resource fork refnum, for later */
84444ea3f5f6 - Rationalized override preferences support, by remembering
Jack Jansen <jack.jansen@cwi.nl>
parents: 4215
diff changeset
275 PyMac_AppRefNum = CurResFile();
84444ea3f5f6 - Rationalized override preferences support, by remembering
Jack Jansen <jack.jansen@cwi.nl>
parents: 4215
diff changeset
276
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
277 /* Initialize toolboxes */
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
278 init_mac_world();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
279
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
280 #ifdef USE_MAC_SHARED_LIBRARY
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
281 /* Add the shared library to the stack of resource files */
8792
0f5e0b405bc2 Initialize the program name before adding shared library resources (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 6444
diff changeset
282 (void)PyMac_init_process_location();
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
283 PyMac_AddLibResources();
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
284 #endif
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
285
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
286 #if defined(USE_GUSI1)
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
287 /* Setup GUSI */
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
288 GUSIDefaultSetup();
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4017
diff changeset
289 PyMac_SetGUSISpin();
4228
84444ea3f5f6 - Rationalized override preferences support, by remembering
Jack Jansen <jack.jansen@cwi.nl>
parents: 4215
diff changeset
290 PyMac_SetGUSIOptions();
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
291 #endif
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
292 #if defined(USE_GUSI)
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5431
diff changeset
293 atexit(PyMac_StopGUSISpin);
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
294 #endif
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
295
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
296 #ifdef USE_SIOUX
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
297 /* Set various SIOUX flags. Some are changed later based on options */
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
298 #if 0
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
299 SIOUXSettings.standalone = 0; /* XXXX Attempting to keep sioux from eating events */
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
300 #endif
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
301 SIOUXSettings.asktosaveonclose = 0;
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
302 SIOUXSettings.showstatusline = 0;
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
303 SIOUXSettings.tabspaces = 4;
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
304 #endif
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
305
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
306 /* Get options from preference file (or from applet resource fork) */
15192
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
307 PyMac_options.keep_console = POPT_KEEPCONSOLE_OUTPUT; /* default-default */
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
308 PyMac_options.unixnewlines = 1;
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
309 #if !TARGET_API_MAC_OSX
15192
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
310 PyMac_PreferenceOptions(&PyMac_options);
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
311 #endif
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
312
4962
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
313 if ( embedded ) {
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
314 static char *emb_argv[] = {"embedded-python", 0};
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
315
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
316 *argcp = 1;
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
317 *argvp = emb_argv;
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
318 } else {
22026
fbe820e0c601 bqackport of 1.73:
Jack Jansen <jack.jansen@cwi.nl>
parents: 20794
diff changeset
319 /* Create argc/argv. Do it before we go into the options event loop.
fbe820e0c601 bqackport of 1.73:
Jack Jansen <jack.jansen@cwi.nl>
parents: 20794
diff changeset
320 ** In MachoPython we skip this step if we already have plausible
fbe820e0c601 bqackport of 1.73:
Jack Jansen <jack.jansen@cwi.nl>
parents: 20794
diff changeset
321 ** command line arguments.
fbe820e0c601 bqackport of 1.73:
Jack Jansen <jack.jansen@cwi.nl>
parents: 20794
diff changeset
322 */
fbe820e0c601 bqackport of 1.73:
Jack Jansen <jack.jansen@cwi.nl>
parents: 20794
diff changeset
323 #if TARGET_API_MAC_OSX
fbe820e0c601 bqackport of 1.73:
Jack Jansen <jack.jansen@cwi.nl>
parents: 20794
diff changeset
324 if (*argcp == 2 && strncmp((*argvp)[1], "-psn_", 5) == 0)
fbe820e0c601 bqackport of 1.73:
Jack Jansen <jack.jansen@cwi.nl>
parents: 20794
diff changeset
325 #endif
fbe820e0c601 bqackport of 1.73:
Jack Jansen <jack.jansen@cwi.nl>
parents: 20794
diff changeset
326 *argcp = PyMac_GetArgv(argvp, PyMac_options.noargs);
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
327 #if !TARGET_API_MAC_OSX
15921
489692e79151 Trigger keep-console-open on GUSISIOUX_STATE_UNKNOWN. Better than the previous complicated expression.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15826
diff changeset
328 #ifndef NO_ARGV0_CHDIR
13638
58398c0f948b MacPython on MacOSX DP4 gets started in the wrong directory. The workaround (ifdeffed by USE_ARGV0_CHDIR) is to do a chdir() to the folder part of our executable name.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
329 if (*argcp >= 1 && (*argvp)[0] && (*argvp)[0][0]) {
58398c0f948b MacPython on MacOSX DP4 gets started in the wrong directory. The workaround (ifdeffed by USE_ARGV0_CHDIR) is to do a chdir() to the folder part of our executable name.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
330 /* Workaround for MacOS X, which currently (DP4) doesn't set
58398c0f948b MacPython on MacOSX DP4 gets started in the wrong directory. The workaround (ifdeffed by USE_ARGV0_CHDIR) is to do a chdir() to the folder part of our executable name.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
331 ** the working folder correctly
58398c0f948b MacPython on MacOSX DP4 gets started in the wrong directory. The workaround (ifdeffed by USE_ARGV0_CHDIR) is to do a chdir() to the folder part of our executable name.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
332 */
58398c0f948b MacPython on MacOSX DP4 gets started in the wrong directory. The workaround (ifdeffed by USE_ARGV0_CHDIR) is to do a chdir() to the folder part of our executable name.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
333 char app_wd[256], *p;
58398c0f948b MacPython on MacOSX DP4 gets started in the wrong directory. The workaround (ifdeffed by USE_ARGV0_CHDIR) is to do a chdir() to the folder part of our executable name.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
334
58398c0f948b MacPython on MacOSX DP4 gets started in the wrong directory. The workaround (ifdeffed by USE_ARGV0_CHDIR) is to do a chdir() to the folder part of our executable name.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
335 strncpy(app_wd, (*argvp)[0], 256);
58398c0f948b MacPython on MacOSX DP4 gets started in the wrong directory. The workaround (ifdeffed by USE_ARGV0_CHDIR) is to do a chdir() to the folder part of our executable name.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
336 p = strrchr(app_wd, ':');
58398c0f948b MacPython on MacOSX DP4 gets started in the wrong directory. The workaround (ifdeffed by USE_ARGV0_CHDIR) is to do a chdir() to the folder part of our executable name.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
337 if ( p ) *p = 0;
58398c0f948b MacPython on MacOSX DP4 gets started in the wrong directory. The workaround (ifdeffed by USE_ARGV0_CHDIR) is to do a chdir() to the folder part of our executable name.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
338 chdir(app_wd);
58398c0f948b MacPython on MacOSX DP4 gets started in the wrong directory. The workaround (ifdeffed by USE_ARGV0_CHDIR) is to do a chdir() to the folder part of our executable name.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
339 }
58398c0f948b MacPython on MacOSX DP4 gets started in the wrong directory. The workaround (ifdeffed by USE_ARGV0_CHDIR) is to do a chdir() to the folder part of our executable name.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
340 #endif
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
341 #endif
4962
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
342 /* Do interactive option setting, if allowed and <option> depressed */
15192
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
343 PyMac_InteractiveOptions(&PyMac_options, argcp, argvp);
4962
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
344 }
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
345
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
346 /* Copy selected options to where the machine-independent stuff wants it */
15192
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
347 Py_VerboseFlag = PyMac_options.verbose;
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
348 /* Py_SuppressPrintingFlag = PyMac_options.suppress_print; */
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
349 Py_OptimizeFlag = PyMac_options.optimize;
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
350 Py_DebugFlag = PyMac_options.debugging;
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
351 Py_NoSiteFlag = PyMac_options.nosite;
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
352 Py_TabcheckFlag = PyMac_options.tabwarn;
19641
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
353 Py_DivisionWarningFlag = PyMac_options.divisionwarn;
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
354 #if !TARGET_API_MAC_OSX
15192
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
355 if ( PyMac_options.noargs ) {
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
356 /* don't process events at all without the scripts permission */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
357 PyMacSchedParams scp;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
358
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
359 PyMac_GetSchedParams(&scp);
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
360 scp.process_events = 0;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
361 /* Should we disable command-dot as well? */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
362 PyMac_SetSchedParams(&scp);
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
363 }
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
364 #endif /* !TARGET_API_MAC_OSX */
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
365
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
366 /* Set buffering */
15192
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
367 if (PyMac_options.unbuffered) {
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
368 #ifndef MPW
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
369 setbuf(stdout, (char *)NULL);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
370 setbuf(stderr, (char *)NULL);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
371 #else
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
372 /* On MPW (3.2) unbuffered seems to hang */
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
373 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
374 setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
375 #endif
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
376 }
4911
21878c849626 Added profiler initialization/finalization code (if __profile__ is defined)
Jack Jansen <jack.jansen@cwi.nl>
parents: 4249
diff changeset
377 #if __profile__ == 1
21878c849626 Added profiler initialization/finalization code (if __profile__ is defined)
Jack Jansen <jack.jansen@cwi.nl>
parents: 4249
diff changeset
378 /* collectSummary or collectDetailed, timebase, #routines, max stack depth */
11350
678a9a79c7e8 Bigger buffer size for C profiler (if profiling is enabled).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8792
diff changeset
379 ProfilerInit(collectSummary, bestTimeBase, 8000, 250);
4911
21878c849626 Added profiler initialization/finalization code (if __profile__ is defined)
Jack Jansen <jack.jansen@cwi.nl>
parents: 4249
diff changeset
380 #endif
5961
35e5acc6532c Adapted for 1.5a3: Py_SupressPrintingFlag is gone, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
381
35e5acc6532c Adapted for 1.5a3: Py_SupressPrintingFlag is gone, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
382 /* Tell the rest of python about our argc/argv */
35e5acc6532c Adapted for 1.5a3: Py_SupressPrintingFlag is gone, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
383 orig_argc = *argcp; /* For Py_GetArgcArgv() */
35e5acc6532c Adapted for 1.5a3: Py_SupressPrintingFlag is gone, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
384 orig_argv = *argvp;
35e5acc6532c Adapted for 1.5a3: Py_SupressPrintingFlag is gone, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
385 Py_SetProgramName((*argvp)[0]);
3422
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
386 }
67f5d29d405b - Reorganized init code
Jack Jansen <jack.jansen@cwi.nl>
parents: 3411
diff changeset
387
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
388 /*
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
389 ** Inspection mode after script/applet termination
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
390 */
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
391 static int
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
392 run_inspect(void)
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
393 {
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
394 int sts = 0;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
395
15192
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
396 if (PyMac_options.inspect && isatty((int)fileno(stdin)))
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
397 sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
398 return sts;
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
399 }
19851
f3f694111ea0 Failing to import macfsn is not a fatal error.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19748
diff changeset
400
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
401 #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
402 /* Applet support */
2031
1739f00ffc86 Enlarged version buffer (nobody expects the spanish inquisition:-)
Jack Jansen <jack.jansen@cwi.nl>
parents: 1821
diff changeset
403
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
404 /* 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
405 static int
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
406 run_main_resource(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
407 {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
408 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
409 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
410 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
411 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
412
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
413 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
414 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
415 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
416 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
417 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
418 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
419 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
420 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
421 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
422 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
423 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
424 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
425 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
426 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
427 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
428 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
429 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
430 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
431 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
432 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
433 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
434 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
435 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
436
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
437 /* 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
438 void
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
439 PyMac_InitApplet(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
440 {
1811
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 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
442 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
443 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
444
4962
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
445 init_common(&argc, &argv, 0);
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
446
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
447 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
448 PySys_SetArgv(argc, argv);
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
449
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
450 err = run_main_resource();
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
451
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
452 err = (run_inspect() || err);
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
453
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
454 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
455 fflush(stdout);
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
456 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
457 /* 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
458 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
459
4962
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
460 /*
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
461 ** Hook for embedding python.
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
462 */
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
463 void
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
464 PyMac_Initialize(void)
4962
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
465 {
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
466 int argc;
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
467 char **argv;
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
468
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
469 init_common(&argc, &argv, 1);
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
470 Py_Initialize();
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
471 PySys_SetArgv(argc, argv);
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
472 }
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
473
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
474 #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
475
20779
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
476 #if TARGET_API_MAC_OSX /* Really: TARGET_API_MAC_CARBON */
19855
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
477
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
478 static int
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
479 locateResourcePy(char * resourceName, char * resourceURLCStr, int length) {
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
480 CFBundleRef mainBundle = NULL;
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
481 CFURLRef URL, absoluteURL;
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
482 CFStringRef filenameString, filepathString, rsrcString;
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
483 CFIndex size, i;
20779
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
484 CFArrayRef arrayRef = NULL;
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
485 int success = 0;
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
486
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
487 #if TARGET_API_MAC_OSX
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
488 CFURLPathStyle thePathStyle = kCFURLPOSIXPathStyle;
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
489 #else
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
490 CFURLPathStyle thePathStyle = kCFURLHFSPathStyle;
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
491 #endif
19855
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
492
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
493 /* Get a reference to our main bundle */
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
494 mainBundle = CFBundleGetMainBundle();
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
495
20779
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
496 /* If we are running inside a bundle, look through it. Otherwise, do nothing. */
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
497 if (mainBundle) {
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
498 /* Create a CFString with the resource name in it */
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
499 rsrcString = CFStringCreateWithCString(0, resourceName, kCFStringEncodingMacRoman);
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
500
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
501 /* Look for py files in the main bundle by type */
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
502 arrayRef = CFBundleCopyResourceURLsOfType( mainBundle,
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
503 CFSTR("py"),
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
504 NULL );
19855
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
505
20779
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
506 /* See if there are any filename matches */
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
507 size = CFArrayGetCount(arrayRef);
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
508 for (i = 0; i < size; i++) {
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
509 URL = CFArrayGetValueAtIndex(arrayRef, i);
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
510 filenameString = CFURLCopyLastPathComponent(URL);
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
511 if (CFStringCompare(filenameString, rsrcString, 0) == kCFCompareEqualTo) {
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
512 /* We found a match, get the file's full path */
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
513 absoluteURL = CFURLCopyAbsoluteURL(URL);
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
514 filepathString = CFURLCopyFileSystemPath(absoluteURL, thePathStyle);
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
515 CFRelease(absoluteURL);
19855
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
516
20779
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
517 /* Copy the full path into the caller's character buffer */
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
518 success = CFStringGetCString(filepathString, resourceURLCStr, length,
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
519 kCFStringEncodingMacRoman);
19855
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
520
20779
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
521 CFRelease(filepathString);
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
522 }
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
523 CFRelease(filenameString);
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
524 }
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
525 CFRelease(arrayRef);
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
526 CFRelease(rsrcString);
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
527 }
19855
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
528 return success;
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
529 }
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
530
20779
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
531 #endif /* TARGET_API_MAC_CARBON */
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
532
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
533 #if TARGET_API_MAC_OSX
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
534
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
535 int
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
536 main(int argc, char **argv)
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
537 {
19855
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
538 int i;
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
539 static char scriptpath[1024];
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
540 char *script = NULL;
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
541
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
542 /* First we see whether we have __rawmain__.py and run that if it
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
543 ** is there
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
544 */
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
545 if (locateResourcePy("__rawmain__.py", scriptpath, 1024)) {
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
546 /* If we have a raw main we don't do AppleEvent processing.
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
547 ** Notice that this also means we keep the -psn.... argv[1]
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
548 ** value intact. Not sure whether that is important to someone,
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
549 ** but you never know...
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
550 */
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
551 script = scriptpath;
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
552 } else {
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
553 /* Otherwise we look for __main__.py. Whether that is
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
554 ** found or not we also process AppleEvent arguments.
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
555 */
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
556 if (locateResourcePy("__main__.py", scriptpath, 1024))
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
557 script = scriptpath;
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
558
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
559 printf("original argc=%d\n", argc);
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
560 for(i=0; i<argc; i++) printf("original argv[%d] = \"%s\"\n", i, argv[i]);
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
561
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
562 init_common(&argc, &argv, 0);
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
563
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
564 printf("modified argc=%d\n", argc);
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
565 for(i=0; i<argc; i++) printf("modified argv[%d] = \"%s\"\n", i, argv[i]);
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
566 }
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
567
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
568 Py_Main(argc, argv, script);
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
569 return 0;
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
570 }
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
571
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
572 #else
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
573
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
574 /* 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
575 void
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
576 PyMac_InitApplication(void)
1811
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
577 {
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
578 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
579 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
580
20779
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
581 static char scriptpath[1024];
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
582 char *script = NULL;
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
583
4962
765d962f4449 Added PyMac_Initialize() routine, to be used by embedding programs (in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4911
diff changeset
584 init_common(&argc, &argv, 0);
20779
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
585
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
586 #if TARGET_API_MAC_OSX /* Really: TARGET_API_MAC_CARBON */
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
587 /* If we are running inside of a bundle, and a __main__.py is available, use it */
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
588 if (locateResourcePy("__main__.py", scriptpath, 1024))
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
589 script = scriptpath;
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
590 #endif
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
591
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
592 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
593 /* 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
594 char curwd[256], *endp;
2313
ff72a5f9a4ee Various changes wrt shared-library python:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2277
diff changeset
595
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
596 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
597 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
598 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
599 *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
600
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
601 chdir(curwd);
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
602 #ifdef USE_GUSI1
3433
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3422
diff changeset
603 /* 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
604 PyMac_FixGUSIcd();
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3422
diff changeset
605 #endif
2313
ff72a5f9a4ee Various changes wrt shared-library python:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2277
diff changeset
606 }
18962
d7590122f9a2 Merging appropriate 2.1.1 fixes back into the main trunk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18386
diff changeset
607 /* Check that the first argument is a text file */
d7590122f9a2 Merging appropriate 2.1.1 fixes back into the main trunk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18386
diff changeset
608 if ( PyMac_getfiletype(argv[1]) != 'TEXT' ) {
d7590122f9a2 Merging appropriate 2.1.1 fixes back into the main trunk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18386
diff changeset
609 Alert(NOTASCRIPT_ID, NULL);
d7590122f9a2 Merging appropriate 2.1.1 fixes back into the main trunk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18386
diff changeset
610 exit(0);
d7590122f9a2 Merging appropriate 2.1.1 fixes back into the main trunk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18386
diff changeset
611 }
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
612 }
20779
61123b860b45 Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19855
diff changeset
613 Py_Main(argc, argv, script);
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
614 }
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
615 #endif /* TARGET_API_MAC_OSX */
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
616
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
617 /* 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
618
4017
5dc8c042905b Guido: added some void's to declarations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3930
diff changeset
619 static void
19855
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
620 Py_Main(int argc, char **argv, char *filename)
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
621 {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
622 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
623 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
624 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
625
19855
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
626 if ( filename ) {
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
627 /* Someone else has found our "script" already */
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
628 argv[0] = filename;
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
629 } else {
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
630 filename = argv[1];
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
631 argv++;
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
632 argc--;
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
633 }
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
634
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
635 if (Py_VerboseFlag ||
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
636 (command == NULL && filename == NULL && isatty((int)fileno(fp))))
14464
17cec96f75bc Use same short banner message as unix/win Python.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14198
diff changeset
637 fprintf(stderr, "Python %s on %s\n%s\n",
17cec96f75bc Use same short banner message as unix/win Python.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14198
diff changeset
638 Py_GetVersion(), Py_GetPlatform(), COPYRIGHT);
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
639
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
640 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
641 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
642 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
643 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
644 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
645 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
646 }
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
647
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
648 #if !TARGET_API_MAC_OSX
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
649 /* We initialize the menubar here, hoping SIOUX is initialized by now */
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4197
diff changeset
650 PyMac_InitMenuBar();
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
651 #endif
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
652
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
653 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
654
18386
8cdff545cbde Set the default 8-bit encoding based on the system script and language.
unknown <tools@python.org>
parents: 17629
diff changeset
655 PyUnicode_SetDefaultEncoding(PyMac_getscript());
8cdff545cbde Set the default 8-bit encoding based on the system script and language.
unknown <tools@python.org>
parents: 17629
diff changeset
656
19855
5568b320914f Mods by Donovan Preston (with changes by me to make them "go with the flow")
Jack Jansen <jack.jansen@cwi.nl>
parents: 19851
diff changeset
657 PySys_SetArgv(argc, 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
658
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
659 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
660 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
661 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
662 (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
663 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
664 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
665 }
1811
ea5b13d11a13 Added macmain.c (separate Mac specific main prog); bump version to 1.1
Guido van Rossum <guido@python.org>
parents:
diff changeset
666 }
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
667 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
668 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
669 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
670 fclose(fp);
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
671
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
672 if ( filename != NULL || command != NULL )
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4228
diff changeset
673 sts = (run_inspect() || sts);
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
674
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
675 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
676 /*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
677 }
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
678
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
679 #if !TARGET_API_MAC_OSX
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
680 /*
15280
a5ca54969a3f Added PyMac_OutputSeen(), which acknowledges all current output in the stdio window, i.e. it acts like input has been read insofar as the keep-console-open option is interested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15192
diff changeset
681 ** Reset the "unseen output" flag
a5ca54969a3f Added PyMac_OutputSeen(), which acknowledges all current output in the stdio window, i.e. it acts like input has been read insofar as the keep-console-open option is interested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15192
diff changeset
682 */
a5ca54969a3f Added PyMac_OutputSeen(), which acknowledges all current output in the stdio window, i.e. it acts like input has been read insofar as the keep-console-open option is interested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15192
diff changeset
683 void
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
684 PyMac_OutputSeen(void)
15280
a5ca54969a3f Added PyMac_OutputSeen(), which acknowledges all current output in the stdio window, i.e. it acts like input has been read insofar as the keep-console-open option is interested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15192
diff changeset
685 {
16647
728c11562187 More changes to attempt to get the menubar back on exit. Without success:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 16557
diff changeset
686 if ( console_output_state == STATE_UNKNOWN )
728c11562187 More changes to attempt to get the menubar back on exit. Without success:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 16557
diff changeset
687 PyMac_InitMenuBar();
16557
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
688 console_output_state = STATE_LASTREAD;
15280
a5ca54969a3f Added PyMac_OutputSeen(), which acknowledges all current output in the stdio window, i.e. it acts like input has been read insofar as the keep-console-open option is interested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15192
diff changeset
689 }
a5ca54969a3f Added PyMac_OutputSeen(), which acknowledges all current output in the stdio window, i.e. it acts like input has been read insofar as the keep-console-open option is interested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15192
diff changeset
690
a5ca54969a3f Added PyMac_OutputSeen(), which acknowledges all current output in the stdio window, i.e. it acts like input has been read insofar as the keep-console-open option is interested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15192
diff changeset
691 /*
16557
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
692 ** Set the "unseen output" flag
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
693 */
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
694 void
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
695 PyMac_OutputNotSeen(void)
16557
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
696 {
16647
728c11562187 More changes to attempt to get the menubar back on exit. Without success:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 16557
diff changeset
697 if ( console_output_state == STATE_UNKNOWN )
728c11562187 More changes to attempt to get the menubar back on exit. Without success:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 16557
diff changeset
698 PyMac_InitMenuBar();
16557
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
699 console_output_state = STATE_LASTWRITE;
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
700 }
17629
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
701
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
702 /*
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
703 ** Override abort() - The default one is not what we want.
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
704 */
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
705 void
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
706 abort(void)
17629
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
707 {
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
708 console_output_state = STATE_LASTWRITE;
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
709 PyMac_Exit(1);
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
710 }
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
711 #endif /* !TARGET_API_MAC_OSX */
16557
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
712
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
713 /*
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
714 ** Terminate application
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
715 */
4017
5dc8c042905b Guido: added some void's to declarations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3930
diff changeset
716 void
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
717 PyMac_Exit(int status)
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
718 {
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
719 #ifdef USE_SIOUX
14773
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
720 int keep = 0;
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
721 #endif
4911
21878c849626 Added profiler initialization/finalization code (if __profile__ is defined)
Jack Jansen <jack.jansen@cwi.nl>
parents: 4249
diff changeset
722
21878c849626 Added profiler initialization/finalization code (if __profile__ is defined)
Jack Jansen <jack.jansen@cwi.nl>
parents: 4249
diff changeset
723 #if __profile__ == 1
21878c849626 Added profiler initialization/finalization code (if __profile__ is defined)
Jack Jansen <jack.jansen@cwi.nl>
parents: 4249
diff changeset
724 ProfilerDump("\pPython Profiler Results");
21878c849626 Added profiler initialization/finalization code (if __profile__ is defined)
Jack Jansen <jack.jansen@cwi.nl>
parents: 4249
diff changeset
725 ProfilerTerm();
21878c849626 Added profiler initialization/finalization code (if __profile__ is defined)
Jack Jansen <jack.jansen@cwi.nl>
parents: 4249
diff changeset
726 #endif
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
727
3247
20d74fa3b50b For MW Python, update titlebar of window when python exits.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3236
diff changeset
728 #ifdef USE_SIOUX
15192
1c63e224f616 Made options global (as PyMac_options) so macosmodule can access it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
729 switch (PyMac_options.keep_console) {
14773
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
730 case POPT_KEEPCONSOLE_NEVER:
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
731 keep = 0;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
732 break;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
733 case POPT_KEEPCONSOLE_OUTPUT:
16557
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
734 if (console_output_state == STATE_LASTWRITE ||
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
735 console_output_state == STATE_UNKNOWN )
14773
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
736 keep = 1;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
737 else
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
738 keep = 0;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
739 break;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
740 case POPT_KEEPCONSOLE_ERROR:
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
741 keep = (status != 0);
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
742 break;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
743 default:
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
744 keep = 1;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14464
diff changeset
745 }
3247
20d74fa3b50b For MW Python, update titlebar of window when python exits.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3236
diff changeset
746 if (keep) {
20d74fa3b50b For MW Python, update titlebar of window when python exits.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3236
diff changeset
747 SIOUXSettings.standalone = 1;
20d74fa3b50b For MW Python, update titlebar of window when python exits.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3236
diff changeset
748 SIOUXSettings.autocloseonquit = 0;
3477
a4f01d43dad6 Replaced non-ascii chars by backslash escapes
Jack Jansen <jack.jansen@cwi.nl>
parents: 3465
diff changeset
749 SIOUXSetTitle("\p\307terminated\310");
17629
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
750 PyMac_RaiseConsoleWindow();
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
751 PyMac_RestoreMenuBar();
5431
a56b44b35505 Workaround for bug in MSL and CWGUSI interaction that stopped the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
752 #ifdef USE_MSL
a56b44b35505 Workaround for bug in MSL and CWGUSI interaction that stopped the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
753 /*
a56b44b35505 Workaround for bug in MSL and CWGUSI interaction that stopped the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
754 ** Temporary workaround: autocloseonquit clearing does not
a56b44b35505 Workaround for bug in MSL and CWGUSI interaction that stopped the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
755 ** currently work for the MSL/GUSI combo.
a56b44b35505 Workaround for bug in MSL and CWGUSI interaction that stopped the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
756 */
a56b44b35505 Workaround for bug in MSL and CWGUSI interaction that stopped the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
757 while(getchar() > 0);
a56b44b35505 Workaround for bug in MSL and CWGUSI interaction that stopped the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
758 #endif
3247
20d74fa3b50b For MW Python, update titlebar of window when python exits.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3236
diff changeset
759 }
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
760 else
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
761 SIOUXSettings.autocloseonquit = 1;
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4017
diff changeset
762 #endif /* USE_SIOUX */
3236
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
763
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
764 exit(status);
463b26fa4d7b Added options for keeping window open on normal/error termination
Jack Jansen <jack.jansen@cwi.nl>
parents: 3228
diff changeset
765 }
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
766
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
767 #if !TARGET_API_MAC_OSX
2985
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
768 /* 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
769 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
770
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
771 void
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
772 Py_GetArgcArgv(int *argc,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
773 {
0d7100ffb61a This is completely different from the old mainmain (which wasn't used
Jack Jansen <jack.jansen@cwi.nl>
parents: 2313
diff changeset
774 *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
775 *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
776 }
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
777 #endif
3930
52c19ee83a6b Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3750
diff changeset
778
52c19ee83a6b Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3750
diff changeset
779 /* More cruft that shouldn't really be here, used in sysmodule.c */
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
780 #if !TARGET_API_MAC_OSX
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
781 /* Return the program name -- some code out there needs this. */
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
782 char *
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
783 Py_GetProgramFullPath(void)
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
784 {
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
785 return orig_argv[0];
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
786 }
3930
52c19ee83a6b Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3750
diff changeset
787
52c19ee83a6b Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3750
diff changeset
788 char *
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
789 Py_GetPrefix(void)
3930
52c19ee83a6b Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3750
diff changeset
790 {
6277
bb5472fb4885 sys.prefix and sys.exec_prefix are now set correctly.
Jack Jansen <jack.jansen@cwi.nl>
parents: 5961
diff changeset
791 return PyMac_GetPythonDir();
3930
52c19ee83a6b Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3750
diff changeset
792 }
52c19ee83a6b Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3750
diff changeset
793
52c19ee83a6b Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3750
diff changeset
794 char *
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
795 Py_GetExecPrefix(void)
3930
52c19ee83a6b Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3750
diff changeset
796 {
6277
bb5472fb4885 sys.prefix and sys.exec_prefix are now set correctly.
Jack Jansen <jack.jansen@cwi.nl>
parents: 5961
diff changeset
797 return PyMac_GetPythonDir();
3930
52c19ee83a6b Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3750
diff changeset
798 }
16557
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
799
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
800 int
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
801 PyMac_GetDelayConsoleFlag(void)
16557
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
802 {
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15921
diff changeset
803 return (int)PyMac_options.delayconsole;
19641
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
804 }
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
805
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
806 #ifndef WITHOUT_UNIX_NEWLINES
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
807 /*
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
808 ** Experimental feature (for 2.2a2): optionally allow unix newlines
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
809 ** as well as Mac newlines on input. We replace a lowlevel
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
810 ** MSL routine to accomplish this.
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
811 */
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
812 void
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
813 __convert_to_newlines(unsigned char * buf, size_t * n_ptr)
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
814 {
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
815 unsigned char *p;
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
816 size_t n = *n_ptr;
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
817
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
818 for(p=buf; n > 0; p++, n--)
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
819 if ( *p == '\r' ) *p = '\n';
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
820 else if ( *p == '\n' && !PyMac_options.unixnewlines )
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
821 *p = '\r';
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
822 }
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
823 #endif /* WITHOUT_UNIX_NEWLINES */
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 19641
diff changeset
824 #endif /* !TARGET_API_MAC_OSX */
19641
c9647fa78f05 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
825