Mercurial > hg > nnchat
comparison util.c @ 713:93d0e1547842
th-libs now uses stdbool.h if possible, so we need to rename all
BOOL/TRUE/FALSE to bool/true/false.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 07 Dec 2022 13:20:25 +0200 |
parents | f3ec1cb11cea |
children |
comparison
equal
deleted
inserted
replaced
712:3a3e4fc53ac7 | 713:93d0e1547842 |
---|---|
5 */ | 5 */ |
6 #include "util.h" | 6 #include "util.h" |
7 #include <time.h> | 7 #include <time.h> |
8 | 8 |
9 | 9 |
10 BOOL str_get_timestamp(char *str, size_t len, const char *fmt) | 10 bool str_get_timestamp(char *str, size_t len, const char *fmt) |
11 { | 11 { |
12 time_t stamp = time(NULL); | 12 time_t stamp = time(NULL); |
13 struct tm *stamp_tm; | 13 struct tm *stamp_tm; |
14 if ((stamp_tm = localtime(&stamp)) != NULL) | 14 if ((stamp_tm = localtime(&stamp)) != NULL) |
15 { | 15 { |
16 strftime(str, len, fmt, stamp_tm); | 16 strftime(str, len, fmt, stamp_tm); |
17 return TRUE; | 17 return true; |
18 } | 18 } |
19 else | 19 else |
20 { | 20 { |
21 str[0] = 0; | 21 str[0] = 0; |
22 return FALSE; | 22 return false; |
23 } | 23 } |
24 } | 24 } |
25 | 25 |
26 | 26 |
27 char * str_trim_left(char *buf) | 27 char * str_trim_left(char *buf) |
235 return NULL; | 235 return NULL; |
236 | 236 |
237 while (*s) | 237 while (*s) |
238 { | 238 { |
239 int i; | 239 int i; |
240 BOOL found = FALSE; | 240 bool found = false; |
241 for (i = 0; i < numHTMLEntities; i++) | 241 for (i = 0; i < numHTMLEntities; i++) |
242 if (HTMLEntities[i].c == *s) | 242 if (HTMLEntities[i].c == *s) |
243 { | 243 { |
244 PUSHSTR(HTMLEntities[i].ent); | 244 PUSHSTR(HTMLEntities[i].ent); |
245 found = TRUE; | 245 found = true; |
246 break; | 246 break; |
247 } | 247 } |
248 if (!found) PUSHCHAR(*s); | 248 if (!found) PUSHCHAR(*s); |
249 | 249 |
250 s++; | 250 s++; |
270 while (*s) | 270 while (*s) |
271 { | 271 { |
272 if (*s == '&') | 272 if (*s == '&') |
273 { | 273 { |
274 int i; | 274 int i; |
275 BOOL found = FALSE; | 275 bool found = false; |
276 for (i = 0; i < numHTMLEntities; i++) | 276 for (i = 0; i < numHTMLEntities; i++) |
277 { | 277 { |
278 const html_entity_t *ent = &HTMLEntities[i]; | 278 const html_entity_t *ent = &HTMLEntities[i]; |
279 size_t len = strlen(ent->ent); | 279 size_t len = strlen(ent->ent); |
280 if (!strncmp(s, ent->ent, len)) | 280 if (!strncmp(s, ent->ent, len)) |
281 { | 281 { |
282 PUSHCHAR(ent->c); | 282 PUSHCHAR(ent->c); |
283 s += len; | 283 s += len; |
284 found = TRUE; | 284 found = true; |
285 break; | 285 break; |
286 } | 286 } |
287 } | 287 } |
288 if (!found) PUSHCHAR(*s++); | 288 if (!found) PUSHCHAR(*s++); |
289 } | 289 } |
331 if (pos >= buf->len) | 331 if (pos >= buf->len) |
332 buf->data[buf->len++] = ch; | 332 buf->data[buf->len++] = ch; |
333 else | 333 else |
334 buf->data[pos] = ch; | 334 buf->data[pos] = ch; |
335 | 335 |
336 buf->dirty = TRUE; | 336 buf->dirty = true; |
337 return 0; | 337 return 0; |
338 } | 338 } |
339 | 339 |
340 | 340 |
341 int nn_editbuf_insert(nn_editbuf_t *buf, size_t pos, char ch) | 341 int nn_editbuf_insert(nn_editbuf_t *buf, size_t pos, char ch) |
351 memmove(&(buf->data[pos+1]), &(buf->data[pos]), buf->len - pos + 1); | 351 memmove(&(buf->data[pos+1]), &(buf->data[pos]), buf->len - pos + 1); |
352 buf->data[pos] = ch; | 352 buf->data[pos] = ch; |
353 } | 353 } |
354 buf->len++; | 354 buf->len++; |
355 | 355 |
356 buf->dirty = TRUE; | 356 buf->dirty = true; |
357 return 0; | 357 return 0; |
358 } | 358 } |
359 | 359 |
360 | 360 |
361 int nn_editbuf_delete(nn_editbuf_t *buf, size_t pos) | 361 int nn_editbuf_delete(nn_editbuf_t *buf, size_t pos) |
362 { | 362 { |
363 if (pos < buf->len) | 363 if (pos < buf->len) |
364 { | 364 { |
365 memmove(&(buf->data[pos]), &(buf->data[pos+1]), buf->len - pos); | 365 memmove(&(buf->data[pos]), &(buf->data[pos+1]), buf->len - pos); |
366 buf->len--; | 366 buf->len--; |
367 buf->dirty = TRUE; | 367 buf->dirty = true; |
368 return 0; | 368 return 0; |
369 } | 369 } |
370 else | 370 else |
371 return -2; | 371 return -2; |
372 } | 372 } |
374 | 374 |
375 void nn_editbuf_clear(nn_editbuf_t *buf) | 375 void nn_editbuf_clear(nn_editbuf_t *buf) |
376 { | 376 { |
377 buf->len = 0; | 377 buf->len = 0; |
378 buf->pos = 0; | 378 buf->pos = 0; |
379 buf->dirty = TRUE; | 379 buf->dirty = true; |
380 } | 380 } |
381 | 381 |
382 | 382 |
383 nn_editbuf_t * nn_editbuf_new(size_t n) | 383 nn_editbuf_t * nn_editbuf_new(size_t n) |
384 { | 384 { |
385 nn_editbuf_t *res = th_malloc0(sizeof(nn_editbuf_t)); | 385 nn_editbuf_t *res = th_malloc0(sizeof(nn_editbuf_t)); |
386 | 386 |
387 res->data = (char *) th_malloc(n); | 387 res->data = (char *) th_malloc(n); |
388 res->size = n; | 388 res->size = n; |
389 res->dirty = TRUE; | 389 res->dirty = true; |
390 | 390 |
391 return res; | 391 return res; |
392 } | 392 } |
393 | 393 |
394 | 394 |
404 | 404 |
405 void nn_editbuf_copy_to(nn_editbuf_t *dst, const nn_editbuf_t *src) | 405 void nn_editbuf_copy_to(nn_editbuf_t *dst, const nn_editbuf_t *src) |
406 { | 406 { |
407 memcpy(dst->data, src->data, src->size); | 407 memcpy(dst->data, src->data, src->size); |
408 dst->pos = dst->len = src->len; | 408 dst->pos = dst->len = src->len; |
409 dst->dirty = TRUE; | 409 dst->dirty = true; |
410 } | 410 } |
411 | 411 |
412 | 412 |
413 nn_editbuf_t * nn_editbuf_copy(const nn_editbuf_t *src) | 413 nn_editbuf_t * nn_editbuf_copy(const nn_editbuf_t *src) |
414 { | 414 { |
455 if (pos >= buf->len) | 455 if (pos >= buf->len) |
456 buf->pos = buf->len; | 456 buf->pos = buf->len; |
457 else | 457 else |
458 buf->pos = pos; | 458 buf->pos = pos; |
459 | 459 |
460 buf->dirty = TRUE; | 460 buf->dirty = true; |
461 } | 461 } |
462 | 462 |
463 | 463 |
464 static uint8_t nn_hash_user(const char *name) | 464 static uint8_t nn_hash_user(const char *name) |
465 { | 465 { |
548 } | 548 } |
549 return NULL; | 549 return NULL; |
550 } | 550 } |
551 | 551 |
552 | 552 |
553 nn_user_t *nn_userhash_match(const nn_userhash_t *list, const char *pattern, const char *current, BOOL again) | 553 nn_user_t *nn_userhash_match(const nn_userhash_t *list, const char *pattern, const char *current, bool again) |
554 { | 554 { |
555 uint8_t hash; | 555 uint8_t hash; |
556 | 556 |
557 if (list == NULL || pattern == NULL) return NULL; | 557 if (list == NULL || pattern == NULL) return NULL; |
558 | 558 |