1 /* Copyright (C) 2001-2019 Artifex Software, Inc.
2 All Rights Reserved.
3
4 This software is provided AS-IS with no warranty, either express or
5 implied.
6
7 This software is distributed under license and may not be copied,
8 modified or distributed except as expressly authorized under the terms
9 of the license contained in the file LICENSE in this distribution.
10
11 Refer to licensing information at http://www.artifex.com or contact
12 Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato,
13 CA 94945, U.S.A., +1(415)492-9861, for further information.
14 */
15
16
17 /* Desqview/X-specific routines for Ghostscript */
18 #include "string_.h"
19 #include "gx.h"
20 #include "gsexit.h"
21 #include "gp.h"
22 #include "time_.h"
23
24 /* Do platform-dependent initialization. */
25 void
gp_init(void)26 gp_init(void)
27 {
28 }
29
30 /* Do platform-dependent cleanup. */
31 void
gp_exit(int exit_status,int code)32 gp_exit(int exit_status, int code)
33 {
34 }
35
36 /* Exit the program. */
37 void
gp_do_exit(int exit_status)38 gp_do_exit(int exit_status)
39 {
40 exit(exit_status);
41 }
42
43 /* ------ Miscellaneous ------ */
44
45 /* Get the string corresponding to an OS error number. */
46 /* All reasonable compilers support it. */
47 const char *
gp_strerror(int errnum)48 gp_strerror(int errnum)
49 {
50 return strerror(errnum);
51 }
52
53 /* We don't have a good way to get a serial number here, so just */
54 /* return what we always used to: GS_SERIALNUMBER. */
55 int
gp_serialnumber(void)56 gp_serialnumber(void)
57 {
58 return (int)(gs_serialnumber);
59 }
60
61 /* ------ Date and time ------ */
62
63 /* Read the current time (in seconds since Jan. 1, 1970) */
64 /* and fraction (in nanoseconds). */
65 void
gp_get_realtime(long * pdt)66 gp_get_realtime(long *pdt)
67 {
68 struct timeval tp;
69 struct timezone tzp;
70
71 if (gettimeofday(&tp, &tzp) == -1) {
72 lprintf("Ghostscript: gettimeofday failed!\n");
73 tp.tv_sec = tp.tv_usec = 0;
74 }
75 /* tp.tv_sec is #secs since Jan 1, 1970 */
76 pdt[0] = tp.tv_sec;
77 pdt[1] = tp.tv_usec * 1000;
78
79 #ifdef DEBUG_CLOCK
80 printf("tp.tv_sec = %d tp.tv_usec = %d pdt[0] = %ld pdt[1] = %ld\n",
81 tp.tv_sec, tp.tv_usec, pdt[0], pdt[1]);
82 #endif
83 }
84
85 /* Read the current user CPU time (in seconds) */
86 /* and fraction (in nanoseconds). */
87 void
gp_get_usertime(long * pdt)88 gp_get_usertime(long *pdt)
89 {
90 gp_get_realtime(pdt); /* Use an approximation for now. */
91 }
92
93 /* ------ Printer accessing ------ */
94
95 static int
dvx_prn_close(FILE *)96 dvx_prn_close(FILE *)
97 {
98 fflush(stdprn);
99 }
100
101 /* Open a connection to a printer. A null file name means use the */
102 /* standard printer connected to the machine, if any. */
103 /* Return NULL if the connection could not be opened. */
104 extern void gp_set_file_binary(int, int);
105 gp_file *
gp_open_printer_impl(gs_memory_t * mem,const char * fname,int * binary_mode,int (** close)(FILE *))106 gp_open_printer_impl(gs_memory_t *mem,
107 const char *fname,
108 int *binary_mode,
109 int (**close)(FILE *))
110 {
111 if (strlen(fname) == 0 || !strcmp(fname, "PRN")) {
112 stdprn->_flag = _IOWRT; /* Make stdprn buffered to improve performance */
113 return stdprn;
114 } else
115 return gp_fopen_impl(mem, fname, (*binary_mode ? "wb" : "w"));
116 }
117
118 /* Close the connection to the printer. */
119 void
gp_close_printer(gp_file * pfile,const char * fname)120 gp_close_printer(gp_file * pfile, const char *fname)
121 {
122 pfile->close(pfile);
123 }
124
125 /* ------ Font enumeration ------ */
126
127 /* This is used to query the native os for a list of font names and
128 * corresponding paths. The general idea is to save the hassle of
129 * building a custom fontmap file.
130 */
131
gp_enumerate_fonts_init(gs_memory_t * mem)132 void *gp_enumerate_fonts_init(gs_memory_t *mem)
133 {
134 return NULL;
135 }
136
gp_enumerate_fonts_next(void * enum_state,char ** fontname,char ** path)137 int gp_enumerate_fonts_next(void *enum_state, char **fontname, char **path)
138 {
139 return 0;
140 }
141
gp_enumerate_fonts_free(void * enum_state)142 void gp_enumerate_fonts_free(void *enum_state)
143 {
144 }
145