This commit was manufactured by cvs2svn to create tag 'r22a4-fork'.
[python/dscho.git] / Mac / Python / macglue.c
blob4e8c9e48a62e41d9e7295656b3f77b8f769abb41
1 /***********************************************************
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
3 The Netherlands.
5 All Rights Reserved
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
26 #include "Python.h"
28 #include "macglue.h"
29 #include "marshal.h"
30 #include "import.h"
31 #include "importdl.h"
32 #include "pymactoolbox.h"
34 #include "pythonresources.h"
36 #ifdef WITHOUT_FRAMEWORKS
37 #include <OSUtils.h> /* for Set(Current)A5 */
38 #include <Files.h>
39 #include <StandardFile.h>
40 #include <Resources.h>
41 #include <Memory.h>
42 #include <Windows.h>
43 #include <Traps.h>
44 #include <Processes.h>
45 #include <Fonts.h>
46 #include <Menus.h>
47 #include <TextUtils.h>
48 #include <LowMem.h>
49 #include <Events.h>
50 #else
51 #include <Carbon/Carbon.h>
52 #endif
54 #if !TARGET_API_MAC_OS8
55 /* Unfortunately this call is probably slower... */
56 #define LMGetTicks() TickCount()
57 #endif
59 #ifdef __MWERKS__
60 #include <SIOUX.h>
61 extern void SIOUXSetupMenus(void);
62 extern void SIOUXDoAboutBox(void);
63 #endif
64 #ifdef USE_GUSI
65 /* Functions we redefine because they're in obscure libraries */
66 extern void SpinCursor(short x);
67 extern void RotateCursor(short x);
68 extern pascal void PLstrcpy(unsigned char *, unsigned char *);
69 extern pascal int PLstrcmp(unsigned char *, unsigned char *);
70 extern pascal unsigned char *PLstrrchr(unsigned char *, unsigned char);
72 #endif
74 #ifdef USE_GUSI1
75 #include <TFileSpec.h> /* For Path2FSSpec */
76 #include <GUSI.h>
77 #endif
79 /* The ID of the Sioux apple menu */
80 #define SIOUX_APPLEID 32000
82 #include <signal.h>
83 #include <stdio.h>
86 ** When less than this amount of stackspace is left we
87 ** raise a MemoryError.
89 #ifndef MINIMUM_STACK_SIZE
90 #define MINIMUM_STACK_SIZE 8192
91 #endif
93 #if TARGET_API_MAC_CARBON
95 ** On MacOSX StackSpace() lies: it gives the distance from heap end to stack pointer,
96 ** but the stack cannot grow that far due to rlimit values. We cannot get at this value
97 ** from Carbon, so we set a maximum to the stack here that is based on the default
98 ** stack limit of 512K.
100 #define MAXIMUM_STACK_SIZE (256*1024)
101 #endif
104 ** We have to be careful, since we can't handle
105 ** things like updates (and they'll keep coming back if we don't
106 ** handle them). Note that we don't know who has windows open, so
107 ** even handing updates off to SIOUX under MW isn't going to work.
109 #define MAINLOOP_EVENTMASK (mDownMask|keyDownMask|osMask|activMask)
111 #include <signal.h>
113 /* XXX We should include Errors.h here, but it has a name conflict
114 ** with the python errors.h. */
115 #define fnfErr -43
117 /* Interrupt code variables: */
118 static int interrupted; /* Set to true when cmd-. seen */
119 static RETSIGTYPE intcatcher(int);
121 #if !TARGET_API_MAC_OSX
122 static int PyMac_Yield(void);
123 #endif
126 ** These are the real scheduling parameters that control what we check
127 ** in the event loop, and how often we check. The values are initialized
128 ** from pyMac_SchedParamStruct.
131 struct real_sched_param_struct {
132 int check_interrupt; /* if true check for command-dot */
133 int process_events; /* if nonzero enable evt processing, this mask */
134 int besocial; /* if nonzero be a little social with CPU */
135 unsigned long check_interval; /* how often to check, in ticks */
136 unsigned long bg_yield; /* yield so long when in background */
137 /* these are computed from previous and clock and such */
138 int enabled; /* check_interrupt OR process_event OR yield */
139 unsigned long next_check; /* when to check/yield next, in ticks */
142 static struct real_sched_param_struct schedparams =
143 { 1, MAINLOOP_EVENTMASK, 1, 15, 15, 1, 0};
146 ** Workaround for sioux/gusi combo: set when we are exiting
148 int PyMac_ConsoleIsDead;
151 ** Sioux menu bar, saved early so we can restore it
153 static MenuBarHandle sioux_mbar;
156 ** Some stuff for our GetDirectory and PromptGetFile routines
158 struct hook_args {
159 int selectcur_hit; /* Set to true when "select current" selected */
160 char *prompt; /* The prompt */
162 #if !TARGET_API_MAC_OS8
163 /* The StandardFile hooks don't exist in Carbon. This breaks GetDirectory,
164 ** but the macfsn code will replace it by a NavServices version anyway.
166 #define myhook_upp NULL
167 #else
168 static DlgHookYDUPP myhook_upp;
169 static int upp_inited = 0;
170 #endif
173 ** The python-code event handler
175 static PyObject *python_event_handler;
178 ** Set to true if we're appearance-compliant
180 int PyMac_AppearanceCompliant;
182 /* Given an FSSpec, return the FSSpec of the parent folder */
184 static OSErr
185 get_folder_parent (FSSpec * fss, FSSpec * parent)
187 CInfoPBRec rec;
188 short err;
190 * parent = * fss;
191 rec.hFileInfo.ioNamePtr = parent->name;
192 rec.hFileInfo.ioVRefNum = parent->vRefNum;
193 rec.hFileInfo.ioDirID = parent->parID;
194 rec.hFileInfo.ioFDirIndex = -1;
195 rec.hFileInfo.ioFVersNum = 0;
196 if (err = PBGetCatInfoSync (& rec))
197 return err;
198 parent->parID = rec.dirInfo.ioDrParID;
199 /* parent->name[0] = 0; */
200 return 0;
203 /* Given an FSSpec return a full, colon-separated pathname */
205 OSErr
206 PyMac_GetFullPathname (FSSpec *fss, char *buf, int length)
208 short err;
209 FSSpec fss_parent, fss_current;
210 char tmpbuf[1024];
211 int plen;
213 fss_current = *fss;
214 plen = fss_current.name[0];
215 if ( plen+2 > length ) {
216 *buf = 0;
217 return errFSNameTooLong;
219 memcpy(buf, &fss_current.name[1], plen);
220 buf[plen] = 0;
221 /* Special case for disk names */
222 if ( fss_current.parID <= 1 ) {
223 buf[plen++] = ':';
224 buf[plen] = 0;
225 return 0;
227 while (fss_current.parID > 1) {
228 /* Get parent folder name */
229 if (err = get_folder_parent(&fss_current, &fss_parent)) {
230 *buf = 0;
231 return err;
233 fss_current = fss_parent;
234 /* Prepend path component just found to buf */
235 plen = fss_current.name[0];
236 if (strlen(buf) + plen + 1 > 1024) {
237 /* Oops... Not enough space (shouldn't happen) */
238 *buf = 0;
239 return errFSNameTooLong;
241 memcpy(tmpbuf, &fss_current.name[1], plen);
242 tmpbuf[plen] = ':';
243 strcpy(&tmpbuf[plen+1], buf);
244 if ( strlen(tmpbuf) > length ) {
245 *buf = 0;
246 return errFSNameTooLong;
248 strcpy(buf, tmpbuf);
250 return 0;
253 #ifdef USE_GUSI1
255 ** GUSI (1.6.0 and earlier, at the least) do not set the MacOS idea of
256 ** the working directory. Hence, we call this routine after each call
257 ** to chdir() to rectify things.
259 void
260 PyMac_FixGUSIcd()
262 WDPBRec pb;
263 FSSpec curdirfss;
265 if ( Path2FSSpec(":x", &curdirfss) != noErr )
266 return;
268 /* Set MacOS "working directory" */
269 pb.ioNamePtr= "\p";
270 pb.ioVRefNum= curdirfss.vRefNum;
271 pb.ioWDDirID= curdirfss.parID;
272 if (PBHSetVolSync(&pb) != noErr)
273 return;
275 #endif
277 #ifdef USE_GUSI
279 ** SpinCursor (needed by GUSI) drags in heaps of stuff, so we
280 ** provide a dummy here.
282 void SpinCursor(short x) { /* Dummy */ }
283 void RotateCursor(short x) { /* Dummy */ }
286 ** Replacement GUSI Spin function
288 #ifdef USE_GUSI1
289 static int
290 PyMac_GUSISpin(spin_msg msg, long arg)
292 static Boolean inForeground = true;
293 int maxsleep = 6; /* 6 ticks is "normal" sleeptime */
295 if (PyMac_ConsoleIsDead) return 0;
296 #if 0
297 if (inForeground)
298 SpinCursor(msg == SP_AUTO_SPIN ? short(arg) : 1);
299 #endif
301 if (interrupted) return -1;
303 if ( msg == SP_AUTO_SPIN )
304 maxsleep = 0;
305 if ( msg==SP_SLEEP||msg==SP_SELECT )
306 maxsleep = arg;
308 PyMac_DoYield(maxsleep, 0); /* XXXX or is it safe to call python here? */
310 return 0;
313 void
314 PyMac_SetGUSISpin() {
315 GUSISetHook(GUSI_SpinHook, (GUSIHook)PyMac_GUSISpin);
317 #endif
319 /* Called at exit() time thru atexit(), to stop event processing */
320 void
321 PyMac_StopGUSISpin() {
322 PyMac_ConsoleIsDead = 1;
325 #if TARGET_API_MAC_OS8
327 ** Replacement routines for the PLstr... functions so we don't need
328 ** StdCLib.
330 pascal void
331 PLstrcpy(unsigned char *to, unsigned char *fr)
333 memcpy(to, fr, fr[0]+1);
336 pascal int
337 PLstrcmp(unsigned char *s1, unsigned char *s2)
339 int res;
340 int l = s1[0] < s2[0] ? s1[0] : s2[0];
342 res = memcmp(s1+1, s2+1, l);
343 if ( res != 0 )
344 return res;
346 if ( s1[0] < s2[0] )
347 return -1;
348 else if ( s1[0] > s2[0] )
349 return 1;
350 else
351 return 0;
354 pascal unsigned char *
355 PLstrrchr(unsigned char *str, unsigned char chr)
357 unsigned char *ptr = 0;
358 unsigned char *p;
360 for(p=str+1; p<str+str[0]; p++)
361 if ( *p == chr )
362 ptr = p;
363 return ptr;
366 #endif /* TARGET_API_MAC_OS8 */
367 #endif /* USE_GUSI */
370 /* Convert C to Pascal string. Returns pointer to static buffer. */
371 unsigned char *
372 Pstring(char *str)
374 static Str255 buf;
375 int len;
377 len = strlen(str);
378 if (len > 255)
379 len = 255;
380 buf[0] = (unsigned char)len;
381 strncpy((char *)buf+1, str, len);
382 return buf;
385 #if TARGET_API_MAC_OS8
386 void
387 c2pstrcpy(unsigned char *dst, const char *src)
389 int len;
391 len = strlen(src);
392 if ( len > 255 ) len = 255;
393 strncpy((char *)dst+1, src, len);
394 dst[0] = len;
396 #endif /* TARGET_API_MAC_OS8 */
398 #ifdef USE_STACKCHECK
399 /* Check for stack overflow */
401 PyOS_CheckStack()
403 char here;
404 static char *sentinel = 0;
405 static PyThreadState *thread_for_sentinel = 0;
407 if ( sentinel == 0 ) {
408 unsigned long stackspace = StackSpace();
410 #ifdef MAXIMUM_STACK_SIZE
411 /* See the comment at the definition */
412 if ( stackspace > MAXIMUM_STACK_SIZE )
413 stackspace = MAXIMUM_STACK_SIZE;
414 #endif
415 sentinel = &here - stackspace + MINIMUM_STACK_SIZE;
417 if ( thread_for_sentinel == 0 ) {
418 thread_for_sentinel = PyThreadState_Get();
420 if ( &here < sentinel ) {
421 if (thread_for_sentinel == PyThreadState_Get()) {
422 return -1;
423 #if 0
424 } else {
425 /* Else we are unsure... */
426 fprintf(stderr, "Stackcheck in other thread (was %x now %x)\n", thread_for_sentinel,PyThreadState_Get());
427 #endif
430 return 0;
432 #endif /* USE_STACKCHECK */
434 #if !TARGET_API_MAC_OSX
435 /* The catcher routine (which may not be used for all compilers) */
436 static RETSIGTYPE
437 intcatcher(sig)
438 int sig;
440 interrupted = 1;
441 signal(SIGINT, intcatcher);
444 void
445 PyOS_InitInterrupts()
447 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
448 signal(SIGINT, intcatcher);
451 void
452 PyOS_FiniInterrupts()
457 ** This routine scans the event queue looking for cmd-.
458 ** This is the only way to get an interrupt under THINK (since it
459 ** doesn't do SIGINT handling), but is also used under MW, when
460 ** the full-fledged event loop is disabled. This way, we can at least
461 ** interrupt a runaway python program.
463 static void
464 scan_event_queue(flush)
465 int flush;
467 #if !TARGET_API_MAC_OS8
468 if ( CheckEventQueueForUserCancel() )
469 interrupted = 1;
470 #else
471 register EvQElPtr q;
473 q = (EvQElPtr) LMGetEventQueue()->qHead;
475 for (; q; q = (EvQElPtr)q->qLink) {
476 if (q->evtQWhat == keyDown &&
477 (char)q->evtQMessage == '.' &&
478 (q->evtQModifiers & cmdKey) != 0) {
479 if ( flush )
480 FlushEvents(keyDownMask, 0);
481 interrupted = 1;
482 break;
485 #endif
489 PyErr_CheckSignals()
491 if (schedparams.enabled) {
492 if ( (unsigned long)LMGetTicks() > schedparams.next_check ) {
493 if ( PyMac_Yield() < 0)
494 return -1;
495 schedparams.next_check = (unsigned long)LMGetTicks()
496 + schedparams.check_interval;
497 if (interrupted) {
498 scan_event_queue(1); /* Eat events up to cmd-. */
499 interrupted = 0;
500 PyErr_SetNone(PyExc_KeyboardInterrupt);
501 return -1;
505 return 0;
509 PyOS_InterruptOccurred()
511 scan_event_queue(1);
512 return interrupted;
515 /* Check whether we are in the foreground */
516 static int
517 PyMac_InForeground(void)
519 static ProcessSerialNumber ours;
520 static inited;
521 ProcessSerialNumber curfg;
522 Boolean eq;
524 if ( inited == 0 ) {
525 (void)GetCurrentProcess(&ours);
526 inited = 1;
528 if ( GetFrontProcess(&curfg) < 0 )
529 eq = 1;
530 else if ( SameProcess(&ours, &curfg, &eq) < 0 )
531 eq = 1;
532 return (int)eq;
534 #endif
537 PyMac_SetEventHandler(PyObject *evh)
539 if ( evh && python_event_handler ) {
540 PyErr_SetString(PyExc_RuntimeError, "Python event handler already set");
541 return 0;
543 if ( python_event_handler )
544 Py_DECREF(python_event_handler);
545 if ( evh )
546 Py_INCREF(evh);
547 python_event_handler = evh;
548 return 1;
552 ** Handle an event, either one found in the mainloop eventhandler or
553 ** one passed back from the python program.
555 void
556 PyMac_HandleEventIntern(evp)
557 EventRecord *evp;
559 #if TARGET_API_MAC_OS8
560 if ( evp->what == mouseDown ) {
561 WindowPtr wp;
563 if ( FindWindow(evp->where, &wp) == inSysWindow ) {
564 SystemClick(evp, wp);
565 return;
568 #endif
569 #ifdef __MWERKS__
571 int siouxdidit;
573 /* If SIOUX wants it we're done */
574 siouxdidit = SIOUXHandleOneEvent(evp);
575 if ( siouxdidit )
576 return;
578 #else
579 /* Other compilers are just unlucky... */
580 #endif /* !__MWERKS__ */
584 ** Handle an event, either through HandleEvent or by passing it to the Python
585 ** event handler.
588 PyMac_HandleEvent(evp)
589 EventRecord *evp;
591 PyObject *rv;
593 if ( python_event_handler ) {
594 rv = PyObject_CallFunction(python_event_handler, "(O&)",
595 PyMac_BuildEventRecord, evp);
596 if ( rv )
597 Py_DECREF(rv);
598 else
599 return -1; /* Propagate exception */
600 } else {
601 PyMac_HandleEventIntern(evp);
603 return 0;
606 #if !TARGET_API_MAC_OSX
608 ** Yield the CPU to other tasks without processing events.
611 PyMac_DoYield(int maxsleep, int maycallpython)
613 EventRecord ev;
614 int gotone;
615 long latest_time_ready;
616 static int in_here = 0;
618 in_here++;
620 ** First check for interrupts, if wanted.
621 ** This sets a flag that will be picked up at an appropriate
622 ** moment in the mainloop.
624 if (schedparams.check_interrupt)
625 scan_event_queue(0);
627 /* XXXX Implementing an idle routine goes here */
630 ** Check which of the eventloop cases we have:
631 ** - process events
632 ** - don't process events but do yield
633 ** - do neither
635 if( in_here > 1 || !schedparams.process_events ||
636 (python_event_handler && !maycallpython) ) {
637 if ( maxsleep >= 0 ) {
638 #if TARGET_API_MAC_OS8
639 SystemTask();
640 #else
641 int xxx = 0;
642 #endif
644 } else {
645 latest_time_ready = LMGetTicks() + maxsleep;
646 do {
647 /* XXXX Hack by Jack.
648 ** In time.sleep() you can click to another application
649 ** once only. If you come back to Python you cannot get away
650 ** again.
652 gotone = WaitNextEvent(schedparams.process_events, &ev, maxsleep, NULL);
653 /* Get out quickly if nothing interesting is happening */
654 if ( !gotone || ev.what == nullEvent )
655 break;
656 if ( PyMac_HandleEvent(&ev) < 0 ) {
657 in_here--;
658 return -1;
660 maxsleep = latest_time_ready - LMGetTicks();
661 } while ( maxsleep > 0 );
663 in_here--;
664 return 0;
668 ** Process events and/or yield the CPU to other tasks if opportune
671 PyMac_Yield() {
672 unsigned long maxsleep;
674 if( PyMac_InForeground() )
675 maxsleep = 0;
676 else
677 maxsleep = schedparams.bg_yield;
679 return PyMac_DoYield(maxsleep, 1);
683 ** Return current scheduler parameters
685 void
686 PyMac_GetSchedParams(PyMacSchedParams *sp)
688 sp->check_interrupt = schedparams.check_interrupt;
689 sp->process_events = schedparams.process_events;
690 sp->besocial = schedparams.besocial;
691 sp->check_interval = schedparams.check_interval / 60.0;
692 sp->bg_yield = schedparams.bg_yield / 60.0;
696 ** Set current scheduler parameters
698 void
699 PyMac_SetSchedParams(PyMacSchedParams *sp)
701 schedparams.check_interrupt = sp->check_interrupt;
702 schedparams.process_events = sp->process_events;
703 schedparams.besocial = sp->besocial;
704 schedparams.check_interval = (unsigned long)(sp->check_interval*60);
705 schedparams.bg_yield = (unsigned long)(sp->bg_yield*60);
706 if ( schedparams.check_interrupt || schedparams.process_events ||
707 schedparams.besocial )
708 schedparams.enabled = 1;
709 else
710 schedparams.enabled = 0;
711 schedparams.next_check = 0; /* Check immedeately */
715 ** Install our menu bar.
717 void
718 PyMac_InitMenuBar()
720 MenuHandle applemenu;
722 if ( sioux_mbar ) return;
723 if ( (sioux_mbar=GetMenuBar()) == NULL ) {
724 /* Sioux menu not installed yet. Do so */
725 SIOUXSetupMenus();
726 if ( (sioux_mbar=GetMenuBar()) == NULL )
727 return;
729 if ( (applemenu=GetMenuHandle(SIOUX_APPLEID)) == NULL ) return;
730 SetMenuItemText(applemenu, 1, "\pAbout Python...");
734 ** Restore sioux menu bar
736 void
737 PyMac_RestoreMenuBar()
739 #if 1
740 /* This doesn't seem to work anymore? Or only for Carbon? */
741 MenuBarHandle curmenubar;
743 curmenubar = GetMenuBar();
744 if ( sioux_mbar ) {
745 SetMenuBar(sioux_mbar);
746 DrawMenuBar();
747 } else {
748 PyMac_InitMenuBar();
749 DrawMenuBar();
751 #endif
754 void
755 PyMac_RaiseConsoleWindow()
757 /* Note: this is a hack. SIOUXTextWindow is SIOUX's internal structure
758 ** and we happen to know that the first entry is the window pointer.
760 extern WindowRef *SIOUXTextWindow;
762 if ( SIOUXTextWindow == NULL || *SIOUXTextWindow == NULL )
763 return;
764 if ( FrontWindow() != *SIOUXTextWindow )
765 BringToFront(*SIOUXTextWindow);
769 ** Our replacement about box
772 #include "patchlevel.h"
774 void
775 SIOUXDoAboutBox(void)
777 DialogPtr theDialog;
778 WindowPtr theWindow;
779 short item;
780 short fontID;
782 if( (theDialog = GetNewDialog(ABOUT_ID, NULL, (WindowPtr)-1)) == NULL )
783 return;
784 theWindow = GetDialogWindow(theDialog);
785 SetPortWindowPort(theWindow);
786 GetFNum("\pPython-Sans", &fontID);
787 if (fontID == 0)
788 fontID = kFontIDGeneva;
789 TextFont(fontID);
790 TextSize(9);
791 ParamText(Pstring(PY_VERSION), "\p", "\p", "\p");
792 ShowWindow(theWindow);
793 ModalDialog(NULL, &item);
794 DisposeDialog(theDialog);
797 #endif /* !TARGET_API_MAC_OSX */
799 #if TARGET_API_MAC_OS8
801 ** Helper routine for GetDirectory
803 static pascal short
804 myhook_proc(short item, DialogPtr theDialog, struct hook_args *dataptr)
806 if ( item == sfHookFirstCall && dataptr->prompt) {
807 Handle prompth;
808 short type;
809 Rect rect;
811 GetDialogItem(theDialog, PROMPT_ITEM, &type, &prompth, &rect);
812 if ( prompth )
813 SetDialogItemText(prompth, (unsigned char *)dataptr->prompt);
814 } else
815 if ( item == SELECTCUR_ITEM ) {
816 item = sfItemCancelButton;
817 dataptr->selectcur_hit = 1;
819 return item;
823 ** Ask the user for a directory. I still can't understand
824 ** why Apple doesn't provide a standard solution for this...
827 PyMac_GetDirectory(dirfss, prompt)
828 FSSpec *dirfss;
829 char *prompt;
831 static SFTypeList list = {'fldr', 0, 0, 0};
832 static Point where = {-1, -1};
833 StandardFileReply reply;
834 struct hook_args hook_args;
836 if ( !upp_inited ) {
837 myhook_upp = NewDlgHookYDProc(myhook_proc);
838 upp_inited = 1;
840 if ( prompt && *prompt )
841 hook_args.prompt = (char *)Pstring(prompt);
842 else
843 hook_args.prompt = NULL;
844 hook_args.selectcur_hit = 0;
845 CustomGetFile((FileFilterYDUPP)0, 1, list, &reply, GETDIR_ID, where, myhook_upp,
846 NULL, NULL, NULL, (void *)&hook_args);
848 reply.sfFile.name[0] = 0;
849 if( FSMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, dirfss) )
850 return 0;
851 return hook_args.selectcur_hit;
855 ** Slightly extended StandardGetFile: accepts a prompt */
856 void PyMac_PromptGetFile(short numTypes, ConstSFTypeListPtr typeList,
857 StandardFileReply *reply, char *prompt)
859 static Point where = {-1, -1};
860 struct hook_args hook_args;
862 if ( !upp_inited ) {
863 myhook_upp = NewDlgHookYDProc(myhook_proc);
864 upp_inited = 1;
866 if ( prompt && *prompt )
867 hook_args.prompt = (char *)Pstring(prompt);
868 else
869 hook_args.prompt = NULL;
870 hook_args.selectcur_hit = 0;
871 CustomGetFile((FileFilterYDUPP)0, numTypes, typeList, reply, GETFILEPROMPT_ID, where,
872 myhook_upp, NULL, NULL, NULL, (void *)&hook_args);
874 #endif /* TARGET_API_MAC_OS8 */