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