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.
This commit is contained in:
Jack Jansen 1995-02-24 22:53:16 +00:00
parent 397c3fb4d7
commit 76efd8e7a1
3 changed files with 74 additions and 36 deletions

View File

@ -29,9 +29,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#endif #endif
#ifdef macintosh #ifdef macintosh
/* The Macintosh main program is in macmain.c */ /* The Macintosh main program is in either macapplet.c or macapplication.c */
#define NO_MAIN #define NO_MAIN
char *fileargument; /* So main() can tell us the program name */
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -42,7 +41,6 @@ char *fileargument; /* So main() can tell us the program name */
#include "osdefs.h" #include "osdefs.h"
#include "intrcheck.h" #include "intrcheck.h"
char *PyMac_GetPythonDir();
#ifndef NO_MAIN #ifndef NO_MAIN
@ -168,12 +166,13 @@ getpythonpath()
** - Prepend the python home-directory (which is obtained from a Preferences ** - Prepend the python home-directory (which is obtained from a Preferences
** resource) ** resource)
** - Add : ** - Add :
** - Chdir to where the source file (if any) lives
*/ */
static char *pythonpath; static char *pythonpath;
char *curwd; char *curwd;
char *p, *endp; char *p, *endp;
int newlen; int newlen;
extern char *PyMac_GetPythonDir();
extern char *PyMac_GetScriptPath();
if ( pythonpath ) return pythonpath; if ( pythonpath ) return pythonpath;
curwd = PyMac_GetPythonDir(); curwd = PyMac_GetPythonDir();
@ -205,14 +204,6 @@ getpythonpath()
pythonpath[newlen] = '\0'; pythonpath[newlen] = '\0';
p = endp + 1; p = endp + 1;
} }
if ( fileargument ) {
strcpy(curwd, fileargument);
endp = strrchr(curwd, ':');
if ( endp && endp > curwd ) {
*endp = '\0';
chdir(curwd);
}
}
return pythonpath; return pythonpath;
#else /* !macintosh */ #else /* !macintosh */
char *path = getenv("PYTHONPATH"); char *path = getenv("PYTHONPATH");
@ -346,13 +337,17 @@ struct {
{"mactcp", initmactcp}, {"mactcp", initmactcp},
#endif #endif
{"AE", initAE}, {"AE", initAE},
#ifndef __MWERKS__
{"Ctl", initCtl}, {"Ctl", initCtl},
{"Dlg", initDlg}, {"Dlg", initDlg},
#endif
{"Evt", initEvt}, {"Evt", initEvt},
{"Menu", initMenu}, {"Menu", initMenu},
#ifndef __MWERKS__
{"Qd", initQd}, {"Qd", initQd},
{"Snd", initSnd}, {"Snd", initSnd},
{"Win", initWin}, {"Win", initWin},
#endif
{"Res", initRes}, {"Res", initRes},
/* -- ADDMODULE MARKER 2 -- */ /* -- ADDMODULE MARKER 2 -- */

View File

@ -0,0 +1,35 @@
/***********************************************************
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
The Netherlands.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior permission.
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/* Macintosh Applet Python main program */
#ifdef __CFM68K__
#pragma lib_export on
#endif
extern void PyMac_InitApplication();
main() {
PyMac_InitApplication();
}

View File

@ -117,7 +117,6 @@ static int in_foreground;
int PyMac_DoYieldEnabled = 1; /* Don't do eventloop when false */ int PyMac_DoYieldEnabled = 1; /* Don't do eventloop when false */
/* Convert C to Pascal string. Returns pointer to static buffer. */ /* Convert C to Pascal string. Returns pointer to static buffer. */
unsigned char * unsigned char *
Pstring(char *str) Pstring(char *str)
@ -787,26 +786,7 @@ PyMac_BuildEventRecord(EventRecord *e)
} }
#ifndef USE_MAC_SHARED_LIBRARY #ifdef USE_MAC_APPLET_SUPPORT
/* For normal application */
void
main()
{
int argc;
char **argv;
#ifdef __MWERKS__
SIOUXSettings.asktosaveonclose = 0;
SIOUXSettings.showstatusline = 0;
SIOUXSettings.tabspaces = 4;
#endif
argc = PyMac_GetArgv(&argv);
Py_Main(argc, argv);
}
#else /* USE_MAC_SHARED_LIBRARY */
/* Applet support */ /* Applet support */
/* Run a compiled Python Python script from 'PYC ' resource __main__ */ /* Run a compiled Python Python script from 'PYC ' resource __main__ */
@ -850,9 +830,7 @@ PyMac_InitApplet()
char **argv; char **argv;
int err; int err;
#ifdef USE_MAC_SHARED_LIBRARY
PyMac_AddLibResources(); PyMac_AddLibResources();
#endif
#ifdef __MWERKS__ #ifdef __MWERKS__
SIOUXSettings.asktosaveonclose = 0; SIOUXSettings.asktosaveonclose = 0;
SIOUXSettings.showstatusline = 0; SIOUXSettings.showstatusline = 0;
@ -873,4 +851,34 @@ PyMac_InitApplet()
/* XXX Should we bother to Py_Exit(sts)? */ /* XXX Should we bother to Py_Exit(sts)? */
} }
#endif /* USE_MAC_SHARED_LIBRARY */ #endif /* USE_MAC_APPLET_SUPPORT */
/* For normal application */
void
PyMac_InitApplication()
{
int argc;
char **argv;
#ifdef USE_MAC_SHARED_LIBRARY
PyMac_AddLibResources();
#endif
#ifdef __MWERKS__
SIOUXSettings.asktosaveonclose = 0;
SIOUXSettings.showstatusline = 0;
SIOUXSettings.tabspaces = 4;
#endif
argc = PyMac_GetArgv(&argv);
if ( argc > 1 ) {
/* We're running a script. Attempt to change current directory */
char curwd[256], *endp;
strcpy(curwd, argv[1]);
endp = strrchr(curwd, ':');
if ( endp && endp > curwd ) {
*endp = '\0';
chdir(curwd);
}
}
Py_Main(argc, argv);
}