1 /* Copyright (c) 1992, 2002 Michael J. Roberts. All Rights Reserved. */ 2 /* 3 Name 4 osunixt.h - operating system definitions for Unix-like system with 5 termcap/termio capability 6 Function 7 Definitions that vary by operating system 8 Notes 9 None 10 Modified 11 Sun Jan 24 13:10:10 EST 1993 Dave Baggett Created. 12 Thu Apr 22 01:38:20 EDT 1993 Dave Baggett Incorporated NeXT, Linux, 13 DJGCC_386, etc. changes. 14 Sat Jan 29 10:49:25 EST 1994 Dave Baggett Updated for TADS 2.1.2.2 15 Fri Aug 26 14:47:38 EDT 1994 Dave Baggett Updated for TADS 2.2.0.0 16 Sun Sep 25 13:43:28 EDT 1994 Dave Baggett Updated for TADS 2.2.0.2 17 Tue Nov 22 15:16:10 EST 1994 Dave Baggett Updated for TADS 2.2.0.5 18 */ 19 20 #ifndef OSUNIXT_INCLUDED 21 #define OSUNIXT_INCLUDED 22 23 #include <time.h> 24 25 26 /* Use UNIXPATCHLEVEL, as defined in the makefile, for the port patch level */ 27 #define TADS_OEM_VERSION UNIXPATCHLEVEL 28 29 /* Use SYSPL, as defined in the makefile, for the patch sub-level */ 30 #define OS_SYSTEM_PATCHSUBLVL SYSPL 31 32 /* Use PORTER, from the makefile, for the OEM maintainer name */ 33 #define TADS_OEM_NAME PORTER 34 35 /* Use SYSNAME, as defined in the makefile, for the system's banner ID */ 36 #define OS_SYSTEM_LDESC SYSNAME 37 38 /* 39 * Define a startup message for the debugger warning that the debugger 40 * only works in 80x50 windows 41 */ 42 #define OS_TDB_STARTUP_MSG \ 43 "NOTE: This program must be run in a 80x50 character window.\n" 44 45 46 /* maximum width (in characters) of a line of text */ 47 #define OS_MAXWIDTH 255 48 49 /* 50 * Make default buffer sizes huge. (Why not? We have virtual memory.) 51 */ 52 #include "osbigmem.h" 53 54 /* 55 * Swapping off by default, since Unix machines tend to be big compared 56 * to adventure games 57 */ 58 #define OS_DEFAULT_SWAP_ENABLED 0 59 60 /* 61 * Usage lines - we use non-default names for the executables on Unix, 62 * so we need to adjust the usage lines accordingly. 63 */ 64 # define OS_TC_USAGE "usage: tadsc [options] file" 65 # define OS_TR_USGAE "usage: tadsr [options] file" 66 67 68 /* 69 * Get GCC varags defs 70 */ 71 72 #if !defined(IBM_RT) 73 #define USE_STDARG 74 #define USE_GCC_STDARG 75 #endif 76 77 #if defined(__STDC__) || defined(ULTRIX_MIPS) || defined(SGI_IRIX) || defined(NEXT) || defined(DJGCC_386) || defined(IBM_AIX) 78 #include <stdarg.h> /* get native stdargs */ 79 #else 80 #include "gccstdar.h" /* get GCC stdargs */ 81 #endif 82 83 /* 84 * Define the following to use sgtty.h instead of termios or direct 85 * ioctl hacking. 86 */ 87 #if defined(NEXT) || defined(IBM_RT) || defined(IBM_AIX) || defined(NETBSD) || defined(OPENBSD) || defined(DARWIN) 88 #define USE_IOCTL_INSTEAD_OF_TERMIOS 89 #define USE_SGTTY 90 #endif 91 92 #if !defined(SUN_SPARC_SUNOS) && !defined(SUN3) && !defined(ULTRIX_MIPS) && !defined(LINUX_386) && !defined(NEXT) && !defined(IBM_RT) && !defined(IBM_AIX) 93 #define HAVE_TPARM /* define if this system has the tparm routine */ 94 #endif 95 96 #if defined(SUN_SPARC_SUNOS) || defined(SUN_SPARC_SOLARIS) || defined(SUN3) || defined(SGI_IRIX) || defined(LINUX_386) || defined(IBM_RT) || defined(FREEBSD_386) || defined(IBM_AIX) || defined(NETBSD) || defined(OPENBSD) || defined(DARWIN) 97 #define OS_USHORT_DEFINED 98 #endif 99 100 #if defined(SUN_SPARC_SUNOS) || defined(SUN_SPARC_SOLARIS) || defined(SUN3) || defined(SGI_IRIX) || defined(LINUX_386) || defined(FREEBSD_386) || defined(IBM_AIX) || defined(NETBSD) || defined(OPENBSD) || defined(DARWIN) 101 #define OS_UINT_DEFINED 102 #endif 103 104 #if defined(SGI_IRIX) || defined(LINUX_386) || defined(SUN_SPARC_SOLARIS) || defined(IBM_AIX) || defined(NETBSD) || defined(OPENBSD) 105 #define OS_ULONG_DEFINED 106 #endif 107 108 #if defined(SGI_IRIX) || defined(LINUX_386) || defined(IBM_AIX) || defined(FREEBSD_386) 109 #define TERMIOS_IS_NOT_IN_SYS 110 #endif 111 112 #define remove(filename) unlink(filename) 113 114 /* 115 * Some systems have stricmp; some have strcasecmp 116 */ 117 #ifdef HAVE_STRCASECMP 118 #define strnicmp strncasecmp 119 #define stricmp strcasecmp 120 #endif 121 122 123 /* far pointer type qualifier (null on most platforms) */ 124 # define osfar_t 125 126 /* maximum theoretical size of malloc argument */ 127 # define OSMALMAX ((size_t)0xffffffff) 128 129 /* cast an expression to void */ 130 # define DISCARD (void) 131 132 #if !defined(IBM_RT) 133 #include <stdlib.h> 134 #endif 135 #include <stdio.h> 136 #if !defined(NEXT) && !defined(IBM_RT) 137 #include <unistd.h> 138 #endif 139 #if !defined(IBM_RT) 140 #include <memory.h> 141 #endif 142 143 #if defined(IBM_RT) 144 #define SEEK_SET 0 145 #define SEEK_CUR 1 146 #define SEEK_END 2 147 #endif 148 149 /* 150 * Need to strip off b's from fopen calls. 151 * 152 * (DBJ: changed so that this is only done for non-standard compilers) 153 */ 154 #if !defined(__STDC__) 155 FILE* our_fopen(char *filename, char *flags); 156 #define fopen our_fopen 157 #endif 158 159 /* 160 * Some machines are missing memmove, so we use our own memcpy/memmove 161 * routine instead. 162 */ 163 void *our_memcpy(void *dst, const void *src, size_t size); 164 #define memcpy our_memcpy 165 #define memmove our_memcpy 166 167 /* display lines on which errors occur */ 168 /* # define OS_ERRLINE 1 */ 169 170 /* 171 * If long cache-manager macros are NOT allowed, define 172 * OS_MCM_NO_MACRO. This forces certain cache manager operations to be 173 * functions, which results in substantial memory savings. 174 */ 175 /* #define OS_MCM_NO_MACRO */ 176 177 /* likewise for the error handling subsystem */ 178 /* #define OS_ERR_NO_MACRO */ 179 180 /* 181 * If error messages are to be included in the executable, define 182 * OS_ERR_LINK_MESSAGES. Otherwise, they'll be read from an external 183 * file that is to be opened with oserrop(). 184 */ 185 #define OS_ERR_LINK_MESSAGES 186 #define ERR_LINK_MESSAGES 187 188 /* round a size to worst-case alignment boundary */ 189 #define osrndsz(s) (((s)+3) & ~3) 190 191 /* round a pointer to worst-case alignment boundary */ 192 #define osrndpt(p) ((uchar *)((((ulong)(p)) + 3) & ~3)) 193 194 #if defined(DJGCC_386) 195 /* DBJ: maybe this should be a test for endian-ness, not for a 196 * very rare compiler. 197 */ 198 199 /* read unaligned portable 2-byte value, returning int */ 200 #define osrp2(p) (*(unsigned short *)(p)) 201 202 /* read unaligned portable signed 2-byte value, returning int */ 203 #define osrp2s(p) ((int)*(short *)(p)) 204 205 /* write int to unaligned portable 2-byte value */ 206 #define oswp2(p, i) (*(unsigned short *)(p)=(i)) 207 208 /* read unaligned portable 4-byte value, returning long */ 209 #define osrp4(p) (*(long *)(p)) 210 211 /* write long to unaligned portable 4-byte value */ 212 #define oswp4(p, l) (*(long *)(p)=(l)) 213 214 #else /* defined(DJGCC_386) */ 215 216 /* service macros for osrp2 etc. */ 217 #define osc2u(p, i) ((uint)(((uchar *)(p))[i])) 218 #define osc2l(p, i) ((ulong)(((uchar *)(p))[i])) 219 220 /* read unaligned portable 2-byte value, returning int */ 221 #define osrp2(p) (osc2u(p, 0) + (osc2u(p, 1) << 8)) 222 223 /* read unaligned portable 2-byte signed value, returning int */ 224 #define osrp2s(p) \ 225 (((int)(short)osc2u(p, 0)) + ((int)(short)(osc2u(p, 1) << 8))) 226 227 /* write int to unaligned portable 2-byte value */ 228 #define oswp2(p, i) ((((uchar *)(p))[1] = (i)>>8), (((uchar *)(p))[0] = (i)&255)) 229 230 /* read unaligned portable 4-byte value, returning long */ 231 #define osrp4(p) \ 232 (osc2l(p, 0) + (osc2l(p, 1) << 8) + (osc2l(p, 2) << 16) + (osc2l(p, 3) << 24)) 233 234 /* write long to unaligned portable 4-byte value */ 235 #define oswp4(p, i) \ 236 ((((uchar *)(p))[0] = (i)), (((uchar *)(p))[1] = (i)>>8),\ 237 (((uchar *)(p))[2] = (i)>>16, (((uchar *)(p))[3] = (i)>>24))) 238 239 #endif /* defined(DJGCC_386) */ 240 241 /* allocate storage - malloc where supported */ 242 /* void *osmalloc(size_t siz); */ 243 #define osmalloc malloc 244 245 /* free storage allocated with osmalloc */ 246 /* void osfree(void *block); */ 247 #define osfree free 248 249 /* reallocate storage */ 250 void *osrealloc(void *buf, size_t len); 251 252 /* copy a structure - dst and src are structures, not pointers */ 253 #define OSCPYSTRUCT(dst, src) ((dst) = (src)) 254 255 /* maximum length of a filename */ 256 #define OSFNMAX 1024 257 258 /* normal path separator character */ 259 #define OSPATHCHAR '/' 260 261 /* alternate path separator characters */ 262 #define OSPATHALT "/" 263 264 /* URL path separator */ 265 #define OSPATHURL "/" 266 267 /* character to separate paths from one another */ 268 #define OSPATHSEP ':' 269 270 /* os file structure */ 271 typedef FILE osfildef; 272 273 /* os file time structure */ 274 struct os_file_time_t 275 { 276 time_t t; 277 }; 278 279 /* main program exit codes */ 280 #define OSEXSUCC 0 /* successful completion */ 281 #define OSEXFAIL 1 /* error occurred */ 282 283 /* open text file for reading; returns NULL on error */ 284 /* osfildef *osfoprt(char *fname, int typ); */ 285 #define osfoprt(fname, typ) fopen(fname, "r") 286 287 /* open text file for writing; returns NULL on error */ 288 /* osfildef *osfopwt(char *fname, int typ); */ 289 #define osfopwt(fname, typ) fopen(fname, "w") 290 291 /* open text file for reading/writing; don't truncate */ 292 osfildef *osfoprwt(const char *fname, os_filetype_t typ); 293 294 /* open text file for reading/writing; truncate; returns NULL on error */ 295 /* osfildef *osfoprwtt(char *fname, int typ); */ 296 #define osfoprwtt(fname, typ) fopen(fname, "w+") 297 298 /* open binary file for writing; returns NULL on error */ 299 /* osfildef *osfopwb(char *fname, int typ); */ 300 #define osfopwb(fname, typ) fopen(fname, "wb") 301 302 /* open source file for reading */ 303 /* osfildef *osfoprs(char *fname, int typ); */ 304 #define osfoprs(fname, typ) osfoprt(fname, typ) 305 306 /* open binary file for reading; returns NULL on erorr */ 307 /* osfildef *osfoprb(char *fname, int typ); */ 308 #define osfoprb(fname, typ) fopen(fname, "rb") 309 310 /* get a line of text from a text file (fgets semantics) */ 311 /* char *osfgets(char *buf, size_t len, osfildef *fp); */ 312 #define osfgets(buf, len, fp) fgets(buf, len, fp) 313 314 /* open binary file for reading/writing; don't truncate */ 315 osfildef *osfoprwb(const char *fname, os_filetype_t typ); 316 317 /* open binary file for reading/writing; truncate; returns NULL on error */ 318 /* osfildef *osfoprwb(char *fname, int typ); */ 319 #define osfoprwtb(fname, typ) fopen(fname, "w+b") 320 321 /* write bytes to file; TRUE ==> error */ 322 /* int osfwb(osfildef *fp, uchar *buf, int bufl); */ 323 #define osfwb(fp, buf, bufl) (fwrite(buf, bufl, 1, fp) != 1) 324 325 /* read bytes from file; TRUE ==> error */ 326 /* int osfrb(osfildef *fp, uchar *buf, int bufl); */ 327 #define osfrb(fp, buf, bufl) (fread(buf, bufl, 1, fp) != 1) 328 329 /* read bytes from file and return count; returns # bytes read, 0=error */ 330 /* size_t osfrbc(osfildef *fp, uchar *buf, size_t bufl); */ 331 #define osfrbc(fp, buf, bufl) (fread(buf, 1, bufl, fp)) 332 333 /* get position in file */ 334 /* long osfpos(osfildef *fp); */ 335 #define osfpos(fp) ftell(fp) 336 337 /* seek position in file; TRUE ==> error */ 338 /* int osfseek(osfildef *fp, long pos, int mode); */ 339 #define osfseek(fp, pos, mode) fseek(fp, pos, mode) 340 #define OSFSK_SET SEEK_SET 341 #define OSFSK_CUR SEEK_CUR 342 #define OSFSK_END SEEK_END 343 344 /* close a file */ 345 /* void osfcls(osfildef *fp); */ 346 #define osfcls(fp) fclose(fp) 347 348 /* delete a file - TRUE if error */ 349 /* int osfdel(char *fname); */ 350 #define osfdel(fname) remove(fname) 351 352 /* access a file - 0 if file exists */ 353 /* int osfacc(char *fname) */ 354 #define osfacc(fname) access(fname, 0) 355 356 /* get a character from a file */ 357 /* int osfgetc(osfildef *fp); */ 358 #define osfgetc(fp) fgetc(fp) 359 360 /* write a string to a file */ 361 /* void osfputs(char *buf, osfildef *fp); */ 362 #define osfputs(buf, fp) fputs(buf, fp) 363 364 365 /* ignore OS_LOADDS definitions */ 366 # define OS_LOADDS 367 368 /* Show cursor as busy */ 369 #define os_csr_busy(show_as_busy) 370 371 /* yield CPU; returns TRUE if user requested interrupt, FALSE to continue */ 372 #define os_yield() FALSE 373 374 /* update progress display with current info, if appropriate */ 375 #define os_progress(fname, linenum) 376 377 #define os_tzset() 378 379 /* 380 * Single/double quote matching macros. Used to allow systems with 381 * extended character codes with weird quote characters (such as Mac) to 382 * match the weird characters. 383 */ 384 #define os_squote(c) ((c) == '\'') 385 #define os_dquote(c) ((c) == '"') 386 #define os_qmatch(a, b) ((a) == (b)) 387 388 /* 389 * Options for this operating system 390 */ 391 # define USE_MORE /* assume more-mode is desired (undef if not true) */ 392 /* # define USEDOSCOMMON */ 393 /* # define USE_OVWCHK */ 394 /* # define USE_DOSEXT */ 395 # define USE_NULLPAUSE 396 # define USE_TIMERAND 397 # define USE_NULLSTYPE 398 # define USE_PATHSEARCH 399 # define STD_OS_HILITE 400 # define STD_OSCLS 401 402 403 /* 404 * Turning this off will enable termcap output. 405 */ 406 /* #define USE_STDIO */ 407 408 #define USE_STDIO_INPDLG 409 410 #ifdef USE_STDIO 411 /* # define USE_NULLINIT */ 412 # define USE_NULLSTAT 413 # define USE_NULLSCORE 414 #else /* USE_STDIO */ 415 # define RUNTIME 416 # define USE_FSDBUG 417 # define USE_STATLINE 418 # define USE_HISTORY 419 # define USE_SCROLLBACK 420 #endif 421 422 # ifdef USE_SCROLLBACK 423 # define OS_SBSTAT "(Review Mode) ^P=Up ^N=Down <=Page Up \ 424 >=Page Down Esc=Exit" 425 # endif /* USE_SCROLLBACK */ 426 427 # ifdef USE_HISTORY 428 # define HISTBUFSIZE 4096 429 # endif /* USE_HISTORY */ 430 431 /* 432 * Some global variables needed for console implementation 433 */ 434 # ifdef OSGEN_INIT 435 # define E 436 # define I(a) =(a) 437 # else /* OSGEN_INIT */ 438 # define E extern 439 # define I(a) 440 # endif /* OSGEN_INIT */ 441 442 E int status_mode; 443 E int sdesc_color I(23); 444 E int ldesc_color I(112); 445 E int debug_color I(0xe); 446 447 E int text_color I(7), text_bold_color I(15), text_normal_color I(7); 448 449 # ifdef USE_GRAPH 450 void ossdsp(); 451 E void (*os_dspptr)() I(ossdsp); 452 # define ossdsp (*os_dspptr) 453 # endif /* USE_GRAPH */ 454 455 # undef E 456 # undef I 457 458 #endif /* OSUNIXT_INCLUDED */ 459