Move setting of ioready 'wait' earlier in call chain, to
[python/dscho.git] / Mac / Python / getapplbycreator.c
blob8c0b00fd93a16bac41ae56a948c168ab95e02523
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 or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
15 permission.
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
33 ** FindApplicationFromCreator uses the Desktop Database to
34 ** locate the creator application for the given document
36 ** this routine will check the desktop database of all local
37 ** disks, then the desktop databases of all server volumes
38 ** (so up to two passes will be made)
40 ** This code was created from FindApplicationFromDocument
41 ** routine, origin unknown.
44 #ifdef WITHOUT_FRAMEWORKS
45 #include <Types.h>
46 #include <Files.h>
47 #include <Errors.h>
48 #else
49 #include <Carbon/Carbon.h>
50 #endif
51 #include "getapplbycreator.h"
54 OSErr FindApplicationFromCreator(OSType creator,
55 FSSpecPtr applicationFSSpecPtr)
57 enum { localPass, remotePass, donePass } volumePass;
58 DTPBRec desktopParams;
59 HParamBlockRec hfsParams;
60 short volumeIndex;
61 Boolean foundFlag;
62 GetVolParmsInfoBuffer volumeInfoBuffer;
63 OSErr retCode;
65 /* dkj 12/94 initialize flag to false (thanks to Peter Baral for pointing out this bug) */
66 foundFlag = false;
68 volumePass = localPass;
69 volumeIndex = 0;
71 do {
73 ** first, find the vRefNum of the volume whose Desktop Database
74 ** we're checking this time
77 volumeIndex++;
79 /* convert the volumeIndex into a vRefNum */
81 hfsParams.volumeParam.ioNamePtr = nil;
82 hfsParams.volumeParam.ioVRefNum = 0;
83 hfsParams.volumeParam.ioVolIndex = volumeIndex;
84 retCode = PBHGetVInfoSync(&hfsParams);
86 /* a nsvErr indicates that the current pass is over */
87 if (retCode == nsvErr) goto SkipThisVolume;
88 if (retCode != noErr) goto Bail;
91 ** call GetVolParms to determine if this volume is a server
92 ** (a remote volume)
95 hfsParams.ioParam.ioBuffer = (Ptr) &volumeInfoBuffer;
96 hfsParams.ioParam.ioReqCount = sizeof(GetVolParmsInfoBuffer);
97 retCode = PBHGetVolParmsSync(&hfsParams);
98 if (retCode != noErr) goto Bail;
101 ** if the vMServerAdr field of the volume information buffer
102 ** is zero, this is a local volume; skip this volume
103 ** if it's local on a remote pass or remote on a local pass
106 if ((volumeInfoBuffer.vMServerAdr != 0) !=
107 (volumePass == remotePass)) goto SkipThisVolume;
109 /* okay, now we've found the vRefNum for our desktop database call */
111 desktopParams.ioVRefNum = hfsParams.volumeParam.ioVRefNum;
114 ** find the path refNum for the desktop database for
115 ** the volume we're interested in
118 desktopParams.ioNamePtr = nil;
120 retCode = PBDTGetPath(&desktopParams);
121 if (retCode == noErr && desktopParams.ioDTRefNum != 0) {
124 ** use the GetAPPL call to find the preferred application
125 ** for opening any document with this one's creator
128 desktopParams.ioIndex = 0;
129 desktopParams.ioFileCreator = creator;
130 desktopParams.ioNamePtr = applicationFSSpecPtr->name;
131 retCode = PBDTGetAPPLSync(&desktopParams);
133 if (retCode == noErr) {
135 ** okay, found it; fill in the application file spec
136 ** and set the flag indicating we're done
139 applicationFSSpecPtr->parID = desktopParams.ioAPPLParID;
140 applicationFSSpecPtr->vRefNum = desktopParams.ioVRefNum;
141 foundFlag = true;
146 SkipThisVolume:
148 ** if retCode indicates a no such volume error or if this
149 ** was the first pass, it's time to move on to the next pass
152 if (retCode == nsvErr) {
153 volumePass++;
154 volumeIndex = 0;
157 } while (foundFlag == false && volumePass != donePass);
159 Bail:
160 if (retCode == nsvErr)
161 return fnfErr; /* More logical than "No such volume" */
162 return retCode;