1 /* Copyright (C) 1989, 1995, 1998 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_dvx.c,v 1.11 2004/01/15 09:27:10 giles Exp $ */
18 /* Desqview/X-specific routines for Ghostscript */
19 #include "string_.h"
20 #include "gx.h"
21 #include "gsexit.h"
22 #include "gp.h"
23 #include "time_.h"
24
25 /* Do platform-dependent initialization. */
26 void
gp_init(void)27 gp_init(void)
28 {
29 }
30
31 /* Do platform-dependent cleanup. */
32 void
gp_exit(int exit_status,int code)33 gp_exit(int exit_status, int code)
34 {
35 }
36
37 /* Exit the program. */
38 void
gp_do_exit(int exit_status)39 gp_do_exit(int exit_status)
40 {
41 exit(exit_status);
42 }
43
44 /* ------ Miscellaneous ------ */
45
46 /* Get the string corresponding to an OS error number. */
47 /* All reasonable compilers support it. */
48 const char *
gp_strerror(int errnum)49 gp_strerror(int errnum)
50 {
51 return strerror(errnum);
52 }
53
54 /* ------ Date and time ------ */
55
56 /* Read the current time (in seconds since Jan. 1, 1970) */
57 /* and fraction (in nanoseconds). */
58 void
gp_get_realtime(long * pdt)59 gp_get_realtime(long *pdt)
60 {
61 struct timeval tp;
62 struct timezone tzp;
63
64 if (gettimeofday(&tp, &tzp) == -1) {
65 lprintf("Ghostscript: gettimeofday failed!\n");
66 tp.tv_sec = tp.tv_usec = 0;
67 }
68 /* tp.tv_sec is #secs since Jan 1, 1970 */
69 pdt[0] = tp.tv_sec;
70 pdt[1] = tp.tv_usec * 1000;
71
72 #ifdef DEBUG_CLOCK
73 printf("tp.tv_sec = %d tp.tv_usec = %d pdt[0] = %ld pdt[1] = %ld\n",
74 tp.tv_sec, tp.tv_usec, pdt[0], pdt[1]);
75 #endif
76 }
77
78 /* Read the current user CPU time (in seconds) */
79 /* and fraction (in nanoseconds). */
80 void
gp_get_usertime(long * pdt)81 gp_get_usertime(long *pdt)
82 {
83 gp_get_realtime(pdt); /* Use an approximation for now. */
84 }
85
86 /* ------ Persistent data cache ------*/
87
88 /* insert a buffer under a (type, key) pair */
gp_cache_insert(int type,byte * key,int keylen,void * buffer,int buflen)89 int gp_cache_insert(int type, byte *key, int keylen, void *buffer, int buflen)
90 {
91 /* not yet implemented */
92 return 0;
93 }
94
95 /* 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)96 int gp_cache_query(int type, byte* key, int keylen, void **buffer,
97 gp_cache_alloc alloc, void *userdata)
98 {
99 /* not yet implemented */
100 return -1;
101 }
102
103 /* ------ Printer accessing ------ */
104
105 /* Open a connection to a printer. A null file name means use the */
106 /* standard printer connected to the machine, if any. */
107 /* Return NULL if the connection could not be opened. */
108 extern void gp_set_file_binary(int, int);
109 FILE *
gp_open_printer(char fname[gp_file_name_sizeof],int binary_mode)110 gp_open_printer(char fname[gp_file_name_sizeof], int binary_mode)
111 {
112 if (strlen(fname) == 0 || !strcmp(fname, "PRN")) {
113 if (binary_mode)
114 gp_set_file_binary(fileno(stdprn), 1);
115 stdprn->_flag = _IOWRT; /* Make stdprn buffered to improve performance */
116 return stdprn;
117 } else
118 return fopen(fname, (binary_mode ? "wb" : "w"));
119 }
120
121 /* Close the connection to the printer. */
122 void
gp_close_printer(FILE * pfile,const char * fname)123 gp_close_printer(FILE * pfile, const char *fname)
124 {
125 if (pfile == stdprn)
126 fflush(pfile);
127 else
128 fclose(pfile);
129 }
130
131 /* ------ Font enumeration ------ */
132
133 /* This is used to query the native os for a list of font names and
134 * corresponding paths. The general idea is to save the hassle of
135 * building a custom fontmap file.
136 */
137
gp_enumerate_fonts_init(gs_memory_t * mem)138 void *gp_enumerate_fonts_init(gs_memory_t *mem)
139 {
140 return NULL;
141 }
142
gp_enumerate_fonts_next(void * enum_state,char ** fontname,char ** path)143 int gp_enumerate_fonts_next(void *enum_state, char **fontname, char **path)
144 {
145 return 0;
146 }
147
gp_enumerate_fonts_free(void * enum_state)148 void gp_enumerate_fonts_free(void *enum_state)
149 {
150 }
151