1994-08-23 10:34:25 -03:00
|
|
|
/***********************************************************
|
1997-01-31 12:15:11 -04:00
|
|
|
Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
|
1995-01-08 10:33:34 -04:00
|
|
|
The Netherlands.
|
1994-08-23 10:34:25 -03:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
1995-08-14 09:33:20 -03:00
|
|
|
/* Python interpreter main program */
|
1994-08-23 10:34:25 -03:00
|
|
|
|
1995-08-14 09:33:20 -03:00
|
|
|
#include "Python.h"
|
|
|
|
#include "pythonresources.h"
|
|
|
|
#include "import.h"
|
|
|
|
#include "marshal.h"
|
1996-09-04 12:24:59 -03:00
|
|
|
#include "macglue.h"
|
1994-08-23 10:34:25 -03:00
|
|
|
|
2001-09-05 19:07:52 -03:00
|
|
|
#ifdef WITHOUT_FRAMEWORKS
|
1995-08-14 09:33:20 -03:00
|
|
|
#include <Memory.h>
|
|
|
|
#include <Resources.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <Events.h>
|
|
|
|
#include <Windows.h>
|
1996-03-07 11:17:11 -04:00
|
|
|
#include <Fonts.h>
|
1997-09-09 10:53:21 -03:00
|
|
|
#include <Balloons.h>
|
2001-10-30 18:48:36 -04:00
|
|
|
#if TARGET_API_MAC_CARBON
|
|
|
|
#include <CFBundle.h>
|
|
|
|
#include <CFURL.h>
|
|
|
|
#include <CFString.h>
|
|
|
|
#include <CFBase.h>
|
|
|
|
#include <CFArray.h>
|
|
|
|
#endif /* TARGET_API_MAC_CARBON */
|
1999-12-07 19:08:10 -04:00
|
|
|
#include <Gestalt.h>
|
|
|
|
#include <Appearance.h>
|
2001-09-05 19:07:52 -03:00
|
|
|
#else
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#endif /* WITHOUT_FRAMEWORKS */
|
|
|
|
|
1995-08-14 09:33:20 -03:00
|
|
|
#ifdef __MWERKS__
|
|
|
|
#include <SIOUX.h>
|
1995-11-10 10:51:26 -04:00
|
|
|
#define USE_SIOUX
|
2000-07-11 18:16:03 -03:00
|
|
|
extern int ccommand(char ***);
|
1997-01-07 12:19:42 -04:00
|
|
|
#if __profile__ == 1
|
|
|
|
#include <profiler.h>
|
2001-09-05 19:07:52 -03:00
|
|
|
#endif /* __profile__ */
|
|
|
|
#endif /* __MWERKS__ */
|
|
|
|
|
2000-06-02 18:28:52 -03:00
|
|
|
#include <unistd.h>
|
2000-07-24 16:52:52 -03:00
|
|
|
#ifdef USE_MAC_SHARED_LIBRARY
|
|
|
|
extern PyMac_AddLibResources(void);
|
|
|
|
#endif
|
1994-08-23 10:34:25 -03:00
|
|
|
|
1995-08-14 09:33:20 -03:00
|
|
|
#define STARTUP "PythonStartup"
|
1994-08-23 10:34:25 -03:00
|
|
|
|
2000-09-08 07:20:37 -03:00
|
|
|
#define COPYRIGHT \
|
|
|
|
"Type \"copyright\", \"credits\" or \"license\" for more information."
|
|
|
|
|
1996-09-06 19:21:07 -03:00
|
|
|
short PyMac_AppRefNum; /* RefNum of application resource fork */
|
1995-08-14 09:33:20 -03:00
|
|
|
|
1996-08-02 12:16:16 -03:00
|
|
|
/* For Py_GetArgcArgv(); set by main() */
|
1995-08-14 09:33:20 -03:00
|
|
|
static char **orig_argv;
|
|
|
|
static int orig_argc;
|
|
|
|
|
2001-02-10 21:08:04 -04:00
|
|
|
/* A flag which remembers whether the user has acknowledged all the console
|
|
|
|
** output (by typing something)
|
|
|
|
*/
|
|
|
|
#define STATE_UNKNOWN 0
|
|
|
|
#define STATE_LASTREAD 1
|
|
|
|
#define STATE_LASTWRITE 2
|
|
|
|
int console_output_state = STATE_UNKNOWN;
|
|
|
|
|
2000-10-12 18:23:19 -03:00
|
|
|
PyMac_PrefRecord PyMac_options;
|
1995-10-27 10:32:30 -03:00
|
|
|
|
2002-08-05 11:13:31 -03:00
|
|
|
static void PyMac_Main(int, char **, char *); /* Forward */
|
2000-07-11 16:51:05 -03:00
|
|
|
void PyMac_Exit(int); /* Forward */
|
1996-08-19 08:18:24 -03:00
|
|
|
|
1996-02-28 11:42:47 -04:00
|
|
|
/* Initialize the Mac toolbox world */
|
|
|
|
|
|
|
|
static void
|
2001-09-05 19:07:52 -03:00
|
|
|
init_mac_world(void)
|
1996-02-28 11:42:47 -04:00
|
|
|
{
|
2000-07-14 19:37:27 -03:00
|
|
|
#if !TARGET_API_MAC_CARBON
|
2000-06-02 18:28:52 -03:00
|
|
|
/* These aren't needed for carbon */
|
1996-02-28 11:42:47 -04:00
|
|
|
MaxApplZone();
|
|
|
|
InitGraf(&qd.thePort);
|
|
|
|
InitFonts();
|
|
|
|
InitWindows();
|
|
|
|
TEInit();
|
|
|
|
InitDialogs((long)0);
|
|
|
|
InitMenus();
|
2000-06-02 18:28:52 -03:00
|
|
|
#endif
|
1996-02-28 11:42:47 -04:00
|
|
|
InitCursor();
|
|
|
|
}
|
|
|
|
|
1996-09-07 14:09:31 -03:00
|
|
|
/*
|
|
|
|
** PyMac_InteractiveOptions - Allow user to set options if option key is pressed
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
PyMac_InteractiveOptions(PyMac_PrefRecord *p, int *argcp, char ***argvp)
|
|
|
|
{
|
|
|
|
KeyMap rmap;
|
|
|
|
unsigned char *map;
|
|
|
|
short item, type;
|
|
|
|
ControlHandle handle;
|
|
|
|
DialogPtr dialog;
|
|
|
|
Rect rect;
|
|
|
|
|
|
|
|
/*
|
|
|
|
** If the preferences disallows interactive options we return,
|
|
|
|
** similarly of <option> isn't pressed.
|
|
|
|
*/
|
|
|
|
if (p->nointopt) return;
|
|
|
|
|
|
|
|
GetKeys(rmap);
|
|
|
|
map = (unsigned char *)rmap;
|
|
|
|
if ( ( map[0x3a>>3] & (1<<(0x3a&7)) ) == 0 ) /* option key is 3a */
|
|
|
|
return;
|
|
|
|
|
|
|
|
dialog = GetNewDialog(OPT_DIALOG, NULL, (WindowPtr)-1);
|
|
|
|
if ( dialog == NULL ) {
|
|
|
|
printf("Option dialog not found - cannot set options\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SetDialogDefaultItem(dialog, OPT_OK);
|
|
|
|
SetDialogCancelItem(dialog, OPT_CANCEL);
|
|
|
|
|
|
|
|
/* Set default values */
|
|
|
|
#define SET_OPT_ITEM(num, var) \
|
|
|
|
GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \
|
1997-04-08 12:27:00 -03:00
|
|
|
SetControlValue(handle, (short)p->var);
|
1996-09-07 14:09:31 -03:00
|
|
|
|
|
|
|
SET_OPT_ITEM(OPT_INSPECT, inspect);
|
|
|
|
SET_OPT_ITEM(OPT_VERBOSE, verbose);
|
2001-09-01 19:37:54 -03:00
|
|
|
/* OPT_VERBOSEVERBOSE is default off */
|
1997-09-09 10:53:21 -03:00
|
|
|
SET_OPT_ITEM(OPT_OPTIMIZE, optimize);
|
1996-09-07 14:09:31 -03:00
|
|
|
SET_OPT_ITEM(OPT_UNBUFFERED, unbuffered);
|
|
|
|
SET_OPT_ITEM(OPT_DEBUGGING, debugging);
|
2000-09-22 18:50:11 -03:00
|
|
|
GetDialogItem(dialog, OPT_KEEPALWAYS, &type, (Handle *)&handle, &rect);
|
|
|
|
SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ALWAYS));
|
|
|
|
GetDialogItem(dialog, OPT_KEEPOUTPUT, &type, (Handle *)&handle, &rect);
|
|
|
|
SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_OUTPUT));
|
|
|
|
GetDialogItem(dialog, OPT_KEEPERROR, &type, (Handle *)&handle, &rect);
|
|
|
|
SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ERROR));
|
|
|
|
GetDialogItem(dialog, OPT_KEEPNEVER, &type, (Handle *)&handle, &rect);
|
|
|
|
SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_NEVER));
|
|
|
|
/* SET_OPT_ITEM(OPT_KEEPCONSOLE, keep_console); */
|
2000-05-05 20:11:14 -03:00
|
|
|
SET_OPT_ITEM(OPT_TABWARN, tabwarn);
|
1997-09-09 10:53:21 -03:00
|
|
|
SET_OPT_ITEM(OPT_NOSITE, nosite);
|
2001-09-01 19:37:54 -03:00
|
|
|
SET_OPT_ITEM(OPT_DIVISIONWARN, divisionwarn);
|
|
|
|
SET_OPT_ITEM(OPT_UNIXNEWLINES, unixnewlines);
|
1996-09-07 14:09:31 -03:00
|
|
|
/* The rest are not settable interactively */
|
|
|
|
|
|
|
|
#undef SET_OPT_ITEM
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
handle = NULL;
|
|
|
|
ModalDialog(NULL, &item);
|
|
|
|
if ( item == OPT_OK )
|
|
|
|
break;
|
|
|
|
if ( item == OPT_CANCEL ) {
|
1997-04-08 12:27:00 -03:00
|
|
|
DisposeDialog(dialog);
|
1996-09-07 14:09:31 -03:00
|
|
|
exit(0);
|
|
|
|
}
|
2000-07-14 19:37:27 -03:00
|
|
|
#if !TARGET_API_MAC_CARBON
|
1997-09-09 10:53:21 -03:00
|
|
|
if ( item == OPT_HELP ) {
|
|
|
|
HMSetBalloons(!HMGetBalloons());
|
|
|
|
}
|
2000-06-02 18:28:52 -03:00
|
|
|
#endif
|
2001-09-05 19:07:52 -03:00
|
|
|
#if !TARGET_API_MAC_OSX
|
1996-09-07 14:09:31 -03:00
|
|
|
if ( item == OPT_CMDLINE ) {
|
2001-09-05 19:07:52 -03:00
|
|
|
int old_argc = *argcp;
|
|
|
|
int i;
|
1996-09-07 14:09:31 -03:00
|
|
|
int new_argc, newer_argc;
|
|
|
|
char **new_argv, **newer_argv;
|
|
|
|
|
|
|
|
new_argc = ccommand(&new_argv);
|
|
|
|
newer_argc = (new_argc-1) + old_argc;
|
|
|
|
newer_argv = malloc((newer_argc+1)*sizeof(char *));
|
|
|
|
if( !newer_argv )
|
|
|
|
Py_FatalError("Cannot malloc argv\n");
|
|
|
|
for(i=0; i<old_argc; i++)
|
|
|
|
newer_argv[i] = (*argvp)[i];
|
|
|
|
for(i=old_argc; i<=newer_argc; i++) /* Copy the NULL too */
|
|
|
|
newer_argv[i] = new_argv[i-old_argc+1];
|
|
|
|
*argvp = newer_argv;
|
|
|
|
*argcp = newer_argc;
|
|
|
|
|
|
|
|
/* XXXX Is it not safe to use free() here, apparently */
|
|
|
|
}
|
2001-09-05 19:07:52 -03:00
|
|
|
#endif /* !TARGET_API_MAC_OSX */
|
1996-09-07 14:09:31 -03:00
|
|
|
#define OPT_ITEM(num, var) \
|
|
|
|
if ( item == (num) ) { \
|
|
|
|
p->var = !p->var; \
|
|
|
|
GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \
|
1997-04-08 12:27:00 -03:00
|
|
|
SetControlValue(handle, (short)p->var); \
|
1996-09-07 14:09:31 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
OPT_ITEM(OPT_INSPECT, inspect);
|
|
|
|
OPT_ITEM(OPT_VERBOSE, verbose);
|
2001-09-01 19:37:54 -03:00
|
|
|
if ( item == OPT_VERBOSEVERBOSE ) {
|
|
|
|
if ( p->verbose == 2 )
|
|
|
|
p->verbose = 1;
|
|
|
|
else
|
|
|
|
p->verbose = 2;
|
|
|
|
GetDialogItem(dialog, OPT_VERBOSE, &type, (Handle *)&handle, &rect);
|
|
|
|
SetControlValue(handle, 1);
|
|
|
|
}
|
|
|
|
GetDialogItem(dialog, OPT_VERBOSEVERBOSE, &type, (Handle *)&handle, &rect);
|
|
|
|
SetControlValue(handle, p->verbose == 2);
|
1997-09-09 10:53:21 -03:00
|
|
|
OPT_ITEM(OPT_OPTIMIZE, optimize);
|
1996-09-07 14:09:31 -03:00
|
|
|
OPT_ITEM(OPT_UNBUFFERED, unbuffered);
|
|
|
|
OPT_ITEM(OPT_DEBUGGING, debugging);
|
2000-09-22 18:50:11 -03:00
|
|
|
if ( item == OPT_KEEPALWAYS ) p->keep_console = POPT_KEEPCONSOLE_ALWAYS;
|
|
|
|
if ( item == OPT_KEEPOUTPUT ) p->keep_console = POPT_KEEPCONSOLE_OUTPUT;
|
|
|
|
if ( item == OPT_KEEPERROR ) p->keep_console = POPT_KEEPCONSOLE_ERROR;
|
|
|
|
if ( item == OPT_KEEPNEVER ) p->keep_console = POPT_KEEPCONSOLE_NEVER;
|
|
|
|
GetDialogItem(dialog, OPT_KEEPALWAYS, &type, (Handle *)&handle, &rect);
|
|
|
|
SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ALWAYS));
|
|
|
|
GetDialogItem(dialog, OPT_KEEPOUTPUT, &type, (Handle *)&handle, &rect);
|
|
|
|
SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_OUTPUT));
|
|
|
|
GetDialogItem(dialog, OPT_KEEPERROR, &type, (Handle *)&handle, &rect);
|
|
|
|
SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ERROR));
|
|
|
|
GetDialogItem(dialog, OPT_KEEPNEVER, &type, (Handle *)&handle, &rect);
|
|
|
|
SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_NEVER));
|
2000-05-05 20:11:14 -03:00
|
|
|
OPT_ITEM(OPT_TABWARN, tabwarn);
|
1997-09-09 10:53:21 -03:00
|
|
|
OPT_ITEM(OPT_NOSITE, nosite);
|
2001-09-01 19:37:54 -03:00
|
|
|
OPT_ITEM(OPT_DIVISIONWARN, divisionwarn);
|
|
|
|
OPT_ITEM(OPT_UNIXNEWLINES, unixnewlines);
|
1996-09-07 14:09:31 -03:00
|
|
|
|
|
|
|
#undef OPT_ITEM
|
|
|
|
}
|
1997-04-08 12:27:00 -03:00
|
|
|
DisposeDialog(dialog);
|
1996-09-07 14:09:31 -03:00
|
|
|
}
|
1996-02-28 11:42:47 -04:00
|
|
|
|
1996-09-07 14:09:31 -03:00
|
|
|
/*
|
|
|
|
** Initialization code, shared by interpreter and applets
|
|
|
|
*/
|
1996-02-28 11:42:47 -04:00
|
|
|
static void
|
1997-01-15 11:49:08 -04:00
|
|
|
init_common(int *argcp, char ***argvp, int embedded)
|
1996-02-28 11:42:47 -04:00
|
|
|
{
|
1996-09-06 19:21:07 -03:00
|
|
|
/* Remember resource fork refnum, for later */
|
|
|
|
PyMac_AppRefNum = CurResFile();
|
|
|
|
|
1996-02-28 11:42:47 -04:00
|
|
|
/* Initialize toolboxes */
|
|
|
|
init_mac_world();
|
|
|
|
|
|
|
|
#ifdef USE_MAC_SHARED_LIBRARY
|
|
|
|
/* Add the shared library to the stack of resource files */
|
1998-07-31 06:38:01 -03:00
|
|
|
(void)PyMac_init_process_location();
|
1996-02-28 11:42:47 -04:00
|
|
|
PyMac_AddLibResources();
|
|
|
|
#endif
|
|
|
|
|
2000-04-07 06:10:49 -03:00
|
|
|
#if defined(USE_GUSI)
|
|
|
|
atexit(PyMac_StopGUSISpin);
|
|
|
|
#endif
|
1996-02-28 11:42:47 -04:00
|
|
|
|
|
|
|
#ifdef USE_SIOUX
|
|
|
|
/* Set various SIOUX flags. Some are changed later based on options */
|
|
|
|
SIOUXSettings.asktosaveonclose = 0;
|
|
|
|
SIOUXSettings.showstatusline = 0;
|
|
|
|
SIOUXSettings.tabspaces = 4;
|
|
|
|
#endif
|
|
|
|
|
1996-09-07 14:09:31 -03:00
|
|
|
/* Get options from preference file (or from applet resource fork) */
|
2000-10-12 18:23:19 -03:00
|
|
|
PyMac_options.keep_console = POPT_KEEPCONSOLE_OUTPUT; /* default-default */
|
2001-09-05 19:07:52 -03:00
|
|
|
PyMac_options.unixnewlines = 1;
|
|
|
|
#if !TARGET_API_MAC_OSX
|
2000-10-12 18:23:19 -03:00
|
|
|
PyMac_PreferenceOptions(&PyMac_options);
|
2001-09-05 19:07:52 -03:00
|
|
|
#endif
|
|
|
|
|
1997-01-15 11:49:08 -04:00
|
|
|
if ( embedded ) {
|
|
|
|
static char *emb_argv[] = {"embedded-python", 0};
|
|
|
|
|
|
|
|
*argcp = 1;
|
|
|
|
*argvp = emb_argv;
|
|
|
|
} else {
|
2002-01-02 18:53:38 -04:00
|
|
|
/* Create argc/argv. Do it before we go into the options event loop.
|
|
|
|
** In MachoPython we skip this step if we already have plausible
|
|
|
|
** command line arguments.
|
|
|
|
*/
|
|
|
|
#if TARGET_API_MAC_OSX
|
|
|
|
if (*argcp == 2 && strncmp((*argvp)[1], "-psn_", 5) == 0)
|
|
|
|
#endif
|
|
|
|
*argcp = PyMac_GetArgv(argvp, PyMac_options.noargs);
|
2001-09-05 19:07:52 -03:00
|
|
|
#if !TARGET_API_MAC_OSX
|
2001-01-16 11:54:58 -04:00
|
|
|
#ifndef NO_ARGV0_CHDIR
|
2000-07-18 06:40:39 -03:00
|
|
|
if (*argcp >= 1 && (*argvp)[0] && (*argvp)[0][0]) {
|
|
|
|
/* Workaround for MacOS X, which currently (DP4) doesn't set
|
|
|
|
** the working folder correctly
|
|
|
|
*/
|
|
|
|
char app_wd[256], *p;
|
|
|
|
|
|
|
|
strncpy(app_wd, (*argvp)[0], 256);
|
|
|
|
p = strrchr(app_wd, ':');
|
|
|
|
if ( p ) *p = 0;
|
|
|
|
chdir(app_wd);
|
|
|
|
}
|
2001-09-05 19:07:52 -03:00
|
|
|
#endif
|
2000-07-18 06:40:39 -03:00
|
|
|
#endif
|
1997-01-15 11:49:08 -04:00
|
|
|
/* Do interactive option setting, if allowed and <option> depressed */
|
2000-10-12 18:23:19 -03:00
|
|
|
PyMac_InteractiveOptions(&PyMac_options, argcp, argvp);
|
1997-01-15 11:49:08 -04:00
|
|
|
}
|
1996-09-07 14:09:31 -03:00
|
|
|
|
|
|
|
/* Copy selected options to where the machine-independent stuff wants it */
|
2000-10-12 18:23:19 -03:00
|
|
|
Py_VerboseFlag = PyMac_options.verbose;
|
|
|
|
/* Py_SuppressPrintingFlag = PyMac_options.suppress_print; */
|
|
|
|
Py_OptimizeFlag = PyMac_options.optimize;
|
|
|
|
Py_DebugFlag = PyMac_options.debugging;
|
|
|
|
Py_NoSiteFlag = PyMac_options.nosite;
|
|
|
|
Py_TabcheckFlag = PyMac_options.tabwarn;
|
2001-09-01 19:37:54 -03:00
|
|
|
Py_DivisionWarningFlag = PyMac_options.divisionwarn;
|
2001-09-05 19:07:52 -03:00
|
|
|
#if !TARGET_API_MAC_OSX
|
2000-10-12 18:23:19 -03:00
|
|
|
if ( PyMac_options.noargs ) {
|
1997-06-03 12:28:29 -03:00
|
|
|
/* don't process events at all without the scripts permission */
|
|
|
|
PyMacSchedParams scp;
|
|
|
|
|
|
|
|
PyMac_GetSchedParams(&scp);
|
|
|
|
scp.process_events = 0;
|
|
|
|
/* Should we disable command-dot as well? */
|
|
|
|
PyMac_SetSchedParams(&scp);
|
|
|
|
}
|
2001-09-05 19:07:52 -03:00
|
|
|
#endif /* !TARGET_API_MAC_OSX */
|
1996-09-07 14:09:31 -03:00
|
|
|
|
|
|
|
/* Set buffering */
|
2000-10-12 18:23:19 -03:00
|
|
|
if (PyMac_options.unbuffered) {
|
1996-09-07 14:09:31 -03:00
|
|
|
#ifndef MPW
|
|
|
|
setbuf(stdout, (char *)NULL);
|
|
|
|
setbuf(stderr, (char *)NULL);
|
|
|
|
#else
|
|
|
|
/* On MPW (3.2) unbuffered seems to hang */
|
|
|
|
setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
|
|
|
|
setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
|
|
|
|
#endif
|
|
|
|
}
|
1997-01-07 12:19:42 -04:00
|
|
|
#if __profile__ == 1
|
|
|
|
/* collectSummary or collectDetailed, timebase, #routines, max stack depth */
|
1999-09-30 08:20:11 -03:00
|
|
|
ProfilerInit(collectSummary, bestTimeBase, 8000, 250);
|
1997-01-07 12:19:42 -04:00
|
|
|
#endif
|
1997-08-08 11:56:41 -03:00
|
|
|
|
|
|
|
/* Tell the rest of python about our argc/argv */
|
|
|
|
orig_argc = *argcp; /* For Py_GetArgcArgv() */
|
|
|
|
orig_argv = *argvp;
|
|
|
|
Py_SetProgramName((*argvp)[0]);
|
1996-02-28 11:42:47 -04:00
|
|
|
}
|
|
|
|
|
1996-09-07 14:09:31 -03:00
|
|
|
/*
|
|
|
|
** Inspection mode after script/applet termination
|
|
|
|
*/
|
|
|
|
static int
|
2001-09-05 19:07:52 -03:00
|
|
|
run_inspect(void)
|
1996-09-07 14:09:31 -03:00
|
|
|
{
|
|
|
|
int sts = 0;
|
|
|
|
|
2000-10-12 18:23:19 -03:00
|
|
|
if (PyMac_options.inspect && isatty((int)fileno(stdin)))
|
1996-09-07 14:09:31 -03:00
|
|
|
sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
|
|
|
|
return sts;
|
|
|
|
}
|
2001-09-11 08:29:31 -03:00
|
|
|
|
1995-08-14 09:33:20 -03:00
|
|
|
#ifdef USE_MAC_APPLET_SUPPORT
|
|
|
|
/* Applet support */
|
|
|
|
|
|
|
|
/* Run a compiled Python Python script from 'PYC ' resource __main__ */
|
|
|
|
static int
|
2001-09-05 19:07:52 -03:00
|
|
|
run_main_resource(void)
|
1995-08-14 09:33:20 -03:00
|
|
|
{
|
|
|
|
Handle h;
|
|
|
|
long size;
|
|
|
|
PyObject *code;
|
|
|
|
PyObject *result;
|
|
|
|
|
|
|
|
h = GetNamedResource('PYC ', "\p__main__");
|
|
|
|
if (h == NULL) {
|
|
|
|
Alert(NOPYC_ALERT, NULL);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
size = GetResourceSizeOnDisk(h);
|
|
|
|
HLock(h);
|
|
|
|
code = PyMarshal_ReadObjectFromString(*h + 8, (int)(size - 8));
|
|
|
|
HUnlock(h);
|
|
|
|
ReleaseResource(h);
|
|
|
|
if (code == NULL) {
|
|
|
|
PyErr_Print();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
result = PyImport_ExecCodeModule("__main__", code);
|
|
|
|
Py_DECREF(code);
|
|
|
|
if (result == NULL) {
|
|
|
|
PyErr_Print();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
Py_DECREF(result);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialization sequence for applets */
|
|
|
|
void
|
2001-09-05 19:07:52 -03:00
|
|
|
PyMac_InitApplet(void)
|
1995-08-14 09:33:20 -03:00
|
|
|
{
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
int err;
|
|
|
|
|
1997-01-15 11:49:08 -04:00
|
|
|
init_common(&argc, &argv, 0);
|
1996-09-07 14:09:31 -03:00
|
|
|
|
1995-08-14 09:33:20 -03:00
|
|
|
Py_Initialize();
|
|
|
|
PySys_SetArgv(argc, argv);
|
1996-09-07 14:09:31 -03:00
|
|
|
|
1995-08-14 09:33:20 -03:00
|
|
|
err = run_main_resource();
|
1996-09-07 14:09:31 -03:00
|
|
|
|
|
|
|
err = (run_inspect() || err);
|
|
|
|
|
1995-08-14 09:33:20 -03:00
|
|
|
fflush(stderr);
|
|
|
|
fflush(stdout);
|
1995-10-27 10:32:30 -03:00
|
|
|
PyMac_Exit(err);
|
1995-08-14 09:33:20 -03:00
|
|
|
/* XXX Should we bother to Py_Exit(sts)? */
|
|
|
|
}
|
1995-02-02 10:27:31 -04:00
|
|
|
|
1997-01-15 11:49:08 -04:00
|
|
|
/*
|
|
|
|
** Hook for embedding python.
|
|
|
|
*/
|
|
|
|
void
|
2001-09-05 19:07:52 -03:00
|
|
|
PyMac_Initialize(void)
|
1997-01-15 11:49:08 -04:00
|
|
|
{
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
|
|
|
|
init_common(&argc, &argv, 1);
|
|
|
|
Py_Initialize();
|
|
|
|
PySys_SetArgv(argc, argv);
|
|
|
|
}
|
|
|
|
|
1995-08-14 09:33:20 -03:00
|
|
|
#endif /* USE_MAC_APPLET_SUPPORT */
|
1994-12-14 09:47:30 -04:00
|
|
|
|
2001-10-30 18:48:36 -04:00
|
|
|
#if TARGET_API_MAC_OSX /* Really: TARGET_API_MAC_CARBON */
|
2001-09-11 10:08:10 -03:00
|
|
|
|
|
|
|
static int
|
2002-03-29 10:43:50 -04:00
|
|
|
locateResourcePy(CFStringRef resourceType, char *resourceName, char *resourceURLCStr, int length)
|
|
|
|
{
|
2001-09-11 10:08:10 -03:00
|
|
|
CFBundleRef mainBundle = NULL;
|
|
|
|
CFURLRef URL, absoluteURL;
|
|
|
|
CFStringRef filenameString, filepathString, rsrcString;
|
|
|
|
CFIndex size, i;
|
2001-10-30 18:48:36 -04:00
|
|
|
CFArrayRef arrayRef = NULL;
|
|
|
|
int success = 0;
|
|
|
|
|
|
|
|
#if TARGET_API_MAC_OSX
|
|
|
|
CFURLPathStyle thePathStyle = kCFURLPOSIXPathStyle;
|
|
|
|
#else
|
|
|
|
CFURLPathStyle thePathStyle = kCFURLHFSPathStyle;
|
|
|
|
#endif
|
2001-09-11 10:08:10 -03:00
|
|
|
|
|
|
|
/* Get a reference to our main bundle */
|
|
|
|
mainBundle = CFBundleGetMainBundle();
|
|
|
|
|
2001-10-30 18:48:36 -04:00
|
|
|
/* If we are running inside a bundle, look through it. Otherwise, do nothing. */
|
|
|
|
if (mainBundle) {
|
|
|
|
/* Create a CFString with the resource name in it */
|
|
|
|
rsrcString = CFStringCreateWithCString(0, resourceName, kCFStringEncodingMacRoman);
|
|
|
|
|
|
|
|
/* Look for py files in the main bundle by type */
|
|
|
|
arrayRef = CFBundleCopyResourceURLsOfType( mainBundle,
|
2002-03-29 10:43:50 -04:00
|
|
|
resourceType,
|
2001-10-30 18:48:36 -04:00
|
|
|
NULL );
|
|
|
|
|
|
|
|
/* See if there are any filename matches */
|
|
|
|
size = CFArrayGetCount(arrayRef);
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
URL = CFArrayGetValueAtIndex(arrayRef, i);
|
|
|
|
filenameString = CFURLCopyLastPathComponent(URL);
|
|
|
|
if (CFStringCompare(filenameString, rsrcString, 0) == kCFCompareEqualTo) {
|
|
|
|
/* We found a match, get the file's full path */
|
|
|
|
absoluteURL = CFURLCopyAbsoluteURL(URL);
|
|
|
|
filepathString = CFURLCopyFileSystemPath(absoluteURL, thePathStyle);
|
|
|
|
CFRelease(absoluteURL);
|
|
|
|
|
|
|
|
/* Copy the full path into the caller's character buffer */
|
|
|
|
success = CFStringGetCString(filepathString, resourceURLCStr, length,
|
|
|
|
kCFStringEncodingMacRoman);
|
|
|
|
|
|
|
|
CFRelease(filepathString);
|
|
|
|
}
|
|
|
|
CFRelease(filenameString);
|
|
|
|
}
|
|
|
|
CFRelease(arrayRef);
|
|
|
|
CFRelease(rsrcString);
|
|
|
|
}
|
2001-09-11 10:08:10 -03:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2001-10-30 18:48:36 -04:00
|
|
|
#endif /* TARGET_API_MAC_CARBON */
|
|
|
|
|
|
|
|
#if TARGET_API_MAC_OSX
|
|
|
|
|
2001-09-05 19:07:52 -03:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2001-09-11 10:08:10 -03:00
|
|
|
static char scriptpath[1024];
|
|
|
|
char *script = NULL;
|
|
|
|
|
|
|
|
/* First we see whether we have __rawmain__.py and run that if it
|
|
|
|
** is there
|
|
|
|
*/
|
2002-03-29 10:43:50 -04:00
|
|
|
if (locateResourcePy(CFSTR("py"), "__rawmain__.py", scriptpath, 1024)) {
|
2001-09-11 10:08:10 -03:00
|
|
|
/* If we have a raw main we don't do AppleEvent processing.
|
|
|
|
** Notice that this also means we keep the -psn.... argv[1]
|
|
|
|
** value intact. Not sure whether that is important to someone,
|
|
|
|
** but you never know...
|
|
|
|
*/
|
|
|
|
script = scriptpath;
|
2002-03-29 10:43:50 -04:00
|
|
|
} else if (locateResourcePy(CFSTR("pyc"), "__rawmain__.pyc", scriptpath, 1024)) {
|
|
|
|
script = scriptpath;
|
2001-09-11 10:08:10 -03:00
|
|
|
} else {
|
|
|
|
/* Otherwise we look for __main__.py. Whether that is
|
|
|
|
** found or not we also process AppleEvent arguments.
|
|
|
|
*/
|
2002-03-29 10:43:50 -04:00
|
|
|
if (locateResourcePy(CFSTR("py"), "__main__.py", scriptpath, 1024))
|
|
|
|
script = scriptpath;
|
|
|
|
else if (locateResourcePy(CFSTR("pyc"), "__main__.pyc", scriptpath, 1024))
|
2001-09-11 10:08:10 -03:00
|
|
|
script = scriptpath;
|
|
|
|
|
|
|
|
init_common(&argc, &argv, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-08-05 11:13:31 -03:00
|
|
|
PyMac_Main(argc, argv, script);
|
2001-09-11 10:08:10 -03:00
|
|
|
return 0;
|
2001-09-05 19:07:52 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
1995-08-14 09:33:20 -03:00
|
|
|
/* For normal application */
|
|
|
|
void
|
2001-09-05 19:07:52 -03:00
|
|
|
PyMac_InitApplication(void)
|
1995-08-14 09:33:20 -03:00
|
|
|
{
|
1994-08-23 10:34:25 -03:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
2002-05-22 12:02:08 -03:00
|
|
|
OSType filetype;
|
1995-08-14 09:33:20 -03:00
|
|
|
|
2001-10-30 18:48:36 -04:00
|
|
|
static char scriptpath[1024];
|
|
|
|
char *script = NULL;
|
|
|
|
|
1997-01-15 11:49:08 -04:00
|
|
|
init_common(&argc, &argv, 0);
|
2001-10-30 18:48:36 -04:00
|
|
|
|
|
|
|
#if TARGET_API_MAC_OSX /* Really: TARGET_API_MAC_CARBON */
|
|
|
|
/* If we are running inside of a bundle, and a __main__.py is available, use it */
|
|
|
|
if (locateResourcePy("__main__.py", scriptpath, 1024))
|
|
|
|
script = scriptpath;
|
|
|
|
#endif
|
1996-09-07 14:09:31 -03:00
|
|
|
|
1995-08-14 09:33:20 -03:00
|
|
|
if ( argc > 1 ) {
|
|
|
|
/* We're running a script. Attempt to change current directory */
|
|
|
|
char curwd[256], *endp;
|
1995-02-13 07:35:34 -04:00
|
|
|
|
1995-08-14 09:33:20 -03:00
|
|
|
strcpy(curwd, argv[1]);
|
|
|
|
endp = strrchr(curwd, ':');
|
|
|
|
if ( endp && endp > curwd ) {
|
|
|
|
*endp = '\0';
|
|
|
|
|
|
|
|
chdir(curwd);
|
1995-02-13 07:35:34 -04:00
|
|
|
}
|
2001-08-03 10:31:36 -03:00
|
|
|
/* Check that the first argument is a text file */
|
2002-05-22 12:02:08 -03:00
|
|
|
filetype = PyMac_getfiletype(argv[1]);
|
|
|
|
if ( filetype != 'TEXT' && filetype != 0 ) {
|
2001-08-03 10:31:36 -03:00
|
|
|
Alert(NOTASCRIPT_ID, NULL);
|
|
|
|
exit(0);
|
|
|
|
}
|
1995-08-14 09:33:20 -03:00
|
|
|
}
|
2002-08-05 11:13:31 -03:00
|
|
|
PyMac_Main(argc, argv, script);
|
1995-08-14 09:33:20 -03:00
|
|
|
}
|
2001-09-05 19:07:52 -03:00
|
|
|
#endif /* TARGET_API_MAC_OSX */
|
1995-08-14 09:33:20 -03:00
|
|
|
|
|
|
|
/* Main program */
|
|
|
|
|
1996-08-19 08:18:24 -03:00
|
|
|
static void
|
2002-08-05 11:13:31 -03:00
|
|
|
PyMac_Main(int argc, char **argv, char *filename)
|
1995-08-14 09:33:20 -03:00
|
|
|
{
|
|
|
|
int sts;
|
|
|
|
char *command = NULL;
|
|
|
|
FILE *fp = stdin;
|
1996-03-12 09:29:04 -04:00
|
|
|
|
2001-09-11 10:08:10 -03:00
|
|
|
if ( filename ) {
|
|
|
|
/* Someone else has found our "script" already */
|
|
|
|
argv[0] = filename;
|
|
|
|
} else {
|
|
|
|
filename = argv[1];
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
}
|
1995-08-14 09:33:20 -03:00
|
|
|
|
|
|
|
if (Py_VerboseFlag ||
|
2001-09-05 19:07:52 -03:00
|
|
|
(command == NULL && filename == NULL && isatty((int)fileno(fp))))
|
2002-03-29 10:27:06 -04:00
|
|
|
fprintf(stderr, "%s %s on %s\n%s\n",
|
|
|
|
#if !TARGET_API_MAC_OSX
|
|
|
|
"Python",
|
|
|
|
#else
|
|
|
|
"Pythonw",
|
|
|
|
#endif
|
2000-09-08 07:20:37 -03:00
|
|
|
Py_GetVersion(), Py_GetPlatform(), COPYRIGHT);
|
1995-08-14 09:33:20 -03:00
|
|
|
|
|
|
|
if (filename != NULL) {
|
2002-04-14 17:12:41 -03:00
|
|
|
if ((fp = fopen(filename, "r" PY_STDIOTEXTMODE)) == NULL) {
|
1995-08-14 09:33:20 -03:00
|
|
|
fprintf(stderr, "%s: can't open file '%s'\n",
|
|
|
|
argv[0], filename);
|
1995-10-27 10:32:30 -03:00
|
|
|
PyMac_Exit(2);
|
1995-08-14 09:33:20 -03:00
|
|
|
}
|
1994-08-23 10:34:25 -03:00
|
|
|
}
|
1995-08-14 09:33:20 -03:00
|
|
|
|
2001-09-05 19:07:52 -03:00
|
|
|
#if !TARGET_API_MAC_OSX
|
1996-09-07 14:09:31 -03:00
|
|
|
/* We initialize the menubar here, hoping SIOUX is initialized by now */
|
1996-09-05 21:30:45 -03:00
|
|
|
PyMac_InitMenuBar();
|
2001-09-05 19:07:52 -03:00
|
|
|
#endif
|
|
|
|
|
1995-08-14 09:33:20 -03:00
|
|
|
Py_Initialize();
|
|
|
|
|
2001-07-04 19:37:19 -03:00
|
|
|
PyUnicode_SetDefaultEncoding(PyMac_getscript());
|
|
|
|
|
2001-09-11 10:08:10 -03:00
|
|
|
PySys_SetArgv(argc, argv);
|
1995-08-14 09:33:20 -03:00
|
|
|
|
|
|
|
if (filename == NULL && isatty((int)fileno(fp))) {
|
2002-04-14 17:12:41 -03:00
|
|
|
FILE *fp = fopen(STARTUP, "r" PY_STDIOTEXTMODE);
|
1995-08-14 09:33:20 -03:00
|
|
|
if (fp != NULL) {
|
|
|
|
(void) PyRun_SimpleFile(fp, STARTUP);
|
|
|
|
PyErr_Clear();
|
|
|
|
fclose(fp);
|
|
|
|
}
|
1994-08-23 10:34:25 -03:00
|
|
|
}
|
1995-08-14 09:33:20 -03:00
|
|
|
sts = PyRun_AnyFile(
|
|
|
|
fp, filename == NULL ? "<stdin>" : filename) != 0;
|
|
|
|
if (filename != NULL)
|
|
|
|
fclose(fp);
|
1996-09-07 14:09:31 -03:00
|
|
|
|
|
|
|
if ( filename != NULL || command != NULL )
|
|
|
|
sts = (run_inspect() || sts);
|
1995-08-14 09:33:20 -03:00
|
|
|
|
|
|
|
Py_Exit(sts);
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
2001-09-05 19:07:52 -03:00
|
|
|
#if !TARGET_API_MAC_OSX
|
2000-10-19 19:02:16 -03:00
|
|
|
/*
|
|
|
|
** Reset the "unseen output" flag
|
|
|
|
*/
|
|
|
|
void
|
2001-09-05 19:07:52 -03:00
|
|
|
PyMac_OutputSeen(void)
|
2000-10-19 19:02:16 -03:00
|
|
|
{
|
2001-02-17 18:02:07 -04:00
|
|
|
if ( console_output_state == STATE_UNKNOWN )
|
|
|
|
PyMac_InitMenuBar();
|
2001-02-10 21:08:04 -04:00
|
|
|
console_output_state = STATE_LASTREAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Set the "unseen output" flag
|
|
|
|
*/
|
|
|
|
void
|
2001-09-05 19:07:52 -03:00
|
|
|
PyMac_OutputNotSeen(void)
|
2001-02-10 21:08:04 -04:00
|
|
|
{
|
2001-02-17 18:02:07 -04:00
|
|
|
if ( console_output_state == STATE_UNKNOWN )
|
|
|
|
PyMac_InitMenuBar();
|
2001-02-10 21:08:04 -04:00
|
|
|
console_output_state = STATE_LASTWRITE;
|
2000-10-19 19:02:16 -03:00
|
|
|
}
|
2001-04-25 19:07:27 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Override abort() - The default one is not what we want.
|
|
|
|
*/
|
|
|
|
void
|
2001-09-05 19:07:52 -03:00
|
|
|
abort(void)
|
2001-04-25 19:07:27 -03:00
|
|
|
{
|
|
|
|
console_output_state = STATE_LASTWRITE;
|
|
|
|
PyMac_Exit(1);
|
|
|
|
}
|
2001-09-05 19:07:52 -03:00
|
|
|
#endif /* !TARGET_API_MAC_OSX */
|
2000-10-19 19:02:16 -03:00
|
|
|
|
1995-10-27 10:32:30 -03:00
|
|
|
/*
|
|
|
|
** Terminate application
|
|
|
|
*/
|
1996-08-19 08:18:24 -03:00
|
|
|
void
|
2001-09-05 19:07:52 -03:00
|
|
|
PyMac_Exit(int status)
|
1995-10-27 10:32:30 -03:00
|
|
|
{
|
2001-09-05 19:07:52 -03:00
|
|
|
#ifdef USE_SIOUX
|
2000-09-22 18:50:11 -03:00
|
|
|
int keep = 0;
|
2001-09-05 19:07:52 -03:00
|
|
|
#endif
|
1997-01-07 12:19:42 -04:00
|
|
|
|
|
|
|
#if __profile__ == 1
|
|
|
|
ProfilerDump("\pPython Profiler Results");
|
|
|
|
ProfilerTerm();
|
|
|
|
#endif
|
1995-10-27 10:32:30 -03:00
|
|
|
|
1995-11-10 10:51:26 -04:00
|
|
|
#ifdef USE_SIOUX
|
2000-10-12 18:23:19 -03:00
|
|
|
switch (PyMac_options.keep_console) {
|
2000-09-22 18:50:11 -03:00
|
|
|
case POPT_KEEPCONSOLE_NEVER:
|
|
|
|
keep = 0;
|
|
|
|
break;
|
|
|
|
case POPT_KEEPCONSOLE_OUTPUT:
|
2001-02-10 21:08:04 -04:00
|
|
|
if (console_output_state == STATE_LASTWRITE ||
|
|
|
|
console_output_state == STATE_UNKNOWN )
|
2000-09-22 18:50:11 -03:00
|
|
|
keep = 1;
|
|
|
|
else
|
|
|
|
keep = 0;
|
|
|
|
break;
|
|
|
|
case POPT_KEEPCONSOLE_ERROR:
|
|
|
|
keep = (status != 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
keep = 1;
|
|
|
|
}
|
1995-11-10 10:51:26 -04:00
|
|
|
if (keep) {
|
|
|
|
SIOUXSettings.standalone = 1;
|
|
|
|
SIOUXSettings.autocloseonquit = 0;
|
1996-03-25 11:46:03 -04:00
|
|
|
SIOUXSetTitle("\p\307terminated\310");
|
2001-04-25 19:07:27 -03:00
|
|
|
PyMac_RaiseConsoleWindow();
|
1997-06-12 07:49:13 -03:00
|
|
|
PyMac_RestoreMenuBar();
|
1997-05-07 12:48:54 -03:00
|
|
|
#ifdef USE_MSL
|
|
|
|
/*
|
|
|
|
** Temporary workaround: autocloseonquit clearing does not
|
|
|
|
** currently work for the MSL/GUSI combo.
|
|
|
|
*/
|
|
|
|
while(getchar() > 0);
|
|
|
|
#endif
|
1995-11-10 10:51:26 -04:00
|
|
|
}
|
1995-10-27 10:32:30 -03:00
|
|
|
else
|
|
|
|
SIOUXSettings.autocloseonquit = 1;
|
1996-09-04 12:24:59 -03:00
|
|
|
#endif /* USE_SIOUX */
|
1995-10-27 10:32:30 -03:00
|
|
|
|
|
|
|
exit(status);
|
|
|
|
}
|
1995-08-14 09:33:20 -03:00
|
|
|
|
2001-09-05 19:07:52 -03:00
|
|
|
#if !TARGET_API_MAC_OSX
|
1995-08-14 09:33:20 -03:00
|
|
|
/* Make the *original* argc/argv available to other modules.
|
|
|
|
This is rare, but it is needed by the secureware extension. */
|
|
|
|
|
|
|
|
void
|
2000-07-11 18:16:03 -03:00
|
|
|
Py_GetArgcArgv(int *argc,char ***argv)
|
1995-08-14 09:33:20 -03:00
|
|
|
{
|
|
|
|
*argc = orig_argc;
|
|
|
|
*argv = orig_argv;
|
1994-08-23 10:34:25 -03:00
|
|
|
}
|
2001-09-05 19:07:52 -03:00
|
|
|
#endif
|
1996-08-02 12:16:16 -03:00
|
|
|
|
|
|
|
/* More cruft that shouldn't really be here, used in sysmodule.c */
|
2001-09-05 19:07:52 -03:00
|
|
|
#if !TARGET_API_MAC_OSX
|
|
|
|
/* Return the program name -- some code out there needs this. */
|
|
|
|
char *
|
|
|
|
Py_GetProgramFullPath(void)
|
|
|
|
{
|
|
|
|
return orig_argv[0];
|
|
|
|
}
|
1996-08-02 12:16:16 -03:00
|
|
|
|
|
|
|
char *
|
2001-09-05 19:07:52 -03:00
|
|
|
Py_GetPrefix(void)
|
1996-08-02 12:16:16 -03:00
|
|
|
{
|
1997-09-08 10:22:22 -03:00
|
|
|
return PyMac_GetPythonDir();
|
1996-08-02 12:16:16 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2001-09-05 19:07:52 -03:00
|
|
|
Py_GetExecPrefix(void)
|
1996-08-02 12:16:16 -03:00
|
|
|
{
|
1997-09-08 10:22:22 -03:00
|
|
|
return PyMac_GetPythonDir();
|
1996-08-02 12:16:16 -03:00
|
|
|
}
|
2001-02-10 21:08:04 -04:00
|
|
|
|
|
|
|
int
|
2001-09-05 19:07:52 -03:00
|
|
|
PyMac_GetDelayConsoleFlag(void)
|
2001-02-10 21:08:04 -04:00
|
|
|
{
|
|
|
|
return (int)PyMac_options.delayconsole;
|
2001-09-01 19:37:54 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef WITHOUT_UNIX_NEWLINES
|
|
|
|
/*
|
|
|
|
** Experimental feature (for 2.2a2): optionally allow unix newlines
|
|
|
|
** as well as Mac newlines on input. We replace a lowlevel
|
|
|
|
** MSL routine to accomplish this.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
__convert_to_newlines(unsigned char * buf, size_t * n_ptr)
|
|
|
|
{
|
|
|
|
unsigned char *p;
|
|
|
|
size_t n = *n_ptr;
|
|
|
|
|
|
|
|
for(p=buf; n > 0; p++, n--)
|
|
|
|
if ( *p == '\r' ) *p = '\n';
|
|
|
|
else if ( *p == '\n' && !PyMac_options.unixnewlines )
|
|
|
|
*p = '\r';
|
|
|
|
}
|
|
|
|
#endif /* WITHOUT_UNIX_NEWLINES */
|
2001-09-05 19:07:52 -03:00
|
|
|
#endif /* !TARGET_API_MAC_OSX */
|
2001-09-01 19:37:54 -03:00
|
|
|
|