annotate Mac/Python/macgetargv.c @ 27998:e27f58a50737 legacy-trunk

SF bug #690377: Dud footnote reference in distutils docs
author Raymond Hettinger <python@rcn.com>
date Fri, 21 Feb 2003 02:47:09 +0000
parents c69b8e61e695
children
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 /***********************************************************
5079
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4552
diff changeset
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
2393
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
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
30 #ifdef WITHOUT_FRAMEWORKS
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 #include <Types.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 #include <Files.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 #include <Events.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #include <Memory.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 #include <Processes.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 #include <Errors.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 #include <AppleEvents.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 #include <AEObjects.h>
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 #include <Fonts.h>
2399
438a8c265eb9 ported back to Think C
Guido van Rossum <guido@python.org>
parents: 2393
diff changeset
40 #include <TextEdit.h>
438a8c265eb9 ported back to Think C
Guido van Rossum <guido@python.org>
parents: 2393
diff changeset
41 #include <Menus.h>
438a8c265eb9 ported back to Think C
Guido van Rossum <guido@python.org>
parents: 2393
diff changeset
42 #include <Dialogs.h>
438a8c265eb9 ported back to Think C
Guido van Rossum <guido@python.org>
parents: 2393
diff changeset
43 #include <Windows.h>
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
44 #else
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
45 #include <Carbon/Carbon.h>
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
46 #endif /* WITHOUT_FRAMEWORKS */
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
18177
826000a40866 Adapted for Universal Headers 3.4: refcon type has changed (sigh) and use modern (UPP in stead of Proc) names for callback object creation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17931
diff changeset
48 typedef long refcontype;
826000a40866 Adapted for Universal Headers 3.4: refcon type has changed (sigh) and use modern (UPP in stead of Proc) names for callback object creation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17931
diff changeset
49
4523
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 "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
51 #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
52
19841
d8dd75e3b304 Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
Jack Jansen <jack.jansen@cwi.nl>
parents: 19748
diff changeset
53 #define PATHNAMELEN 256
d8dd75e3b304 Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
Jack Jansen <jack.jansen@cwi.nl>
parents: 19748
diff changeset
54
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 static int arg_count;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 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
57 FSSpec PyMac_ApplicationFSSpec;
19841
d8dd75e3b304 Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
Jack Jansen <jack.jansen@cwi.nl>
parents: 19748
diff changeset
58 char PyMac_ApplicationPath[PATHNAMELEN];
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
3215
3b2be811a66a Export strdup (parsermodule needs it)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3054
diff changeset
60 /* 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
61 ** and others use it
3b2be811a66a Export strdup (parsermodule needs it)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3054
diff changeset
62 */
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 12962
diff changeset
63 #ifndef HAVE_STRDUP
3215
3b2be811a66a Export strdup (parsermodule needs it)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3054
diff changeset
64 char *
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 12962
diff changeset
65 strdup(const char *src)
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 char *dst = malloc(strlen(src) + 1);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 if (dst)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 strcpy(dst, src);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 return dst;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 }
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 12962
diff changeset
72 #endif
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
73
4523
4d0681f7cf6b Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
74 /* Initialize FSSpec and full name of current application */
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
75
3054
2cb1416010b3 Python will now attempt (again) to create at least a minimal
Jack Jansen <jack.jansen@cwi.nl>
parents: 2874
diff changeset
76 OSErr
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
77 PyMac_init_process_location(void)
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 ProcessSerialNumber currentPSN;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 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
81 OSErr err;
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
82 static int applocation_inited;
2393
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 if ( applocation_inited ) return 0;
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 currentPSN.highLongOfPSN = 0;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 currentPSN.lowLongOfPSN = kCurrentProcess;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 info.processInfoLength = sizeof(ProcessInfoRec);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 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
89 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
90 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
91 return err;
19841
d8dd75e3b304 Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
Jack Jansen <jack.jansen@cwi.nl>
parents: 19748
diff changeset
92 if ( err=PyMac_GetFullPathname(&PyMac_ApplicationFSSpec, PyMac_ApplicationPath, PATHNAMELEN) )
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 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
94 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
95 return 0;
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
97
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 /* 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
99
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 static OSErr
12832
b90d601d4d59 Fixed callback function arguments to be carbon-compatible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
101 get_missing_params(const AppleEvent *theAppleEvent)
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 DescType theType;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 Size actualSize;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 OSErr err;
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 err = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 &theType, nil, 0, &actualSize);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 if (err == errAEDescNotFound)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 return noErr;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 else
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 return errAEEventNotHandled;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 }
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 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
116
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 /* Handle the Print or Quit events (by failing) */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 static pascal OSErr
18177
826000a40866 Adapted for Universal Headers 3.4: refcon type has changed (sigh) and use modern (UPP in stead of Proc) names for callback object creation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17931
diff changeset
120 handle_not(const AppleEvent *theAppleEvent, AppleEvent *reply, refcontype refCon)
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 #pragma unused (reply, refCon)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 got_one = 1;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 return errAEEventNotHandled;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 }
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 /* Handle the Open Application event (by ignoring it) */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
128
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 static pascal OSErr
18177
826000a40866 Adapted for Universal Headers 3.4: refcon type has changed (sigh) and use modern (UPP in stead of Proc) names for callback object creation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17931
diff changeset
130 handle_open_app(const AppleEvent *theAppleEvent, AppleEvent *reply, refcontype refCon)
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 #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
133 #if 0
1cf6e10522e0 Continue looking for "open doc" events even after "open app". This
Jack Jansen <jack.jansen@cwi.nl>
parents: 3215
diff changeset
134 /* Test by Jack: would removing this facilitate debugging? */
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 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
136 #endif
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 return get_missing_params(theAppleEvent);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
139
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 /* Handle the Open Document event, by adding an argument */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
141
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 static pascal OSErr
18177
826000a40866 Adapted for Universal Headers 3.4: refcon type has changed (sigh) and use modern (UPP in stead of Proc) names for callback object creation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17931
diff changeset
143 handle_open_doc(const AppleEvent *theAppleEvent, AppleEvent *reply, refcontype refCon)
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 #pragma unused (reply, refCon)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 OSErr err;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 AEDescList doclist;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 AEKeyword keywd;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 DescType rttype;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 long i, ndocs, size;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 FSSpec fss;
19841
d8dd75e3b304 Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
Jack Jansen <jack.jansen@cwi.nl>
parents: 19748
diff changeset
152 char path[PATHNAMELEN];
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
153
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 got_one = 1;
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
155 if ((err = AEGetParamDesc(theAppleEvent,
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
156 keyDirectObject, typeAEList, &doclist)))
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 return err;
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
158 if ((err = get_missing_params(theAppleEvent)))
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 return err;
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
160 if ((err = AECountItems(&doclist, &ndocs)))
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 return err;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 for(i = 1; i <= ndocs; i++) {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 err = AEGetNthPtr(&doclist, i, typeFSS,
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 &keywd, &rttype, &fss, sizeof(fss), &size);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 if (err)
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 break;
19841
d8dd75e3b304 Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
Jack Jansen <jack.jansen@cwi.nl>
parents: 19748
diff changeset
167 PyMac_GetFullPathname(&fss, path, PATHNAMELEN);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 arg_vector[arg_count++] = strdup(path);
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 return err;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 }
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 /* 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
174 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
175 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
176 AEEventHandlerUPP not_upp;
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
177
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 static void
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
179 set_ae_handlers(void)
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 {
18177
826000a40866 Adapted for Universal Headers 3.4: refcon type has changed (sigh) and use modern (UPP in stead of Proc) names for callback object creation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17931
diff changeset
181 open_doc_upp = NewAEEventHandlerUPP(&handle_open_doc);
826000a40866 Adapted for Universal Headers 3.4: refcon type has changed (sigh) and use modern (UPP in stead of Proc) names for callback object creation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17931
diff changeset
182 open_app_upp = NewAEEventHandlerUPP(&handle_open_app);
826000a40866 Adapted for Universal Headers 3.4: refcon type has changed (sigh) and use modern (UPP in stead of Proc) names for callback object creation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17931
diff changeset
183 not_upp = NewAEEventHandlerUPP(&handle_not);
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
184
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 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
186 open_app_upp, 0L, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 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
188 open_doc_upp, 0L, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 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
190 not_upp, 0L, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 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
192 not_upp, 0L, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
194
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 /* Uninstall standard core event handlers */
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 static void
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
198 reset_ae_handlers(void)
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 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
201 open_app_upp, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 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
203 open_doc_upp, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 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
205 not_upp, false);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 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
207 not_upp, false);
2393
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 /* 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
211
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 static void
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
213 event_loop(void)
2393
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 EventRecord event;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 int n;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 int ok;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
218
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 got_one = 0;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 for (n = 0; n < 100 && !got_one; n++) {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 ok = GetNextEvent(everyEvent, &event);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 if (ok && event.what == kHighLevelEvent) {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 AEProcessAppleEvent(&event);
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 }
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
227
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 /* Get the argv vector, return argc */
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
229
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 int
19748
c93d7d0857a2 Changes to make these work under OSX as the main program for a
Jack Jansen <jack.jansen@cwi.nl>
parents: 18177
diff changeset
231 PyMac_GetArgv(char ***pargv, int noevents)
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 {
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 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
234 (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
235 arg_vector[arg_count++] = strdup(PyMac_ApplicationPath);
2393
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
236
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4020
diff changeset
237 if( !noevents ) {
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4020
diff changeset
238 set_ae_handlers();
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4020
diff changeset
239 event_loop();
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4020
diff changeset
240 reset_ae_handlers();
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4020
diff changeset
241 }
2393
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 arg_vector[arg_count] = NULL;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
244
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 *pargv = arg_vector;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 return arg_count;
b156bf4be62f get argc/argv from AppleEvents
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 }