Mercurial > hg > nnchat
comparison 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 |
comparison
equal
deleted
inserted
replaced
430:aaadf6cea6be | 431:a9b20b31cae1 |
---|---|
1 /* | |
2 * NNChat - Custom chat client for NewbieNudes.com chatrooms | |
3 * Written by Matti 'ccr' Hämäläinen | |
4 * (C) Copyright 2008-2012 Tecnic Software productions (TNSP) | |
5 */ | |
6 #ifndef LIBNNUTIL_H | |
7 #define LIBNNUTIL_H | |
8 | |
9 #include <stdio.h> | |
10 #include <unistd.h> | |
11 #include "th_types.h" | |
12 #include "th_string.h" | |
13 | |
14 | |
15 #define NN_TMPBUF_SIZE (4096) | |
16 #define NN_ALLOC_SIZE (128) | |
17 #define NN_NUM_BUCKETS (256) | |
18 #define NN_BACKBUF_LEN (512) // Backbuffer size (in lines) | |
19 | |
20 | |
21 typedef struct _nn_user_t | |
22 { | |
23 char *name; | |
24 time_t lastspoke, joined; | |
25 struct _nn_user_t *next; | |
26 } nn_user_t; | |
27 | |
28 | |
29 typedef struct | |
30 { | |
31 nn_user_t *buckets[NN_NUM_BUCKETS]; | |
32 } nn_userhash_t; | |
33 | |
34 | |
35 nn_userhash_t *nn_userhash_new(void); | |
36 nn_user_t * nn_userhash_foreach(const nn_userhash_t *, int (*func)(const nn_user_t *)); | |
37 nn_user_t * nn_user_match(const nn_userhash_t *list, const char *str, const char *current, BOOL again); | |
38 int nn_userhash_insert(nn_userhash_t *, const char *name); | |
39 int nn_userhash_delete(nn_userhash_t *, const char *name); | |
40 void nn_userhash_free(nn_userhash_t *); | |
41 void nn_user_free(nn_user_t *); | |
42 void nn_user_free_list(nn_user_t *); | |
43 nn_user_t * nn_user_copy(const nn_user_t *src); | |
44 nn_user_t * nn_user_find(const nn_userhash_t *list, const char *name); | |
45 | |
46 | |
47 char * nn_encode_str1(const char *str); | |
48 char * nn_decode_str1(const char *str); | |
49 char * nn_encode_str2(const char *str); | |
50 char * nn_decode_str2(const char *str); | |
51 char * nn_strip_tags(const char *str); | |
52 char * nn_dbldecode_str(const char *str); | |
53 char * nn_dblencode_str(const char *str); | |
54 | |
55 char * nn_username_encode(char *str); | |
56 char * nn_username_decode(char *str); | |
57 | |
58 | |
59 typedef struct | |
60 { | |
61 size_t pos, len, size; | |
62 char *data; | |
63 } nn_editbuf_t; | |
64 | |
65 int nn_editbuf_write(nn_editbuf_t *buf, size_t pos, char ch); | |
66 int nn_editbuf_insert(nn_editbuf_t *buf, size_t pos, char ch); | |
67 int nn_editbuf_delete(nn_editbuf_t *buf, size_t pos); | |
68 void nn_editbuf_clear(nn_editbuf_t *buf); | |
69 nn_editbuf_t * nn_editbuf_new(size_t n); | |
70 void nn_editbuf_free(nn_editbuf_t *buf); | |
71 nn_editbuf_t * nn_editbuf_copy(nn_editbuf_t *src); | |
72 void nn_editbuf_setpos(nn_editbuf_t *buf, size_t pos); | |
73 char * nn_editbuf_get_string(nn_editbuf_t *buf, size_t start, size_t end); | |
74 | |
75 | |
76 typedef struct | |
77 { | |
78 qringbuf_t *data; // "Backbuffer" data for this window | |
79 int pos; // Current position in the window, 0 = real time | |
80 BOOL dirty; | |
81 | |
82 char *id; // Chatter ID, NULL = main window | |
83 int num; // Window number | |
84 | |
85 char *buf; | |
86 size_t len, bufsize; | |
87 size_t chlen; | |
88 } nn_window_t; | |
89 | |
90 nn_window_t *nn_window_new(const char *); | |
91 void nn_window_free(nn_window_t *); | |
92 | |
93 | |
94 typedef struct | |
95 { | |
96 size_t len; | |
97 char *str; | |
98 } nn_strtuple_t; | |
99 | |
100 | |
101 nn_strtuple_t *nn_strtuple_new(size_t, char *); | |
102 void nn_strtuple_free(nn_strtuple_t *); | |
103 | |
104 #endif |