Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 01fbc68

Browse files
committed
- Reorganized init code
- Fixed serious bug in code to get options from a resource
1 parent dc1c64a commit 01fbc68

5 files changed

Lines changed: 63 additions & 45 deletions

File tree

Mac/Include/pythonresources.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,10 @@
7575
#define POPT_DEBUGGING 4
7676
#define POPT_KEEPNORM 5
7777
#define POPT_KEEPERR 6
78+
79+
/* From macgetpath.c: */
80+
void PyMac_PreferenceOptions Py_PROTO((int *inspect, int *verbose, int *suppress_print,
81+
int *unbuffered, int *debugging, int *keep_normal,
82+
int *keep_error));
83+
7884

Mac/Python/macapplication.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3131
extern void PyMac_InitApplication();
3232

3333
main() {
34-
#if defined(USE_GUSI)
35-
GUSIDefaultSetup();
36-
#endif
3734
#if defined(__MWERKS__) && defined(__CFM68K__)
3835
printf("Hello, world!\n");
3936
#endif

Mac/Python/macgetargv.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -295,31 +295,12 @@ event_loop()
295295
}
296296
}
297297

298-
/* Initialize the Mac toolbox world */
299-
300-
static void
301-
init_mac_world()
302-
{
303-
#ifdef THINK_C
304-
printf("\n");
305-
#else
306-
MaxApplZone();
307-
InitGraf(&qd.thePort);
308-
InitFonts();
309-
InitWindows();
310-
TEInit();
311-
InitDialogs((long)0);
312-
InitMenus();
313-
InitCursor();
314-
#endif
315-
}
316298
/* Get the argv vector, return argc */
317299

318300
int
319301
PyMac_GetArgv(pargv)
320302
char ***pargv;
321303
{
322-
init_mac_world();
323304

324305
arg_count = 0;
325306
arg_vector[arg_count++] = strdup(get_application_name());

Mac/Python/macgetpath.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ getpythonpath()
4343
char *curwd;
4444
char *p, *endp;
4545
int newlen;
46-
extern char *PyMac_GetPythonDir();
46+
staticforward char *PyMac_GetPythonDir();
4747
#ifndef USE_BUILTIN_PATH
48-
extern char *PyMac_GetPythonPath();
48+
staticforward char *PyMac_GetPythonPath();
4949
#endif
5050

5151
if ( pythonpath ) return pythonpath;
@@ -89,7 +89,7 @@ getpythonpath()
8989
/*
9090
** Open/create the Python Preferences file, return the handle
9191
*/
92-
short
92+
static short
9393
PyMac_OpenPrefFile()
9494
{
9595
AliasHandle handle;
@@ -142,7 +142,7 @@ PyMac_OpenPrefFile()
142142
/*
143143
** Return the name of the Python directory
144144
*/
145-
char *
145+
static char *
146146
PyMac_GetPythonDir()
147147
{
148148
static char name[256];
@@ -187,7 +187,7 @@ PyMac_GetPythonDir()
187187
}
188188

189189
#ifndef USE_BUILTIN_PATH
190-
char *
190+
static char *
191191
PyMac_GetPythonPath(dir)
192192
char *dir;
193193
{

Mac/Python/macmain.c

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,54 @@ static int orig_argc;
6868
static int keep_normal;
6969
static int keep_error = 1;
7070

71+
/* Initialize the Mac toolbox world */
72+
73+
static void
74+
init_mac_world()
75+
{
76+
#ifdef THINK_C
77+
printf("\n");
78+
#else
79+
MaxApplZone();
80+
InitGraf(&qd.thePort);
81+
InitFonts();
82+
InitWindows();
83+
TEInit();
84+
InitDialogs((long)0);
85+
InitMenus();
86+
InitCursor();
87+
#endif
88+
}
89+
90+
/* Initialization code shared by interpreter and applets */
91+
92+
static void
93+
init_common()
94+
{
95+
96+
/* Initialize toolboxes */
97+
init_mac_world();
98+
99+
#ifdef USE_MAC_SHARED_LIBRARY
100+
/* Add the shared library to the stack of resource files */
101+
PyMac_AddLibResources();
102+
#endif
103+
104+
#if defined(USE_GUSI)
105+
/* Setup GUSI */
106+
GUSIDefaultSetup();
107+
#endif
108+
109+
#ifdef USE_SIOUX
110+
/* Set various SIOUX flags. Some are changed later based on options */
111+
SIOUXSettings.asktosaveonclose = 0;
112+
SIOUXSettings.showstatusline = 0;
113+
SIOUXSettings.tabspaces = 4;
114+
#endif
115+
116+
}
117+
118+
71119
#ifdef USE_MAC_APPLET_SUPPORT
72120
/* Applet support */
73121

@@ -112,14 +160,7 @@ PyMac_InitApplet()
112160
char **argv;
113161
int err;
114162

115-
#ifdef USE_MAC_SHARED_LIBRARY
116-
PyMac_AddLibResources();
117-
#endif
118-
#ifdef USE_SIOUX
119-
SIOUXSettings.asktosaveonclose = 0;
120-
SIOUXSettings.showstatusline = 0;
121-
SIOUXSettings.tabspaces = 4;
122-
#endif
163+
init_common();
123164
argc = PyMac_GetArgv(&argv);
124165
Py_Initialize();
125166
PySys_SetArgv(argc, argv);
@@ -139,14 +180,7 @@ PyMac_InitApplication()
139180
int argc;
140181
char **argv;
141182

142-
#ifdef USE_MAC_SHARED_LIBRARY
143-
PyMac_AddLibResources();
144-
#endif
145-
#ifdef USE_SIOUX
146-
SIOUXSettings.asktosaveonclose = 0;
147-
SIOUXSettings.showstatusline = 0;
148-
SIOUXSettings.tabspaces = 4;
149-
#endif
183+
init_common();
150184
argc = PyMac_GetArgv(&argv);
151185
if ( argc > 1 ) {
152186
/* We're running a script. Attempt to change current directory */
@@ -181,8 +215,8 @@ PyMac_InteractiveOptions(int *inspect, int *verbose, int *suppress_print,
181215
/* Default-defaults: */
182216
*keep_error = 1;
183217
/* Get default settings from our preference file */
184-
PyMac_PreferenceOptions(&inspect, &Py_VerboseFlag, &Py_SuppressPrintingFlag,
185-
&unbuffered, &Py_DebugFlag, &keep_normal, &keep_error);
218+
PyMac_PreferenceOptions(inspect, verbose, suppress_print,
219+
unbuffered, debugging, keep_normal, keep_error);
186220
/* If option is pressed override these */
187221
GetKeys(rmap);
188222
map = (unsigned char *)rmap;

0 commit comments

Comments
 (0)