Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84fa5ec

Browse files
committed
Initial version of FSSpec and Alias code. Non-functional as of now.
1 parent d50e4e1 commit 84fa5ec

3 files changed

Lines changed: 261 additions & 0 deletions

File tree

Mac/Compat/nfullpath.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* GET FULL PATHNAME OF A FILE.
2+
** Original by Guido, modified by Jack to handle FSSpecs
3+
** (and only tested under MetroWerks, so far)
4+
*/
5+
6+
#if defined(MPW) || defined(__MWERKS__)
7+
#include <Files.h>
8+
#endif
9+
#ifdef THINK_C_PRE_5_0
10+
#include <HFS.h>
11+
#endif
12+
13+
#include "nfullpath.h"
14+
15+
/* Mac file system parameters */
16+
#define MAXPATH 256 /* Max path name length+1 */
17+
#define SEP ':' /* Separator in path names */
18+
#define ROOTID 2 /* DirID of a volume's root directory */
19+
20+
/* Macro to find out whether we can do HFS-only calls: */
21+
#define FSFCBLen (* (short *) 0x3f6)
22+
#define hfsrunning() (FSFCBLen > 0)
23+
24+
int
25+
nfullpath(fsp, retbuf)
26+
FSSpec *fsp;
27+
char *retbuf;
28+
{
29+
union {
30+
HFileInfo f;
31+
DirInfo d;
32+
WDPBRec w;
33+
VolumeParam v;
34+
} pb;
35+
static char cwd[2*MAXPATH];
36+
unsigned char namebuf[MAXPATH];
37+
short err;
38+
int dir;
39+
long dirid;
40+
char *next= cwd + sizeof cwd - 1;
41+
int len;
42+
43+
44+
if (!hfsrunning())
45+
return -1;
46+
47+
dir = fsp->vRefNum;
48+
dirid = fsp->parID;
49+
/* Stuff the filename into the buffer */
50+
len = fsp->name[0];
51+
*next = '\0';
52+
next -= len+1;
53+
memcpy(next, &fsp->name[1], len);
54+
55+
for (;;) {
56+
pb.d.ioNamePtr= namebuf;
57+
pb.d.ioVRefNum= dir;
58+
pb.d.ioFDirIndex= -1;
59+
pb.d.ioDrDirID= dirid;
60+
err= PBGetCatInfo((CInfoPBPtr)&pb.d, 0);
61+
if (err != noErr) {
62+
return err;
63+
}
64+
*--next= SEP;
65+
len= namebuf[0];
66+
if ( len + strlen(next) >= MAXPATH )
67+
return -1;
68+
next -= len;
69+
memcpy(next, (char *)namebuf+1, len);
70+
if (pb.d.ioDrDirID == ROOTID)
71+
break;
72+
dirid= pb.d.ioDrParID;
73+
}
74+
strcpy(retbuf, next);
75+
return 0;
76+
}

Mac/Compat/nfullpath.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int nfullpath(FSSpec *, char *); /* Generate full path from fsspec */

Mac/Modules/macfsmodule.c

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/***********************************************************
2+
Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
3+
Amsterdam, The Netherlands.
4+
5+
All Rights Reserved
6+
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.
14+
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.
22+
23+
******************************************************************/
24+
25+
#include "allobjects.h"
26+
#include "modsupport.h" /* For getargs() etc. */
27+
#include "macglue.h"
28+
29+
#include <Files.h>
30+
#include <StandardFile.h>
31+
#include <Aliases.h>
32+
33+
#include "nfullpath.h"
34+
35+
static object *ErrorObject;
36+
37+
/* ----------------------------------------------------- */
38+
39+
static object *
40+
mfs_NewAlias(self, args)
41+
object *self; /* Not used */
42+
object *args;
43+
{
44+
FSSpec src, dst, *dstptr;
45+
46+
src.name[0] = 0;
47+
if (!newgetargs(args, "O&|O&", GetFSSpec, &dst, GetFSSpec, &src))
48+
return NULL;
49+
50+
/* XXXX */
51+
52+
INCREF(None);
53+
return None;
54+
}
55+
56+
static object *
57+
mfs_ResolveAlias(self, args)
58+
object *self; /* Not used */
59+
object *args;
60+
{
61+
62+
if (!newgetargs(args, ""))
63+
return NULL;
64+
INCREF(None);
65+
return None;
66+
}
67+
68+
static object *
69+
mfs_ResolveAliasFile(self, args)
70+
object *self; /* Not used */
71+
object *args;
72+
{
73+
74+
if (!newgetargs(args, ""))
75+
return NULL;
76+
INCREF(None);
77+
return None;
78+
}
79+
80+
static object *
81+
mfs_StandardPutFile(self, args)
82+
object *self; /* Not used */
83+
object *args;
84+
{
85+
Str255 prompt, dft;
86+
StandardFileReply reply;
87+
88+
dft[0] = 0;
89+
if (!newgetargs(args, "O&|O&", GetStr255, &prompt, GetStr255, &dft) )
90+
return NULL;
91+
StandardPutFile(prompt, dft, &reply);
92+
return mkvalue("(iO)", reply.sfGood, PyMac_BuildFSSpec(&reply.sfFile));
93+
}
94+
95+
static object *
96+
mfs_StandardGetFile(self, args)
97+
object *self; /* Not used */
98+
object *args;
99+
{
100+
char *list[4];
101+
SFTypeList typelist;
102+
short numtypes;
103+
StandardFileReply reply;
104+
105+
list[0] = list[1] = list[2] = list[3] = 0;
106+
numtypes = 0;
107+
/* XXXX I don't understand newgetargs, why doesn't |s|s|s|s work? */
108+
if (!newgetargs(args, "|s", &list[0] /*, &list[1], &list[2], &list[3]*/) )
109+
return NULL;
110+
while ( list[numtypes] && numtypes < 4 ) {
111+
memcpy((char *)&typelist[numtypes], list[numtypes], 4);
112+
numtypes++;
113+
}
114+
StandardGetFile((FileFilterUPP)0, numtypes, typelist, &reply);
115+
return mkvalue("(iO)", reply.sfGood, PyMac_BuildFSSpec(&reply.sfFile));
116+
}
117+
118+
static object *
119+
mfs_FSSpecNormalize(self, args)
120+
object *self; /* Not used */
121+
object *args;
122+
{
123+
FSSpec fss;
124+
125+
if (!newgetargs(args, "O&", GetFSSpec, &fss))
126+
return NULL;
127+
return PyMac_BuildFSSpec(&fss);
128+
}
129+
130+
static object *
131+
mfs_FSSpecPath(self, args)
132+
object *self; /* Not used */
133+
object *args;
134+
{
135+
FSSpec fss;
136+
char strbuf[257];
137+
OSErr err;
138+
139+
if (!newgetargs(args, "O&", GetFSSpec, &fss))
140+
return NULL;
141+
err = nfullpath(&fss, strbuf);
142+
if ( err ) {
143+
PyErr_Mac(ErrorObject, err);
144+
return NULL;
145+
}
146+
return newstringobject(strbuf);
147+
}
148+
149+
/* List of methods defined in the module */
150+
151+
static struct methodlist mfs_methods[] = {
152+
{"NewAlias", mfs_NewAlias, 1},
153+
{"ResolveAlias", mfs_ResolveAlias, 1},
154+
{"ResolveAliasFile",mfs_ResolveAliasFile, 1},
155+
{"StandardPutFile", mfs_StandardPutFile, 1},
156+
{"StandardGetFile", mfs_StandardGetFile, 1},
157+
{"FSSpecNormalize", mfs_FSSpecNormalize, 1},
158+
{"FSSpecPath", mfs_FSSpecPath, 1},
159+
160+
{NULL, NULL} /* sentinel */
161+
};
162+
163+
164+
/* Initialization function for the module (*must* be called initmacfs) */
165+
166+
void
167+
initmacfs()
168+
{
169+
object *m, *d;
170+
171+
/* Create the module and add the functions */
172+
m = initmodule("macfs", mfs_methods);
173+
174+
/* Add some symbolic constants to the module */
175+
d = getmoduledict(m);
176+
ErrorObject = newstringobject("macfs.error");
177+
dictinsert(d, "error", ErrorObject);
178+
179+
/* XXXX Add constants here */
180+
181+
/* Check for errors */
182+
if (err_occurred())
183+
fatal("can't initialize module macfs");
184+
}

0 commit comments

Comments
 (0)