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