Debian Codegraph @

terps/tads/tads2/msdos/osdosbas.h

raw symbols SCIP
1 /* $Header: d:/cvsroot/tads/TADS2/msdos/OSDOSBAS.H,v 1.4 1999/07/11 00:46:37 MJRoberts Exp $ */
2
3 /*
4 * Copyright (c) 1998, 2002 Michael J. Roberts. All Rights Reserved.
5 *
6 * Please see the accompanying license file, LICENSE.TXT, for information
7 * on using and copying this software.
8 */
9 /*
10 Name
11 osdosbas.h - DOS Base definitions
12 Function
13 These definitions apply to DOS, Windows, and OS/2.
14 Notes
15
16 Modified
17 10/17/98 MJRoberts - Creation
18 */
19
20 #ifndef OSDOSBAS_H
21 #define OSDOSBAS_H
22
23 #include <time.h>
24 #include <stdarg.h>
25 #include <io.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <stddef.h>
29 #include <sys/stat.h>
30 #ifdef TURBO
31 # include <conio.h>
32 #endif
33 #ifdef DJGPP
34 # include <dir.h>
35 # include <unistd.h>
36 # include <sys/stat.h>
37 #endif
38
39 /* ------------------------------------------------------------------------ */
40 /*
41 * Define the maintainer for this platform
42 */
43 #define TADS_OEM_NAME "Mike Roberts <[email protected]>"
44
45 /* ------------------------------------------------------------------------ */
46 /*
47 * For the Microsoft compiler, turn on error C4057 ("type1 differs in
48 * indirection to slightly different base types from type2"), which
49 * catches implicit conversions of pointers from signed to unsigned
50 * types and vice versa. The Microsoft compiler does not by default
51 * flag this condition as an error or warning, whereas many compilers on
52 * other platforms do. We must thus explicitly enable this warning to
53 * catch these with the Microsoft compiler. We turn on the error so
54 * that we catch these types of errors before anyone tries to port the
55 * code to a platform with a stricter compiler.
56 *
57 * To enable the error, use the warning pragma to assign warning level 2
58 * to message 4057. This warning normally has warning level 4, which is
59 * far too pedantic to use globally (the biggest problem is that many of
60 * the system headers generate tons of warnings at this level); by
61 * moving the message to level 2, we will ensure that we see this
62 * warning, without having to see all of the excessively pedantic
63 * warnings at level 4.
64 */
65 #ifdef MICROSOFT
66 # pragma warning(2: 4057)
67 #endif
68
69 /* ------------------------------------------------------------------------ */
70 /*
71 * For the Microsoft compiler, fill out case tables fully where 'switch'
72 * performance is critical.
73 *
74 * Use the Microsoft-specific "__assume(0)" construct in the 'default' case
75 * to tell the compiler to assume that case tables are fully populated.
76 */
77 #ifdef MICROSOFT
78 # define OS_FILL_OUT_CASE_TABLES
79 # define OS_IMPOSSIBLE_DEFAULT_CASE default: __assume(0);
80 #endif
81
82 /* ------------------------------------------------------------------------ */
83 /*
84 * If TRUE and FALSE aren't defined, define them now
85 */
86 #ifndef TRUE
87 # define TRUE 1
88 #endif
89 #ifndef FALSE
90 # define FALSE 0
91 #endif
92
93 /* ------------------------------------------------------------------------ */
94 /*
95 * Define the exact-size integer types.
96 */
97
98 #if defined(MICROSOFT) || defined(_MSC_VER)
99 /*
100 * Older Microsoft compilers don't provide <stdint.h> with the ANSI type
101 * definitions, but they do have built-in equivalents of their own.
102 */
103 typedef __int16 int16_t;
104 typedef unsigned __int16 uint16_t;
105 typedef __int32 int32_t;
106 typedef unsigned __int32 uint32_t;
107 typedef __int64 int64_t;
108 typedef unsigned __int64 uint64_t;
109 #endif /* MICROSOFT */
110
111 #if defined(TURBO) || defined(DJGPP)
112 /*
113 * Borland C doesn't have stdint.h equivalents, but since it only has a
114 * 32-bit configuration, we know that 'short' is 16 bits and 'long' is 32
115 * bits. The same goes for djgpp.
116 */
117 typedef short int16_t;
118 typedef unsigned short uint16_t;
119 typedef long int32_t;
120 typedef unsigned long uint32_t;
121 #endif /* TURBO || DJGPP */
122
123 #ifdef DJGPP
124 typedef long long int64_t;
125 typedef unsigned long long uint64_t;
126 #endif
127
128 /* ------------------------------------------------------------------------ */
129 /*
130 * osgen configuration options for this operating system. These
131 * determine which routines from osgen are included. Routines from
132 * osgen can be omitted by turning off various of these symbols, if the
133 * OS wants to provide its own more custom definition for the routine.
134 */
135 #define STD_OSCLS
136 #define STD_OS_HILITE
137 #define USEDOSCOMMON
138 #define USE_OVWCHK
139 #define USE_DOSEXT
140 #define USE_NULLPAUSE
141 #define USE_TIMERAND
142 #define USE_NULLSTYPE
143 #define USE_PATHSEARCH /* use search paths for tads files */
144 #define USE_STDARG
145
146 #if defined(TURBO) || defined(DJGPP)
147 #define USE_GENRAND
148 #endif
149
150
151 /* ------------------------------------------------------------------------ */
152 /*
153 * os_va_copy - on Intel platforms, va_list is a simple pointer type, so
154 * this can be handled with a simple assignment. Don't define this for
155 * DJGPP, since we can use the compiler-provided va_copy instead (which
156 * we'll do in osifc.h).
157 */
158 #ifndef DJGPP
159 # define os_va_copy(dst, src) ((dst) = (src))
160 # define os_va_copy_end(dst)
161 #endif
162
163 /* ------------------------------------------------------------------------ */
164 /*
165 * Display configuration. For HTML TADS builds, use OS-level line wrapping
166 * and MORE mode; for text-only builds, use formatter-level line wrapping
167 * and MORE mode.
168 */
169 #ifdef USE_HTML
170 # define USE_OS_LINEWRAP /* HTML mode - use OS-level wrapping and MORE mode */
171 #else
172 # define USE_MORE /* text-only - use formatter-level wrapping and MORE mode */
173 #endif
174
175 /* maximum width (in characters) of a line of text */
176 #define OS_MAXWIDTH 135
177
178 #ifdef RUNTIME
179 # define USE_STDIO_INPDLG
180 # define USE_FSDBUG /* full-screen debug mode */
181 # define USE_STATLINE
182 # define USE_HISTORY
183 # define USE_SCROLLBACK
184
185 # ifdef USE_SCROLLBACK
186 # define OS_SBSTAT "(Review Mode) \030=Up \031=Down PgUp=Page Up \
187 PgDn=Page Down F1=Exit"
188 # endif /* USE_SCROLLBACK */
189
190 # ifdef USE_HISTORY
191 # define HISTBUFSIZE 4096
192 # endif /* USE_HISTORY */
193
194 /*
195 * Some global variables needed for console implementation
196 */
197 # ifdef OSGEN_INIT
198 # define E
199 # define I(a) =(a)
200 # else /* OSGEN_INIT */
201 # define E extern
202 # define I(a)
203 # endif /* OSGEN_INIT */
204
205 E int status_mode;
206 E int ldesc_color I(112);
207 E int text_color I(0x17), text_bold_color I(0x1F), text_normal_color I(0x17);
208 E int sdesc_color I(0x70);
209 E int debug_color I(0xe);
210
211 # undef E
212 # undef I
213
214 #else /* RUNTIME */
215 # define USE_STDIO
216 # define USE_NULLSTAT
217 # define USE_NULLSCORE
218 #endif /* RUNTIME */
219
220
221 /* ------------------------------------------------------------------------ */
222 /*
223 * DOS-specific interfaces to low-level support routines
224 */
225 void oss_con_init(void);
226 void oss_con_uninit(void);
227 void ossgmx(int *max_line, int *max_column);
228 int ossmon(void);
229 void oss_win_resize_event(void);
230
231 /*
232 * low-level console character reader - DOS-specific interface
233 */
234 char os_getch(void);
235
236 /*
237 * Get a character from the keyboard with a timeout. The timeout is an
238 * interval in milliseconds; for example, a timeout of 1000 specifies
239 * that we should wait no more than one second for a character to be
240 * pressed.
241 *
242 * If a key is pressed before the timeout elapses, this should return
243 * OS_GETS_OK and put the character value in *ch. If the timeout elapses
244 * before a key is pressed, this returns OS_GETS_TIMEOUT. If an error
245 * occurs, this returns OS_GETS_EOF.
246 */
247 int oss_getc_timeout(unsigned char *ch, unsigned long timeout);
248
249 /* status codes for timeout-based input functions */
250 #define OS_GETS_OK 0
251 #define OS_GETS_EOF 1
252 #define OS_GETS_TIMEOUT 2
253
254
255 /* ------------------------------------------------------------------------ */
256 /*
257 * Far pointers - any 32-bit version (DPMI32, Win32) makes no
258 * distinction between near and far pointers. 16-bit platforms
259 * distinguish near and far pointers; define the type 'osfar_t' to 'far'
260 * on those platforms.
261 */
262
263 #if defined(__DPMI32__) || defined(T_WIN32) || defined(WIN32) || defined(DJGPP)
264 #define __32BIT__
265 #define osfar_t
266 #endif
267
268 #ifndef osfar_t
269 #define osfar_t far
270 #endif
271
272
273 /* ------------------------------------------------------------------------ */
274 /*
275 * OS_LOADDS - special function qualifier needed for certain types of
276 * callback functions.
277 */
278
279 /* define OS_LOADDS appropriately for the Microsoft compiler */
280 #ifdef MICROSOFT
281 # ifndef T_WIN32
282 # define OS_LOADDS _loadds
283 # endif /* T_WIN32 */
284 #endif /* MICROSOFT */
285
286 /* if OS_LOADDS isn't defined, define it to nothing */
287 #ifndef OS_LOADDS
288 # define OS_LOADDS
289 #endif
290
291
292 /* ------------------------------------------------------------------------ */
293 /*
294 * OS_DECL_TLS - special syntax for declaring a global variable using
295 * thread-local storage.
296 */
297 #if defined(MICROSOFT) || defined(TURBO) || defined(T_WIN32)
298 # define OS_DECLARATIVE_TLS
299 # define OS_DECL_TLS(typ, varname) __declspec(thread) typ varname
300 #endif
301 #if defined(DJGPP)
302 # define OS_DECLARATIVE_TLS
303 # define OS_DECL_TLS(typ, varname) __thread typ varname
304 #endif
305
306
307 /* ------------------------------------------------------------------------ */
308 /*
309 * General compiler configuration
310 */
311
312 /* void a return value */
313 #define DISCARD (void)
314
315 /* copy a structure - dst and src are structures, not pointers */
316 #define OSCPYSTRUCT(dst, src) ((dst) = (src))
317
318 /* ANSI compiler */
319 #define OSANSI
320
321
322 /* ------------------------------------------------------------------------ */
323 /*
324 * General operating system interfaces
325 */
326
327 /* allocate/release storage - malloc/free where supported */
328 /* void *osmalloc(size_t siz); */
329 /* void *osrealloc(void *block, size_t siz); */
330 /* void osfree(void *block); */
331
332 #if defined(_Windows) && !defined(__DPMI32__) && !defined(T_WIN32)
333
334 /*
335 * 16-bit Windows - use our ltk_ routines
336 */
337 #include "ltk.h"
338
339 void *ltk_alloc(size_t siz);
340 void ltk_free(void *blk);
341 # define osmalloc(siz) ltk_alloc(siz)
342 # define osfree(block) ltk_free(block)
343 # define osrealloc(ptr, siz) ltk_realloc(ptr, siz)
344
345 #else /* _Windows */
346
347 # ifdef T_WIN32
348 /*
349 * Win32 - we'll define our own routines that implement the memory
350 * management functions
351 */
352 # define osmalloc(siz) oss_win_malloc(siz)
353 # define osfree(ptr) oss_win_free(ptr)
354 # define osrealloc(ptr, siz) oss_win_realloc(ptr, siz)
355
356 /* our internal routines that implement osmalloc, etc */
357 void *oss_win_malloc(size_t siz);
358 void oss_win_free(void *ptr);
359 void *oss_win_realloc(void *ptr, size_t siz);
360
361 /* free all allocated memory blocks */
362 void oss_win_free_all();
363
364 /*
365 * notify oss_win that we've reached the program's main entrypoing; this
366 * detaches any existing memory allocations from the master deletion list,
367 * since anything allocated before 'main' must have been allocated by a C++
368 * static object constructor, and thus must not be considered dynamic
369 * memory to be deleted between interpreter invocations
370 */
371 void oss_win_static_init_done();
372
373 # else /* T_WIN32 */
374
375 /*
376 * For any other case, use the standard library malloc functions
377 */
378 # define osmalloc(siz) malloc(siz)
379 # define osfree(block) free(block)
380 # define osrealloc(ptr, siz) realloc(ptr, siz)
381
382 # endif /* T_WIN32 */
383 #endif /* _Windows */
384
385 /* main program exit codes */
386 #define OSEXSUCC 0 /* successful completion */
387 #define OSEXFAIL 1 /* error occurred */
388
389
390 /* ------------------------------------------------------------------------ */
391 /*
392 * File system interface
393 */
394
395 /* maximum length of a filename */
396 #ifdef _MAX_PATH
397 /* this is the Microsoft macro for the maximum length of a file path */
398 # define OSFNMAX _MAX_PATH
399 #else
400 /* this is the Borland macro for the maximum length of a file path */
401 # define OSFNMAX MAXPATH
402 #endif
403
404 /* normal path separator character */
405 #define OSPATHCHAR '\\'
406
407 /* alternate path separator characters */
408 #define OSPATHALT "/:"
409
410 /*
411 * URL path separators - do not include ":", since we don't want to convert
412 * this to a "/" in a URL
413 */
414 #define OSPATHURL "\\/"
415
416 /* directory separator character for PATH-style environment variables */
417 #define OSPATHSEP ';' /* ':' on UNIX */
418
419 /* current working directory */
420 #define OSPATHPWD "."
421
422
423 /*
424 * OS file structure type. All files are manipulated through pointers
425 * to this type.
426 */
427 typedef FILE osfildef;
428
429 /*
430 * Directory search handle, for os_open_dir() et al. The file search
431 * mechanism we use varies by compiler, so we'll define this as an opaque
432 * pointer type; the concrete implementations for the different compilers
433 * use this to point to appropriate structure types.
434 */
435 typedef void *osdirhdl_t;
436
437
438 #ifdef MICROSOFT
439 # define os_time_t __time64_t
440 # define os_gmtime(t) _gmtime64(t)
441 # define os_localtime(t) _localtime64(t)
442 # define os_time(t) _time64(t)
443 #else
444 /*
445 * OS file time structure
446 */
447 struct os_file_time_t
448 {
449 time_t t;
450 };
451 #endif
452
453
454 /* get a line of text from a text file (fgets semantics) */
455 /* char *osfgets(char *buf, size_t len, osfildef *fp); */
456 #define osfgets(buf, len, fp) fgets(buf, len, fp)
457
458 /* write a line of text to a text file (fputs semantics) */
459 /* void osfputs(const char *buf, osfildef *fp); */
460 #define osfputs(buf, fp) fputs(buf, fp)
461
462 /* write bytes to file; TRUE ==> error */
463 /* int osfwb(osfildef *fp, const uchar *buf, int bufl); */
464 #define osfwb(fp, buf, bufl) (fwrite(buf, bufl, 1, fp) != 1)
465
466 /* flush buffers; TRUE ==> error */
467 /* void osfflush(osfildef *fp); */
468 #define osfflush(fp) fflush(fp)
469
470 /* read bytes from file; TRUE ==> error */
471 /* int osfrb(osfildef *fp, uchar *buf, int bufl); */
472 #define osfrb(fp, buf, bufl) (fread(buf, bufl, 1, fp) != 1)
473
474 /* read bytes from file and return count; returns # bytes read, 0=error */
475 /* size_t osfrbc(osfildef *fp, uchar *buf, size_t bufl); */
476 #define osfrbc(fp, buf, bufl) (fread(buf, 1, bufl, fp))
477
478 /* get position in file */
479 /* long osfpos(osfildef *fp); */
480 #define osfpos(fp) ftell(fp)
481
482 /* seek position in file; TRUE ==> error */
483 /* int osfseek(osfildef *fp, long pos, int mode); */
484 #define osfseek(fp, pos, mode) fseek(fp, pos, mode)
485 #define OSFSK_SET SEEK_SET
486 #define OSFSK_CUR SEEK_CUR
487 #define OSFSK_END SEEK_END
488
489 /* close a file */
490 /* void osfcls(osfildef *fp); */
491 #define osfcls(fp) fclose(fp)
492
493 /* delete a file - TRUE if error */
494 /* int osfdel(const char *fname); */
495 #define osfdel(fname) remove(fname)
496
497 /* rename a file - true on success, false on failure */
498 /* int os_rename_file(const char *oldname, const char *newname); */
499 #define os_rename_file(oldname, newname) (rename(oldname, newname) == 0)
500
501 /* access a file - 0 if file exists */
502 /* int osfacc(const char *fname) */
503 #define osfacc(fname) access(fname, 0)
504
505 /* file mode */
506 int osfmode(const char *fname, int follow_links,
507 unsigned long *mode, unsigned long *attrs);
508
509 #ifdef MICROSOFT
510 # define OSFMODE_FILE _S_IFREG
511 # define OSFMODE_DIR _S_IFDIR
512 # define OSFMODE_BLK 0
513 # define OSFMODE_CHAR _S_IFCHR
514 # define OSFMODE_PIPE _S_IFIFO
515 # define OSFMODE_SOCKET 0
516 # define OSFMODE_LINK 0
517 #endif
518 #if defined(DJGPP) || defined(TURBO)
519 # define OSFMODE_FILE S_IFREG
520 # define OSFMODE_DIR S_IFDIR
521 # define OSFMODE_BLK 0
522 # define OSFMODE_CHAR S_IFCHR
523 # define OSFMODE_PIPE S_IFIFO
524 # define OSFMODE_SOCKET 0
525 # define OSFMODE_LINK 0
526 #endif
527
528 /*
529 * file attributes - we define our own bits for these, since the osifc set
530 * doesn't correspond exactly to the DOS/Windows set (DOS/Win has a
531 * READONLY flag, whereas osifc has separate READ and WRITE flags;
532 * furthermore, WRITE isn't merely the inverse of READONLY, but also
533 * conveys information on ACL permissions on NTFS volumes).
534 */
535 # define OSFATTR_HIDDEN 0x0001
536 # define OSFATTR_SYSTEM 0x0002
537 # define OSFATTR_READ 0x0004
538 # define OSFATTR_WRITE 0x0008
539
540 /* get a character from a file */
541 /* int osfgetc(osfildef *fp); */
542 #define osfgetc(fp) fgetc(fp)
543
544 /*
545 * on 16-bit protected-mode DOS, we need to check manually for break, so
546 * do this in os_yield; on other DOS versions, we don't need to do
547 * anything in os_yield
548 */
549 #ifndef __DPMI16__
550 # define os_yield() FALSE
551 #endif
552
553 /*
554 * Set "busy" cursor on/off. For systems with a mouse cursor, set the
555 * cursor to an appropriate shape to notify the user that the system is
556 * busy. Does nothing on DOS.
557 */
558 /* void os_csr_busy(int show_as_busy); */
559 #define os_csr_busy(show_as_busy)
560
561
562
563 /* ------------------------------------------------------------------------ */
564 /*
565 * TADS 2 macro/function configuration. Modern configurations always
566 * use the no-macro versions, so these definitions should always be set
567 * as shown below.
568 */
569 #define OS_MCM_NO_MACRO
570 #define ERR_NO_MACRO
571
572
573 #endif /* OSDOSBAS_H */
574