1 #include "config.h"
2 #include "copyright.h"
3
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 #include "Wlib.h"
8 #include "defs.h"
9 #include "struct.h"
10 #include "data.h"
11 #include "packets.h"
12 #include "cowmain.h"
13 #include "defaults.h"
14 #include "docwin.h"
15
16 extern char cbugs[];
17
18 #define NORMAL 0
19 #define BOLD 1
20 #define ITALIC 2
21
22 struct list
23 {
24 int face;
25 struct list *next;
26 char *data;
27 };
28
29 static struct list *docdata = NULL;
30 static struct list *xtrekrcdata = NULL;
31
32 char *malloc_fail = "Warning: couldn't malloc space for a new doc line!\n";
33
showdocs(int atline)34 void showdocs(int atline)
35 {
36 int i, length, top, center;
37 struct list *data;
38 int count;
39 char buf[128];
40 W_Font font;
41
42 if (!docwin)
43 docwin = W_MakeWindow("DocWin", 0, 181, 500, 500, 0, 2,
44 foreColor);
45
46 W_ClearWindow(docwin);
47
48 if (!W_IsMapped(docwin))
49 W_MapWindow(docwin);
50
51 snprintf(buf, sizeof(buf), "--- %s ---", (char *) query_cowid());
52 length = strlen(buf);
53
54 /* using GWINSIDE instead of TWINSIDE because with small_screen set it
55 * makes more sense to use the smaller width in the interest of saving
56 * screen real estate */
57 center = GWINSIDE / 2 - (length * W_Textwidth) / 2;
58 W_WriteText(docwin, center, W_Textheight, textColor,
59 buf, length, W_BoldFont);
60 snprintf(buf, sizeof(buf), "%s", cbugs);
61 length = strlen(buf);
62 center = GWINSIDE / 2 - (length * W_Textwidth) / 2;
63 W_WriteText(docwin, center, 3 * W_Textheight, textColor,
64 buf, length, W_RegularFont);
65
66 if (!docdata)
67 loaddocs();
68
69 top = 10;
70
71 if (atline > maxdoclines)
72 atline = maxdoclines - 28;
73
74 data = docdata;
75
76 for (i = 0; i < atline; i++)
77 {
78 if (data == NULL)
79 {
80 atline = 0;
81 data = docdata;
82 break;
83 }
84 data = data->next;
85 }
86
87 count = 28; /* Magical # of lines to display */
88
89 for (i = top; i < 50; i++)
90 {
91 if (data == NULL)
92 break;
93
94 if (data->data == NULL)
95 continue;
96
97 switch (data->face)
98 {
99 case BOLD:
100 font = W_BoldFont;
101 break;
102 case ITALIC:
103 font = W_UnderlineFont;
104 break;
105 case NORMAL:
106 font = W_RegularFont;
107 break;
108 }
109
110
111 W_WriteText(docwin, 20, i * W_Textheight, textColor, data->data,
112 strlen(data->data), font);
113 data = data->next;
114 count--;
115
116 if (count <= 0)
117 break;
118 }
119 }
120
loaddocs(void)121 void loaddocs(void)
122 {
123 FILE *fptr;
124 struct list *temp = NULL;
125 struct list *fl = NULL;
126 char line[80], *filename = NULL;
127 int i;
128
129 filename = getdefault("documentation");
130
131 if (filename)
132 {
133 if ((fptr = fopen(filename, "r")) == NULL)
134 return;
135 }
136 else if ((fptr = fopen("BRM.DOC", "r")) == NULL)
137 return;
138
139 temp = (struct list *) malloc(sizeof(struct list));
140
141 if (temp == NULL)
142 { /* malloc error checking -- 10/30/92 EM */
143 printf("%s", malloc_fail);
144 return;
145 }
146
147 while (fgets(line, 80, fptr) != NULL)
148 {
149 if (fl == NULL)
150 fl = temp;
151
152 if (line[strlen(line) - 1] == '\n')
153 line[strlen(line) - 1] = '\0';
154
155 temp->face = NORMAL;
156
157 if (line[0] == '\f')
158 line[0] = ' ';
159
160 if (line[0] == 0x1b)
161 {
162 switch (line[1])
163 {
164 case 'b':
165 temp->face = BOLD;
166 break;
167 case 'i':
168 temp->face = ITALIC;
169 break;
170 }
171
172 line[0] = line[1] = ' ';
173 }
174
175 for (i = 0; i < strlen(line); i++)
176 if (line[i] == '\t')
177 line[i] = ' ';
178
179 temp->data = (char *) malloc(strlen(line) + 1);
180 strcpy(temp->data, line);
181
182 temp->next = (struct list *) malloc(sizeof(struct list));
183
184 if (temp->next == NULL)
185 { /* malloc error checking -- 10/30/92 EM */
186 printf("%s", malloc_fail);
187 return;
188 }
189
190 maxdoclines++;
191 temp = temp->next;
192 temp->data = NULL;
193 temp->next = NULL;
194 }
195
196 temp->next = NULL;
197 docdata = fl;
198 }
199
200
showxtrekrc(int atline)201 void showxtrekrc(int atline)
202 {
203 int i, length, top, center;
204 struct list *data;
205 int count;
206 char buf[128];
207 W_Font font;
208
209 if (!xtrekrcwin)
210 xtrekrcwin = W_MakeWindow("xtrekrcWin", 0, 200, 500, 500, 0, 2,
211 foreColor);
212
213 W_ClearWindow(xtrekrcwin);
214
215 if (!W_IsMapped(xtrekrcwin))
216 W_MapWindow(xtrekrcwin);
217
218 snprintf(buf, sizeof(buf), "--- %s ---", (char *) query_cowid());
219 length = strlen(buf);
220 center = GWINSIDE / 2 - (length * W_Textwidth) / 2;
221 W_WriteText(xtrekrcwin, center, W_Textheight, textColor,
222 buf, length, W_BoldFont);
223 snprintf(buf, sizeof(buf), "%s", cbugs);
224 length = strlen(buf);
225 center = GWINSIDE / 2 - (length * W_Textwidth) / 2;
226 W_WriteText(xtrekrcwin, center, 3 * W_Textheight, textColor,
227 buf, length, W_RegularFont);
228
229 if (!xtrekrcdata)
230 loadxtrekrc();
231
232 top = 10;
233
234 if (atline > maxxtrekrclines)
235 atline = maxxtrekrclines - 28;
236
237 data = xtrekrcdata;
238
239 for (i = 0; i < atline; i++)
240 {
241 if (data == NULL)
242 {
243 atline = 0;
244 data = xtrekrcdata;
245 break;
246 }
247 data = data->next;
248 }
249
250 count = 28; /* Magical # of lines to display */
251
252 for (i = top; i < 50; i++)
253 {
254 if (data == NULL)
255 break;
256
257 if (data->data == NULL)
258 continue;
259
260 switch (data->face)
261 {
262 case BOLD:
263 font = W_BoldFont;
264 break;
265 case ITALIC:
266 font = W_UnderlineFont;
267 break;
268 case NORMAL:
269 font = W_RegularFont;
270 break;
271 }
272
273
274 W_WriteText(xtrekrcwin, 20, i * W_Textheight, textColor, data->data,
275 strlen(data->data), font);
276 data = data->next;
277 count--;
278
279 if (count <= 0)
280 break;
281 }
282 }
283
loadxtrekrc(void)284 void loadxtrekrc(void)
285 {
286 FILE *fptr;
287 struct list *temp = NULL;
288 struct list *fl = NULL;
289 char line[80], filename[256];
290 int i;
291
292 filename[0] = '\0';
293
294 #ifndef WIN32
295 if (!findfile(".netrekrc", filename) && !findfile(".xtrekrc", filename))
296 return;
297 #else
298 if (!findfile("netrekrc", filename) && !findfile("xtrekrc", filename))
299 return;
300 #endif
301
302 if ((fptr = fopen(filename, "r")) == NULL)
303 return;
304
305 temp = (struct list *) malloc(sizeof(struct list));
306
307 if (temp == NULL)
308 { /* malloc error checking -- 10/30/92 EM */
309 printf("%s", malloc_fail);
310 return;
311 }
312
313 while (fgets(line, 80, fptr) != NULL)
314 {
315 if (fl == NULL)
316 fl = temp;
317
318 if (line[strlen(line) - 1] == '\n')
319 line[strlen(line) - 1] = '\0';
320
321 temp->face = NORMAL;
322
323 if (line[0] == '\f')
324 line[0] = ' ';
325
326 if (line[0] == '#')
327 temp->face = ITALIC;
328
329 for (i = 0; i < strlen(line); i++)
330 if (line[i] == '\t')
331 line[i] = ' ';
332
333 temp->data = (char *) malloc(strlen(line) + 1);
334 strcpy(temp->data, line);
335
336 temp->next = (struct list *) malloc(sizeof(struct list));
337
338 if (temp->next == NULL)
339 { /* malloc error checking -- 10/30/92 EM */
340 printf("%s", malloc_fail);
341 return;
342 }
343
344 maxxtrekrclines++;
345 temp = temp->next;
346 temp->data = NULL;
347 temp->next = NULL;
348 }
349
350 temp->next = NULL;
351 xtrekrcdata = fl;
352 }
353