annotate util.h @ 676:cfbc5ddf74e5

Possibly fix external build things and llvm static analyzer runs.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 25 Oct 2017 18:23:32 +0300
parents 32c13602c091
children ceb73b712121
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * NNChat - Custom chat client for NewbieNudes.com chatrooms
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Written by Matti 'ccr' Hämäläinen
668
f212cbfbd93c Bump copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 656
diff changeset
4 * (C) Copyright 2008-2016 Tecnic Software productions (TNSP)
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 */
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #ifndef LIBNNUTIL_H
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #define LIBNNUTIL_H
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include <stdio.h>
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include <unistd.h>
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include "th_types.h"
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #include "th_string.h"
669
32c13602c091 Some functions used were factored into new th_datastruct module in th-libs,
Matti Hamalainen <ccr@tnsp.org>
parents: 668
diff changeset
13 #include "th_datastruct.h"
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #define NN_TMPBUF_SIZE (4096)
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #define NN_ALLOC_SIZE (128)
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 #define NN_NUM_BUCKETS (256)
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 typedef struct _nn_user_t
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 {
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 char *name;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 time_t lastspoke, joined;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 struct _nn_user_t *next;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 } nn_user_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 typedef struct
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 {
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 nn_user_t *buckets[NN_NUM_BUCKETS];
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 } nn_userhash_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 nn_userhash_t *nn_userhash_new(void);
485
ad7ddce47878 Improve nn_userhash_foreach() by adding user data parameter.
Matti Hamalainen <ccr@tnsp.org>
parents: 466
diff changeset
36 nn_user_t * nn_userhash_foreach(const nn_userhash_t *, int (*func)(const nn_user_t *, void *userdata), void *data);
446
3396acd40147 Rename and remove some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
37 nn_user_t * nn_userhash_match(const nn_userhash_t *list, const char *str, const char *current, BOOL again);
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 int nn_userhash_insert(nn_userhash_t *, const char *name);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 int nn_userhash_delete(nn_userhash_t *, const char *name);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 void nn_userhash_free(nn_userhash_t *);
446
3396acd40147 Rename and remove some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
41 nn_user_t * nn_userhash_find(const nn_userhash_t *list, const char *name);
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 char * nn_encode_str1(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 char * nn_decode_str1(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 char * nn_encode_str2(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 char * nn_decode_str2(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 char * nn_dbldecode_str(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 char * nn_dblencode_str(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
655
68994cb1f1a6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 581
diff changeset
51 char * nn_strip_tags(const char *str);
68994cb1f1a6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 581
diff changeset
52
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 char * nn_username_encode(char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 char * nn_username_decode(char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 typedef struct
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 {
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 size_t pos, len, size;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 char *data;
492
73f8df0ecffe Add dirty flag to editbuf struct and handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
61 BOOL dirty;
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 } nn_editbuf_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
656
10c05931dfe5 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 655
diff changeset
64
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 int nn_editbuf_write(nn_editbuf_t *buf, size_t pos, char ch);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 int nn_editbuf_insert(nn_editbuf_t *buf, size_t pos, char ch);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 int nn_editbuf_delete(nn_editbuf_t *buf, size_t pos);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 void nn_editbuf_clear(nn_editbuf_t *buf);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 nn_editbuf_t * nn_editbuf_new(size_t n);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 void nn_editbuf_free(nn_editbuf_t *buf);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 nn_editbuf_t * nn_editbuf_copy(nn_editbuf_t *src);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 void nn_editbuf_setpos(nn_editbuf_t *buf, size_t pos);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 char * nn_editbuf_get_string(nn_editbuf_t *buf, size_t start, size_t end);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 typedef struct
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 {
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 size_t len;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 char *str;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 } nn_strtuple_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 nn_strtuple_t *nn_strtuple_new(size_t, char *);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 void nn_strtuple_free(nn_strtuple_t *);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
464
35d67bd0613b Move str_*() functions to util.c
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
86
35d67bd0613b Move str_*() functions to util.c
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
87 BOOL str_get_timestamp(char *str, size_t len, const char *fmt);
35d67bd0613b Move str_*() functions to util.c
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
88 char * str_trim_left(char *buf);
498
b6f6c989deab Add str_trim_right().
Matti Hamalainen <ccr@tnsp.org>
parents: 492
diff changeset
89 char * str_trim_right(char *buf);
464
35d67bd0613b Move str_*() functions to util.c
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
90 int str_compare(const void *s1, const void *s2);
35d67bd0613b Move str_*() functions to util.c
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
91
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 #endif