Tell Solaris users where to get XPM.
[wine/dcerpc.git] / console / interface.c
blob5d5c03ad74f89a1bda1ea220e9e047e6fd420867
1 /* interface.c */
3 /* The primary purpose of this function is to provide CONSOLE_*
4 reotines that immediately call the appropiate driver handler.
5 This cleans up code in the individual modules considerably.
6 This could be done using a macro, but additional functionality
7 may be provided here in the future. */
9 #include "config.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
15 #include "windef.h"
16 #include "console.h"
17 #include "options.h"
19 CONSOLE_device driver;
21 static int pop_driver(char **, char **, int *);
23 static int console_initialized = FALSE;
25 static int CONSOLE_Init(void)
27 char buffer[256];
28 char *single, *drivers = buffer;
29 int length;
30 char initial_rows[5];
31 char initial_columns[5];
33 /* Suitable defaults... */
34 driver.console_out = stdout;
35 driver.console_in = stdin;
37 /* drivers should be a string that consists of driver names
38 followed by plus (+) signs to denote additions.
40 For example:
41 drivers = tty Load just the tty driver
42 drivers = ncurses+xterm Load ncurses then xterm
44 The "default" value is just tty.
46 PROFILE_GetWineIniString( "console", "Drivers", CONSOLE_DEFAULT_DRIVER,
47 buffer, sizeof(buffer) );
49 while (pop_driver(&drivers, &single, &length))
51 if (!strncmp(single, "tty", length))
52 TTY_Start();
53 #ifdef WINE_NCURSES
54 else if (!strncmp(single, "ncurses", length))
55 NCURSES_Start();
56 #endif /* WINE_NCURSES */
57 else if (!strncmp(single, "xterm", length))
58 XTERM_Start();
61 /* Read in generic configuration */
62 /* This is primarily to work around a limitation in nxterm where
63 this information is not correctly passed to the ncurses layer
64 through the terminal. At least, I'm not doing it correctly if there
65 is a way. But this serves as a generic way to do the same anyway. */
67 /* We are setting this to 80x25 here which is *not* the default for
68 most xterm variants... It is however the standard VGA resolution */
70 /* FIXME: We need to be able to be able to specify that the window's
71 dimensions should be used. This is required for correct emulation
72 of Win32's console and Win32's DOS emulation */
74 PROFILE_GetWineIniString("console", "InitialRows",
75 "24", initial_rows, 5);
76 PROFILE_GetWineIniString("console", "InitialColumns",
77 "80", initial_columns, 5);
79 sscanf(initial_rows, "%d", &driver.y_res);
80 sscanf(initial_columns, "%d", &driver.x_res);
82 GENERIC_Start();
84 if (driver.init)
85 driver.init();
87 /* Not all terminals let our programs know the proper resolution
88 if the resolution is set on the command-line... */
89 CONSOLE_NotifyResizeScreen(driver.x_res, driver.y_res);
91 atexit(CONSOLE_Close);
93 /* For now, always return TRUE */
94 return TRUE;
97 void CONSOLE_Write(char out, int fg_color, int bg_color, int attribute)
99 if (!console_initialized)
100 console_initialized = CONSOLE_Init();
102 if (driver.write)
104 driver.write(out, fg_color, bg_color, attribute);
105 if (!driver.norefresh)
106 CONSOLE_Refresh();
110 void CONSOLE_Close(void)
112 if (driver.close)
113 driver.close();
116 void CONSOLE_MoveCursor(char row, char col)
118 if (!console_initialized)
119 console_initialized = CONSOLE_Init();
121 if (driver.moveCursor)
123 driver.moveCursor(row, col);
124 if (!driver.norefresh)
125 CONSOLE_Refresh();
129 void CONSOLE_ClearWindow(char row1, char col1, char row2, char col2,
130 int bg_color, int attribute)
132 if (!console_initialized)
133 console_initialized = CONSOLE_Init();
135 if (driver.clearWindow)
137 driver.clearWindow(row1, col1, row2, col2, bg_color, attribute);
138 if (!driver.norefresh)
139 CONSOLE_Refresh();
143 void CONSOLE_ScrollUpWindow(char row1, char col1, char row2, char col2,
144 char lines, int bg_color, int attribute)
146 if (!console_initialized)
147 console_initialized = CONSOLE_Init();
149 if (driver.scrollUpWindow)
151 driver.scrollUpWindow(row1, col1, row2, col2, lines, bg_color,
152 attribute);
153 if (!driver.norefresh)
154 CONSOLE_Refresh();
158 void CONSOLE_ScrollDownWindow(char row1, char col1, char row2, char col2,
159 char lines, int bg_color, int attribute)
161 if (!console_initialized)
162 console_initialized = CONSOLE_Init();
164 if (driver.scrollDownWindow)
166 driver.scrollDownWindow(row1, col1, row2, col2, lines, bg_color,
167 attribute);
168 if (!driver.norefresh)
169 CONSOLE_Refresh();
173 int CONSOLE_CheckForKeystroke(char *scan, char *ascii)
174 /* These functions need to go through a conversion layer. Scancodes
175 should *not* be determined by the driver, rather they should have
176 a conv_* function in int16.c. Yuck. */
178 if (!console_initialized)
179 console_initialized = CONSOLE_Init();
181 if (driver.checkForKeystroke)
182 return driver.checkForKeystroke(scan, ascii);
183 else
184 return FALSE;
187 void CONSOLE_GetKeystroke(char *scan, char *ascii)
189 if (!console_initialized)
190 console_initialized = CONSOLE_Init();
192 if (driver.getKeystroke)
193 driver.getKeystroke(scan, ascii);
196 void CONSOLE_GetCursorPosition(char *row, char *col)
198 if (!console_initialized)
199 console_initialized = CONSOLE_Init();
201 if (driver.getCursorPosition)
202 driver.getCursorPosition(row, col);
205 void CONSOLE_GetCharacterAtCursor(char *ch, int *fg, int *bg, int *a)
207 if (!console_initialized)
208 console_initialized = CONSOLE_Init();
210 if (driver.getCharacterAtCursor)
211 driver.getCharacterAtCursor(ch, fg, bg, a);
214 void CONSOLE_Refresh()
216 if (!console_initialized)
217 console_initialized = CONSOLE_Init();
219 if (driver.refresh)
220 driver.refresh();
223 int CONSOLE_AllocColor(int color)
225 if (!console_initialized)
226 console_initialized = CONSOLE_Init();
228 if (driver.allocColor)
229 return driver.allocColor(color);
230 else
231 return 0;
234 void CONSOLE_ClearScreen()
236 if (!console_initialized)
237 console_initialized = CONSOLE_Init();
239 if (driver.clearScreen)
241 driver.clearScreen();
242 if (!driver.norefresh)
243 CONSOLE_Refresh();
247 char CONSOLE_GetCharacter()
249 if (!console_initialized)
250 console_initialized = CONSOLE_Init();
252 /* I'm not sure if we need this really. This is a function that can be
253 accelerated that returns the next *non extended* keystroke */
254 if (driver.getCharacter)
255 return driver.getCharacter();
256 else
257 return (char) 0; /* Sure, this will probably break programs... */
260 void CONSOLE_ResizeScreen(int x, int y)
262 if (!console_initialized)
263 console_initialized = CONSOLE_Init();
265 if (driver.resizeScreen)
266 driver.resizeScreen(x, y);
269 void CONSOLE_NotifyResizeScreen(int x, int y)
271 if (driver.notifyResizeScreen)
272 driver.notifyResizeScreen(x, y);
275 void CONSOLE_SetBackgroundColor(int fg, int bg)
277 if (!console_initialized)
278 console_initialized = CONSOLE_Init();
280 if (driver.setBackgroundColor)
281 driver.setBackgroundColor(fg, bg);
284 void CONSOLE_GetBackgroundColor(int *fg, int *bg)
286 if (!console_initialized)
287 console_initialized = CONSOLE_Init();
289 if (driver.getBackgroundColor)
290 driver.getBackgroundColor(fg, bg);
293 void CONSOLE_WriteRawString(char *str)
295 if (!console_initialized)
296 console_initialized = CONSOLE_Init();
298 /* This is a special function that is only for internal use and
299 does not actually call any of the console drivers. It's
300 primary purpose is to provide a way for higher-level drivers
301 to write directly to the underlying terminal without worry that
302 there will be any retranslation done by the assorted drivers. Care
303 should be taken to ensure that this only gets called when the thing
304 written does not actually produce any output or a CONSOLE_Redraw()
305 is called immediately afterwards.
306 CONSOLE_Redraw() is not yet implemented.
308 fprintf(driver.console_out, "%s", str);
311 /* This function is only at the CONSOLE level. */
312 /* Admittably, calling the variable norefresh might be a bit dumb...*/
313 void CONSOLE_SetRefresh(int setting)
315 if (setting)
316 driver.norefresh = FALSE;
317 else
318 driver.norefresh = TRUE;
321 /* This function is only at the CONSOLE level. */
322 int CONSOLE_GetRefresh()
324 if (driver.norefresh)
325 return FALSE;
326 else
327 return TRUE;
331 /* Utility functions... */
333 int pop_driver(char **drivers, char **single, int *length)
335 /* Take the string in drivers and extract the first "driver" entry */
336 /* Advance the pointer in drivers to the next entry, put the origional
337 pointer in single, and put the length in length. */
338 /* Return TRUE if we found one */
340 if (!*drivers)
341 return FALSE;
343 *single = *drivers;
344 *length = 0;
346 while ((*drivers[0] != '\0') && (*drivers[0] != '+'))
348 (*drivers)++;
349 (*length)++;
352 while (*drivers[0] == '+')
353 (*drivers)++;
355 if (*length)
356 return TRUE;
357 else
358 return FALSE;