1 /* Copyright (C) 1992, 1993, 1994 Aladdin Enterprises. All rights reserved.
2
3 This software is provided AS-IS with no warranty, either express or
4 implied.
5
6 This software is distributed under license and may not be copied,
7 modified or distributed except as expressly authorized under the terms
8 of the license contained in the file LICENSE in this distribution.
9
10 For more information about licensing, please refer to
11 http://www.ghostscript.com/licensing/. For information on
12 commercial licensing, go to http://www.artifex.com/licensing/ or
13 contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 San Rafael, CA 94903, U.S.A., +1(415)492-9861.
15 */
16
17 /* $Id: gp_msdos.c,v 1.4 2002/02/21 22:24:52 giles Exp $ */
18 /* Common platform-specific routines for MS-DOS (any compiler) */
19 #include "stdio_.h"
20 #include "string_.h" /* for strerror */
21 #include "dos_.h"
22 #include "gstypes.h"
23 #include "gsmemory.h" /* for gp.h */
24 #include "gp.h"
25
26 /* ------ Miscellaneous ------ */
27
28 /* Get the string corresponding to an OS error number. */
29 /* This is compiler-, not OS-, specific, but it is ANSI-standard and */
30 /* all MS-DOS and MS Windows compilers support it. */
31 const char *
gp_strerror(int errnum)32 gp_strerror(int errnum)
33 {
34 return strerror(errnum);
35 }
36
37 /* ------ Date and time ------ */
38
39 /* Read the current time (in seconds since Jan. 1, 1980) */
40 /* and fraction (in nanoseconds). */
41 void
gp_get_realtime(long * pdt)42 gp_get_realtime(long *pdt)
43 {
44 union REGS osdate, ostime;
45 long idate;
46 static const int mstart[12] =
47 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
48
49 osdate.h.ah = 0x2a; /* get date */
50 intdos(&osdate, &osdate);
51 #define da_year rshort.cx
52 #define da_mon h.dh
53 #define da_day h.dl
54 ostime.h.ah = 0x2c; /* get time */
55 intdos(&ostime, &ostime);
56 #define ti_hour h.ch
57 #define ti_min h.cl
58 #define ti_sec h.dh
59 #define ti_hund h.dl
60 idate = (long)osdate.da_year * 365 +
61 ( /* intervening leap days */
62 ((osdate.da_year + 1979) / 4 - 1979 / 4) +
63 (1979 / 100 - (osdate.da_year + 1979) / 100) +
64 ((osdate.da_year + 1979) / 400 - 1979 / 400) +
65 mstart[osdate.da_mon - 1] + /* month is 1-origin */
66 osdate.da_day - 1); /* day of month is 1-origin */
67 idate += (2 < osdate.da_mon
68 && (osdate.da_year % 4 == 0
69 && ((osdate.da_year + 1980) % 100 != 0
70 || (osdate.da_year + 1980) % 400 == 0)));
71 pdt[0] =
72 ((idate * 24 + ostime.ti_hour) * 60 + ostime.ti_min) * 60 +
73 ostime.ti_sec;
74 pdt[1] = ostime.ti_hund * 10000000;
75 }
76
77 /* Read the current user CPU time (in seconds) */
78 /* and fraction (in nanoseconds). */
79 void
gp_get_usertime(long * pdt)80 gp_get_usertime(long *pdt)
81 {
82 gp_get_realtime(pdt); /* Use an approximation for now. */
83 }
84
85 /* ------ Console management ------ */
86
87 /* Answer whether a given file is the console (input or output). */
88 /* This is not a standard gp procedure, */
89 /* but the MS Windows configuration needs it, */
90 /* and other MS-DOS configurations might need it someday. */
91 int
gp_file_is_console(FILE * f)92 gp_file_is_console(FILE * f)
93 {
94 union REGS regs;
95
96 #ifdef __DLL__
97 if (f == NULL)
98 return 1;
99 #else
100 if (f == NULL)
101 return 0;
102 #endif
103 regs.h.ah = 0x44; /* ioctl */
104 regs.h.al = 0; /* get device info */
105 regs.rshort.bx = fileno(f);
106 intdos(®s, ®s);
107 return ((regs.h.dl & 0x80) != 0 && (regs.h.dl & 3) != 0);
108 }
109
110 /* ------ Screen management ------ */
111
112 /* Get the environment variable that specifies the display to use. */
113 const char *
gp_getenv_display(void)114 gp_getenv_display(void)
115 {
116 return NULL;
117 }
118
119 /* ------ File names ------ */
120
121 /* Define the default scratch file name prefix. */
122 const char gp_scratch_file_name_prefix[] = "_temp_";
123
124 /* Define the name of the null output file. */
125 const char gp_null_file_name[] = "nul";
126
127 /* Define the name that designates the current directory. */
128 const char gp_current_directory_name[] = ".";
129