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

Skip to content

Commit 76efd8e

Browse files
committed
MAde a few things more orthogonal and did some cleanups:
- Applications now have their (minimal) main prrogram in macapplication.c and the rest of the init code in macglue.c. - A new define, USE_MAC_APPLET_SUPPORT, independent of USE_MAC_SHARED_LIB - chdir to script directory now done in PyMac_InitApplication.
1 parent 397c3fb commit 76efd8e

3 files changed

Lines changed: 74 additions & 36 deletions

File tree

Mac/Modules/config.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2929
#endif
3030

3131
#ifdef macintosh
32-
/* The Macintosh main program is in macmain.c */
32+
/* The Macintosh main program is in either macapplet.c or macapplication.c */
3333
#define NO_MAIN
34-
char *fileargument; /* So main() can tell us the program name */
3534
#endif
3635

3736
#include <stdio.h>
@@ -42,7 +41,6 @@ char *fileargument; /* So main() can tell us the program name */
4241
#include "osdefs.h"
4342
#include "intrcheck.h"
4443

45-
char *PyMac_GetPythonDir();
4644

4745
#ifndef NO_MAIN
4846

@@ -168,12 +166,13 @@ getpythonpath()
168166
** - Prepend the python home-directory (which is obtained from a Preferences
169167
** resource)
170168
** - Add :
171-
** - Chdir to where the source file (if any) lives
172169
*/
173170
static char *pythonpath;
174171
char *curwd;
175172
char *p, *endp;
176173
int newlen;
174+
extern char *PyMac_GetPythonDir();
175+
extern char *PyMac_GetScriptPath();
177176

178177
if ( pythonpath ) return pythonpath;
179178
curwd = PyMac_GetPythonDir();
@@ -205,14 +204,6 @@ getpythonpath()
205204
pythonpath[newlen] = '\0';
206205
p = endp + 1;
207206
}
208-
if ( fileargument ) {
209-
strcpy(curwd, fileargument);
210-
endp = strrchr(curwd, ':');
211-
if ( endp && endp > curwd ) {
212-
*endp = '\0';
213-
chdir(curwd);
214-
}
215-
}
216207
return pythonpath;
217208
#else /* !macintosh */
218209
char *path = getenv("PYTHONPATH");
@@ -346,13 +337,17 @@ struct {
346337
{"mactcp", initmactcp},
347338
#endif
348339
{"AE", initAE},
340+
#ifndef __MWERKS__
349341
{"Ctl", initCtl},
350342
{"Dlg", initDlg},
343+
#endif
351344
{"Evt", initEvt},
352345
{"Menu", initMenu},
346+
#ifndef __MWERKS__
353347
{"Qd", initQd},
354348
{"Snd", initSnd},
355349
{"Win", initWin},
350+
#endif
356351
{"Res", initRes},
357352

358353
/* -- ADDMODULE MARKER 2 -- */

Mac/Python/macapplication.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/***********************************************************
2+
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3+
The Netherlands.
4+
5+
All Rights Reserved
6+
7+
Permission to use, copy, modify, and distribute this software and its
8+
documentation for any purpose and without fee is hereby granted,
9+
provided that the above copyright notice appear in all copies and that
10+
both that copyright notice and this permission notice appear in
11+
supporting documentation, and that the names of Stichting Mathematisch
12+
Centrum or CWI not be used in advertising or publicity pertaining to
13+
distribution of the software without specific, written prior permission.
14+
15+
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16+
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17+
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18+
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21+
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22+
23+
******************************************************************/
24+
25+
/* Macintosh Applet Python main program */
26+
27+
#ifdef __CFM68K__
28+
#pragma lib_export on
29+
#endif
30+
31+
extern void PyMac_InitApplication();
32+
33+
main() {
34+
PyMac_InitApplication();
35+
}

Mac/Python/macglue.c

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ static int in_foreground;
117117

118118
int PyMac_DoYieldEnabled = 1; /* Don't do eventloop when false */
119119

120-
121120
/* Convert C to Pascal string. Returns pointer to static buffer. */
122121
unsigned char *
123122
Pstring(char *str)
@@ -787,26 +786,7 @@ PyMac_BuildEventRecord(EventRecord *e)
787786
}
788787

789788

790-
#ifndef USE_MAC_SHARED_LIBRARY
791-
792-
/* For normal application */
793-
void
794-
main()
795-
{
796-
int argc;
797-
char **argv;
798-
799-
#ifdef __MWERKS__
800-
SIOUXSettings.asktosaveonclose = 0;
801-
SIOUXSettings.showstatusline = 0;
802-
SIOUXSettings.tabspaces = 4;
803-
#endif
804-
argc = PyMac_GetArgv(&argv);
805-
Py_Main(argc, argv);
806-
}
807-
808-
#else /* USE_MAC_SHARED_LIBRARY */
809-
789+
#ifdef USE_MAC_APPLET_SUPPORT
810790
/* Applet support */
811791

812792
/* Run a compiled Python Python script from 'PYC ' resource __main__ */
@@ -850,9 +830,7 @@ PyMac_InitApplet()
850830
char **argv;
851831
int err;
852832

853-
#ifdef USE_MAC_SHARED_LIBRARY
854833
PyMac_AddLibResources();
855-
#endif
856834
#ifdef __MWERKS__
857835
SIOUXSettings.asktosaveonclose = 0;
858836
SIOUXSettings.showstatusline = 0;
@@ -873,4 +851,34 @@ PyMac_InitApplet()
873851
/* XXX Should we bother to Py_Exit(sts)? */
874852
}
875853

876-
#endif /* USE_MAC_SHARED_LIBRARY */
854+
#endif /* USE_MAC_APPLET_SUPPORT */
855+
856+
/* For normal application */
857+
void
858+
PyMac_InitApplication()
859+
{
860+
int argc;
861+
char **argv;
862+
863+
#ifdef USE_MAC_SHARED_LIBRARY
864+
PyMac_AddLibResources();
865+
#endif
866+
#ifdef __MWERKS__
867+
SIOUXSettings.asktosaveonclose = 0;
868+
SIOUXSettings.showstatusline = 0;
869+
SIOUXSettings.tabspaces = 4;
870+
#endif
871+
argc = PyMac_GetArgv(&argv);
872+
if ( argc > 1 ) {
873+
/* We're running a script. Attempt to change current directory */
874+
char curwd[256], *endp;
875+
876+
strcpy(curwd, argv[1]);
877+
endp = strrchr(curwd, ':');
878+
if ( endp && endp > curwd ) {
879+
*endp = '\0';
880+
chdir(curwd);
881+
}
882+
}
883+
Py_Main(argc, argv);
884+
}

0 commit comments

Comments
 (0)