Mercurial > ~darius > hgwebdir.cgi > paradise_client
comparison macrowin.c @ 3:5a977ccbc7a9 default tip
Empty changelog
author | darius |
---|---|
date | Sat, 06 Dec 1997 05:41:29 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:fba0b6e6cdc7 | 3:5a977ccbc7a9 |
---|---|
1 /* $Id: macrowin.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */ | |
2 | |
3 /* | |
4 * macrowin.c from helpwin.c | |
5 * copyright 1993 Nick Trown | |
6 * copyright 1991 ERic mehlhaff | |
7 * Free to use, hack, etc. Just keep these credits here. | |
8 * Use of this code may be dangerous to your health and/or system. | |
9 * Its use is at your own risk. | |
10 * I assume no responsibility for damages, real, potential, or imagined, | |
11 * resulting from the use of it. | |
12 * Yeah.....what Eric said... | |
13 */ | |
14 /* Modified for Paradise, 4/94 -JR */ | |
15 | |
16 /*#include "config.h"*/ | |
17 #include <stdio.h> | |
18 #include <math.h> | |
19 #include <signal.h> | |
20 #include <sys/types.h> | |
21 | |
22 #include <time.h> | |
23 /*#include INC_SYS_TIME*/ | |
24 /*#include INC_STRINGS*/ | |
25 | |
26 #include "Wlib.h" | |
27 #include "defs.h" | |
28 #include "struct.h" | |
29 #include "data.h" | |
30 | |
31 | |
32 /* | |
33 Fills in macro window with the macros defined in the .xtrekrc. | |
34 */ | |
35 | |
36 #define NUMLINES 80 | |
37 | |
38 #define MAXMACRO 65 | |
39 /* maximum length in characters of key explanation */ | |
40 | |
41 #define MACROLEN 255 | |
42 /* length of construction string since we don't know how long a macro can be */ | |
43 | |
44 | |
45 int lineno = 0; | |
46 char maclines[10][MAXMACRO]; | |
47 int maclevel = 0; | |
48 int macrocnt = 0; /* a global from COW-lite, only needed here | |
49 for Paradise. */ | |
50 | |
51 int | |
52 formatline(line) | |
53 char *line; | |
54 { | |
55 register int end; | |
56 char *temp; | |
57 int num = 0; | |
58 | |
59 if (!line) | |
60 return 0; | |
61 if (strlen(line) <= MAXMACRO) { | |
62 strncpy(maclines[num], line, sizeof(maclines[0])); | |
63 lineno++; | |
64 return 1; | |
65 } | |
66 temp = line; | |
67 while (1) { | |
68 end = MAXMACRO - 1; | |
69 if (end > strlen(temp)) { | |
70 lineno++; | |
71 strncpy(maclines[num++], temp, sizeof(maclines[0])); | |
72 return (num); | |
73 } else | |
74 for (; temp[end] != '%'; end--); | |
75 | |
76 lineno++; | |
77 strncpy(maclines[num++], temp, end); | |
78 | |
79 temp = temp + end; | |
80 } | |
81 } | |
82 | |
83 | |
84 void | |
85 filldist(fill) | |
86 int fill; | |
87 { | |
88 register int i; | |
89 register int row; | |
90 register int c; | |
91 int num; | |
92 char key[3]; | |
93 | |
94 lineno = 0; | |
95 for (i = 1, row = 5; distmacro[i].macro != '\0'; i++) { | |
96 if (fill) { | |
97 if (distmacro[i].c < 128) | |
98 sprintf(key, " %c", distmacro[i].c); | |
99 else | |
100 sprintf(key, "^%c", distmacro[i].c - 128); | |
101 sprintf(maclines[0], "%-8s %s", | |
102 key, | |
103 distmacro[i].name); | |
104 W_WriteText(macroWin, 2, row++, W_Yellow, maclines[0], | |
105 strlen(maclines[0]), W_RegularFont); | |
106 } | |
107 lineno++; | |
108 num = formatline(distmacro[i].macro); | |
109 if (fill) { | |
110 for (c = 0; c < num; c++) { | |
111 W_WriteText(macroWin, 8, row++, textColor, maclines[c], | |
112 strlen(maclines[c]), W_RegularFont); | |
113 } | |
114 } | |
115 if (lineno > NUMLINES) | |
116 continue; | |
117 } | |
118 } | |
119 | |
120 | |
121 | |
122 void | |
123 fillmacro() | |
124 { | |
125 register int row, i; | |
126 char macromessage[MACROLEN]; | |
127 struct macro *m; | |
128 | |
129 W_ClearWindow(macroWin); | |
130 sprintf(macromessage, "Packages active: %s%s", | |
131 (F_UseNewMacro ? ", NEWMACRO" : ""), | |
132 (F_gen_distress ? ", RCD" : "")); | |
133 /* (UseSmartMacro ? ", SMARTMACRO" : "")); */ | |
134 | |
135 W_WriteText(macroWin, 2, 1, textColor, | |
136 macromessage, strlen(macromessage), W_RegularFont); | |
137 | |
138 sprintf(macromessage, "Currently showing: %s", | |
139 (maclevel ? "Macros" : "RCDS")); | |
140 | |
141 W_WriteText(macroWin, 2, 2, textColor, | |
142 macromessage, strlen(macromessage), W_RegularFont); | |
143 | |
144 | |
145 if (maclevel == 0) { | |
146 W_WriteText(macroWin, 2, 4, W_Yellow, | |
147 "Key Distress Name", 21, W_RegularFont); | |
148 filldist(1); | |
149 return; | |
150 } | |
151 /* 4 column macro window. This may be changed depending on font size */ | |
152 for (row = 4, i = 0; i < 256; i++) { | |
153 for (m = macrotable[i]; m; m = m->next, row++) { | |
154 if (m->flags & MACRCD) | |
155 break; | |
156 if (i <= 128) | |
157 sprintf(macromessage, "%c ", i); | |
158 else | |
159 sprintf(macromessage, "^%c", i - 128); | |
160 #ifdef NEWMOUSE | |
161 if (macro[i].type == NEWMMOUSE) { | |
162 switch (macro[i].who) { | |
163 case MACRO_PLAYER: | |
164 strcat(macromessage, " PL MS "); | |
165 break; | |
166 case MACRO_TEAM: | |
167 strcat(macromessage, " TM MS "); | |
168 break; | |
169 default: | |
170 strcat(macromessage, " SELF "); | |
171 break; | |
172 } | |
173 } else { | |
174 #endif | |
175 switch (m->to) { | |
176 case 'T': | |
177 strcat(macromessage, " TEAM "); | |
178 break; | |
179 case 'A': | |
180 strcat(macromessage, " ALL "); | |
181 break; | |
182 case 'F': | |
183 strcat(macromessage, " FED "); | |
184 break; | |
185 case 'R': | |
186 strcat(macromessage, " ROM "); | |
187 break; | |
188 case 'K': | |
189 strcat(macromessage, " KLI "); | |
190 break; | |
191 case 'O': | |
192 strcat(macromessage, " ORI "); | |
193 break; | |
194 #ifdef MOO | |
195 case 'M': | |
196 strcat(macromessage, " MOO "); | |
197 break; | |
198 #endif | |
199 #ifdef TOOLS | |
200 case '!': | |
201 strcat(macromessage, " SHELL "); | |
202 break; | |
203 #endif | |
204 #ifdef NEWMACRO | |
205 case '\0': | |
206 strcat(macromessage, " SPEC "); | |
207 break; | |
208 #endif | |
209 case -1: | |
210 switch (m->specialto) { | |
211 case 'I': | |
212 case 'C': | |
213 strcat(macromessage, " SELF "); | |
214 break; | |
215 case 'U': | |
216 case 'P': | |
217 strcat(macromessage, " PL MS "); | |
218 break; | |
219 case 'T': | |
220 case 'Z': | |
221 strcat(macromessage, " TM MS "); | |
222 break; | |
223 case 'G': | |
224 strcat(macromessage, " NR FR "); | |
225 break; | |
226 case 'H': | |
227 strcat(macromessage, " NR EN "); | |
228 break; | |
229 } | |
230 break; | |
231 case -2: | |
232 strcat(macromessage, " QUERY "); | |
233 break; | |
234 default: | |
235 strcat(macromessage, " ---- "); | |
236 break; | |
237 } | |
238 | |
239 #ifdef NEWMOUSE | |
240 } | |
241 #endif | |
242 strcat(macromessage, m->string); | |
243 macromessage[MAXMACRO] = '\0'; | |
244 W_WriteText(macroWin, 2, row, textColor, | |
245 macromessage, strlen(macromessage), W_RegularFont); | |
246 } | |
247 } | |
248 } | |
249 | |
250 void | |
251 switchmacros() | |
252 { | |
253 int num, i; | |
254 struct macro *m; | |
255 | |
256 if (!macroWin) | |
257 return; /* paranoia? */ | |
258 | |
259 maclevel = abs(maclevel - 1); | |
260 | |
261 if (maclevel == 0) { | |
262 lineno = 0; | |
263 filldist(0); | |
264 num = lineno + 5; | |
265 } else { | |
266 for (i = 0, macrocnt = 0; i < 256; i++) { | |
267 for (m = macrotable[i]; m; m = m->next) { | |
268 if (m->flags & MACRCD) | |
269 break; | |
270 macrocnt++; | |
271 #if 0 | |
272 len = strlen(m->string); | |
273 while (len > 0) { | |
274 totmacros++; | |
275 len -= 70; | |
276 } | |
277 #endif | |
278 } | |
279 } | |
280 num = macrocnt + 5; | |
281 } | |
282 W_ResizeText(macroWin, 80, num); | |
283 #if 0 | |
284 W_SetWindowExposeHandler(macroWin, fillmacro); | |
285 W_SetWindowButtonHandler(macroWin, switchmacros); | |
286 #endif | |
287 W_MapWindow(macroWin); | |
288 } | |
289 | |
290 | |
291 | |
292 void showMacroWin() | |
293 { | |
294 int num, i; | |
295 struct macro *m; | |
296 | |
297 if (!macroWin) { | |
298 if (maclevel == 0) { | |
299 lineno = 0; | |
300 filldist(0); | |
301 num = lineno + 5; | |
302 } else { | |
303 for (i = 0, macrocnt = 0; i < 256; i++) { | |
304 for (m = macrotable[i]; m; m = m->next) { | |
305 if (m->flags & MACRCD) | |
306 break; | |
307 macrocnt++; | |
308 #if 0 | |
309 len = strlen(m->string); | |
310 while (len > 0) { | |
311 totmacros++; | |
312 len -= 70; | |
313 } | |
314 #endif | |
315 } | |
316 } | |
317 num = macrocnt + 5; | |
318 } | |
319 | |
320 macroWin = W_MakeTextWindow("macrow", WINSIDE + BORDER, BORDER, | |
321 80, num, NULL, (char*)0, BORDER); | |
322 | |
323 W_ResizeText(macroWin, 80, num); | |
324 #if 0 | |
325 W_DefineTrekCursor(macroWin); | |
326 W_SetWindowExposeHandler(macroWin, fillmacro); | |
327 W_SetWindowButtonHandler(macroWin, switchmacros); | |
328 #endif | |
329 W_MapWindow(macroWin); | |
330 } else if (W_IsMapped(macroWin)) { | |
331 W_DestroyWindow(macroWin); | |
332 macroWin = 0; | |
333 } else | |
334 W_MapWindow(macroWin); | |
335 } |