annotate distress.c @ 3:5a977ccbc7a9 default tip

Empty changelog
author darius
date Sat, 06 Dec 1997 05:41:29 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1 /* $Id: distress.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
2
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
3 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
4 * distress.c
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
5 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
6 #include "copyright.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
7
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
8 #include <stdio.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
9 #include <stdlib.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
10 #include <signal.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
11 #include <ctype.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
12 #include <string.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
13 #ifndef SERVER
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
14 #include "Wlib.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
15 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
16 #include "defs.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
17 #include "struct.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
18 #include "data.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
19 #include "gameconf.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
20 #include "proto.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
21
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
22 /* #$!@$#% length of address field of messages */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
23 #define ADDRLEN 10
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
24 #define MAXMACLEN 256
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
25 #define MZERO bzero
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
26
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
27
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
28 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
29 * The two in-line defs that follow enable us to avoid calling strcat over
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
30 * and over again.
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
31 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
32 char *pappend;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
33 #define APPEND(ptr,str) \
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
34 pappend = str; \
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
35 while(*pappend) \
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
36 *ptr++ = *pappend++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
37
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
38 #define APPEND_CAP(ptr,cap,str) \
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
39 pappend = str; \
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
40 while(*pappend) \
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
41 { \
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
42 *ptr++ = (cap ? toupper(*pappend) : *pappend); \
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
43 pappend++; \
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
44 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
45
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
46 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
47 * This is a hacked version from the K&R book. Basically it puts <n> into
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
48 * <s> in reverse and then reverses the string...
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
49 * MH. 10-18-93
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
50 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
51 int
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
52 itoa2(n, s)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
53 int n;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
54 char s[];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
55 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
56 int i, c, j, len;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
57
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
58 if ((c = n) < 0)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
59 n = -n;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
60
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
61 i = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
62 do {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
63 s[i++] = n % 10 + '0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
64 } while ((n /= 10) > 0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
65
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
66 if (c < 0)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
67 s[i++] = '-';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
68
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
69 s[i] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
70
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
71 len = i--;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
72
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
73 for (j = 0; i > j; j++, i--) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
74 c = s[i];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
75 s[i] = s[j];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
76 s[j] = c;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
77 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
78
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
79 return len;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
80 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
81
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
82 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
83 * Like APPEND, and APPEND_CAP, APPEND_INT is an in-line function that
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
84 * stops us from calling sprintf over and over again.
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
85 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
86 #define APPEND_INT(ptr, i) \
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
87 ptr += itoa2(i, ptr);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
88
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
89
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
90 #ifdef SERVER
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
91 #define ADDRLEN 10
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
92 #define MAXMACLEN 85
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
93 extern char *shiptypes[];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
94 #define warning(x) fprintf(stderr,x)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
95 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
96
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
97
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
98 char *getaddr(), *getaddr2();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
99
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
100
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
101
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
102 /* This takes an MDISTR flagged message and makes it into a dist struct */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
103 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
104 HandleGenDistr(message, from, to, dist)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
105 char *message;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
106 struct distress *dist;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
107 unsigned char from, to;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
108 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
109
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
110 char *mtext;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
111 unsigned char i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
112
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
113 mtext = &message[ADDRLEN];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
114 #ifndef SERVER
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
115 MZERO((char *) dist, sizeof(dist));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
116 #else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
117 bzero((char *) dist, sizeof(dist));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
118 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
119
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
120 dist->sender = from;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
121 dist->distype = mtext[0] & 0x1f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
122 dist->macroflag = ((mtext[0] & 0x20) > 0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
123 dist->fuelp = mtext[1] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
124 dist->dam = mtext[2] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
125 dist->shld = mtext[3] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
126 dist->etmp = mtext[4] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
127 dist->wtmp = mtext[5] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
128 dist->arms = mtext[6] & 0x1f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
129 dist->sts = mtext[7] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
130 dist->wtmpflag = ((dist->sts & PFWEP) != 0) ? 1 : 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
131 dist->etempflag = ((dist->sts & PFENG) != 0) ? 1 : 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
132 dist->cloakflag = ((dist->sts & PFCLOAK) != 0) ? 1 : 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
133 dist->close_pl = mtext[8] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
134 dist->close_en = mtext[9] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
135 dist->tclose_pl = mtext[10] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
136 dist->tclose_en = mtext[11] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
137 dist->tclose_j = mtext[12] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
138 dist->close_j = mtext[13] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
139 dist->tclose_fr = mtext[14] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
140 dist->close_fr = mtext[15] & 0x7f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
141 i = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
142 while ((mtext[16 + i] & 0xc0) == 0xc0 && (i < 6)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
143 dist->cclist[i] = mtext[16 + i] & 0x1f;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
144 i++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
145 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
146 dist->cclist[i] = mtext[16 + i];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
147 if (dist->cclist[i] == 0x80)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
148 dist->pre_app = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
149 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
150 dist->pre_app = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
151 dist->preappend[0] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
152
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
153 if (mtext[16 + i + 1] != '\0') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
154 strncpy(dist->preappend, &mtext[16 + i + 1], MSG_LEN - 1);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
155 dist->preappend[MSG_LEN - 1] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
156 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
157 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
158
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
159 /* this converts a dist struct to the appropriate text
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
160 (excludes F1->FED text bit).. sorry if this is not what we said
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
161 earlier jeff.. but I lost the paper towel I wrote it all down on */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
162 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
163 Dist2Mesg(dist, buf)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
164 struct distress *dist;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
165 char *buf;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
166 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
167 int len, i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
168
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
169 sprintf(buf, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
170 (dist->macroflag << 5) + (dist->distype),
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
171 dist->fuelp | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
172 dist->dam | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
173 dist->shld | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
174 dist->etmp | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
175 dist->wtmp | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
176 dist->arms | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
177 dist->sts | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
178 dist->close_pl | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
179 dist->close_en | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
180 dist->tclose_pl | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
181 dist->tclose_en | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
182 dist->tclose_j | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
183 dist->close_j | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
184 dist->tclose_fr | 0x80,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
185 dist->close_fr | 0x80);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
186
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
187 /* cclist better be terminated properly otherwise we hose here */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
188 i = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
189 while (((dist->cclist[i] & 0xc0) == 0xc0)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
190 buf[16 + i] = dist->cclist[i];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
191 i++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
192 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
193 /* get the pre/append cclist terminator in there */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
194 buf[16 + i] = dist->cclist[i];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
195 buf[16 + i + 1] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
196
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
197 len = 16 + i + 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
198 if (dist->preappend[0] != '\0') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
199 strncat(buf, dist->preappend, MSG_LEN - len); /* false sense of
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
200 security? */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
201 buf[MSG_LEN - 1] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
202 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
203 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
204
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
205 /* small permutation on the newmacro code... this takes a pointer to
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
206 ** a distress structure and a pointer to a macro syntax string,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
207 ** and converts it into a line of text.
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
208 ** 9/1/93 - jn
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
209 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
210 int
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
211 makedistress(dist, cry, pm)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
212 struct distress *dist; /* the info */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
213 char *cry; /* the call for help! (output) - should be
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
214 array */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
215 char *pm; /* macro to parse, used for distress and
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
216 macro */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
217 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
218 char buf1[10 * MAXMACLEN];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
219 char *pbuf1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
220 char buf2[10 * MAXMACLEN];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
221 char buf3[10 * MAXMACLEN];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
222 char tmp[10 * MAXMACLEN];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
223 int index = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
224 int index2 = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
225 int index3 = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
226 int cap = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
227 struct player *sender;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
228 struct player *j;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
229 struct planet *l;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
230 char *strcap();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
231 #ifndef SERVER
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
232 extern int ping_tloss_sc; /* total % loss 0--100, server to client */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
233 extern int ping_tloss_cs; /* total % loss 0--100, client to server */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
234 extern int ping_av; /* average rt */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
235 extern int ping_sd; /* standard deviation */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
236 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
237 char c;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
238
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
239
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
240 sender = &players[dist->sender];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
241
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
242 if (!(*pm)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
243 cry[0] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
244 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
245 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
246 buf1[0] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
247 pbuf1 = buf1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
248
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
249 /* first step is to substitute variables */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
250 while (*pm) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
251 if (*pm == '%') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
252 pm++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
253
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
254 if (!pm)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
255 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
256
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
257 switch (c = *(pm++)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
258 case ' ':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
259 APPEND(pbuf1, " \0");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
260 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
261 case 'O': /* push a 3 character team name into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
262 cap = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
263 case 'o': /* push a 3 character team name into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
264 APPEND_CAP(pbuf1, cap, teaminfo[sender->p_teami].shortname);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
265 cap = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
266 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
267 case 'a': /* push army number into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
268 APPEND_INT(pbuf1, dist->arms);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
269 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
270 case 'd': /* push damage into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
271 APPEND_INT(pbuf1, dist->dam);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
272 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
273 case 's': /* push shields into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
274 APPEND_INT(pbuf1, dist->shld);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
275 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
276 case 'f': /* push fuel into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
277 APPEND_INT(pbuf1, dist->fuelp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
278 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
279 case 'w': /* push wtemp into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
280 APPEND_INT(pbuf1, dist->wtmp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
281 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
282 case 'e': /* push etemp into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
283 APPEND_INT(pbuf1, dist->etmp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
284 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
285
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
286 case 'P': /* push player id into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
287 case 'G': /* push friendly player id into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
288 case 'H': /* push enemy target player id into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
289
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
290 case 'p': /* push player id into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
291 case 'g': /* push friendly player id into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
292 case 'h': /* push enemy target player id into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
293
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
294 switch (c) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
295 case 'p':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
296 j = &players[dist->tclose_j];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
297 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
298 case 'g':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
299 j = &players[dist->tclose_fr];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
300 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
301 case 'h':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
302 j = &players[dist->tclose_en];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
303 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
304 case 'P':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
305 j = &players[dist->close_j];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
306 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
307 case 'G':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
308 j = &players[dist->close_fr];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
309 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
310 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
311 j = &players[dist->close_en];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
312 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
313 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
314 tmp[0] = j->p_mapchars[1];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
315 tmp[1] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
316 APPEND(pbuf1, tmp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
317 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
318
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
319 case 'n': /* push planet armies into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
320 l = &planets[dist->tclose_pl];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
321 APPEND_INT(pbuf1,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
322 ((l->pl_info & idx_to_mask(sender->p_teami))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
323 ? l->pl_armies : -1));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
324 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
325 case 'B':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
326 cap = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
327 case 'b': /* push planet into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
328 l = &planets[dist->close_pl];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
329 tmp[0] = l->pl_name[0] - 'A' + 'a';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
330 tmp[1] = l->pl_name[1];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
331 tmp[2] = l->pl_name[2];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
332 tmp[3] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
333 APPEND_CAP(pbuf1, cap, tmp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
334 cap = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
335 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
336 case 'L':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
337 cap = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
338 case 'l': /* push planet into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
339 l = &planets[dist->tclose_pl];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
340 tmp[0] = l->pl_name[0] - 'A' + 'a';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
341 tmp[1] = l->pl_name[1];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
342 tmp[2] = l->pl_name[2];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
343 tmp[3] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
344 APPEND_CAP(pbuf1, cap, tmp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
345 cap = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
346 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
347 case 'Z': /* push a 3 character team name into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
348 cap = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
349 case 'z': /* push a 3 character team name into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
350 l = &planets[dist->tclose_pl];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
351 APPEND_CAP(pbuf1, cap,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
352 teaminfo[mask_to_idx(l->pl_owner)].shortname);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
353 cap = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
354 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
355 case 't': /* push a team character into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
356 l = &planets[dist->tclose_pl];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
357 tmp[0] = teaminfo[mask_to_idx(l->pl_owner)].letter;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
358 tmp[1] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
359 APPEND(pbuf1, tmp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
360 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
361 case 'T': /* push my team into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
362 tmp[0] = teaminfo[sender->p_teami].letter;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
363 tmp[1] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
364 APPEND(pbuf1, tmp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
365 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
366 case 'c': /* push my id char into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
367 tmp[0] = sender->p_mapchars[1];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
368 tmp[1] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
369 APPEND(pbuf1, tmp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
370 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
371 case 'W': /* push WTEMP flag into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
372 if (dist->wtmpflag)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
373 tmp[0] = '1';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
374 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
375 tmp[0] = '0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
376 tmp[1] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
377 APPEND(pbuf1, tmp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
378 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
379 case 'E': /* push ETEMP flag into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
380 if (dist->etempflag)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
381 tmp[0] = '1';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
382 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
383 tmp[0] = '0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
384 tmp[1] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
385 APPEND(pbuf1, tmp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
386 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
387 case 'K':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
388 cap = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
389 case 'k':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
390 if (cap)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
391 j = &players[dist->tclose_en];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
392 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
393 j = sender;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
394
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
395 if (j->p_ship->s_type == STARBASE)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
396 sprintf(tmp, "%5.2f", j->p_stats.st_sbkills / 100.0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
397 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
398 sprintf(tmp, "%5.2f", (j->p_stats.st_kills + j->p_stats.st_tkills) / 100.0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
399 APPEND(pbuf1, tmp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
400 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
401
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
402 case 'U': /* push player name into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
403 cap = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
404 case 'u': /* push player name into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
405 j = &players[dist->tclose_en];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
406 APPEND_CAP(pbuf1, cap, j->p_name);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
407 cap = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
408 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
409 case 'I': /* my player name into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
410 cap = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
411 case 'i': /* my player name into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
412 APPEND_CAP(pbuf1, cap, sender->p_name);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
413 cap = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
414 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
415 case 'S': /* push ship type into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
416 #ifndef SERVER
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
417 *pbuf1++ = sender->p_ship->s_desig[0];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
418 *pbuf1++ = sender->p_ship->s_desig[1];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
419 #else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
420 APPEND(pbuf1, shiptypes[sender->p_ship->s_type]);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
421 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
422 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
423
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
424 #ifdef SERVER
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
425 case 'v': /* push average ping round trip time into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
426 case 'V': /* push ping stdev into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
427 case 'y': /* push packet loss into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
428 APPEND(pbuf1, "0\0");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
429 case 'M': /* push capitalized lastMessage into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
430 case 'm': /* push lastMessage into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
431 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
432 #else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
433 case 'M': /* push capitalized lastMessage into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
434 cap = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
435 case 'm': /* push lastMessage into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
436 APPEND_CAP(pbuf1, cap, lastMessage);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
437 cap = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
438 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
439
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
440 case 'v': /* push average ping round trip time into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
441 APPEND_INT(pbuf1, ping_av);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
442 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
443
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
444 case 'V': /* push ping stdev into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
445 APPEND_INT(pbuf1, ping_sd);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
446 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
447
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
448 case 'y': /* push packet loss into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
449 /* this is the weighting formula used be socket.c ntserv */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
450 APPEND_INT(pbuf1, (2 * ping_tloss_sc + ping_tloss_cs) / 3);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
451 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
452 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
453
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
454 case '*': /* push %} into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
455 APPEND(pbuf1, "%*\0");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
456 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
457 case '}': /* push %} into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
458 APPEND(pbuf1, "%}\0");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
459 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
460 case '{': /* push %{ into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
461 APPEND(pbuf1, "%{\0");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
462 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
463 case '!': /* push %! into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
464 APPEND(pbuf1, "%!\0");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
465 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
466 case '?': /* push %? into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
467 APPEND(pbuf1, "%?\0");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
468 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
469 case '%': /* push %% into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
470 APPEND(pbuf1, "%%\0");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
471 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
472 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
473 /* try to continue
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
474 ** bad macro character is skipped entirely,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
475 ** the message will be parsed without whatever %. has occurred. - jn
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
476 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
477 warning("Bad Macro character in distress!");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
478 fprintf(stderr, "Unrecognizable special character in distress pass 1: %c\n", *(pm - 1));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
479 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
480 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
481 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
482 tmp[0] = *pm;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
483 tmp[1] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
484 APPEND(pbuf1, tmp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
485 pm++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
486 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
487
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
488 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
489
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
490 *pbuf1 = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
491
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
492 /* second step is to evaluate tests, buf1->buf2 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
493 testmacro(buf1, buf2, &index, &index2);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
494 buf2[index2] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
495
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
496 if (index2 <= 0) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
497 cry[0] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
498 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
499 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
500 index2 = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
501
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
502 /* third step is to include conditional text, buf2->buf3 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
503 condmacro(buf2, buf3, &index2, &index3, 1);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
504
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
505 if (index3 <= 0) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
506 cry[0] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
507 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
508 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
509 buf3[index3] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
510
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
511 cry[0] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
512 strncat(cry, buf3, MSG_LEN);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
513
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
514 return (index3);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
515 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
516
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
517 int
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
518 testmacro(bufa, bufb, inda, indb)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
519 char *bufa;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
520 char *bufb;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
521 int *inda;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
522 int *indb;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
523 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
524 int state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
525
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
526 if (*indb >= 10 * MAXMACLEN)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
527 return 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
528 /* maybe we should do something more "safe" here (and at other returns)? */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
529
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
530
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
531 while (bufa[*inda] && (*indb < 10 * MAXMACLEN)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
532 if (state) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
533 switch (bufa[(*inda)++]) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
534 case '*': /* push %* into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
535 if (*indb < 10 * MAXMACLEN - 2) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
536 bufb[*indb] = '%';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
537 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
538 bufb[*indb] = '*';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
539 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
540 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
541 return (0); /* we are full, so we are done */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
542 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
543 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
544 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
545
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
546 case '%': /* push %% into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
547 if (*indb < 10 * MAXMACLEN - 2) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
548 bufb[*indb] = '%';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
549 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
550 bufb[*indb] = '%';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
551 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
552 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
553 return (0); /* we are full, so we are done */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
554 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
555 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
556 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
557
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
558 case '{': /* push %{ into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
559 if (*indb < 10 * MAXMACLEN - 2) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
560 bufb[*indb] = '%';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
561 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
562 bufb[*indb] = '{';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
563 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
564 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
565 return (0); /* we are full, so we are done */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
566 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
567 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
568 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
569
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
570 case '}': /* push %} into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
571 if (*indb < 10 * MAXMACLEN - 2) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
572 bufb[*indb] = '%';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
573 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
574 bufb[*indb] = '}';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
575 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
576 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
577 return (0); /* we are full, so we are done */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
578 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
579 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
580 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
581
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
582 case '!': /* push %! into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
583 if (*indb < 10 * MAXMACLEN - 2) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
584 bufb[*indb] = '%';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
585 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
586 bufb[*indb] = '!';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
587 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
588 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
589 return (0); /* we are full, so we are done */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
590 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
591 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
592 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
593
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
594 case '?': /* the dreaded conditional, evaluate it */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
595 bufb[*indb] = '0' + solvetest(bufa, inda);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
596 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
597 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
598 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
599 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
600
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
601 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
602 warning("Bad character in Macro!");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
603 printf("Unrecognizable special character in macro pass2: %c Trying to continue.\n",
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
604 bufa[(*inda) - 1]);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
605 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
606 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
607 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
608 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
609 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
610 if (bufa[*inda] == '%') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
611 state++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
612 (*inda)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
613 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
614 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
615 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
616
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
617
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
618 if (*indb < 10 * MAXMACLEN) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
619 bufb[*indb] = bufa[*inda];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
620 (*inda)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
621 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
622 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
623 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
624 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
625
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
626 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
627 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
628
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
629 int
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
630 solvetest(bufa, inda)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
631 char *bufa;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
632 int *inda;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
633 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
634 int state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
635 char bufh[10 * MAXMACLEN];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
636 char bufc[10 * MAXMACLEN];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
637 int indh = 0, indc = 0, i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
638 char operation;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
639
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
640
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
641 while (bufa[*inda] &&
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
642 bufa[*inda] != '<' &&
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
643 bufa[*inda] != '>' &&
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
644 bufa[*inda] != '=') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
645
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
646 bufh[indh++] = bufa[(*inda)++];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
647 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
648 bufh[indh] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
649
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
650 operation = bufa[(*inda)++];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
651
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
652 while (bufa[*inda] &&
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
653 !(state &&
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
654 ((bufa[*inda] == '?') ||
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
655 (bufa[*inda] == '{')))) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
656
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
657 if (state && (bufa[*inda] == '%' ||
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
658 bufa[*inda] == '!' ||
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
659 bufa[*inda] == '}')) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
660 bufc[indc++] = '%';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
661 } else if (bufa[*inda] == '%') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
662 state = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
663 (*inda)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
664 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
665 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
666 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
667 bufc[indc++] = bufa[(*inda)++];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
668 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
669 bufc[indc] = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
670
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
671 if (bufa[*inda])
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
672 (*inda)--;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
673
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
674 if (!operation) /* incomplete is truth, just ask Godel */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
675 return (1);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
676
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
677 switch (operation) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
678 case '=': /* character by character equality */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
679 if (indc != indh)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
680 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
681 for (i = 0; i < indc; i++) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
682 if (bufc[i] != bufh[i])
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
683 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
684 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
685 return (1);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
686 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
687
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
688 case '<':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
689 if (atoi(bufh) < atoi(bufc))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
690 return (1);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
691 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
692 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
693 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
694
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
695 case '>':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
696 if (atoi(bufh) > atoi(bufc))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
697 return (1);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
698 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
699 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
700 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
701
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
702 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
703 warning("Bad operation in Macro!");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
704 printf("Unrecognizable operation in macro pass3: %c Trying to continue.\n",
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
705 operation);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
706 return (1); /* don't know what happened, pretend we do */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
707 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
708 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
709 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
710
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
711 int
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
712 condmacro(bufa, bufb, inda, indb, flag)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
713 char *bufa;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
714 char *bufb;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
715 int *inda;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
716 int *indb;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
717 int flag;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
718 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
719 int newflag, include;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
720 int state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
721
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
722
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
723 if (*indb >= MAXMACLEN)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
724 return 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
725
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
726 include = flag;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
727
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
728 while (bufa[*inda] && (*indb < MAXMACLEN)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
729 if (state) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
730 switch (bufa[(*inda)++]) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
731 case '}': /* done with this conditional, return */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
732 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
733 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
734
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
735 case '{': /* handle new conditional */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
736 if (*indb > 0) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
737 (*indb)--;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
738 if (bufb[*indb] == '0')
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
739 newflag = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
740 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
741 newflag = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
742 } else /* moron starting with cond, assume true */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
743 newflag = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
744
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
745 if (include)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
746 condmacro(bufa, bufb, inda, indb, newflag);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
747 else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
748 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
749 *inda = skipmacro(bufa, *inda);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
750 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
751
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
752 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
753 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
754 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
755
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
756 case '!': /* handle not indicator */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
757 if (flag)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
758 include = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
759 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
760 include = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
761
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
762 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
763 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
764 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
765
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
766 case '%': /* push % into buf */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
767 if (include) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
768 if (*indb < MAXMACLEN) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
769 bufb[*indb] = '%';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
770 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
771 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
772 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
773 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
774 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
775 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
776
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
777 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
778 warning("Bad character in Macro!");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
779 printf("Unrecognizable special character in macro pass4: %c Trying to continue.\n",
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
780 bufa[(*inda) - 1]);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
781 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
782 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
783 if (bufa[*inda] == '%') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
784 state++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
785 (*inda)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
786 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
787 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
788 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
789
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
790
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
791 if (include) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
792 if (*indb < MAXMACLEN) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
793 bufb[*indb] = bufa[*inda];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
794 (*inda)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
795 (*indb)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
796 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
797 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
798 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
799 (*inda)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
800 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
801 return (0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
802 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
803
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
804 int
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
805 skipmacro(buf, index)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
806 char buf[];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
807 int index;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
808 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
809 int state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
810 int end = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
811
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
812 if (index == 0)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
813 index++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
814
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
815 while (buf[index] && !end) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
816 if (state) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
817 switch (buf[index++]) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
818 case '{':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
819 index = skipmacro(buf, index);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
820 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
821 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
822 case '}':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
823 end = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
824 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
825 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
826 case '!':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
827 case '%':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
828 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
829 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
830 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
831 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
832 warning("Bad character in Macro!");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
833 printf("Unrecognizable special character in macro pass5: %c Trying to continue.\n",
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
834 buf[index - 1]);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
835 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
836 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
837 if (buf[index] == '%') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
838 state++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
839 index++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
840 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
841 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
842 state = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
843 index++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
844 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
845
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
846 return (index);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
847 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
848
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
849
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
850 /* return a pointer to a capitalized copy of string s */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
851 char *
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
852 strcap(s)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
853 char *s;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
854 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
855 static char buf[256]; /* returns static */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
856 register char *t = buf;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
857
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
858 while (*s) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
859 if (islower(*s))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
860 *t++ = toupper(*s++);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
861 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
862 *t++ = *s++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
863 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
864 *t = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
865 if (buf[255]) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
866 fprintf(stderr, "ERROR: String constant overwritten\n");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
867 return NULL;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
868 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
869 return buf;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
870 }