Mercurial > hg > nnchat
comparison nnchat.c @ 12:df23968f0c6a
Asdf.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 22 Mar 2008 03:24:04 +0000 |
parents | 53e127854dca |
children | 86fe5f0d1a85 |
comparison
equal
deleted
inserted
replaced
11:707e35b03f89 | 12:df23968f0c6a |
---|---|
174 BOOL bufRealloc(char **buf, size_t *size, size_t add) | 174 BOOL bufRealloc(char **buf, size_t *size, size_t add) |
175 { | 175 { |
176 return ((*buf = th_realloc(*buf, *size + add)) != NULL); | 176 return ((*buf = th_realloc(*buf, *size + add)) != NULL); |
177 } | 177 } |
178 | 178 |
179 #define pushChar(x) bufPushChar(&result, &resSize, &resPos, x) | 179 #define PUSHCHAR(x) bufPushChar(&result, &resSize, &resPos, x) |
180 BOOL bufPushChar(char **buf, size_t *size, size_t *pos, char ch) | 180 BOOL bufPushChar(char **buf, size_t *size, size_t *pos, char ch) |
181 { | 181 { |
182 if (*pos >= *size && !bufRealloc(buf, size, SET_ALLOC_SIZE)) | 182 if (*pos >= *size && !bufRealloc(buf, size, SET_ALLOC_SIZE)) |
183 return FALSE; | 183 return FALSE; |
184 | 184 |
185 (*buf)[*pos] = ch; | 185 (*buf)[*pos] = ch; |
186 (*pos)++; | 186 (*pos)++; |
187 return TRUE; | 187 return TRUE; |
188 } | 188 } |
189 | 189 |
190 #define pushStr(x) bufPushStr(&result, &resSize, &resPos, x) | 190 #define PUSHSTR(x) bufPushStr(&result, &resSize, &resPos, x) |
191 BOOL bufPushStr(char **buf, size_t *size, size_t *pos, char *str) | 191 BOOL bufPushStr(char **buf, size_t *size, size_t *pos, char *str) |
192 { | 192 { |
193 size_t tmpLen; | 193 size_t tmpLen; |
194 | 194 |
195 if (!str) return FALSE; | 195 if (!str) return FALSE; |
216 return NULL; | 216 return NULL; |
217 | 217 |
218 while (*s) { | 218 while (*s) { |
219 switch (*s) { | 219 switch (*s) { |
220 case 32: | 220 case 32: |
221 pushChar('+'); | 221 PUSHCHAR('+'); |
222 break; | 222 break; |
223 | 223 |
224 default: | 224 default: |
225 if (th_isalnum(*s)) | 225 if (th_isalnum(*s)) |
226 pushChar(*s); | 226 PUSHCHAR(*s); |
227 else { | 227 else { |
228 char tmpStr[4]; | 228 char tmpStr[4]; |
229 sprintf(tmpStr, "%2X", (unsigned char) *s); | 229 sprintf(tmpStr, "%2X", (unsigned char) *s); |
230 pushChar('%'); | 230 PUSHCHAR('%'); |
231 pushStr(tmpStr); | 231 PUSHSTR(tmpStr); |
232 } | 232 } |
233 break; | 233 break; |
234 } | 234 } |
235 s++; | 235 s++; |
236 } | 236 } |
237 pushChar(0); | 237 PUSHCHAR(0); |
238 | 238 |
239 return result; | 239 return result; |
240 } | 240 } |
241 | 241 |
242 int getxdigit(int c, int shift) | 242 int getxdigit(int c, int shift) |
268 return NULL; | 268 return NULL; |
269 | 269 |
270 while (*s) { | 270 while (*s) { |
271 switch (*s) { | 271 switch (*s) { |
272 case '+': | 272 case '+': |
273 pushChar(' '); | 273 PUSHCHAR(' '); |
274 s++; | 274 s++; |
275 break; | 275 break; |
276 | 276 |
277 case '%': | 277 case '%': |
278 s++; | 278 s++; |
279 if (*s == '%') | 279 if (*s == '%') |
280 pushChar('%'); | 280 PUSHCHAR('%'); |
281 else if ((c = getxdigit(*s, 4)) >= 0) { | 281 else if ((c = getxdigit(*s, 4)) >= 0) { |
282 int i = getxdigit(*(++s), 0); | 282 int i = getxdigit(*(++s), 0); |
283 if (i >= 0) { | 283 if (i >= 0) { |
284 pushChar(c | i); | 284 PUSHCHAR(c | i); |
285 } else { | 285 } else { |
286 pushChar('§'); | 286 PUSHCHAR('§'); |
287 pushChar(*s); | 287 PUSHCHAR(*s); |
288 } | 288 } |
289 } else { | 289 } else { |
290 pushChar('§'); | 290 PUSHCHAR('§'); |
291 pushChar(*s); | 291 PUSHCHAR(*s); |
292 } | 292 } |
293 s++; | 293 s++; |
294 break; | 294 break; |
295 | 295 |
296 default: | 296 default: |
297 pushChar(*s); | 297 PUSHCHAR(*s); |
298 s++; | 298 s++; |
299 } | 299 } |
300 } | 300 } |
301 pushChar(0); | 301 PUSHCHAR(0); |
302 | 302 |
303 return result; | 303 return result; |
304 } | 304 } |
305 | 305 |
306 | 306 |
318 while (*s) { | 318 while (*s) { |
319 if (*s == '<') { | 319 if (*s == '<') { |
320 while (*s && *s != '>') s++; | 320 while (*s && *s != '>') s++; |
321 if (*s == '>') s++; | 321 if (*s == '>') s++; |
322 } else | 322 } else |
323 pushChar(*s++); | 323 PUSHCHAR(*s++); |
324 } | 324 } |
325 pushChar(0); | 325 PUSHCHAR(0); |
326 | 326 |
327 return result; | 327 return result; |
328 } | 328 } |
329 | 329 |
330 | 330 |
363 while (*s) { | 363 while (*s) { |
364 int i; | 364 int i; |
365 BOOL found = FALSE; | 365 BOOL found = FALSE; |
366 for (i = 0; i < numHTMLEntities; i++) | 366 for (i = 0; i < numHTMLEntities; i++) |
367 if (HTMLEntities[i].c == *s) { | 367 if (HTMLEntities[i].c == *s) { |
368 pushStr(HTMLEntities[i].ent); | 368 PUSHSTR(HTMLEntities[i].ent); |
369 found = TRUE; | 369 found = TRUE; |
370 break; | 370 break; |
371 } | 371 } |
372 if (!found) pushChar(*s); | 372 if (!found) PUSHCHAR(*s); |
373 | 373 |
374 s++; | 374 s++; |
375 } | 375 } |
376 pushChar(0); | 376 PUSHCHAR(0); |
377 | 377 |
378 return result; | 378 return result; |
379 } | 379 } |
380 | 380 |
381 | 381 |
396 BOOL found = FALSE; | 396 BOOL found = FALSE; |
397 for (i = 0; i < numHTMLEntities; i++) { | 397 for (i = 0; i < numHTMLEntities; i++) { |
398 html_entity_t *ent = &HTMLEntities[i]; | 398 html_entity_t *ent = &HTMLEntities[i]; |
399 int len = strlen(ent->ent); | 399 int len = strlen(ent->ent); |
400 if (!strncmp(s, ent->ent, len)) { | 400 if (!strncmp(s, ent->ent, len)) { |
401 pushChar(ent->c); | 401 PUSHCHAR(ent->c); |
402 s += len; | 402 s += len; |
403 found = TRUE; | 403 found = TRUE; |
404 break; | 404 break; |
405 } | 405 } |
406 } | 406 } |
407 if (!found) pushChar(*s++); | 407 if (!found) PUSHCHAR(*s++); |
408 } else | 408 } else |
409 pushChar(*s++); | 409 PUSHCHAR(*s++); |
410 } | 410 } |
411 pushChar(0); | 411 PUSHCHAR(0); |
412 | 412 |
413 return result; | 413 return result; |
414 } | 414 } |
415 | 415 |
416 | 416 |