1 /* $Id: console.c,v 1.9 2003-03-17 09:33:49 btb Exp $ */
4 * FIXME: put description here
26 int text_console_enabled = 1;
29 #define text_console_enabled (!isvga())
32 cvar_t *cvar_vars = NULL;
34 /* Console specific cvars */
35 /* How discriminating we are about which messages are displayed */
36 cvar_t con_threshold = {"con_threshold", "0",};
38 /* Private console stuff */
39 #define CON_NUM_LINES 40
40 #define CON_LINE_LEN 40
41 static char con_display[40][40];
42 static int con_line; /* Current display line */
45 * con_init - Initialise the console.
50 /* Make sure the output is unbuffered */
51 if (text_console_enabled) {
52 setbuf (stdout, NULL);
53 setbuf (stderr, NULL);
56 memset(con_display, ' ', sizeof(con_display));
59 /* Initialise the cvars */
60 cvar_registervariable (&con_threshold);
65 * con_printf - Print a message to the console.
68 void con_printf(int priority, char *fmt, ...)
73 if (priority <= ((int)con_threshold.value))
75 va_start (arglist, fmt);
76 vsprintf (buffer, fmt, arglist);
78 if (text_console_enabled) {
79 va_start (arglist, fmt);
80 vprintf(fmt, arglist);
84 /* for (i=0; i<l; i+=CON_LINE_LEN,con_line++)
86 memcpy(con_display, &buffer[i], min(80, l-i));
92 * con_update - Check for new console input. If it's there, use it.
97 char buffer[CMD_MAX_LENGTH], *t;
99 /* Check for new input */
100 t = fgets(buffer, sizeof(buffer), stdin);
101 if (t == NULL) return;
108 * cvar_registervariable - Register a CVar
111 void cvar_registervariable (cvar_t *cvar)
115 Assert(cvar != NULL);
118 cvar->value = strtod(cvar->string, (char **) NULL);
120 if (cvar_vars == NULL)
125 for (ptr = cvar_vars; ptr->next != NULL; ptr = ptr->next) ;
131 * cvar_set - Set a CVar's value
134 void cvar_set (char *cvar_name, char *value)
138 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
139 if (!strcmp(cvar_name, ptr->name)) break;
141 if (ptr == NULL) return; // If we didn't find the cvar, give up
143 ptr->value = strtod(value, (char **) NULL);
147 * cvar() - Get a CVar's value
150 float cvar (char *cvar_name)
154 for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
155 if (!strcmp(cvar_name, ptr->name)) break;
157 if (ptr == NULL) return 0.0; // If we didn't find the cvar, give up
163 /* ==========================================================================
165 * ==========================================================================
169 char buffer[CON_LINE_LEN+1];
171 for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
173 memcpy(buffer, con_display[i], CON_LINE_LEN);
174 buffer[CON_LINE_LEN] = 0;
175 gr_string(1,j*10,buffer);