|
| 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