Commit | Line | Data |
---|---|---|
fac14bbe MW |
1 | |
2 | /* Copyright (c) 1995, 1997, 1998, 1999, 2000, 2002 by Arkkra Enterprises */ | |
3 | /* All rights reserved */ | |
4 | ||
5 | /* initialization table and routine for Mup/Ghostscript display program */ | |
6 | ||
7 | /* when adding support for additional terminal types, you will need to | |
8 | * add the declarations of relevant functions and add an entry to the | |
9 | * Config table */ | |
10 | ||
11 | ||
12 | #include <string.h> | |
13 | #include <stdlib.h> | |
14 | #include "mupdisp.h" | |
15 | ||
16 | /* declare the functions, etc for each supported terminal type */ | |
17 | ||
18 | #ifdef XWINDOW | |
19 | extern void parse_X_options P((void)); | |
20 | extern void xterm_setup P((void)); | |
21 | extern void xterm_cleanup P((int status)); | |
22 | extern void xterm_draw P((int line, int small)); | |
23 | extern void xterm_user_interf P((void)); | |
24 | extern void xterm_error P((char *msg)); | |
25 | extern void xterm_raster P((unsigned char *bitmap, int width, int height)); | |
26 | #define XVIDLINES (400) /* request 400 lines when in 640x480 mode */ | |
27 | #endif | |
28 | ||
29 | #if defined(AT386) && ! defined(__DOS__) | |
30 | extern void at386_setup P((void)); | |
31 | extern void at386_cleanup P((int status)); | |
32 | extern void at386_draw P((int line, int small)); | |
33 | extern void at386_user_interf P((void)); | |
34 | extern void at386_error P((char *msg)); | |
35 | extern void at386_raster P((unsigned char *bitmap, int width, int height)); | |
36 | #define VIDLINES (350) /* for 640x350 display mode */ | |
37 | #endif | |
38 | ||
39 | #if defined(linux) && ! defined(NO_VGA_LIB) | |
40 | extern void vgalib_setup P((void)); | |
41 | extern void vgalib_cleanup P((int status)); | |
42 | extern void vgalib_draw P((int line, int small)); | |
43 | extern void vgalib_user_interf P((void)); | |
44 | extern void vgalib_error P((char *msg)); | |
45 | extern void vgalib_raster P((unsigned char *bitmap, int width, int height)); | |
46 | #define LINVGAVIDLINES (480) /* for 640x480 display mode */ | |
47 | #endif | |
48 | ||
49 | #ifdef __WATCOMC__ | |
50 | extern void dos_setup P((void)); | |
51 | extern void dos_cleanup P((int status)); | |
52 | extern void dos_draw P((int line, int small)); | |
53 | extern void dos_user_interf P((void)); | |
54 | extern void dos_error P((char *msg)); | |
55 | extern void dos_raster P((unsigned char *bitmap, int width, int height)); | |
56 | /* video lines determined at run time */ | |
57 | #endif | |
58 | \f | |
59 | ||
60 | ||
61 | /* list of supported $TERM types and which functions and parameters to use | |
62 | * to implement them. To support a new terminal type, write appropriate | |
63 | * functions, and add to the Config table. | |
64 | */ | |
65 | struct CONFIG Config [] = { | |
66 | ||
67 | #if defined(AT386) && ! defined(__DOS__) | |
68 | { | |
69 | "AT386", /* terminal type name */ | |
70 | at386_setup, /* setup function */ | |
71 | at386_cleanup, /* cleanup function */ | |
72 | at386_draw, /* function for drawing a screen full of bits */ | |
73 | at386_user_interf, /* function to read user input and call do_cmd on it */ | |
74 | at386_error, /* error reporting function */ | |
75 | at386_raster, /* function to display a raster bitmap centered on screen */ | |
76 | VIDLINES, /* screen vertical lines */ | |
77 | 0.75 /* aspect ratio */ | |
78 | }, | |
79 | #endif | |
80 | ||
81 | #ifdef XWINDOW | |
82 | { | |
83 | "xterm", /* terminal type name */ | |
84 | xterm_setup, /* setup function */ | |
85 | xterm_cleanup, /* cleanup function */ | |
86 | xterm_draw, /* function for drawing a screen full of bits */ | |
87 | xterm_user_interf, /* function to read user input and call do_cmd on it */ | |
88 | xterm_error, /* error reporting function */ | |
89 | xterm_raster, /* function to display a raster bitmap centered on screen */ | |
90 | XVIDLINES, /* screen vertical lines */ | |
91 | 1.0 /* aspect ratio */ | |
92 | }, | |
93 | #endif | |
94 | ||
95 | #if defined(linux) && ! defined(NO_VGA_LIB) | |
96 | { | |
97 | "linux", /* terminal type name */ | |
98 | vgalib_setup, /* setup function */ | |
99 | vgalib_cleanup, /* cleanup function */ | |
100 | vgalib_draw, /* function for drawing a screen full of bits */ | |
101 | vgalib_user_interf, /* function to read user input and call do_cmd on it */ | |
102 | vgalib_error, /* error reporting function */ | |
103 | vgalib_raster, /* function to display a raster bitmap centered on screen */ | |
104 | LINVGAVIDLINES, /* screen vertical lines */ | |
105 | 1.0 /* aspect ratio */ | |
106 | }, | |
107 | ||
108 | #endif | |
109 | #ifdef __WATCOMC__ | |
110 | { | |
111 | "DOS", /* terminal type name */ | |
112 | dos_setup, /* setup function */ | |
113 | dos_cleanup, /* cleanup function */ | |
114 | dos_draw, /* function for drawing a screen full of bits */ | |
115 | dos_user_interf, /* function to read user input and call do_cmd on it */ | |
116 | dos_error, /* error reporting function */ | |
117 | dos_raster, /* function to display a raster bitmap centered on screen */ | |
118 | 0, /* screen vertical lines--will get set at run time */ | |
119 | 0.0 /* aspect ratio adjust--will get set at run time */ | |
120 | } | |
121 | #endif | |
122 | }; | |
123 | \f | |
124 | ||
125 | /* initialize. Make sure TERM is supported, and set up for it. */ | |
126 | ||
127 | void | |
128 | init() | |
129 | ||
130 | { | |
131 | struct CONFIG *c_p; /* terminal configuration info */ | |
132 | char *termname; /* $TERM */ | |
133 | int numtypes; | |
134 | #ifdef XWINDOW | |
135 | struct CONFIG *xwindow_conf_p = 0; /* info for running under X */ | |
136 | #endif | |
137 | ||
138 | ||
139 | #ifdef __WATCOMC__ | |
140 | termname = "DOS"; | |
141 | #else | |
142 | if ((termname = getenv("TERM")) == NULL) { | |
143 | fprintf(stderr, "can't determine $TERM\n"); | |
144 | generalcleanup(1); | |
145 | } | |
146 | #endif | |
147 | ||
148 | /* find appropriate functions to use based on terminal type */ | |
149 | numtypes = sizeof(Config) / sizeof(struct CONFIG); | |
150 | for (c_p = Config; numtypes > 0; c_p++, numtypes--) { | |
151 | if (strcmp(c_p->termname, termname) == 0) { | |
152 | Conf_info_p = c_p; | |
153 | break; | |
154 | } | |
155 | #ifdef XWINDOW | |
156 | /* save the xwindow config. If we don't find a | |
157 | * matching terminal type here, we're try some other | |
158 | * tricks later to guess if we're running under X */ | |
159 | if (strcmp(c_p->termname, "xterm") == 0) { | |
160 | xwindow_conf_p = c_p; | |
161 | } | |
162 | #endif | |
163 | } | |
164 | ||
165 | #ifdef XWINDOW | |
166 | if (Conf_info_p == (struct CONFIG *) 0) { | |
167 | /* There can be several variations on xterm, so | |
168 | * if $TERM at least starts with xterm, consider that | |
169 | * good enough to try. And to try even harder to | |
170 | * recognize if we're probably running under X, and | |
171 | * thus the 'xterm' type will probably work, check if | |
172 | * $DISPLAY is set. Chances are, if it is, we're probably | |
173 | * in X. If it turns out we're not, we'll fail eventually, | |
174 | * but we will have at least tried pretty hard | |
175 | * to find something that would work... */ | |
176 | if (strncmp(termname, "xterm", 5) == 0 || | |
177 | getenv("DISPLAY") != (char *) 0) { | |
178 | Conf_info_p = xwindow_conf_p; | |
179 | } | |
180 | } | |
181 | #endif | |
182 | ||
183 | /* Make sure we managed to find a $TERM we can work with */ | |
184 | if (Conf_info_p == (struct CONFIG *) 0 ) { | |
185 | fprintf(stderr, "$TERM type not supported\n"); | |
186 | generalcleanup(1); | |
187 | } | |
188 | ||
189 | #ifdef XWINDOW | |
190 | /* X has some extra options, so handle them */ | |
191 | if (strcmp(Conf_info_p->termname, "xterm") == 0) { | |
192 | parse_X_options(); | |
193 | } | |
194 | #endif | |
195 | } |