annotate util.h @ 431:a9b20b31cae1

More code cleanups, this time using clang with excessive warnings enabled. Also re-added util.h, that was missing. Oops.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 24 May 2012 20:57:06 +0300
parents
children 3396acd40147
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
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2008-2012 Tecnic Software productions (TNSP)
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"
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
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 #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
16 #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
17 #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
18 #define NN_BACKBUF_LEN (512) // Backbuffer size (in lines)
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);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 nn_user_t * nn_userhash_foreach(const nn_userhash_t *, int (*func)(const nn_user_t *));
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 nn_user_t * nn_user_match(const nn_userhash_t *list, const char *str, const char *current, BOOL again);
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 *);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 void nn_user_free(nn_user_t *);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 void nn_user_free_list(nn_user_t *);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 nn_user_t * nn_user_copy(const nn_user_t *src);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 nn_user_t * nn_user_find(const nn_userhash_t *list, const char *name);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 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
48 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
49 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
50 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
51 char * nn_strip_tags(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 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
53 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
54
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 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
56 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
57
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 typedef struct
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 {
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 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
62 char *data;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 } nn_editbuf_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
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 qringbuf_t *data; // "Backbuffer" data for this window
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 int pos; // Current position in the window, 0 = real time
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 BOOL dirty;
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 char *id; // Chatter ID, NULL = main window
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 int num; // Window number
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 char *buf;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 size_t len, bufsize;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 size_t chlen;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 } nn_window_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 nn_window_t *nn_window_new(const char *);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 void nn_window_free(nn_window_t *);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 typedef struct
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 {
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 size_t len;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 char *str;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 } nn_strtuple_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 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
102 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
103
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 #endif