[Python-checkins] CVS: python/dist/src/Mac/Python macgetargv.c,1.24,1.25 macmain.c,1.67,1.68
Jack Jansen
jackjansen@users.sourceforge.net
2001年9月05日 15:07:54 -0700
Update of /cvsroot/python/python/dist/src/Mac/Python
In directory usw-pr-cvs1:/tmp/cvs-serv25188/Python
Modified Files:
macgetargv.c macmain.c
Log Message:
Changes to make these work under OSX as the main program for a
fullblown drag and drop application. To my surprise it is starting
to work already: Python actually executes a script dropped on it.
To be done:
- Make sure this still works in MacPython
- Don't lose argv[0] in the process
- Applet support
Index: macgetargv.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Python/macgetargv.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** macgetargv.c 2001年06月20日 20:50:19 1.24
--- macgetargv.c 2001年09月05日 22:07:52 1.25
***************
*** 28,31 ****
--- 28,32 ----
#include <stdlib.h>
+ #ifdef WITHOUT_FRAMEWORKS
#include <Types.h>
#include <Files.h>
***************
*** 41,44 ****
--- 42,48 ----
#include <Dialogs.h>
#include <Windows.h>
+ #else
+ #include <Carbon/Carbon.h>
+ #endif /* WITHOUT_FRAMEWORKS */
#if UNIVERSAL_INTERFACES_VERSION >= 0x0340
***************
*** 55,59 ****
FSSpec PyMac_ApplicationFSSpec;
char PyMac_ApplicationPath[256];
- static int applocation_inited;
/* Duplicate a string to the heap. We also export this since it isn't standard
--- 59,62 ----
***************
*** 71,82 ****
#endif
/* Initialize FSSpec and full name of current application */
OSErr
! PyMac_init_process_location()
{
ProcessSerialNumber currentPSN;
ProcessInfoRec info;
OSErr err;
if ( applocation_inited ) return 0;
--- 74,104 ----
#endif
+ #if TARGET_API_MAC_OSX
+ OSErr
+ PyMac_GetFullPath(FSSpec *fss, char *path)
+ {
+ FSRef fsr;
+ OSErr err;
+
+ *path = '0円';
+ err = FSpMakeFSRef(fss, &fsr);
+ if ( err ) return err;
+ err = (OSErr)FSRefMakePath(&fsr, path, 1024);
+ if ( err ) return err;
+ return 0;
+ }
+ #endif /* TARGET_API_MAC_OSX */
+
+
+ #if !TARGET_API_MAC_OSX
/* Initialize FSSpec and full name of current application */
OSErr
! PyMac_init_process_location(void)
{
ProcessSerialNumber currentPSN;
ProcessInfoRec info;
OSErr err;
+ static int applocation_inited;
if ( applocation_inited ) return 0;
***************
*** 93,96 ****
--- 115,119 ----
return 0;
}
+ #endif /* !TARGET_API_MAC_OSX */
/* Check that there aren't any args remaining in the event */
***************
*** 148,160 ****
long i, ndocs, size;
FSSpec fss;
! char path[256];
got_one = 1;
! if (err = AEGetParamDesc(theAppleEvent,
! keyDirectObject, typeAEList, &doclist))
return err;
! if (err = get_missing_params(theAppleEvent))
return err;
! if (err = AECountItems(&doclist, &ndocs))
return err;
for(i = 1; i <= ndocs; i++) {
--- 171,183 ----
long i, ndocs, size;
FSSpec fss;
! char path[1024];
got_one = 1;
! if ((err = AEGetParamDesc(theAppleEvent,
! keyDirectObject, typeAEList, &doclist)))
return err;
! if ((err = get_missing_params(theAppleEvent)))
return err;
! if ((err = AECountItems(&doclist, &ndocs)))
return err;
for(i = 1; i <= ndocs; i++) {
***************
*** 175,179 ****
static void
! set_ae_handlers()
{
open_doc_upp = NewAEEventHandlerUPP(&handle_open_doc);
--- 198,202 ----
static void
! set_ae_handlers(void)
{
open_doc_upp = NewAEEventHandlerUPP(&handle_open_doc);
***************
*** 194,198 ****
static void
! reset_ae_handlers()
{
AERemoveEventHandler(kCoreEventClass, kAEOpenApplication,
--- 217,221 ----
static void
! reset_ae_handlers(void)
{
AERemoveEventHandler(kCoreEventClass, kAEOpenApplication,
***************
*** 209,213 ****
static void
! event_loop()
{
EventRecord event;
--- 232,236 ----
static void
! event_loop(void)
{
EventRecord event;
***************
*** 230,241 ****
int
! PyMac_GetArgv(pargv, noevents)
! char ***pargv;
! int noevents;
{
-
arg_count = 0;
(void)PyMac_init_process_location();
arg_vector[arg_count++] = strdup(PyMac_ApplicationPath);
if( !noevents ) {
--- 253,266 ----
int
! PyMac_GetArgv(char ***pargv, int noevents)
{
arg_count = 0;
+ #if TARGET_API_MAC_OSX
+ /* In an OSX bundle argv[0] is okay */
+ arg_count++;
+ #else
(void)PyMac_init_process_location();
arg_vector[arg_count++] = strdup(PyMac_ApplicationPath);
+ #endif /* TARGET_API_MAC_OSX */
if( !noevents ) {
Index: macmain.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Python/macmain.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -C2 -d -r1.67 -r1.68
*** macmain.c 2001年09月01日 22:37:48 1.67
--- macmain.c 2001年09月05日 22:07:52 1.68
***************
*** 31,34 ****
--- 31,35 ----
#include "macglue.h"
+ #ifdef WITHOUT_FRAMEWORKS
#include <Memory.h>
#include <Resources.h>
***************
*** 42,45 ****
--- 43,50 ----
#include <Appearance.h>
#endif /* USE_APPEARANCE */
+ #else
+ #include <Carbon/Carbon.h>
+ #endif /* WITHOUT_FRAMEWORKS */
+
#ifdef __MWERKS__
#include <SIOUX.h>
***************
*** 48,60 ****
#if __profile__ == 1
#include <profiler.h>
! #endif
! #endif
#include <unistd.h>
#ifdef USE_MAC_SHARED_LIBRARY
extern PyMac_AddLibResources(void);
#endif
- //#ifdef USE_GUSI
- //#include "GUSISIOUX.h"
- //#endif
#define STARTUP "PythonStartup"
--- 53,63 ----
#if __profile__ == 1
#include <profiler.h>
! #endif /* __profile__ */
! #endif /* __MWERKS__ */
!
#include <unistd.h>
#ifdef USE_MAC_SHARED_LIBRARY
extern PyMac_AddLibResources(void);
#endif
#define STARTUP "PythonStartup"
***************
*** 82,86 ****
void PyMac_Exit(int); /* Forward */
! static void init_appearance()
{
#ifdef USE_APPEARANCE
--- 85,89 ----
void PyMac_Exit(int); /* Forward */
! static void init_appearance(void)
{
#ifdef USE_APPEARANCE
***************
*** 100,104 ****
static void
! init_mac_world()
{
#if !TARGET_API_MAC_CARBON
--- 103,107 ----
static void
! init_mac_world(void)
{
#if !TARGET_API_MAC_CARBON
***************
*** 128,133 ****
DialogPtr dialog;
Rect rect;
- int old_argc = *argcp;
- int i;
/*
--- 131,134 ----
***************
*** 192,196 ****
--- 193,200 ----
}
#endif
+ #if !TARGET_API_MAC_OSX
if ( item == OPT_CMDLINE ) {
+ int old_argc = *argcp;
+ int i;
int new_argc, newer_argc;
char **new_argv, **newer_argv;
***************
*** 210,213 ****
--- 214,218 ----
/* XXXX Is it not safe to use free() here, apparently */
}
+ #endif /* !TARGET_API_MAC_OSX */
#define OPT_ITEM(num, var) \
if ( item == (num) ) { \
***************
*** 284,288 ****
#ifdef USE_SIOUX
/* Set various SIOUX flags. Some are changed later based on options */
! /* SIOUXSettings.standalone = 0; /* XXXX Attempting to keep sioux from eating events */
SIOUXSettings.asktosaveonclose = 0;
SIOUXSettings.showstatusline = 0;
--- 289,295 ----
#ifdef USE_SIOUX
/* Set various SIOUX flags. Some are changed later based on options */
! #if 0
! SIOUXSettings.standalone = 0; /* XXXX Attempting to keep sioux from eating events */
! #endif
SIOUXSettings.asktosaveonclose = 0;
SIOUXSettings.showstatusline = 0;
***************
*** 292,297 ****
/* Get options from preference file (or from applet resource fork) */
PyMac_options.keep_console = POPT_KEEPCONSOLE_OUTPUT; /* default-default */
PyMac_PreferenceOptions(&PyMac_options);
!
if ( embedded ) {
static char *emb_argv[] = {"embedded-python", 0};
--- 299,307 ----
/* Get options from preference file (or from applet resource fork) */
PyMac_options.keep_console = POPT_KEEPCONSOLE_OUTPUT; /* default-default */
+ PyMac_options.unixnewlines = 1;
+ #if !TARGET_API_MAC_OSX
PyMac_PreferenceOptions(&PyMac_options);
! #endif
!
if ( embedded ) {
static char *emb_argv[] = {"embedded-python", 0};
***************
*** 302,305 ****
--- 312,316 ----
/* Create argc/argv. Do it before we go into the options event loop. */
*argcp = PyMac_GetArgv(argvp, PyMac_options.noargs);
+ #if !TARGET_API_MAC_OSX
#ifndef NO_ARGV0_CHDIR
if (*argcp >= 1 && (*argvp)[0] && (*argvp)[0][0]) {
***************
*** 315,318 ****
--- 326,330 ----
}
#endif
+ #endif
/* Do interactive option setting, if allowed and <option> depressed */
PyMac_InteractiveOptions(&PyMac_options, argcp, argvp);
***************
*** 327,330 ****
--- 339,343 ----
Py_TabcheckFlag = PyMac_options.tabwarn;
Py_DivisionWarningFlag = PyMac_options.divisionwarn;
+ #if !TARGET_API_MAC_OSX
if ( PyMac_options.noargs ) {
/* don't process events at all without the scripts permission */
***************
*** 336,340 ****
PyMac_SetSchedParams(&scp);
}
! /* XXXX dispatch oldexc and nosite */
/* Set buffering */
--- 349,353 ----
PyMac_SetSchedParams(&scp);
}
! #endif /* !TARGET_API_MAC_OSX */
/* Set buffering */
***************
*** 364,368 ****
*/
static int
! run_inspect()
{
int sts = 0;
--- 377,381 ----
*/
static int
! run_inspect(void)
{
int sts = 0;
***************
*** 379,383 ****
*/
static void
! PyMac_InstallNavServicesForSF()
{
if ( !PyMac_options.nonavservice ) {
--- 392,396 ----
*/
static void
! PyMac_InstallNavServicesForSF(void)
{
if ( !PyMac_options.nonavservice ) {
***************
*** 402,406 ****
/* Run a compiled Python Python script from 'PYC ' resource __main__ */
static int
! run_main_resource()
{
Handle h;
--- 415,419 ----
/* Run a compiled Python Python script from 'PYC ' resource __main__ */
static int
! run_main_resource(void)
{
Handle h;
***************
*** 435,439 ****
/* Initialization sequence for applets */
void
! PyMac_InitApplet()
{
int argc;
--- 448,452 ----
/* Initialization sequence for applets */
void
! PyMac_InitApplet(void)
{
int argc;
***************
*** 461,465 ****
*/
void
! PyMac_Initialize()
{
int argc;
--- 474,478 ----
*/
void
! PyMac_Initialize(void)
{
int argc;
***************
*** 474,480 ****
#endif /* USE_MAC_APPLET_SUPPORT */
/* For normal application */
void
! PyMac_InitApplication()
{
int argc;
--- 487,509 ----
#endif /* USE_MAC_APPLET_SUPPORT */
+ #if TARGET_API_MAC_OSX
+ int
+ main(int argc, char **argv)
+ {
+ int i;
+ printf("first argc=%d\n", argc);
+ for(i=0; i<argc; i++) printf("first argv[%d] = \"%s\"\n", i, argv[i]);
+ init_common(&argc, &argv, 0);
+ printf("second argc=%d\n", argc);
+ for(i=0; i<argc; i++) printf("second argv[%d] = \"%s\"\n", i, argv[i]);
+ Py_Main(argc, argv);
+ return 0;
+ }
+
+ #else
+
/* For normal application */
void
! PyMac_InitApplication(void)
{
int argc;
***************
*** 506,516 ****
Py_Main(argc, argv);
}
/* Main program */
static void
! Py_Main(argc, argv)
! int argc;
! char **argv;
{
int sts;
--- 535,544 ----
Py_Main(argc, argv);
}
+ #endif /* TARGET_API_MAC_OSX */
/* Main program */
static void
! Py_Main(int argc, char **argv)
{
int sts;
***************
*** 522,526 ****
if (Py_VerboseFlag ||
! command == NULL && filename == NULL && isatty((int)fileno(fp)))
fprintf(stderr, "Python %s on %s\n%s\n",
Py_GetVersion(), Py_GetPlatform(), COPYRIGHT);
--- 550,554 ----
if (Py_VerboseFlag ||
! (command == NULL && filename == NULL && isatty((int)fileno(fp))))
fprintf(stderr, "Python %s on %s\n%s\n",
Py_GetVersion(), Py_GetPlatform(), COPYRIGHT);
***************
*** 534,540 ****
}
/* We initialize the menubar here, hoping SIOUX is initialized by now */
PyMac_InitMenuBar();
!
Py_Initialize();
--- 562,570 ----
}
+ #if !TARGET_API_MAC_OSX
/* We initialize the menubar here, hoping SIOUX is initialized by now */
PyMac_InitMenuBar();
! #endif
!
Py_Initialize();
***************
*** 565,573 ****
}
/*
** Reset the "unseen output" flag
*/
void
! PyMac_OutputSeen()
{
if ( console_output_state == STATE_UNKNOWN )
--- 595,604 ----
}
+ #if !TARGET_API_MAC_OSX
/*
** Reset the "unseen output" flag
*/
void
! PyMac_OutputSeen(void)
{
if ( console_output_state == STATE_UNKNOWN )
***************
*** 580,584 ****
*/
void
! PyMac_OutputNotSeen()
{
if ( console_output_state == STATE_UNKNOWN )
--- 611,615 ----
*/
void
! PyMac_OutputNotSeen(void)
{
if ( console_output_state == STATE_UNKNOWN )
***************
*** 591,599 ****
*/
void
! abort()
{
console_output_state = STATE_LASTWRITE;
PyMac_Exit(1);
}
/*
--- 622,631 ----
*/
void
! abort(void)
{
console_output_state = STATE_LASTWRITE;
PyMac_Exit(1);
}
+ #endif /* !TARGET_API_MAC_OSX */
/*
***************
*** 601,608 ****
*/
void
! PyMac_Exit(status)
! int status;
{
int keep = 0;
#if __profile__ == 1
--- 633,641 ----
*/
void
! PyMac_Exit(int status)
{
+ #ifdef USE_SIOUX
int keep = 0;
+ #endif
#if __profile__ == 1
***************
*** 649,661 ****
exit(status);
}
-
- /* Return the program name -- some code out there needs this. */
- char *
- Py_GetProgramFullPath()
- {
- return orig_argv[0];
- }
!
/* Make the *original* argc/argv available to other modules.
This is rare, but it is needed by the secureware extension. */
--- 682,687 ----
exit(status);
}
! #if !TARGET_API_MAC_OSX
/* Make the *original* argc/argv available to other modules.
This is rare, but it is needed by the secureware extension. */
***************
*** 667,675 ****
*argv = orig_argv;
}
/* More cruft that shouldn't really be here, used in sysmodule.c */
char *
! Py_GetPrefix()
{
return PyMac_GetPythonDir();
--- 693,709 ----
*argv = orig_argv;
}
+ #endif
/* More cruft that shouldn't really be here, used in sysmodule.c */
+ #if !TARGET_API_MAC_OSX
+ /* Return the program name -- some code out there needs this. */
+ char *
+ Py_GetProgramFullPath(void)
+ {
+ return orig_argv[0];
+ }
char *
! Py_GetPrefix(void)
{
return PyMac_GetPythonDir();
***************
*** 677,681 ****
char *
! Py_GetExecPrefix()
{
return PyMac_GetPythonDir();
--- 711,715 ----
char *
! Py_GetExecPrefix(void)
{
return PyMac_GetPythonDir();
***************
*** 683,687 ****
int
! PyMac_GetDelayConsoleFlag()
{
return (int)PyMac_options.delayconsole;
--- 717,721 ----
int
! PyMac_GetDelayConsoleFlag(void)
{
return (int)PyMac_options.delayconsole;
***************
*** 706,708 ****
--- 740,743 ----
}
#endif /* WITHOUT_UNIX_NEWLINES */
+ #endif /* !TARGET_API_MAC_OSX */