Change a couple of names that would conflict after all 32[AW] suffixes
[wine/dcerpc.git] / console / interface.c
blob1cfb1a9e027a70139e31062ac8e2463a3b0fa57c
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 <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
13 #include "windows.h"
14 #include "console.h"
15 #include "config.h"
17 static int pop_driver(char **, char **, int *);
19 void CONSOLE_Write(char out, int fg_color, int bg_color, int attribute)
21 if (driver.write)
23 driver.write(out, fg_color, bg_color, attribute);
24 if (!driver.norefresh)
25 CONSOLE_Refresh();
29 void CONSOLE_Init(char *drivers)
31 /* When this function is called drivers should be a string
32 that consists of driver names followed by plus (+) signs
33 to denote additions.
35 For example:
36 drivers = tty Load just the tty driver
37 drivers = ncurses+xterm Load ncurses then xterm
39 The "default" value is just tty.
42 char *single;
43 int length;
45 /* Suitable defaults... */
46 driver.console_out = stdout;
47 driver.console_in = stdin;
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 GENERIC_Start();
63 if (driver.init)
64 driver.init();
67 void CONSOLE_Close()
69 if (driver.close)
70 driver.close();
73 void CONSOLE_MoveCursor(char row, char col)
75 if (driver.moveCursor)
77 driver.moveCursor(row, col);
78 if (!driver.norefresh)
79 CONSOLE_Refresh();
83 void CONSOLE_ClearWindow(char row1, char col1, char row2, char col2,
84 int bg_color, int attribute)
86 if (driver.clearWindow)
88 driver.clearWindow(row1, col1, row2, col2, bg_color, attribute);
89 if (!driver.norefresh)
90 CONSOLE_Refresh();
94 void CONSOLE_ScrollUpWindow(char row1, char col1, char row2, char col2,
95 char lines, int bg_color, int attribute)
97 if (driver.scrollUpWindow)
99 driver.scrollUpWindow(row1, col1, row2, col2, lines, bg_color,
100 attribute);
101 if (!driver.norefresh)
102 CONSOLE_Refresh();
106 void CONSOLE_ScrollDownWindow(char row1, char col1, char row2, char col2,
107 char lines, int bg_color, int attribute)
109 if (driver.scrollDownWindow)
111 driver.scrollDownWindow(row1, col1, row2, col2, lines, bg_color,
112 attribute);
113 if (!driver.norefresh)
114 CONSOLE_Refresh();
118 int CONSOLE_CheckForKeystroke(char *scan, char *ascii)
119 /* These functions need to go through a conversion layer. Scancodes
120 should *not* be determined by the driver, rather they should have
121 a conv_* function in int16.c. Yuck. */
123 if (driver.checkForKeystroke)
124 return driver.checkForKeystroke(scan, ascii);
125 else
126 return FALSE;
129 void CONSOLE_GetKeystroke(char *scan, char *ascii)
131 if (driver.getKeystroke)
132 driver.getKeystroke(scan, ascii);
135 void CONSOLE_GetCursorPosition(char *row, char *col)
137 if (driver.getCursorPosition)
138 driver.getCursorPosition(row, col);
141 void CONSOLE_GetCharacterAtCursor(char *ch, int *fg, int *bg, int *a)
143 if (driver.getCharacterAtCursor)
144 driver.getCharacterAtCursor(ch, fg, bg, a);
147 void CONSOLE_Refresh()
149 if (driver.refresh)
150 driver.refresh();
153 int CONSOLE_AllocColor(int color)
155 if (driver.allocColor)
156 return driver.allocColor(color);
157 else
158 return 0;
161 /* This function is only at the CONSOLE level. */
162 /* Admittably, calling the variable norefresh might be a bit dumb...*/
163 void CONSOLE_SetRefresh(int setting)
165 if (setting)
166 driver.norefresh = FALSE;
167 else
168 driver.norefresh = TRUE;
171 /* This function is only at the CONSOLE level. */
172 int CONSOLE_GetRefresh()
174 if (driver.norefresh)
175 return FALSE;
176 else
177 return TRUE;
180 void CONSOLE_ClearScreen()
182 if (driver.clearScreen)
184 driver.clearScreen();
185 if (!driver.norefresh)
186 CONSOLE_Refresh();
190 char CONSOLE_GetCharacter()
192 /* I'm not sure if we need this really. This is a function that can be
193 accelerated that returns the next *non extended* keystroke */
194 if (driver.getCharacter)
195 return driver.getCharacter();
196 else
197 return (char) 0; /* Sure, this will probably break programs... */
200 void CONSOLE_ResizeScreen(int x, int y)
202 if (driver.resizeScreen)
203 driver.resizeScreen(x, y);
206 void CONSOLE_NotifyResizeScreen(int x, int y)
208 if (driver.notifyResizeScreen)
209 driver.notifyResizeScreen(x, y);
212 void CONSOLE_SetBackgroundColor(int fg, int bg)
214 if (driver.setBackgroundColor)
215 driver.setBackgroundColor(fg, bg);
218 void CONSOLE_WriteRawString(char *str)
220 /* This is a special function that is only for internal use and
221 does not actually call any of the console drivers. It's
222 primary purpose is to provide a way for higher-level drivers
223 to write directly to the underlying terminal without worry that
224 there will be any retranslation done by the assorted drivers. Care
225 should be taken to ensure that this only gets called when the thing
226 written does not actually produce any output or a CONSOLE_Redraw()
227 is called immediately afterwards.
228 CONSOLE_Redraw() is not yet implemented.
230 fprintf(driver.console_out, "%s", str);
233 /* Utility functions... */
235 int pop_driver(char **drivers, char **single, int *length)
237 /* Take the string in drivers and extract the first "driver" entry */
238 /* Advance the pointer in drivers to the next entry, put the origional
239 pointer in single, and put the length in length. */
240 /* Return TRUE if we found one */
242 if (!*drivers)
243 return FALSE;
245 *single = *drivers;
246 *length = 0;
248 while ((*drivers[0] != NULL) && (*drivers[0] != '+'))
250 (*drivers)++;
251 (*length)++;
254 while (*drivers[0] == '+')
255 (*drivers)++;
257 if (*length)
258 return TRUE;
259 else
260 return FALSE;