Mercurial > hg > nnchat
annotate libnnutil.h @ 414:ac4862a94cd1
Move some structures around.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 24 May 2012 06:45:23 +0300 |
parents | 3e64acb433e8 |
children | d015ecbd231d |
rev | line source |
---|---|
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * NNChat - Custom chat client for NewbieNudes.com chatrooms |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Written by Matti 'ccr' Hämäläinen |
394 | 4 * (C) Copyright 2008-2012 Tecnic Software productions (TNSP) |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 */ |
412
3e64acb433e8
Split libnnchat into libnnet and libnnutil
Matti Hamalainen <ccr@tnsp.org>
parents:
396
diff
changeset
|
6 #ifndef LIBNNUTIL_H |
3e64acb433e8
Split libnnchat into libnnet and libnnutil
Matti Hamalainen <ccr@tnsp.org>
parents:
396
diff
changeset
|
7 #define LIBNNUTIL_H |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include <unistd.h> |
365
88ac689d11bc
Win32/MinGW specific fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
360
diff
changeset
|
11 #include "th_types.h" |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 #include "th_string.h" |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 |
412
3e64acb433e8
Split libnnchat into libnnet and libnnutil
Matti Hamalainen <ccr@tnsp.org>
parents:
396
diff
changeset
|
14 |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
15 #define NN_TMPBUF_SIZE (4096) |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
16 #define NN_ALLOC_SIZE (128) |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
17 #define NN_NUM_BUCKETS (256) |
325
c086345d176b
Move some functions to libnnchat and rename nn_find_window to findWindow()
Matti Hamalainen <ccr@tnsp.org>
parents:
285
diff
changeset
|
18 #define NN_BACKBUF_LEN (512) /* Backbuffer size (in lines) */ |
102 | 19 |
396
07a46ca075ab
Add some new functions for socket / connection input buffer
Matti Hamalainen <ccr@tnsp.org>
parents:
395
diff
changeset
|
20 |
390 | 21 typedef struct _nn_user_t |
22 { | |
330
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
23 char *name; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
24 time_t lastspoke, joined; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
25 struct _nn_user_t *next; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
26 } nn_user_t; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
27 |
412
3e64acb433e8
Split libnnchat into libnnet and libnnutil
Matti Hamalainen <ccr@tnsp.org>
parents:
396
diff
changeset
|
28 |
390 | 29 typedef struct |
30 { | |
330
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
31 nn_user_t *buckets[NN_NUM_BUCKETS]; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
32 } nn_userhash_t; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
33 |
412
3e64acb433e8
Split libnnchat into libnnet and libnnutil
Matti Hamalainen <ccr@tnsp.org>
parents:
396
diff
changeset
|
34 |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
35 nn_userhash_t *nn_userhash_new(void); |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
36 nn_user_t * nn_userhash_foreach(const nn_userhash_t *, int (*func)(const nn_user_t *)); |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
37 nn_user_t * nn_user_match(const nn_userhash_t *list, const char *str, const char *current, BOOL again); |
106
c587a99e2096
Drop internal use and storage of encoded usernames.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
38 int nn_userhash_insert(nn_userhash_t *, const char *name); |
c587a99e2096
Drop internal use and storage of encoded usernames.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
39 int nn_userhash_delete(nn_userhash_t *, const char *name); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
40 void nn_userhash_free(nn_userhash_t *); |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
41 void nn_user_free(nn_user_t *); |
102 | 42 void nn_user_free_list(nn_user_t *); |
43 nn_user_t * nn_user_copy(const nn_user_t *src); | |
106
c587a99e2096
Drop internal use and storage of encoded usernames.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
44 nn_user_t * nn_user_find(const nn_userhash_t *list, const char *name); |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
46 |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
47 char * nn_encode_str1(const char *str); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
48 char * nn_decode_str1(const char *str); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
49 char * nn_encode_str2(const char *str); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
50 char * nn_decode_str2(const char *str); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
51 char * nn_strip_tags(const char *str); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
52 char * nn_dbldecode_str(const char *str); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
53 char * nn_dblencode_str(const char *str); |
65
e763ef5cfd53
Move more functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
54 |
285
b765f15f9895
Move nn_username_{de,en}code() to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
55 char * nn_username_encode(char *str); |
b765f15f9895
Move nn_username_{de,en}code() to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
56 char * nn_username_decode(char *str); |
b765f15f9895
Move nn_username_{de,en}code() to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
57 |
89
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
78
diff
changeset
|
58 |
390 | 59 typedef struct |
60 { | |
330
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
61 ssize_t pos, len, size; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
62 char *data; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
63 } nn_editbuf_t; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
64 |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
65 int nn_editbuf_write(nn_editbuf_t *buf, ssize_t pos, int ch); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
66 int nn_editbuf_insert(nn_editbuf_t *buf, ssize_t pos, int ch); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
67 int nn_editbuf_delete(nn_editbuf_t *buf, ssize_t pos); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
68 void nn_editbuf_clear(nn_editbuf_t *buf); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
69 nn_editbuf_t * nn_editbuf_new(ssize_t n); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
70 void nn_editbuf_free(nn_editbuf_t *buf); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
71 nn_editbuf_t * nn_editbuf_copy(nn_editbuf_t *src); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
72 void nn_editbuf_setpos(nn_editbuf_t *buf, ssize_t pos); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
73 char * nn_editbuf_get_string(nn_editbuf_t *buf, ssize_t start, ssize_t end); |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 |
390 | 76 typedef struct |
77 { | |
330
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
78 qringbuf_t *data; /* "Backbuffer" data for this window */ |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
79 int pos; /* Current position in the window, 0 = real time */ |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
80 BOOL dirty; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
81 |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
82 char *id; /* Chatter ID, NULL = main window */ |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
83 int num; /* Window number */ |
390 | 84 |
330
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
85 char *buf; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
86 size_t len, bufsize; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
87 size_t chlen; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
88 } nn_window_t; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
89 |
325
c086345d176b
Move some functions to libnnchat and rename nn_find_window to findWindow()
Matti Hamalainen <ccr@tnsp.org>
parents:
285
diff
changeset
|
90 nn_window_t *nn_window_new(const char *); |
c086345d176b
Move some functions to libnnchat and rename nn_find_window to findWindow()
Matti Hamalainen <ccr@tnsp.org>
parents:
285
diff
changeset
|
91 void nn_window_free(nn_window_t *); |
c086345d176b
Move some functions to libnnchat and rename nn_find_window to findWindow()
Matti Hamalainen <ccr@tnsp.org>
parents:
285
diff
changeset
|
92 |
330
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
93 |
390 | 94 typedef struct |
95 { | |
330
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
96 size_t len; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
97 char *str; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
98 } nn_strtuple_t; |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
99 |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
100 |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
101 nn_strtuple_t *nn_strtuple_new(size_t, char *); |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
102 void nn_strtuple_free(nn_strtuple_t *); |
8e509d6546d3
Move nn_strtuple_* functions to libnnchat.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
103 |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 #endif |