8
8
#include "pymactoolbox.h"
10
#ifndef HAVE_MACOS105_SDK
11
typedef SInt16 FSIORefNum;
10
14
/* Macro to test whether a weak-loaded CFM function exists */
11
15
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
12
16
PyErr_SetString(PyExc_NotImplementedError, \
18
22
#include <Carbon/Carbon.h>
20
24
#ifdef USE_TOOLBOX_OBJECT_GLUE
21
27
extern int _PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
28
extern PyObject *_PyMac_BuildFSSpec(FSSpec *spec);
29
#define PyMac_BuildFSSpec _PyMac_BuildFSSpec
22
32
extern int _PyMac_GetFSRef(PyObject *v, FSRef *fsr);
23
extern PyObject *_PyMac_BuildFSSpec(FSSpec *spec);
24
33
extern PyObject *_PyMac_BuildFSRef(FSRef *spec);
34
#define PyMac_BuildFSRef _PyMac_BuildFSRef
26
35
#define PyMac_GetFSSpec _PyMac_GetFSSpec
27
36
#define PyMac_GetFSRef _PyMac_GetFSRef
28
#define PyMac_BuildFSSpec _PyMac_BuildFSSpec
29
#define PyMac_BuildFSRef _PyMac_BuildFSRef
38
#else /* !USE_TOOLBOX_OBJECT_GLUE */
31
41
extern int PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
42
extern PyObject *PyMac_BuildFSSpec(FSSpec *spec);
32
45
extern int PyMac_GetFSRef(PyObject *v, FSRef *fsr);
33
extern PyObject *PyMac_BuildFSSpec(FSSpec *spec);
34
46
extern PyObject *PyMac_BuildFSRef(FSRef *spec);
48
#endif /* !USE_TOOLBOX_OBJECT_GLUE */
37
50
/* Forward declarations */
51
static PyObject *FSRef_New(FSRef *itself);
38
53
static PyObject *FInfo_New(FInfo *itself);
39
static PyObject *FSRef_New(FSRef *itself);
40
55
static PyObject *FSSpec_New(FSSpec *itself);
56
#define FSSpec_Convert PyMac_GetFSSpec
57
#endif /* !__LP64__ */
41
59
static PyObject *Alias_New(AliasHandle itself);
42
61
static int FInfo_Convert(PyObject *v, FInfo *p_itself);
62
#endif /* !__LP64__ */
43
63
#define FSRef_Convert PyMac_GetFSRef
44
#define FSSpec_Convert PyMac_GetFSSpec
45
64
static int Alias_Convert(PyObject *v, AliasHandle *p_itself);
283
306
static PyObject *FSCatalogInfo_get_permissions(FSCatalogInfoObject *self, void *closure)
285
return Py_BuildValue("(llll)", self->ob_itself.permissions[0], self->ob_itself.permissions[1], self->ob_itself.permissions[2], self->ob_itself.permissions[3]);
308
FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
309
return Py_BuildValue("(llll)", info->userID, info->groupID, info->userAccess, info->mode);
288
312
static int FSCatalogInfo_set_permissions(FSCatalogInfoObject *self, PyObject *v, void *closure)
290
return PyArg_Parse(v, "(llll)", &self->ob_itself.permissions[0], &self->ob_itself.permissions[1], &self->ob_itself.permissions[2], &self->ob_itself.permissions[3])-1;
320
FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
322
r = PyArg_Parse(v, "(llll)", &userID, &groupID, &userAccess, &mode);
326
info->userID = userID;
327
info->groupID = groupID;
328
info->userAccess = userAccess;
893
937
static PyMethodDef Alias_methods[] = {
894
939
{"ResolveAlias", (PyCFunction)Alias_ResolveAlias, 1,
895
940
PyDoc_STR("(FSSpec fromFile) -> (FSSpec target, Boolean wasChanged)")},
896
941
{"GetAliasInfo", (PyCFunction)Alias_GetAliasInfo, 1,
899
944
PyDoc_STR("(FSSpec fromFile, unsigned long mountFlags) -> (FSSpec target, Boolean wasChanged)")},
900
945
{"FollowFinderAlias", (PyCFunction)Alias_FollowFinderAlias, 1,
901
946
PyDoc_STR("(FSSpec fromFile, Boolean logon) -> (FSSpec target, Boolean wasChanged)")},
947
#endif /* !__LP64__ */
902
948
{"FSResolveAliasWithMountFlags", (PyCFunction)Alias_FSResolveAliasWithMountFlags, 1,
903
949
PyDoc_STR("(FSRef fromFile, unsigned long mountFlags) -> (FSRef target, Boolean wasChanged)")},
904
950
{"FSResolveAlias", (PyCFunction)Alias_FSResolveAlias, 1,
1568
1616
FSCatalogInfoBitmap whichInfo;
1569
1617
FSCatalogInfo catalogInfo;
1571
1620
FSSpec newSpec;
1572
1622
if (!PyArg_ParseTuple(_args, "u#lO&",
1573
1623
&nameLength__in__, &nameLength__in_len__,
1635
#else /* __LP64__ */
1637
#endif /* __LP64__*/
1584
1639
if (_err != noErr) return PyMac_Error(_err);
1585
1642
_res = Py_BuildValue("O&O&",
1586
1643
FSRef_New, &newRef,
1587
1644
FSSpec_New, &newSpec);
1645
#else /* __LP64__ */
1646
_res = Py_BuildValue("O&O", FSRef_New, &newRef, Py_None);
1647
#endif /* __LP64__ */
1598
1659
FSCatalogInfoBitmap whichInfo;
1599
1660
FSCatalogInfo catalogInfo;
1601
1663
FSSpec newSpec;
1664
#endif /* !__LP64__ */
1602
1665
UInt32 newDirID;
1603
1666
if (!PyArg_ParseTuple(_args, "u#lO&",
1604
1667
&nameLength__in__, &nameLength__in_len__,
1790
#else /* __LP64__ */
1792
#endif /* __LP64__ */
1713
1794
if (_err != noErr) return PyMac_Error(_err);
1714
1797
_res = Py_BuildValue("O&O&O&O&",
1715
1798
FSCatalogInfo_New, &catalogInfo,
1716
1799
PyMac_BuildHFSUniStr255, &outName,
1717
1800
FSSpec_New, &fsSpec,
1718
1801
FSRef_New, &parentRef);
1802
#else /* __LP64__ */
1803
_res = Py_BuildValue("O&O&OO&",
1804
FSCatalogInfo_New, &catalogInfo,
1805
PyMac_BuildHFSUniStr255, &outName,
1807
FSRef_New, &parentRef);
1808
#endif /* __LP64__ */
1784
1874
UniCharCount forkNameLength__len__;
1785
1875
int forkNameLength__in_len__;
1786
1876
SInt8 permissions;
1877
FSIORefNum forkRefNum;
1788
1878
if (!PyArg_ParseTuple(_args, "u#b",
1789
1879
&forkNameLength__in__, &forkNameLength__in_len__,
3052
3145
static PyMethodDef File_methods[] = {
3053
3147
{"UnmountVol", (PyCFunction)File_UnmountVol, 1,
3054
3148
PyDoc_STR("(Str63 volName, short vRefNum) -> None")},
3055
3149
{"FlushVol", (PyCFunction)File_FlushVol, 1,
3100
3194
PyDoc_STR("(short vRefNum, long dirID, Str255 oldName, long newDirID, Str255 newName) -> None")},
3101
3195
{"FSMakeFSSpec", (PyCFunction)File_FSMakeFSSpec, 1,
3102
3196
PyDoc_STR("(short vRefNum, long dirID, Str255 fileName) -> (FSSpec spec)")},
3197
#endif /* !__LP64__*/
3103
3198
{"FSGetForkPosition", (PyCFunction)File_FSGetForkPosition, 1,
3104
3199
PyDoc_STR("(SInt16 forkRefNum) -> (SInt64 position)")},
3105
3200
{"FSSetForkPosition", (PyCFunction)File_FSSetForkPosition, 1,
3124
3219
PyDoc_STR("(UInt8 * path, FNMessage message, OptionBits flags) -> None")},
3125
3220
{"FNNotifyAll", (PyCFunction)File_FNNotifyAll, 1,
3126
3221
PyDoc_STR("(FNMessage message, OptionBits flags) -> None")},
3127
3223
{"NewAlias", (PyCFunction)File_NewAlias, 1,
3128
3224
PyDoc_STR("(FSSpec fromFile, FSSpec target) -> (AliasHandle alias)")},
3129
3225
{"NewAliasMinimalFromFullPath", (PyCFunction)File_NewAliasMinimalFromFullPath, 1,
3136
3232
PyDoc_STR("(FSSpec fromFile, FSSpec target, AliasHandle alias) -> (Boolean wasChanged)")},
3137
3233
{"ResolveAliasFileWithMountFlagsNoUI", (PyCFunction)File_ResolveAliasFileWithMountFlagsNoUI, 1,
3138
3234
PyDoc_STR("(FSSpec theSpec, Boolean resolveAliasChains, unsigned long mountFlags) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
3235
#endif /* !__LP64__ */
3139
3236
{"FSNewAlias", (PyCFunction)File_FSNewAlias, 1,
3140
3237
PyDoc_STR("(FSRef fromFile, FSRef target) -> (AliasHandle inAlias)")},
3141
3238
{"FSResolveAliasFileWithMountFlags", (PyCFunction)File_FSResolveAliasFileWithMountFlags, 1,
3205
3305
char *path = NULL;
3206
3306
if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path))
3208
if ( (err=FSPathMakeRef(path, fsr, NULL)) )
3308
if ( (err=FSPathMakeRef((unsigned char*)path, fsr, NULL)) )
3209
3309
PyMac_Error(err);
3210
3310
PyMem_Free(path);
3213
3313
/* XXXX Should try unicode here too */
3214
3316
/* Otherwise we try to go via an FSSpec */
3215
3317
if (FSSpec_Check(v)) {
3216
3318
fss = ((FSSpecObject *)v)->ob_itself;
3246
3352
PyMac_INIT_TOOLBOX_OBJECT_NEW(FSSpec *, PyMac_BuildFSSpec);
3353
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
3354
#endif /* !__LP64__ */
3247
3356
PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef);
3248
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
3249
3357
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef);
3262
3370
/* Backward-compatible name */
3263
3371
Py_INCREF(&FSCatalogInfo_Type);
3264
3372
PyModule_AddObject(m, "FSCatalogInfoType", (PyObject *)&FSCatalogInfo_Type);
3265
3375
FInfo_Type.ob_type = &PyType_Type;
3266
3376
if (PyType_Ready(&FInfo_Type) < 0) return;
3267
3377
Py_INCREF(&FInfo_Type);
3269
3379
/* Backward-compatible name */
3270
3380
Py_INCREF(&FInfo_Type);
3271
3381
PyModule_AddObject(m, "FInfoType", (PyObject *)&FInfo_Type);
3382
#endif /* !__LP64__ */
3272
3383
Alias_Type.ob_type = &PyType_Type;
3273
3384
if (PyType_Ready(&Alias_Type) < 0) return;
3274
3385
Py_INCREF(&Alias_Type);
3276
3387
/* Backward-compatible name */
3277
3388
Py_INCREF(&Alias_Type);
3278
3389
PyModule_AddObject(m, "AliasType", (PyObject *)&Alias_Type);
3279
3392
FSSpec_Type.ob_type = &PyType_Type;
3280
3393
if (PyType_Ready(&FSSpec_Type) < 0) return;
3281
3394
Py_INCREF(&FSSpec_Type);
3283
3396
/* Backward-compatible name */
3284
3397
Py_INCREF(&FSSpec_Type);
3285
3398
PyModule_AddObject(m, "FSSpecType", (PyObject *)&FSSpec_Type);
3399
#endif /* !__LP64__ */
3286
3400
FSRef_Type.ob_type = &PyType_Type;
3287
3401
if (PyType_Ready(&FSRef_Type) < 0) return;
3288
3402
Py_INCREF(&FSRef_Type);