diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2002-11-22 15:53:32 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2002-11-22 15:53:32 (GMT) |
commit | d0e59fb68d62939477e0f5afb53bd4cc47f8288e (patch) | |
tree | d8328afa1121d888e7ef60fae7e3649aef03a832 /Mac | |
parent | e2ba87396cde5b57259405722910c560f7d237c6 (diff) | |
download | cpython-d0e59fb68d62939477e0f5afb53bd4cc47f8288e.zip cpython-d0e59fb68d62939477e0f5afb53bd4cc47f8288e.tar.gz cpython-d0e59fb68d62939477e0f5afb53bd4cc47f8288e.tar.bz2 |
Added the alias manager too. The interface isn't perfect yet: the alias
manager doesn't always have the alias as the first argument, so things
become functions in stead of methods.
Diffstat (limited to 'Mac')
-rw-r--r-- | Mac/Lib/Carbon/Alias.py | 1 | ||||
-rw-r--r-- | Mac/Lib/Carbon/Aliases.py | 18 | ||||
-rw-r--r-- | Mac/Modules/alias/_Aliasmodule.c | 663 | ||||
-rw-r--r-- | Mac/Modules/alias/aliasscan.py | 71 | ||||
-rw-r--r-- | Mac/Modules/alias/aliassupport.py | 117 |
5 files changed, 870 insertions, 0 deletions
diff --git a/Mac/Lib/Carbon/Alias.py b/Mac/Lib/Carbon/Alias.py new file mode 100644 index 0000000..cb612a6 --- /dev/null +++ b/Mac/Lib/Carbon/Alias.py @@ -0,0 +1 @@ +from _Alias import * diff --git a/Mac/Lib/Carbon/Aliases.py b/Mac/Lib/Carbon/Aliases.py new file mode 100644 index 0000000..1211e3d --- /dev/null +++ b/Mac/Lib/Carbon/Aliases.py @@ -0,0 +1,18 @@ +# Generated from 'Aliases.h' + +def FOUR_CHAR_CODE(x): return x +true = True +false = False +rAliasType = FOUR_CHAR_CODE('alis') +kARMMountVol = 0x00000001 +kARMNoUI = 0x00000002 +kARMMultVols = 0x00000008 +kARMSearch = 0x00000100 +kARMSearchMore = 0x00000200 +kARMSearchRelFirst = 0x00000400 +asiZoneName = -3 +asiServerName = -2 +asiVolumeName = -1 +asiAliasName = 0 +asiParentName = 1 +kResolveAliasFileNoUI = 0x00000001 diff --git a/Mac/Modules/alias/_Aliasmodule.c b/Mac/Modules/alias/_Aliasmodule.c new file mode 100644 index 0000000..7b30d05 --- /dev/null +++ b/Mac/Modules/alias/_Aliasmodule.c @@ -0,0 +1,663 @@ + +/* ========================= Module _Alias ========================== */ + +#include "Python.h" + + + +#ifdef _WIN32 +#include "pywintoolbox.h" +#else +#include "macglue.h" +#include "pymactoolbox.h" +#endif + +/* Macro to test whether a weak-loaded CFM function exists */ +#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ + PyErr_SetString(PyExc_NotImplementedError, \ + "Not available in this shared library/OS version"); \ + return NULL; \ + }} while(0) + + +#ifdef WITHOUT_FRAMEWORKS +#include <Files.h> +#else +#include <Carbon/Carbon.h> +#endif + +static PyObject *Alias_Error; + +/* ----------------------- Object type Alias ------------------------ */ + +PyTypeObject Alias_Type; + +#define AliasObj_Check(x) ((x)->ob_type == &Alias_Type) + +typedef struct AliasObject { + PyObject_HEAD + AliasHandle ob_itself; + void (*ob_freeit)(AliasHandle ptr); +} AliasObject; + +PyObject *AliasObj_New(AliasHandle itself) +{ + AliasObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + it = PyObject_NEW(AliasObject, &Alias_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + it->ob_freeit = NULL; + return (PyObject *)it; +} +int AliasObj_Convert(PyObject *v, AliasHandle *p_itself) +{ + if (!AliasObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "Alias required"); + return 0; + } + *p_itself = ((AliasObject *)v)->ob_itself; + return 1; +} + +static void AliasObj_dealloc(AliasObject *self) +{ + if (self->ob_freeit && self->ob_itself) + { + self->ob_freeit(self->ob_itself); + } + self->ob_itself = NULL; + PyObject_Del(self); +} + +static PyObject *AliasObj_GetAliasInfo(AliasObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + AliasInfoType index; + Str63 theString; + if (!PyArg_ParseTuple(_args, "h", + &index)) + return NULL; + _err = GetAliasInfo(_self->ob_itself, + index, + theString); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + PyMac_BuildStr255, theString); + return _res; +} + +static PyMethodDef AliasObj_methods[] = { + {"GetAliasInfo", (PyCFunction)AliasObj_GetAliasInfo, 1, + PyDoc_STR("(AliasInfoType index) -> (Str63 theString)")}, + {NULL, NULL, 0} +}; + +PyMethodChain AliasObj_chain = { AliasObj_methods, NULL }; + +static PyObject *AliasObj_getattr(AliasObject *self, char *name) +{ + return Py_FindMethodInChain(&AliasObj_chain, (PyObject *)self, name); +} + +#define AliasObj_setattr NULL + +#define AliasObj_compare NULL + +#define AliasObj_repr NULL + +#define AliasObj_hash NULL + +PyTypeObject Alias_Type = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "_Alias.Alias", /*tp_name*/ + sizeof(AliasObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) AliasObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) AliasObj_getattr, /*tp_getattr*/ + (setattrfunc) AliasObj_setattr, /*tp_setattr*/ + (cmpfunc) AliasObj_compare, /*tp_compare*/ + (reprfunc) AliasObj_repr, /*tp_repr*/ + (PyNumberMethods *)0, /* tp_as_number */ + (PySequenceMethods *)0, /* tp_as_sequence */ + (PyMappingMethods *)0, /* tp_as_mapping */ + (hashfunc) AliasObj_hash, /*tp_hash*/ +}; + +/* --------------------- End object type Alias ---------------------- */ + + +static PyObject *Alias_NewAlias(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSSpec fromFile; + FSSpec target; + AliasHandle alias; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetFSSpec, &fromFile, + PyMac_GetFSSpec, &target)) + return NULL; + _err = NewAlias(&fromFile, + &target, + &alias); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AliasObj_New, alias); + return _res; +} + +static PyObject *Alias_NewAliasMinimal(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSSpec target; + AliasHandle alias; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetFSSpec, &target)) + return NULL; + _err = NewAliasMinimal(&target, + &alias); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AliasObj_New, alias); + return _res; +} + +static PyObject *Alias_NewAliasMinimalFromFullPath(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + char *fullPath__in__; + int fullPath__len__; + int fullPath__in_len__; + Str32 zoneName; + Str31 serverName; + AliasHandle alias; + if (!PyArg_ParseTuple(_args, "s#O&O&", + &fullPath__in__, &fullPath__in_len__, + PyMac_GetStr255, zoneName, + PyMac_GetStr255, serverName)) + return NULL; + fullPath__len__ = fullPath__in_len__; + _err = NewAliasMinimalFromFullPath(fullPath__len__, fullPath__in__, + zoneName, + serverName, + &alias); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AliasObj_New, alias); + return _res; +} + +static PyObject *Alias_ResolveAlias(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSSpec fromFile; + AliasHandle alias; + FSSpec target; + Boolean wasChanged; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetFSSpec, &fromFile, + AliasObj_Convert, &alias)) + return NULL; + _err = ResolveAlias(&fromFile, + alias, + &target, + &wasChanged); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&b", + PyMac_BuildFSSpec, &target, + wasChanged); + return _res; +} + +static PyObject *Alias_IsAliasFile(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSSpec fileFSSpec; + Boolean aliasFileFlag; + Boolean folderFlag; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetFSSpec, &fileFSSpec)) + return NULL; + _err = IsAliasFile(&fileFSSpec, + &aliasFileFlag, + &folderFlag); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("bb", + aliasFileFlag, + folderFlag); + return _res; +} + +static PyObject *Alias_ResolveAliasWithMountFlags(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSSpec fromFile; + AliasHandle alias; + FSSpec target; + Boolean wasChanged; + unsigned long mountFlags; + if (!PyArg_ParseTuple(_args, "O&O&l", + PyMac_GetFSSpec, &fromFile, + AliasObj_Convert, &alias, + &mountFlags)) + return NULL; + _err = ResolveAliasWithMountFlags(&fromFile, + alias, + &target, + &wasChanged, + mountFlags); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&b", + PyMac_BuildFSSpec, &target, + wasChanged); + return _res; +} + +static PyObject *Alias_ResolveAliasFile(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSSpec theSpec; + Boolean resolveAliasChains; + Boolean targetIsFolder; + Boolean wasAliased; + if (!PyArg_ParseTuple(_args, "b", + &resolveAliasChains)) + return NULL; + _err = ResolveAliasFile(&theSpec, + resolveAliasChains, + &targetIsFolder, + &wasAliased); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&bb", + PyMac_BuildFSSpec, &theSpec, + targetIsFolder, + wasAliased); + return _res; +} + +static PyObject *Alias_ResolveAliasFileWithMountFlags(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSSpec theSpec; + Boolean resolveAliasChains; + Boolean targetIsFolder; + Boolean wasAliased; + unsigned long mountFlags; + if (!PyArg_ParseTuple(_args, "bl", + &resolveAliasChains, + &mountFlags)) + return NULL; + _err = ResolveAliasFileWithMountFlags(&theSpec, + resolveAliasChains, + &targetIsFolder, + &wasAliased, + mountFlags); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&bb", + PyMac_BuildFSSpec, &theSpec, + targetIsFolder, + wasAliased); + return _res; +} + +static PyObject *Alias_FollowFinderAlias(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSSpec fromFile; + AliasHandle alias; + Boolean logon; + FSSpec target; + Boolean wasChanged; + if (!PyArg_ParseTuple(_args, "O&O&b", + PyMac_GetFSSpec, &fromFile, + AliasObj_Convert, &alias, + &logon)) + return NULL; + _err = FollowFinderAlias(&fromFile, + alias, + logon, + &target, + &wasChanged); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&b", + PyMac_BuildFSSpec, &target, + wasChanged); + return _res; +} + +static PyObject *Alias_UpdateAlias(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSSpec fromFile; + FSSpec target; + AliasHandle alias; + Boolean wasChanged; + if (!PyArg_ParseTuple(_args, "O&O&O&", + PyMac_GetFSSpec, &fromFile, + PyMac_GetFSSpec, &target, + AliasObj_Convert, &alias)) + return NULL; + _err = UpdateAlias(&fromFile, + &target, + alias, + &wasChanged); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("b", + wasChanged); + return _res; +} + +static PyObject *Alias_ResolveAliasFileWithMountFlagsNoUI(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSSpec theSpec; + Boolean resolveAliasChains; + Boolean targetIsFolder; + Boolean wasAliased; + unsigned long mountFlags; + if (!PyArg_ParseTuple(_args, "bl", + &resolveAliasChains, + &mountFlags)) + return NULL; + _err = ResolveAliasFileWithMountFlagsNoUI(&theSpec, + resolveAliasChains, + &targetIsFolder, + &wasAliased, + mountFlags); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&bb", + PyMac_BuildFSSpec, &theSpec, + targetIsFolder, + wasAliased); + return _res; +} + +static PyObject *Alias_FSNewAlias(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSRef fromFile; + FSRef target; + AliasHandle inAlias; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetFSRef, &fromFile, + PyMac_GetFSRef, &target)) + return NULL; + _err = FSNewAlias(&fromFile, + &target, + &inAlias); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AliasObj_New, inAlias); + return _res; +} + +static PyObject *Alias_FSNewAliasMinimal(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSRef target; + AliasHandle inAlias; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetFSRef, &target)) + return NULL; + _err = FSNewAliasMinimal(&target, + &inAlias); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AliasObj_New, inAlias); + return _res; +} + +static PyObject *Alias_FSIsAliasFile(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSRef fileRef; + Boolean aliasFileFlag; + Boolean folderFlag; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetFSRef, &fileRef)) + return NULL; + _err = FSIsAliasFile(&fileRef, + &aliasFileFlag, + &folderFlag); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("bb", + aliasFileFlag, + folderFlag); + return _res; +} + +static PyObject *Alias_FSResolveAliasWithMountFlags(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSRef fromFile; + AliasHandle inAlias; + FSRef target; + Boolean wasChanged; + unsigned long mountFlags; + if (!PyArg_ParseTuple(_args, "O&O&l", + PyMac_GetFSRef, &fromFile, + AliasObj_Convert, &inAlias, + &mountFlags)) + return NULL; + _err = FSResolveAliasWithMountFlags(&fromFile, + inAlias, + &target, + &wasChanged, + mountFlags); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&b", + PyMac_BuildFSRef, &target, + wasChanged); + return _res; +} + +static PyObject *Alias_FSResolveAlias(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSRef fromFile; + AliasHandle alias; + FSRef target; + Boolean wasChanged; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetFSRef, &fromFile, + AliasObj_Convert, &alias)) + return NULL; + _err = FSResolveAlias(&fromFile, + alias, + &target, + &wasChanged); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&b", + PyMac_BuildFSRef, &target, + wasChanged); + return _res; +} + +static PyObject *Alias_FSResolveAliasFileWithMountFlags(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSRef theRef; + Boolean resolveAliasChains; + Boolean targetIsFolder; + Boolean wasAliased; + unsigned long mountFlags; + if (!PyArg_ParseTuple(_args, "bl", + &resolveAliasChains, + &mountFlags)) + return NULL; + _err = FSResolveAliasFileWithMountFlags(&theRef, + resolveAliasChains, + &targetIsFolder, + &wasAliased, + mountFlags); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&bb", + PyMac_BuildFSRef, &theRef, + targetIsFolder, + wasAliased); + return _res; +} + +static PyObject *Alias_FSResolveAliasFile(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSRef theRef; + Boolean resolveAliasChains; + Boolean targetIsFolder; + Boolean wasAliased; + if (!PyArg_ParseTuple(_args, "b", + &resolveAliasChains)) + return NULL; + _err = FSResolveAliasFile(&theRef, + resolveAliasChains, + &targetIsFolder, + &wasAliased); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&bb", + PyMac_BuildFSRef, &theRef, + targetIsFolder, + wasAliased); + return _res; +} + +static PyObject *Alias_FSFollowFinderAlias(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSRef fromFile; + AliasHandle alias; + Boolean logon; + FSRef target; + Boolean wasChanged; + if (!PyArg_ParseTuple(_args, "O&b", + AliasObj_Convert, &alias, + &logon)) + return NULL; + _err = FSFollowFinderAlias(&fromFile, + alias, + logon, + &target, + &wasChanged); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&O&b", + PyMac_BuildFSRef, &fromFile, + PyMac_BuildFSRef, &target, + wasChanged); + return _res; +} + +static PyObject *Alias_FSUpdateAlias(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OSErr _err; + FSRef fromFile; + FSRef target; + AliasHandle alias; + Boolean wasChanged; + if (!PyArg_ParseTuple(_args, "O&O&O&", + PyMac_GetFSRef, &fromFile, + PyMac_GetFSRef, &target, + AliasObj_Convert, &alias)) + return NULL; + _err = FSUpdateAlias(&fromFile, + &target, + alias, + &wasChanged); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("b", + wasChanged); + return _res; +} + +static PyMethodDef Alias_methods[] = { + {"NewAlias", (PyCFunction)Alias_NewAlias, 1, + PyDoc_STR("(FSSpec fromFile, FSSpec target) -> (AliasHandle alias)")}, + {"NewAliasMinimal", (PyCFunction)Alias_NewAliasMinimal, 1, + PyDoc_STR("(FSSpec target) -> (AliasHandle alias)")}, + {"NewAliasMinimalFromFullPath", (PyCFunction)Alias_NewAliasMinimalFromFullPath, 1, + PyDoc_STR("(Buffer fullPath, Str32 zoneName, Str31 serverName) -> (AliasHandle alias)")}, + {"ResolveAlias", (PyCFunction)Alias_ResolveAlias, 1, + PyDoc_STR("(FSSpec fromFile, AliasHandle alias) -> (FSSpec target, Boolean wasChanged)")}, + {"IsAliasFile", (PyCFunction)Alias_IsAliasFile, 1, + PyDoc_STR("(FSSpec fileFSSpec) -> (Boolean aliasFileFlag, Boolean folderFlag)")}, + {"ResolveAliasWithMountFlags", (PyCFunction)Alias_ResolveAliasWithMountFlags, 1, + PyDoc_STR("(FSSpec fromFile, AliasHandle alias, unsigned long mountFlags) -> (FSSpec target, Boolean wasChanged)")}, + {"ResolveAliasFile", (PyCFunction)Alias_ResolveAliasFile, 1, + PyDoc_STR("(Boolean resolveAliasChains) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")}, + {"ResolveAliasFileWithMountFlags", (PyCFunction)Alias_ResolveAliasFileWithMountFlags, 1, + PyDoc_STR("(Boolean resolveAliasChains, unsigned long mountFlags) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")}, + {"FollowFinderAlias", (PyCFunction)Alias_FollowFinderAlias, 1, + PyDoc_STR("(FSSpec fromFile, AliasHandle alias, Boolean logon) -> (FSSpec target, Boolean wasChanged)")}, + {"UpdateAlias", (PyCFunction)Alias_UpdateAlias, 1, + PyDoc_STR("(FSSpec fromFile, FSSpec target, AliasHandle alias) -> (Boolean wasChanged)")}, + {"ResolveAliasFileWithMountFlagsNoUI", (PyCFunction)Alias_ResolveAliasFileWithMountFlagsNoUI, 1, + PyDoc_STR("(Boolean resolveAliasChains, unsigned long mountFlags) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")}, + {"FSNewAlias", (PyCFunction)Alias_FSNewAlias, 1, + PyDoc_STR("(FSRef fromFile, FSRef target) -> (AliasHandle inAlias)")}, + {"FSNewAliasMinimal", (PyCFunction)Alias_FSNewAliasMinimal, 1, + PyDoc_STR("(FSRef target) -> (AliasHandle inAlias)")}, + {"FSIsAliasFile", (PyCFunction)Alias_FSIsAliasFile, 1, + PyDoc_STR("(FSRef fileRef) -> (Boolean aliasFileFlag, Boolean folderFlag)")}, + {"FSResolveAliasWithMountFlags", (PyCFunction)Alias_FSResolveAliasWithMountFlags, 1, + PyDoc_STR("(FSRef fromFile, AliasHandle inAlias, unsigned long mountFlags) -> (FSRef target, Boolean wasChanged)")}, + {"FSResolveAlias", (PyCFunction)Alias_FSResolveAlias, 1, + PyDoc_STR("(FSRef fromFile, AliasHandle alias) -> (FSRef target, Boolean wasChanged)")}, + {"FSResolveAliasFileWithMountFlags", (PyCFunction)Alias_FSResolveAliasFileWithMountFlags, 1, + PyDoc_STR("(Boolean resolveAliasChains, unsigned long mountFlags) -> (FSRef theRef, Boolean targetIsFolder, Boolean wasAliased)")}, + {"FSResolveAliasFile", (PyCFunction)Alias_FSResolveAliasFile, 1, + PyDoc_STR("(Boolean resolveAliasChains) -> (FSRef theRef, Boolean targetIsFolder, Boolean wasAliased)")}, + {"FSFollowFinderAlias", (PyCFunction)Alias_FSFollowFinderAlias, 1, + PyDoc_STR("(AliasHandle alias, Boolean logon) -> (FSRef fromFile, FSRef target, Boolean wasChanged)")}, + {"FSUpdateAlias", (PyCFunction)Alias_FSUpdateAlias, 1, + PyDoc_STR("(FSRef fromFile, FSRef target, AliasHandle alias) -> (Boolean wasChanged)")}, + {NULL, NULL, 0} +}; + + + + +void init_Alias(void) +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("_Alias", Alias_methods); + d = PyModule_GetDict(m); + Alias_Error = PyMac_GetOSErrException(); + if (Alias_Error == NULL || + PyDict_SetItemString(d, "Error", Alias_Error) != 0) + return; + Alias_Type.ob_type = &PyType_Type; + Py_INCREF(&Alias_Type); + if (PyDict_SetItemString(d, "AliasType", (PyObject *)&Alias_Type) != 0) + Py_FatalError("can't initialize AliasType"); +} + +/* ======================= End module _Alias ======================== */ + diff --git a/Mac/Modules/alias/aliasscan.py b/Mac/Modules/alias/aliasscan.py new file mode 100644 index 0000000..a21d3f2 --- /dev/null +++ b/Mac/Modules/alias/aliasscan.py @@ -0,0 +1,71 @@ +# Scan an Apple header file, generating a Python file of generator calls. + +import sys +import os +from bgenlocations import TOOLBOXDIR, BGENDIR +sys.path.append(BGENDIR) +from scantools import Scanner_OSX + +LONG = "Aliases" +SHORT = "alias" +OBJECT = "AliasHandle" + +def main(): + input = LONG + ".h" + output = SHORT + "gen.py" + defsoutput = TOOLBOXDIR + LONG + ".py" + scanner = MyScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + scanner.gentypetest(SHORT+"typetest.py") + print "=== Testing definitions output code ===" + execfile(defsoutput, {}, {}) + print "=== Done scanning and generating, now importing the generated code... ===" + exec "import " + SHORT + "support" + print "=== Done. It's up to you to compile it now! ===" + +class MyScanner(Scanner_OSX): + + def destination(self, type, name, arglist): + classname = "Function" + listname = "functions" + if arglist: + t, n, m = arglist[0] + # This is non-functional today + if t == OBJECT and m == "InMode": + classname = "Method" + listname = "methods" + return classname, listname + + def makeblacklistnames(self): + return [ + # Constants with incompatible definitions + + ] + + def makeblacklisttypes(self): + return [ + "AliasFilterProcPtr", + "AliasFilterUPP", + "CInfoPBPtr", + ] + + def makerepairinstructions(self): + return [ + ([('Str63', 'theString', 'InMode')], + [('Str63', 'theString', 'OutMode')]), + + ([('short', 'fullPathLength', 'InMode'), + ('void_ptr', 'fullPath', 'InMode')], + [('FullPathName', 'fullPath', 'InMode')]), + + ] + + + def writeinitialdefs(self): + self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") + self.defsfile.write("true = True\n") + self.defsfile.write("false = False\n") + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/alias/aliassupport.py b/Mac/Modules/alias/aliassupport.py new file mode 100644 index 0000000..932eed7 --- /dev/null +++ b/Mac/Modules/alias/aliassupport.py @@ -0,0 +1,117 @@ +# This script generates a Python interface for an Apple Macintosh Manager. +# It uses the "bgen" package to generate C code. +# The function specifications are generated by scanning the mamager's header file, +# using the "scantools" package (customized for this particular manager). + +import string + +# Declarations that change for each manager +MACHEADERFILE = 'Aliases.h' # The Apple header file +MODNAME = '_Alias' # The name of the module + +# The following is *usually* unchanged but may still require tuning +MODPREFIX = 'Alias' # The prefix for module-wide routines +INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner +OUTPUTFILE = MODNAME + "module.c" # The file generated by this program + +from macsupport import * + + +# Create the type objects + +class VarReverseInputBufferType(ReverseInputBufferMixin, VarInputBufferType): + pass + +FullPathName = VarReverseInputBufferType() + +AliasHandle = OpaqueByValueType("AliasHandle", "AliasObj") +AliasInfoType = Type("AliasInfoType", "h") +ConstStr31Param = OpaqueArrayType("Str31", "PyMac_BuildStr255", "PyMac_GetStr255") +ConstStr32Param = OpaqueArrayType("Str32", "PyMac_BuildStr255", "PyMac_GetStr255") +#FSSpecArrayPtr +#Ptr +Str63 = OpaqueArrayType("Str63", "PyMac_BuildStr255", "PyMac_GetStr255") +#void_ptr +# class UniCharCountBuffer(InputOnlyType): +# pass +# +# #CatPositionRec +# ConstStr63Param = OpaqueArrayType("Str63", "PyMac_BuildStr255", "PyMac_GetStr255") +# FInfo = OpaqueByValueStructType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo") +# FInfo_ptr = OpaqueType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo") +# FNMessage = Type("FNMessage", "l") +# FSAllocationFlags = Type("FSAllocationFlags", "H") +# #FSCatalogInfo +# FSCatalogInfoBitmap = Type("FSCatalogInfoBitmap", "l") +# #FSForkInfo +# #FSIterator +# FSIteratorFlags = Type("FSIteratorFlags", "l") +# #FSVolumeInfo +# FSVolumeRefNum = Type("FSVolumeRefNum", "h") +# HFSUniStr255 = OpaqueType("HFSUniStr255", "PyMac_BuildHFSUniStr255", "PyMac_GetHFSUniStr255") +# SInt64 = Type("SInt64", "L") +# UInt64 = Type("UInt64", "L") +# #UInt8_ptr +# #UniCharCount +# #char_ptr +# #void_ptr + + +includestuff = includestuff + """ +#ifdef WITHOUT_FRAMEWORKS +#include <Files.h> +#else +#include <Carbon/Carbon.h> +#endif +""" + +execfile(string.lower(MODPREFIX) + 'typetest.py') + +# From here on it's basically all boiler plate... + +# Create the generator groups and link them +module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) + +class AliasDefinition(GlobalObjectDefinition): + + def outputCheckNewArg(self): + Output("if (itself == NULL) return PyMac_Error(resNotFound);") + + def outputStructMembers(self): + GlobalObjectDefinition.outputStructMembers(self) + Output("void (*ob_freeit)(%s ptr);", self.itselftype) + + def outputInitStructMembers(self): + GlobalObjectDefinition.outputInitStructMembers(self) + Output("it->ob_freeit = NULL;") + + def outputCleanupStructMembers(self): + Output("if (self->ob_freeit && self->ob_itself)") + OutLbrace() + Output("self->ob_freeit(self->ob_itself);") + OutRbrace() + Output("self->ob_itself = NULL;") + + +aliasobject = AliasDefinition('Alias', 'AliasObj', 'AliasHandle') +module.addobject(aliasobject) +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +methods = [] +execfile(INPUTFILE) + +# Manual generators: + +# add the populated lists to the generator groups +# (in a different wordl the scan program would generate this) +for f in methods: aliasobject.add(f) +for f in functions: module.add(f) + +# generate output (open the output file as late as possible) +SetOutputFileName(OUTPUTFILE) +module.generate() + |