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