1 /* Copyright (C) 1989, 2000 artofcode LLC. All rights reserved.
2
3 This program is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2 of the License, or (at your
6 option) any later version.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 59 Temple Place, Suite 330, Boston, MA, 02111-1307.
16
17 */
18
19 /*$Id: gp_os9.c,v 1.4.2.1.2.1 2003/01/17 00:49:02 giles Exp $ */
20 /* OSK-specific routines for Ghostscript */
21 #include "pipe_.h"
22 #include "string_.h"
23 #include "time_.h"
24 #include "gx.h"
25 #include "gp.h"
26 #include <signal.h>
27 #include <stdlib.h> /* for exit */
28 #include <sys/param.h> /* for MAXPATHLEN */
29
30 int interrupted;
31
32 /* Forward declarations */
33 private void signalhandler(P1(int));
34 private FILE *rbfopen(P2(char *, char *));
35
36 /* Do platform-dependent initialization */
37 void
gp_init(void)38 gp_init(void)
39 {
40 intercept(signalhandler);
41 }
42
43 /* Do platform-dependent cleanup. */
44 void
gp_exit(int exit_status,int code)45 gp_exit(int exit_status, int code)
46 {
47 }
48
49 /* Exit the program. */
50 void
gp_do_exit(int exit_status)51 gp_do_exit(int exit_status)
52 {
53 }
54
55 private void
signalhandler(int sig)56 signalhandler(int sig)
57 {
58 clearerr(stdin);
59 switch (sig) {
60 case SIGINT:
61 case SIGQUIT:
62 interrupted = 1;
63 break;
64 case SIGFPE:
65 interrupted = 2;
66 break;
67 default:
68 break;
69 }
70 }
71
72 /* ------ Date and time ------ */
73
74 /* Read the current time (in seconds since Jan. 1, 1980) */
75 /* and fraction (in nanoseconds). */
76 #define PS_YEAR_0 80
77 #define PS_MONTH_0 1
78 #define PS_DAY_0 1
79 void
gp_get_realtime(long * pdt)80 gp_get_realtime(long *pdt)
81 {
82 long date, time, pstime, psdate, tick;
83 short day;
84
85 _sysdate(0, &time, &date, &day, &tick);
86 _julian(&time, &date);
87
88 pstime = 0;
89 psdate = (PS_YEAR_0 << 16) + (PS_MONTH_0 << 8) + PS_DAY_0;
90 _julian(&pstime, &psdate);
91
92 pdt[0] = (date - psdate) * 86400 + time;
93 pdt[1] = 0;
94
95 #ifdef DEBUG_CLOCK
96 printf("pdt[0] = %ld pdt[1] = %ld\n", pdt[0], pdt[1]);
97 #endif
98 }
99
100 /* Read the current user CPU time (in seconds) */
101 /* and fraction (in nanoseconds). */
102 void
gp_get_usertime(long * pdt)103 gp_get_usertime(long *pdt)
104 {
105 return gp_get_realtime(pdt); /* not yet implemented */
106 }
107
108 /* ------ Printer accessing ------ */
109
110 /* Open a connection to a printer. A null file name means use the */
111 /* standard printer connected to the machine, if any. */
112 /* "|command" opens an output pipe. */
113 /* Return NULL if the connection could not be opened. */
114 FILE *
gp_open_printer(char fname[gp_file_name_sizeof],int binary_mode)115 gp_open_printer(char fname[gp_file_name_sizeof], int binary_mode)
116 {
117 return
118 (strlen(fname) == 0 ? 0 :
119 fname[0] == '|' ? popen(fname + 1, "w") :
120 rbfopen(fname, "w"));
121 }
122
123 FILE *
rbfopen(char * fname,char * perm)124 rbfopen(char *fname, char *perm)
125 {
126 FILE *file = fopen(fname, perm);
127
128 file->_flag |= _RBF;
129 return file;
130 }
131
132 /* Close the connection to the printer. */
133 void
gp_close_printer(FILE * pfile,const char * fname)134 gp_close_printer(FILE * pfile, const char *fname)
135 {
136 if (fname[0] == '|')
137 pclose(pfile);
138 else
139 fclose(pfile);
140 }
141
142 /* ------ File accessing -------- */
143
144 /* Set a file into binary or text mode. */
145 int
gp_setmode_binary(FILE * pfile,bool binary)146 gp_setmode_binary(FILE * pfile, bool binary)
147 {
148 if (binary)
149 file->_flag |= _RBF;
150 else
151 file->_flag &= ~_RBF;
152 return 0;
153 }
154