Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 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 | |
Guido van Rossum | a42960c | 1995-01-19 00:03:47 +0000 | [diff] [blame] | 35 | #ifdef THINK_C |
| 36 | #define FileFilterUPP FileFilterProcPtr |
| 37 | #endif |
| 38 | |
Jack Jansen | 84fa5ec | 1995-01-18 14:04:40 +0000 | [diff] [blame] | 39 | static object *ErrorObject; |
| 40 | |
| 41 | /* ----------------------------------------------------- */ |
| 42 | |
| 43 | static object * |
| 44 | mfs_NewAlias(self, args) |
| 45 | object *self; /* Not used */ |
| 46 | object *args; |
| 47 | { |
| 48 | FSSpec src, dst, *dstptr; |
| 49 | |
| 50 | src.name[0] = 0; |
| 51 | if (!newgetargs(args, "O&|O&", GetFSSpec, &dst, GetFSSpec, &src)) |
| 52 | return NULL; |
| 53 | |
| 54 | /* XXXX */ |
| 55 | |
| 56 | INCREF(None); |
| 57 | return None; |
| 58 | } |
| 59 | |
| 60 | static object * |
| 61 | mfs_ResolveAlias(self, args) |
| 62 | object *self; /* Not used */ |
| 63 | object *args; |
| 64 | { |
| 65 | |
| 66 | if (!newgetargs(args, "")) |
| 67 | return NULL; |
| 68 | INCREF(None); |
| 69 | return None; |
| 70 | } |
| 71 | |
| 72 | static object * |
| 73 | mfs_ResolveAliasFile(self, args) |
| 74 | object *self; /* Not used */ |
| 75 | object *args; |
| 76 | { |
| 77 | |
| 78 | if (!newgetargs(args, "")) |
| 79 | return NULL; |
| 80 | INCREF(None); |
| 81 | return None; |
| 82 | } |
| 83 | |
| 84 | static object * |
| 85 | mfs_StandardPutFile(self, args) |
| 86 | object *self; /* Not used */ |
| 87 | object *args; |
| 88 | { |
| 89 | Str255 prompt, dft; |
| 90 | StandardFileReply reply; |
| 91 | |
| 92 | dft[0] = 0; |
| 93 | if (!newgetargs(args, "O&|O&", GetStr255, &prompt, GetStr255, &dft) ) |
| 94 | return NULL; |
| 95 | StandardPutFile(prompt, dft, &reply); |
| 96 | return mkvalue("(iO)", reply.sfGood, PyMac_BuildFSSpec(&reply.sfFile)); |
| 97 | } |
| 98 | |
| 99 | static object * |
| 100 | mfs_StandardGetFile(self, args) |
| 101 | object *self; /* Not used */ |
| 102 | object *args; |
| 103 | { |
| 104 | char *list[4]; |
| 105 | SFTypeList typelist; |
| 106 | short numtypes; |
| 107 | StandardFileReply reply; |
| 108 | |
| 109 | list[0] = list[1] = list[2] = list[3] = 0; |
| 110 | numtypes = 0; |
| 111 | /* XXXX I don't understand newgetargs, why doesn't |s|s|s|s work? */ |
| 112 | if (!newgetargs(args, "|s", &list[0] /*, &list[1], &list[2], &list[3]*/) ) |
| 113 | return NULL; |
| 114 | while ( list[numtypes] && numtypes < 4 ) { |
| 115 | memcpy((char *)&typelist[numtypes], list[numtypes], 4); |
| 116 | numtypes++; |
| 117 | } |
| 118 | StandardGetFile((FileFilterUPP)0, numtypes, typelist, &reply); |
| 119 | return mkvalue("(iO)", reply.sfGood, PyMac_BuildFSSpec(&reply.sfFile)); |
| 120 | } |
| 121 | |
| 122 | static object * |
| 123 | mfs_FSSpecNormalize(self, args) |
| 124 | object *self; /* Not used */ |
| 125 | object *args; |
| 126 | { |
| 127 | FSSpec fss; |
| 128 | |
| 129 | if (!newgetargs(args, "O&", GetFSSpec, &fss)) |
| 130 | return NULL; |
| 131 | return PyMac_BuildFSSpec(&fss); |
| 132 | } |
| 133 | |
| 134 | static object * |
| 135 | mfs_FSSpecPath(self, args) |
| 136 | object *self; /* Not used */ |
| 137 | object *args; |
| 138 | { |
| 139 | FSSpec fss; |
| 140 | char strbuf[257]; |
| 141 | OSErr err; |
| 142 | |
| 143 | if (!newgetargs(args, "O&", GetFSSpec, &fss)) |
| 144 | return NULL; |
| 145 | err = nfullpath(&fss, strbuf); |
| 146 | if ( err ) { |
| 147 | PyErr_Mac(ErrorObject, err); |
| 148 | return NULL; |
| 149 | } |
| 150 | return newstringobject(strbuf); |
| 151 | } |
| 152 | |
| 153 | /* List of methods defined in the module */ |
| 154 | |
| 155 | static struct methodlist mfs_methods[] = { |
| 156 | {"NewAlias", mfs_NewAlias, 1}, |
| 157 | {"ResolveAlias", mfs_ResolveAlias, 1}, |
| 158 | {"ResolveAliasFile",mfs_ResolveAliasFile, 1}, |
| 159 | {"StandardPutFile", mfs_StandardPutFile, 1}, |
| 160 | {"StandardGetFile", mfs_StandardGetFile, 1}, |
| 161 | {"FSSpecNormalize", mfs_FSSpecNormalize, 1}, |
| 162 | {"FSSpecPath", mfs_FSSpecPath, 1}, |
| 163 | |
| 164 | {NULL, NULL} /* sentinel */ |
| 165 | }; |
| 166 | |
| 167 | |
| 168 | /* Initialization function for the module (*must* be called initmacfs) */ |
| 169 | |
| 170 | void |
| 171 | initmacfs() |
| 172 | { |
| 173 | object *m, *d; |
| 174 | |
| 175 | /* Create the module and add the functions */ |
| 176 | m = initmodule("macfs", mfs_methods); |
| 177 | |
| 178 | /* Add some symbolic constants to the module */ |
| 179 | d = getmoduledict(m); |
| 180 | ErrorObject = newstringobject("macfs.error"); |
| 181 | dictinsert(d, "error", ErrorObject); |
| 182 | |
| 183 | /* XXXX Add constants here */ |
| 184 | |
| 185 | /* Check for errors */ |
| 186 | if (err_occurred()) |
| 187 | fatal("can't initialize module macfs"); |
| 188 | } |