annotate util.h @ 464:35d67bd0613b

Move str_*() functions to util.c
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 26 May 2012 06:01:06 +0300
parents 3396acd40147
children 796508f828f6
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 *));
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_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
49 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
50 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
51
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 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
53 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
54
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 typedef struct
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 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
59 char *data;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 } nn_editbuf_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 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
63 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
64 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
65 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
66 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
67 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
68 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
69 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
70 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
71
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 typedef struct
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 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
76 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
77 BOOL dirty;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 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
80 int num; // Window number
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 *buf;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 size_t len, bufsize;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 size_t chlen;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 } nn_window_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 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
88 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
89
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 typedef struct
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 size_t len;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 char *str;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 } nn_strtuple_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 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
99 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
100
464
35d67bd0613b Move str_*() functions to util.c
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
101
35d67bd0613b Move str_*() functions to util.c
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
102 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
103 char * str_trim_left(char *buf);
35d67bd0613b Move str_*() functions to util.c
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
104 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
105
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 #endif