1 /* Copyright (C) 1989, 2000-2003 artofcode LLC. 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_os9.c,v 1.12 2004/01/15 09:27:10 giles Exp $ */
18 /* OSK-specific routines for Ghostscript */
19
20 #include "pipe_.h"
21 #include "string_.h"
22 #include "time_.h"
23 #include "gx.h"
24 #include "gp.h"
25 #include <signal.h>
26 #include <stdlib.h> /* for exit */
27
28 int interrupted;
29
30 /* Forward declarations */
31 private void signalhandler(int);
32 private FILE *rbfopen(char *, char *);
33
34 /* Do platform-dependent initialization */
35 void
gp_init(void)36 gp_init(void)
37 {
38 intercept(signalhandler);
39 }
40
41 /* Do platform-dependent cleanup. */
42 void
gp_exit(int exit_status,int code)43 gp_exit(int exit_status, int code)
44 {
45 }
46
47 /* Exit the program. */
48 void
gp_do_exit(int exit_status)49 gp_do_exit(int exit_status)
50 {
51 exit(exit_status);
52 }
53
54 private void
signalhandler(int sig)55 signalhandler(int sig)
56 {
57 clearerr(stdin);
58 switch (sig) {
59 case SIGINT:
60 case SIGQUIT:
61 interrupted = 1;
62 break;
63 case SIGFPE:
64 interrupted = 2;
65 break;
66 default:
67 break;
68 }
69 }
70
71 /* ------ Date and time ------ */
72
73 /* Read the current time (in seconds since Jan. 1, 1980) */
74 /* and fraction (in nanoseconds). */
75 #define PS_YEAR_0 80
76 #define PS_MONTH_0 1
77 #define PS_DAY_0 1
78 void
gp_get_realtime(long * pdt)79 gp_get_realtime(long *pdt)
80 {
81 long date, time, pstime, psdate, tick;
82 short day;
83
84 _sysdate(0, &time, &date, &day, &tick);
85 _julian(&time, &date);
86
87 pstime = 0;
88 psdate = (PS_YEAR_0 << 16) + (PS_MONTH_0 << 8) + PS_DAY_0;
89 _julian(&pstime, &psdate);
90
91 pdt[0] = (date - psdate) * 86400 + time;
92 pdt[1] = 0;
93
94 #ifdef DEBUG_CLOCK
95 printf("pdt[0] = %ld pdt[1] = %ld\n", pdt[0], pdt[1]);
96 #endif
97 }
98
99 /* Read the current user CPU time (in seconds) */
100 /* and fraction (in nanoseconds). */
101 void
gp_get_usertime(long * pdt)102 gp_get_usertime(long *pdt)
103 {
104 return gp_get_realtime(pdt); /* not yet implemented */
105 }
106
107
108 /* ------ Persistent data cache ------*/
109
110 /* insert a buffer under a (type, key) pair */
gp_cache_insert(int type,byte * key,int keylen,void * buffer,int buflen)111 int gp_cache_insert(int type, byte *key, int keylen, void *buffer, int buflen)
112 {
113 /* not yet implemented */
114 return 0;
115 }
116
117 /* look up a (type, key) in the cache */
gp_cache_query(int type,byte * key,int keylen,void ** buffer,gp_cache_alloc alloc,void * userdata)118 int gp_cache_query(int type, byte* key, int keylen, void **buffer,
119 gp_cache_alloc alloc, void *userdata)
120 {
121 /* not yet implemented */
122 return -1;
123 }
124
125 /* ------ Printer accessing ------ */
126
127 /* Open a connection to a printer. A null file name means use the */
128 /* standard printer connected to the machine, if any. */
129 /* "|command" opens an output pipe. */
130 /* Return NULL if the connection could not be opened. */
131 FILE *
gp_open_printer(char fname[gp_file_name_sizeof],int binary_mode)132 gp_open_printer(char fname[gp_file_name_sizeof], int binary_mode)
133 {
134 return
135 (strlen(fname) == 0 ? 0 :
136 fname[0] == '|' ? popen(fname + 1, "w") :
137 rbfopen(fname, "w"));
138 }
139
140 FILE *
rbfopen(char * fname,char * perm)141 rbfopen(char *fname, char *perm)
142 {
143 FILE *file = fopen(fname, perm);
144
145 file->_flag |= _RBF;
146 return file;
147 }
148
149 /* Close the connection to the printer. */
150 void
gp_close_printer(FILE * pfile,const char * fname)151 gp_close_printer(FILE * pfile, const char *fname)
152 {
153 if (fname[0] == '|')
154 pclose(pfile);
155 else
156 fclose(pfile);
157 }
158
159 /* ------ File accessing -------- */
160
161 /* Set a file into binary or text mode. */
162 int
gp_setmode_binary(FILE * pfile,bool binary)163 gp_setmode_binary(FILE * pfile, bool binary)
164 {
165 if (binary)
166 file->_flag |= _RBF;
167 else
168 file->_flag &= ~_RBF;
169 return 0;
170 }
171
172 /* ------ Font enumeration ------ */
173
174 /* This is used to query the native os for a list of font names and
175 * corresponding paths. The general idea is to save the hassle of
176 * building a custom fontmap file.
177 */
178
gp_enumerate_fonts_init(gs_memory_t * mem)179 void *gp_enumerate_fonts_init(gs_memory_t *mem)
180 {
181 return NULL;
182 }
183
gp_enumerate_fonts_next(void * enum_state,char ** fontname,char ** path)184 int gp_enumerate_fonts_next(void *enum_state, char **fontname, char **path)
185 {
186 return 0;
187 }
188
gp_enumerate_fonts_free(void * enum_state)189 void gp_enumerate_fonts_free(void *enum_state)
190 {
191 }
192