1 /* $Id: macmisc.c,v 1.1 2003/02/12 23:53:15 ben Exp $ */
3 * Copyright (c) 1999, 2003 Ben Harris
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 #include <Quickdraw.h>
32 #include <TextUtils.h>
39 #if TARGET_API_MAC_CARBON
41 * This is used by (I think) CarbonStdCLib, but only exists in
42 * CarbonLib 1.1 and later. Muppets. Happily, it's documented to be
46 const CFAllocatorRef kCFAllocatorDefault = NULL;
51 void fatalbox(char *fmt, ...) {
56 /* We'd like stuff to be a Pascal string */
57 stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap);
59 ParamText(stuff, NULL, NULL, NULL);
64 void modalfatalbox(char *fmt, ...) {
69 /* We'd like stuff to be a Pascal string */
70 stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap);
72 ParamText(stuff, NULL, NULL, NULL);
77 Filename filename_from_str(const char *str)
82 /* XXX This fails for filenames over 255 characters long. */
84 FSMakeFSSpec(0, 0, tmp, &ret.fss);
89 * Convert a filename to a string for display purposes.
90 * See pp 2-44--2-46 of IM:Files
92 * XXX static storage considered harmful
94 const char *filename_to_str(const Filename *fn)
99 static char *path = NULL;
102 if (path != NULL) sfree(path);
103 path = smalloc(fn->fss.name[0]);
104 p2cstrcpy(path, fn->fss.name);
105 pb.dirInfo.ioNamePtr = dirname;
106 pb.dirInfo.ioVRefNum = fn->fss.vRefNum;
107 pb.dirInfo.ioDrParID = fn->fss.parID;
108 pb.dirInfo.ioFDirIndex = -1;
110 pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID;
111 err = PBGetCatInfoSync(&pb);
113 /* XXX Assume not A/UX */
114 newpath = smalloc(strlen(path) + dirname[0] + 2);
115 p2cstrcpy(newpath, dirname);
116 strcat(newpath, ":");
117 strcat(newpath, path);
120 } while (pb.dirInfo.ioDrDirID != fsRtDirID);
124 int filename_equal(Filename f1, Filename f2)
127 return f1.fss.vRefNum == f2.fss.vRefNum &&
128 f1.fss.parID == f2.fss.parID &&
129 f1.fss.name[0] == f2.fss.name[0] &&
130 memcmp(f1.fss.name + 1, f2.fss.name + 1, f1.fss.name[0]) == 0;
133 int filename_is_null(Filename fn)
136 return fn.fss.vRefNum == 0 && fn.fss.parID == 0 && fn.fss.name[0] == 0;
139 FILE *f_open(Filename fn, char const *mode)
146 HGetVol(NULL, &savevol, &savedir);
147 if (HSetVol(NULL, fn.fss.vRefNum, fn.fss.parID) == noErr) {
148 p2cstrcpy(tmp, fn.fss.name);
149 ret = fopen(tmp, mode);
152 HSetVol(NULL, savevol, savedir);
158 * c-file-style: "simon"