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