]> icculus.org git repositories - btb/d2x.git/blob - main/console.c
unification of input headers
[btb/d2x.git] / main / console.c
1 #include <conf.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <stdarg.h>
5 #include <string.h>
6 #include <fcntl.h>
7 #include "pstypes.h"
8 #include "u_mem.h"
9 #include "error.h"
10 #include "console.h"
11 #include "cmd.h"
12
13 #ifdef __ENV_LINUX__
14 int text_console_enabled = 1;
15 #else
16 int isvga();
17 #define text_console_enabled (!isvga())
18 #endif
19
20 cvar_t *cvar_vars = NULL;
21
22 /* Console specific cvars */
23 /* How discriminating we are about which messages are displayed */
24 cvar_t con_threshold = {"con_threshold", "0",};
25
26 /* Private console stuff */
27 #define CON_NUM_LINES 40
28 #define CON_LINE_LEN 40
29 static char con_display[40][40];
30 static int  con_line; /* Current display line */
31
32 /* ======
33  * con_init - Initialise the console.
34  * ======
35  */
36 int con_init(void)
37 {
38         /* Make sure the output is unbuffered */
39         if (text_console_enabled) {
40                 setbuf (stdout, NULL);
41                 setbuf (stderr, NULL);
42         }
43
44         memset(con_display, ' ', sizeof(con_display));
45         con_line = 0;
46
47         /* Initialise the cvars */
48         cvar_registervariable (&con_threshold);
49         return 0;       
50 }
51
52 /* ======
53  * con_printf - Print a message to the console.
54  * ======
55  */
56 void con_printf(int priority, char *fmt, ...)
57 {
58         va_list arglist;
59         char buffer[2048];
60
61         if (priority <= ((int)con_threshold.value))
62         {
63                 va_start (arglist, fmt);
64                 vsprintf (buffer,  fmt, arglist);
65                 if (text_console_enabled) vprintf(fmt, arglist);
66                 va_end (arglist);
67
68 /*              for (i=0; i<l; i+=CON_LINE_LEN,con_line++)
69                 {
70                         memcpy(con_display, &buffer[i], min(80, l-i));  
71                 }*/
72         }
73 }
74
75 /* ======
76  * con_update - Check for new console input. If it's there, use it.
77  * ======
78  */
79 void con_update(void)
80 {
81 //      char buffer[CMD_MAX_LENGTH], *t;
82
83         /* Check for new input */
84 /*      t = fgets(buffer, sizeof(buffer), stdin);
85         if (t == NULL) return;
86
87         cmd_parse(buffer);*/
88 //      con_draw();
89 }
90
91 /* ======
92  * cvar_registervariable - Register a CVar
93  * ======
94  */
95 void cvar_registervariable (cvar_t *cvar)
96 {
97         cvar_t *ptr;
98         
99         Assert(cvar != NULL);
100
101         cvar->next = NULL;
102         cvar->value = strtod(cvar->string, (char **) NULL);
103
104         if (cvar_vars == NULL)
105         {
106                 cvar_vars = cvar;
107         } else
108         {
109                 for (ptr = cvar_vars; ptr->next != NULL; ptr = ptr->next) ;
110                 ptr->next = cvar;
111         }
112 }
113
114 /* ======
115  * cvar_set - Set a CVar's value
116  * ======
117  */
118 void cvar_set (char *cvar_name, char *value)
119 {
120         cvar_t *ptr;
121
122         for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
123                 if (!strcmp(cvar_name, ptr->name)) break;
124
125         if (ptr == NULL) return; // If we didn't find the cvar, give up
126
127         ptr->value = strtod(value, (char **) NULL);
128 }
129
130 /* ======
131  * cvar() - Get a CVar's value
132  * ======
133  */
134 float cvar (char *cvar_name)
135 {
136         cvar_t *ptr;
137
138         for (ptr = cvar_vars; ptr != NULL; ptr = ptr->next)
139                 if (!strcmp(cvar_name, ptr->name)) break;
140
141         if (ptr == NULL) return 0.0; // If we didn't find the cvar, give up
142
143         return ptr->value;
144 }
145
146
147 /* ==========================================================================
148  * DRAWING
149  * ==========================================================================
150  */
151 void con_draw(void)
152 {
153 /*      char buffer[CON_LINE_LEN+1];
154         int i,j; */
155 /*      for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
156         {
157                 memcpy(buffer, con_display[i], CON_LINE_LEN);
158                 buffer[CON_LINE_LEN] = 0;
159                 gr_string(1,j*10,buffer);
160         }*/
161 }