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 <MacWindows.h>
32 #include <Processes.h>
33 #include <Quickdraw.h>
34 #include <TextUtils.h>
43 #if TARGET_API_MAC_CARBON
45 * This is used by (I think) CarbonStdCLib, but only exists in
46 * CarbonLib 1.1 and later. Muppets. Happily, it's documented to be
50 const CFAllocatorRef kCFAllocatorDefault
= NULL
;
56 * Like FrontWindow(), but return NULL if we aren't the front process
57 * (i.e. the front window isn't one of ours).
59 WindowPtr
mac_frontwindow(void)
61 ProcessSerialNumber frontpsn
;
62 ProcessSerialNumber curpsn
= { 0, kCurrentProcess
};
65 GetFrontProcess(&frontpsn
);
66 if (SameProcess(&frontpsn
, &curpsn
, &result
) == noErr
&& result
)
71 void fatalbox(char *fmt
, ...) {
76 /* We'd like stuff to be a Pascal string */
77 stuff
[0] = vsprintf((char *)(&stuff
[1]), fmt
, ap
);
79 ParamText(stuff
, NULL
, NULL
, NULL
);
84 void modalfatalbox(char *fmt
, ...) {
89 /* We'd like stuff to be a Pascal string */
90 stuff
[0] = vsprintf((char *)(&stuff
[1]), fmt
, ap
);
92 ParamText(stuff
, NULL
, NULL
, NULL
);
97 Filename
filename_from_str(const char *str
)
102 /* XXX This fails for filenames over 255 characters long. */
104 FSMakeFSSpec(0, 0, tmp
, &ret
.fss
);
109 * Convert a filename to a string for display purposes.
110 * See pp 2-44--2-46 of IM:Files
112 * XXX static storage considered harmful
114 const char *filename_to_str(const Filename
*fn
)
119 static char *path
= NULL
;
122 if (path
!= NULL
) sfree(path
);
123 path
= snewn(fn
->fss
.name
[0], char);
124 p2cstrcpy(path
, fn
->fss
.name
);
125 pb
.dirInfo
.ioNamePtr
= dirname
;
126 pb
.dirInfo
.ioVRefNum
= fn
->fss
.vRefNum
;
127 pb
.dirInfo
.ioDrParID
= fn
->fss
.parID
;
128 pb
.dirInfo
.ioFDirIndex
= -1;
130 pb
.dirInfo
.ioDrDirID
= pb
.dirInfo
.ioDrParID
;
131 err
= PBGetCatInfoSync(&pb
);
133 /* XXX Assume not A/UX */
134 newpath
= snewn(strlen(path
) + dirname
[0] + 2, char);
135 p2cstrcpy(newpath
, dirname
);
136 strcat(newpath
, ":");
137 strcat(newpath
, path
);
140 } while (pb
.dirInfo
.ioDrDirID
!= fsRtDirID
);
144 int filename_equal(Filename f1
, Filename f2
)
147 return f1
.fss
.vRefNum
== f2
.fss
.vRefNum
&&
148 f1
.fss
.parID
== f2
.fss
.parID
&&
149 f1
.fss
.name
[0] == f2
.fss
.name
[0] &&
150 memcmp(f1
.fss
.name
+ 1, f2
.fss
.name
+ 1, f1
.fss
.name
[0]) == 0;
153 int filename_is_null(Filename fn
)
156 return fn
.fss
.vRefNum
== 0 && fn
.fss
.parID
== 0 && fn
.fss
.name
[0] == 0;
159 FILE *f_open(Filename fn
, char const *mode
, int is_private
)
166 HGetVol(NULL
, &savevol
, &savedir
);
167 if (HSetVol(NULL
, fn
.fss
.vRefNum
, fn
.fss
.parID
) == noErr
) {
168 p2cstrcpy(tmp
, fn
.fss
.name
);
169 ret
= fopen(tmp
, mode
);
172 HSetVol(NULL
, savevol
, savedir
);
176 struct tm
ltime(void)
187 tm
.tm_year
=d
.year
-1900;
188 tm
.tm_wday
=d
.dayOfWeek
;
189 tm
.tm_yday
=1; /* GetTime doesn't tell us */
190 tm
.tm_isdst
=0; /* Have to do DST ourselves */
192 /* XXX find out DST adjustment and add it */
197 const int platform_uses_x11_unix_by_default
= FALSE
;
199 char *platform_get_x_display(void) {
205 * c-file-style: "simon"