annotate Mac/Python/macgetargv.c @ 4566:6403c94de50d legacy-trunk

Added safeguard against failure in __del__.
author Guido van Rossum <guido@python.org>
date Wed, 27 Nov 1996 19:39:58 +0000
parents efb2938ce676
children d6b292a33cfe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 The Netherlands.
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 documentation for any purpose and without fee is hereby granted,
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 both that copyright notice and this permission notice appear in
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 distribution of the software without specific, written prior permission.
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 ******************************************************************/
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
24
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 /* Construct argc and argv for main() by using Apple Events */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 /* From Jack's implementation for STDWIN */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 #include <stdlib.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 #ifndef SystemSevenOrLater
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 #define SystemSevenOrLater 1
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 #endif
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #include <Types.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 #include <Files.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 #include <Events.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 #include <Memory.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 #include <Processes.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 #include <Errors.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 #include <AppleEvents.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 #include <AEObjects.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 #include <Desk.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 #include <Fonts.h>
2399
438a8c265eb9 ported back to Think C
Guido van Rossum <guido@python.org>
parents: 2393
diff changeset
44 #include <TextEdit.h>
438a8c265eb9 ported back to Think C
Guido van Rossum <guido@python.org>
parents: 2393
diff changeset
45 #include <Menus.h>
438a8c265eb9 ported back to Think C
Guido van Rossum <guido@python.org>
parents: 2393
diff changeset
46 #include <Dialogs.h>
438a8c265eb9 ported back to Think C
Guido van Rossum <guido@python.org>
parents: 2393
diff changeset
47 #include <Windows.h>
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
49 #include "Python.h"
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
50 #include "macglue.h"
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
51
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 #ifdef GENERATINGCFM /* Defined to 0 or 1 in Universal headers */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 #define HAVE_UNIVERSAL_HEADERS
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 #endif
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
55
2794
823f3a8ecfe4 Initial port to CodeWarrior CFM68K support (mainly by disabling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2411
diff changeset
56 #ifdef SYMANTEC__CFM68K__
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 #pragma lib_export on
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 #endif
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 #ifndef HAVE_UNIVERSAL_HEADERS
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 #define NewAEEventHandlerProc(x) (x)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 #define AEEventHandlerUPP EventHandlerProcPtr
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 #endif
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
64
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 static int arg_count;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 static char *arg_vector[256];
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
67 FSSpec PyMac_ApplicationFSSpec;
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
68 char PyMac_ApplicationPath[256];
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
69 static int applocation_inited;
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
3215
3b2be811a66a Export strdup (parsermodule needs it)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3054
diff changeset
71 /* Duplicate a string to the heap. We also export this since it isn't standard
3b2be811a66a Export strdup (parsermodule needs it)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3054
diff changeset
72 ** and others use it
3b2be811a66a Export strdup (parsermodule needs it)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3054
diff changeset
73 */
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
3215
3b2be811a66a Export strdup (parsermodule needs it)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3054
diff changeset
75 char *
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 strdup(char *src)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 char *dst = malloc(strlen(src) + 1);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 if (dst)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 strcpy(dst, src);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 return dst;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
84 /* Initialize FSSpec and full name of current application */
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
85
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2874
diff changeset
86 OSErr
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
87 PyMac_init_process_location()
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 ProcessSerialNumber currentPSN;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 ProcessInfoRec info;
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
91 OSErr err;
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
93 if ( applocation_inited ) return 0;
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 currentPSN.highLongOfPSN = 0;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 currentPSN.lowLongOfPSN = kCurrentProcess;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 info.processInfoLength = sizeof(ProcessInfoRec);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 info.processName = NULL;
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
98 info.processAppSpec = &PyMac_ApplicationFSSpec;
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
99 if ( err=GetProcessInformation(&currentPSN, &info))
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
100 return err;
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
101 if ( err=PyMac_GetFullPath(&PyMac_ApplicationFSSpec, PyMac_ApplicationPath) )
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
102 return err;
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
103 applocation_inited = 1;
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
104 return 0;
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
106
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 /* Given an FSSpec, return the FSSpec of the parent folder */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
108
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 static OSErr
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 get_folder_parent (FSSpec * fss, FSSpec * parent)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 CInfoPBRec rec;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 short err;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 * parent = * fss;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 rec.hFileInfo.ioNamePtr = parent->name;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 rec.hFileInfo.ioVRefNum = parent->vRefNum;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 rec.hFileInfo.ioDirID = parent->parID;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 rec.hFileInfo.ioFDirIndex = -1;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 rec.hFileInfo.ioFVersNum = 0;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 if (err = PBGetCatInfoSync (& rec))
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 return err;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 parent->parID = rec.dirInfo.ioDrParID;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 /* parent->name[0] = 0; */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 return 0;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
127
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 /* Given an FSSpec return a full, colon-separated pathname */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
130 OSErr
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
131 PyMac_GetFullPath (FSSpec *fss, char *buf)
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 short err;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 FSSpec fss_parent, fss_current;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 char tmpbuf[256];
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 int plen;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
137
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 fss_current = *fss;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 plen = fss_current.name[0];
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 memcpy(buf, &fss_current.name[1], plen);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 buf[plen] = 0;
4552
efb2938ce676 Fixed FSSpec->pathname code to add colon if the fsspec points to a disk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
142 /* Special case for disk names */
efb2938ce676 Fixed FSSpec->pathname code to add colon if the fsspec points to a disk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
143 if ( fss_current.parID <= 1 ) {
efb2938ce676 Fixed FSSpec->pathname code to add colon if the fsspec points to a disk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
144 buf[plen++] = ':';
efb2938ce676 Fixed FSSpec->pathname code to add colon if the fsspec points to a disk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
145 buf[plen] = 0;
efb2938ce676 Fixed FSSpec->pathname code to add colon if the fsspec points to a disk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
146 return 0;
efb2938ce676 Fixed FSSpec->pathname code to add colon if the fsspec points to a disk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4523
diff changeset
147 }
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 while (fss_current.parID > 1) {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 /* Get parent folder name */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 if (err = get_folder_parent(&fss_current, &fss_parent))
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 return err;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 fss_current = fss_parent;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 /* Prepend path component just found to buf */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 plen = fss_current.name[0];
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 if (strlen(buf) + plen + 1 > 256) {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 /* Oops... Not enough space (shouldn't happen) */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 *buf = 0;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 return -1;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 memcpy(tmpbuf, &fss_current.name[1], plen);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 tmpbuf[plen] = ':';
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 strcpy(&tmpbuf[plen+1], buf);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 strcpy(buf, tmpbuf);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 return 0;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
167
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 /* Check that there aren't any args remaining in the event */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
169
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 static OSErr
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 get_missing_params(AppleEvent *theAppleEvent)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 DescType theType;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 Size actualSize;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 OSErr err;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
176
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 err = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 &theType, nil, 0, &actualSize);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 if (err == errAEDescNotFound)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 return noErr;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 else
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 return errAEEventNotHandled;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
184
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 static int got_one; /* Flag that we can stop getting events */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
186
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 /* Handle the Print or Quit events (by failing) */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
188
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 static pascal OSErr
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 handle_not(AppleEvent *theAppleEvent, AppleEvent *reply, long refCon)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 #pragma unused (reply, refCon)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 got_one = 1;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 return errAEEventNotHandled;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
196
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 /* Handle the Open Application event (by ignoring it) */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
198
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 static pascal OSErr
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 handle_open_app(AppleEvent *theAppleEvent, AppleEvent *reply, long refCon)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 #pragma unused (reply, refCon)
3249
1cf6e10522e0 Continue looking for "open doc" events even after "open app". This
Jack Jansen <jack.jansen@cwi.nl>
parents: 3215
diff changeset
203 #if 0
1cf6e10522e0 Continue looking for "open doc" events even after "open app". This
Jack Jansen <jack.jansen@cwi.nl>
parents: 3215
diff changeset
204 /* Test by Jack: would removing this facilitate debugging? */
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 got_one = 1;
3249
1cf6e10522e0 Continue looking for "open doc" events even after "open app". This
Jack Jansen <jack.jansen@cwi.nl>
parents: 3215
diff changeset
206 #endif
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 return get_missing_params(theAppleEvent);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
209
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 /* Handle the Open Document event, by adding an argument */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
211
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 static pascal OSErr
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 handle_open_doc(AppleEvent *theAppleEvent, AppleEvent *reply, long refCon)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 #pragma unused (reply, refCon)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 OSErr err;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 AEDescList doclist;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 AEKeyword keywd;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 DescType rttype;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 long i, ndocs, size;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 FSSpec fss;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 char path[256];
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
223
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 got_one = 1;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 if (err = AEGetParamDesc(theAppleEvent,
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 keyDirectObject, typeAEList, &doclist))
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 return err;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 if (err = get_missing_params(theAppleEvent))
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 return err;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 if (err = AECountItems(&doclist, &ndocs))
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 return err;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 for(i = 1; i <= ndocs; i++) {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 err = AEGetNthPtr(&doclist, i, typeFSS,
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 &keywd, &rttype, &fss, sizeof(fss), &size);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 if (err)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 break;
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
237 PyMac_GetFullPath(&fss, path);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 arg_vector[arg_count++] = strdup(path);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 return err;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
242
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 /* Install standard core event handlers */
2874
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
244 AEEventHandlerUPP open_doc_upp;
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
245 AEEventHandlerUPP open_app_upp;
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
246 AEEventHandlerUPP not_upp;
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
247
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 static void
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 set_ae_handlers()
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 {
2874
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
251 open_doc_upp = NewAEEventHandlerProc(handle_open_doc);
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
252 open_app_upp = NewAEEventHandlerProc(handle_open_app);
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
253 not_upp = NewAEEventHandlerProc(handle_not);
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
254
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
2874
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
256 open_app_upp, 0L, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
2874
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
258 open_doc_upp, 0L, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
2874
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
260 not_upp, 0L, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
2874
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
262 not_upp, 0L, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
264
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 /* Uninstall standard core event handlers */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
266
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 static void
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 reset_ae_handlers()
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 AERemoveEventHandler(kCoreEventClass, kAEOpenApplication,
2874
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
271 open_app_upp, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments,
2874
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
273 open_doc_upp, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 AERemoveEventHandler(kCoreEventClass, kAEPrintDocuments,
2874
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
275 not_upp, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 AERemoveEventHandler(kCoreEventClass, kAEQuitApplication,
2874
927f4839fbfa Un-installing of AE handlers fixed (AE is very picky that you specify
Jack Jansen <jack.jansen@cwi.nl>
parents: 2794
diff changeset
277 not_upp, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
279
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
280 /* Wait for events until a core event has been handled */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
281
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
282 static void
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 event_loop()
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
285 EventRecord event;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 int n;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 int ok;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
288
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 got_one = 0;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 for (n = 0; n < 100 && !got_one; n++) {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 SystemTask();
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 ok = GetNextEvent(everyEvent, &event);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 if (ok && event.what == kHighLevelEvent) {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
294 AEProcessAppleEvent(&event);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
295 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
298
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
299 /* Get the argv vector, return argc */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
300
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 int
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4020
diff changeset
302 PyMac_GetArgv(pargv, noevents)
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 char ***pargv;
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4020
diff changeset
304 int noevents;
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
305 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
306
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 arg_count = 0;
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
308 (void)PyMac_init_process_location();
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
309 arg_vector[arg_count++] = strdup(PyMac_ApplicationPath);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
310
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4020
diff changeset
311 if( !noevents ) {
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4020
diff changeset
312 set_ae_handlers();
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4020
diff changeset
313 event_loop();
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4020
diff changeset
314 reset_ae_handlers();
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4020
diff changeset
315 }
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
316
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 arg_vector[arg_count] = NULL;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
318
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 *pargv = arg_vector;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 return arg_count;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 }