| 1 | /* |
| 2 | * osbeos.h - TADS2 operating system definitions for BeOS |
| 3 | * |
| 4 | * Copyright (c) 2000 by Christopher Tate. All rights reserve |
| 5 | * |
| 6 | * Please see the accompanying license file, LICENSE.TXT, for information |
| 7 | * on using and copying this software. d. |
| 8 | */ |
| 9 | |
| 10 | #ifndef OSBEOS_H |
| 11 | #define OSBEOS_H 1 |
| 12 | |
| 13 | #include <stdlib.h> |
| 14 | #include <stdio.h> |
| 15 | #include <unistd.h> |
| 16 | #include <string.h> |
| 17 | #include <time.h> |
| 18 | #include <wchar.h> |
| 19 | |
| 20 | #ifdef __cplusplus |
| 21 | extern "C" { |
| 22 | #endif |
| 23 | |
| 24 | /* Use BEOSPATCHLEVEL, as defined in the makefile, for the port patch level */ |
| 25 | #define TADS_OEM_VERSION BEOSPATCHLEVEL |
| 26 | |
| 27 | /* Use SYSPL, as defined in the makefile, for the patch sub-level */ |
| 28 | #define OS_SYSTEM_PATCHSUBLVL SYSPL |
| 29 | |
| 30 | /* Use PORTER, from the makefile, for the OEM maintainer name */ |
| 31 | #define TADS_OEM_NAME PORTER |
| 32 | |
| 33 | /* Use SYSNAME, as defined in the makefile, for the system's banner ID */ |
| 34 | #define OS_SYSTEM_NAME "BeOS" |
| 35 | #define OS_SYSTEM_LDESC OS_SYSTEM_NAME |
| 36 | |
| 37 | /* |
| 38 | * Define a startup message for the debugger warning that the debugger |
| 39 | * only works in 80x50 windows |
| 40 | */ |
| 41 | #define OS_TDB_STARTUP_MSG \ |
| 42 | "NOTE: This program must be run in a 80x50 character window.\n" |
| 43 | |
| 44 | |
| 45 | /* maximum width (in characters) of a line of text */ |
| 46 | #define OS_MAXWIDTH 1024 |
| 47 | |
| 48 | /* |
| 49 | * Make default buffer sizes huge. (Why not? We have virtual memory.) |
| 50 | */ |
| 51 | #include "osbigmem.h" |
| 52 | |
| 53 | /* |
| 54 | * Swapping off by default, since Unix machines tend to be big compared |
| 55 | * to adventure games |
| 56 | */ |
| 57 | #define OS_DEFAULT_SWAP_ENABLED 0 |
| 58 | |
| 59 | /* |
| 60 | * Usage lines - we use non-default names for the executables on Unix, |
| 61 | * so we need to adjust the usage lines accordingly. |
| 62 | */ |
| 63 | # define OS_TC_USAGE "usage: tadsc [options] file" |
| 64 | # define OS_TR_USGAE "usage: tadsr [options] file" |
| 65 | |
| 66 | |
| 67 | /* |
| 68 | * Get GCC varags defs |
| 69 | */ |
| 70 | |
| 71 | #include <stdarg.h> /* get native stdargs */ |
| 72 | |
| 73 | //#define HAVE_TPARM /* define if this system has the tparm routine */ |
| 74 | |
| 75 | #define OS_USHORT_DEFINED |
| 76 | #define OS_UINT_DEFINED |
| 77 | #define OS_ULONG_DEFINED |
| 78 | |
| 79 | #define remove(filename) unlink(filename) |
| 80 | |
| 81 | /* |
| 82 | * BeOS has strcasecmp, not stricmp |
| 83 | */ |
| 84 | #define stricmp strcasecmp |
| 85 | #define strnicmp strncasecmp |
| 86 | |
| 87 | /* |
| 88 | * Prototype memicmp since it's not a standard C or POSIX function. |
| 89 | */ |
| 90 | int memicmp(const char *s1, const char *s2, size_t len); |
| 91 | |
| 92 | /* far pointer type qualifier (null on most platforms) */ |
| 93 | # define osfar_t |
| 94 | |
| 95 | /* maximum theoretical size of malloc argument */ |
| 96 | # define OSMALMAX ((size_t)0xffffffff) |
| 97 | |
| 98 | /* cast an expression to void */ |
| 99 | # define DISCARD (void) |
| 100 | |
| 101 | /* display lines on which errors occur */ |
| 102 | /* # define OS_ERRLINE 1 */ |
| 103 | |
| 104 | /* |
| 105 | * If long cache-manager macros are NOT allowed, define |
| 106 | * OS_MCM_NO_MACRO. This forces certain cache manager operations to be |
| 107 | * functions, which results in substantial memory savings. |
| 108 | */ |
| 109 | /* #define OS_MCM_NO_MACRO */ |
| 110 | |
| 111 | /* likewise for the error handling subsystem */ |
| 112 | /* #define OS_ERR_NO_MACRO */ |
| 113 | |
| 114 | /* |
| 115 | * If error messages are to be included in the executable, define |
| 116 | * OS_ERR_LINK_MESSAGES. Otherwise, they'll be read from an external |
| 117 | * file that is to be opened with oserrop(). |
| 118 | */ |
| 119 | #define OS_ERR_LINK_MESSAGES |
| 120 | #define ERR_LINK_MESSAGES |
| 121 | |
| 122 | /* round a size to worst-case alignment boundary */ |
| 123 | #define osrndsz(s) (((s)+3) & ~3) |
| 124 | |
| 125 | /* round a pointer to worst-case alignment boundary */ |
| 126 | #define osrndpt(p) ((uchar *)((((ulong)(p)) + 3) & ~3)) |
| 127 | |
| 128 | /* service macros for osrp2 etc. */ |
| 129 | #define osc2u(p, i) ((uint)(((uchar *)(p))[i])) |
| 130 | #define osc2l(p, i) ((ulong)(((uchar *)(p))[i])) |
| 131 | |
| 132 | /* |
| 133 | * The portable representation is little-endian, like x86s, so under |
| 134 | * BeOS x86 these are simple macros |
| 135 | */ |
| 136 | |
| 137 | /* read unaligned portable unsigned 2-byte value, returning int */ |
| 138 | #define osrp2(p) ((int)*(unsigned short *)(p)) |
| 139 | |
| 140 | /* read unaligned portable signed 2-byte value, returning int */ |
| 141 | #define osrp2s(p) ((int)*(short *)(p)) |
| 142 | |
| 143 | /* write int to unaligned portable 2-byte value */ |
| 144 | #define oswp2(p, i) (*(unsigned short *)(p)=(unsigned short)(i)) |
| 145 | |
| 146 | /* read unaligned portable 4-byte value, returning long */ |
| 147 | #define osrp4(p) (*(long *)(p)) |
| 148 | |
| 149 | /* write long to unaligned portable 4-byte value */ |
| 150 | #define oswp4(p, l) (*(long *)(p)=(l)) |
| 151 | |
| 152 | /* use standard malloc/free/realloc functions */ |
| 153 | #define osmalloc malloc |
| 154 | #define osfree free |
| 155 | #define osrealloc realloc |
| 156 | |
| 157 | /* copy a structure - dst and src are structures, not pointers */ |
| 158 | #define OSCPYSTRUCT(dst, src) ((dst) = (src)) |
| 159 | |
| 160 | /* maximum length of a filename */ |
| 161 | #define OSFNMAX NAME_MAX |
| 162 | |
| 163 | /* path separator characters */ |
| 164 | #define OSPATHCHAR '/' |
| 165 | #define OSPATHALT "/" |
| 166 | #define OSPATHSEP ':' |
| 167 | #define OSPATHURL "/" |
| 168 | |
| 169 | /* os file structure */ |
| 170 | typedef FILE osfildef; |
| 171 | |
| 172 | /* os file time structure */ |
| 173 | struct os_file_time_t |
| 174 | { |
| 175 | time_t t; |
| 176 | }; |
| 177 | |
| 178 | /* main program exit codes */ |
| 179 | #define OSEXSUCC 0 /* successful completion */ |
| 180 | #define OSEXFAIL 1 /* error occurred */ |
| 181 | |
| 182 | /* open text file for reading; returns NULL on error */ |
| 183 | /* osfildef *osfoprt(char *fname, int typ); */ |
| 184 | #define osfoprt(fname, typ) fopen(fname, "r") |
| 185 | |
| 186 | /* open text file for reading in volatile ('deny none') mode */ |
| 187 | /* osfildef *osfoprtv(char *fname, int typ); */ |
| 188 | #define osfoprtv(fname, typ) osfoprt(fname, typ) |
| 189 | |
| 190 | /* open text file for writing; returns NULL on error */ |
| 191 | /* osfildef *osfopwt(char *fname, int typ); */ |
| 192 | #define osfopwt(fname, typ) fopen(fname, "w") |
| 193 | |
| 194 | /* open text file for reading/writing; don't truncate */ |
| 195 | osfildef *osfoprwt(const char *fname, os_filetype_t typ); |
| 196 | |
| 197 | /* open text file for reading/writing; truncate; returns NULL on error */ |
| 198 | /* osfildef *osfoprwtt(char *fname, int typ); */ |
| 199 | #define osfoprwtt(fname, typ) fopen(fname, "w+") |
| 200 | |
| 201 | /* open binary file for writing; returns NULL on error */ |
| 202 | /* osfildef *osfopwb(char *fname, int typ); */ |
| 203 | #define osfopwb(fname, typ) fopen(fname, "wb") |
| 204 | |
| 205 | /* open source file for reading */ |
| 206 | /* osfildef *osfoprs(char *fname, int typ); */ |
| 207 | #define osfoprs(fname, typ) osfoprt(fname, typ) |
| 208 | |
| 209 | /* open binary file for reading; returns NULL on erorr */ |
| 210 | /* osfildef *osfoprb(char *fname, int typ); */ |
| 211 | #define osfoprb(fname, typ) fopen(fname, "rb") |
| 212 | |
| 213 | /* open binary file for 'volatile' reading; returns NULL on erorr */ |
| 214 | /* osfildef *osfoprbv(char *fname, int typ); */ |
| 215 | #define osfoprbv(fname, typ) osfoprb(fname, typ) |
| 216 | |
| 217 | /* get a line of text from a text file (fgets semantics) */ |
| 218 | /* char *osfgets(char *buf, size_t len, osfildef *fp); */ |
| 219 | #define osfgets(buf, len, fp) fgets(buf, len, fp) |
| 220 | |
| 221 | /* open binary file for reading/writing; don't truncate */ |
| 222 | osfildef *osfoprwb(const char *fname, os_filetype_t typ); |
| 223 | |
| 224 | /* open binary file for reading/writing; truncate; returns NULL on error */ |
| 225 | /* osfildef *osfoprwtb(char *fname, int typ); */ |
| 226 | #define osfoprwtb(fname, typ) fopen(fname, "w+b") |
| 227 | |
| 228 | /* write bytes to file; TRUE ==> error */ |
| 229 | /* int osfwb(osfildef *fp, uchar *buf, int bufl); */ |
| 230 | #define osfwb(fp, buf, bufl) (fwrite(buf, bufl, 1, fp) != 1) |
| 231 | |
| 232 | /* flush buffers; TRUE ==> error */ |
| 233 | /* void osfflush(osfildef *fp); */ |
| 234 | #define osfflush(fp) fflush(fp) |
| 235 | |
| 236 | /* read bytes from file; TRUE ==> error */ |
| 237 | /* int osfrb(osfildef *fp, uchar *buf, int bufl); */ |
| 238 | #define osfrb(fp, buf, bufl) (fread(buf, bufl, 1, fp) != 1) |
| 239 | |
| 240 | /* read bytes from file and return count; returns # bytes read, 0=error */ |
| 241 | /* size_t osfrbc(osfildef *fp, uchar *buf, size_t bufl); */ |
| 242 | #define osfrbc(fp, buf, bufl) (fread(buf, 1, bufl, fp)) |
| 243 | |
| 244 | /* get position in file */ |
| 245 | /* long osfpos(osfildef *fp); */ |
| 246 | #define osfpos(fp) ftell(fp) |
| 247 | |
| 248 | /* seek position in file; TRUE ==> error */ |
| 249 | /* int osfseek(osfildef *fp, long pos, int mode); */ |
| 250 | #define osfseek(fp, pos, mode) fseek(fp, pos, mode) |
| 251 | #define OSFSK_SET SEEK_SET |
| 252 | #define OSFSK_CUR SEEK_CUR |
| 253 | #define OSFSK_END SEEK_END |
| 254 | |
| 255 | /* close a file */ |
| 256 | /* void osfcls(osfildef *fp); */ |
| 257 | #define osfcls(fp) fclose(fp) |
| 258 | |
| 259 | /* delete a file - TRUE if error */ |
| 260 | /* int osfdel(char *fname); */ |
| 261 | #define osfdel(fname) remove(fname) |
| 262 | |
| 263 | /* access a file - 0 if file exists */ |
| 264 | /* int osfacc(char *fname) */ |
| 265 | #define osfacc(fname) access(fname, 0) |
| 266 | |
| 267 | /* get a character from a file */ |
| 268 | /* int osfgetc(osfildef *fp); */ |
| 269 | #define osfgetc(fp) fgetc(fp) |
| 270 | |
| 271 | /* write a string to a file */ |
| 272 | /* void osfputs(char *buf, osfildef *fp); */ |
| 273 | #define osfputs(buf, fp) fputs(buf, fp) |
| 274 | |
| 275 | |
| 276 | /* ignore OS_LOADDS definitions */ |
| 277 | # define OS_LOADDS |
| 278 | |
| 279 | /* Show cursor as busy */ |
| 280 | #define os_csr_busy(show_as_busy) |
| 281 | |
| 282 | /* yield CPU; returns TRUE if user requested interrupt, FALSE to continue */ |
| 283 | #define os_yield() FALSE |
| 284 | |
| 285 | /* update progress display with current info, if appropriate */ |
| 286 | #define os_progress(fname, linenum) |
| 287 | |
| 288 | #define os_tzset() |
| 289 | |
| 290 | /* |
| 291 | * Single/double quote matching macros. Used to allow systems with |
| 292 | * extended character codes with weird quote characters (such as Mac) to |
| 293 | * match the weird characters. |
| 294 | */ |
| 295 | #define os_squote(c) ((c) == '\'') |
| 296 | #define os_dquote(c) ((c) == '"') |
| 297 | #define os_qmatch(a, b) ((a) == (b)) |
| 298 | |
| 299 | /* |
| 300 | * Options for this operating system |
| 301 | */ |
| 302 | # define USE_MORE /* assume more-mode is desired (undef if not true) */ |
| 303 | /* # define USEDOSCOMMON */ |
| 304 | /* # define USE_OVWCHK */ |
| 305 | /* # define USE_DOSEXT */ |
| 306 | # define USE_NULLPAUSE |
| 307 | # define USE_TIMERAND |
| 308 | # define USE_NULLSTYPE |
| 309 | # define USE_PATHSEARCH |
| 310 | # define STD_OS_HILITE |
| 311 | # define STD_OSCLS |
| 312 | |
| 313 | |
| 314 | /* |
| 315 | * Turning this off will enable termcap output. |
| 316 | */ |
| 317 | /* #define USE_STDIO */ |
| 318 | |
| 319 | #define USE_STDIO_INPDLG |
| 320 | |
| 321 | #ifdef USE_STDIO |
| 322 | /* # define USE_NULLINIT */ |
| 323 | # define USE_NULLSTAT |
| 324 | # define USE_NULLSCORE |
| 325 | #else /* USE_STDIO */ |
| 326 | # define RUNTIME |
| 327 | # define USE_FSDBUG |
| 328 | # define USE_STATLINE |
| 329 | # define USE_HISTORY |
| 330 | # define USE_SCROLLBACK |
| 331 | #endif |
| 332 | |
| 333 | # ifdef USE_SCROLLBACK |
| 334 | # define OS_SBSTAT "(Review Mode) ^P=Up ^N=Down <=Page Up \ |
| 335 | >=Page Down Esc=Exit" |
| 336 | # endif /* USE_SCROLLBACK */ |
| 337 | |
| 338 | # ifdef USE_HISTORY |
| 339 | # define HISTBUFSIZE 4096 |
| 340 | # endif /* USE_HISTORY */ |
| 341 | |
| 342 | /* |
| 343 | * Some global variables needed for console implementation |
| 344 | */ |
| 345 | # ifdef OSGEN_INIT |
| 346 | # define E |
| 347 | # define I(a) =(a) |
| 348 | # else /* OSGEN_INIT */ |
| 349 | # define E extern |
| 350 | # define I(a) |
| 351 | # endif /* OSGEN_INIT */ |
| 352 | |
| 353 | E int status_mode; |
| 354 | E int score_column I(70); |
| 355 | E int sdesc_line I(0), sdesc_column I(0), sdesc_color I(23); |
| 356 | E int ldesc_line I(1), ldesc_column I(0), ldesc_color I(112); |
| 357 | E int debug_color I(0xe); |
| 358 | |
| 359 | E int text_line I(1); |
| 360 | E int text_column I(0); |
| 361 | E int text_color I(7), text_bold_color I(15), text_normal_color I(7); |
| 362 | E int max_line I(24), max_column I(79); |
| 363 | E int ldesc_curline; |
| 364 | E int text_lastcol; |
| 365 | |
| 366 | # undef E |
| 367 | # undef I |
| 368 | |
| 369 | /* BeOS R5 doesn't provide the proper wcs*() functions, so we do here */ |
| 370 | wchar_t* wcscpy(wchar_t* dest, const wchar_t* src); |
| 371 | size_t wcslen(const wchar_t* str); |
| 372 | long wcstol(const wchar_t* str, wchar_t** endptr, int base); |
| 373 | |
| 374 | #ifdef __cplusplus |
| 375 | } |
| 376 | #endif |
| 377 | |
| 378 | #endif /* OSUNIXT_INCLUDED */ |