Mercurial > hg > nnchat
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util.h Thu May 24 20:57:06 2012 +0300 @@ -0,0 +1,104 @@ +/* + * NNChat - Custom chat client for NewbieNudes.com chatrooms + * Written by Matti 'ccr' Hämäläinen + * (C) Copyright 2008-2012 Tecnic Software productions (TNSP) + */ +#ifndef LIBNNUTIL_H +#define LIBNNUTIL_H + +#include <stdio.h> +#include <unistd.h> +#include "th_types.h" +#include "th_string.h" + + +#define NN_TMPBUF_SIZE (4096) +#define NN_ALLOC_SIZE (128) +#define NN_NUM_BUCKETS (256) +#define NN_BACKBUF_LEN (512) // Backbuffer size (in lines) + + +typedef struct _nn_user_t +{ + char *name; + time_t lastspoke, joined; + struct _nn_user_t *next; +} nn_user_t; + + +typedef struct +{ + nn_user_t *buckets[NN_NUM_BUCKETS]; +} nn_userhash_t; + + +nn_userhash_t *nn_userhash_new(void); +nn_user_t * nn_userhash_foreach(const nn_userhash_t *, int (*func)(const nn_user_t *)); +nn_user_t * nn_user_match(const nn_userhash_t *list, const char *str, const char *current, BOOL again); +int nn_userhash_insert(nn_userhash_t *, const char *name); +int nn_userhash_delete(nn_userhash_t *, const char *name); +void nn_userhash_free(nn_userhash_t *); +void nn_user_free(nn_user_t *); +void nn_user_free_list(nn_user_t *); +nn_user_t * nn_user_copy(const nn_user_t *src); +nn_user_t * nn_user_find(const nn_userhash_t *list, const char *name); + + +char * nn_encode_str1(const char *str); +char * nn_decode_str1(const char *str); +char * nn_encode_str2(const char *str); +char * nn_decode_str2(const char *str); +char * nn_strip_tags(const char *str); +char * nn_dbldecode_str(const char *str); +char * nn_dblencode_str(const char *str); + +char * nn_username_encode(char *str); +char * nn_username_decode(char *str); + + +typedef struct +{ + size_t pos, len, size; + char *data; +} nn_editbuf_t; + +int nn_editbuf_write(nn_editbuf_t *buf, size_t pos, char ch); +int nn_editbuf_insert(nn_editbuf_t *buf, size_t pos, char ch); +int nn_editbuf_delete(nn_editbuf_t *buf, size_t pos); +void nn_editbuf_clear(nn_editbuf_t *buf); +nn_editbuf_t * nn_editbuf_new(size_t n); +void nn_editbuf_free(nn_editbuf_t *buf); +nn_editbuf_t * nn_editbuf_copy(nn_editbuf_t *src); +void nn_editbuf_setpos(nn_editbuf_t *buf, size_t pos); +char * nn_editbuf_get_string(nn_editbuf_t *buf, size_t start, size_t end); + + +typedef struct +{ + qringbuf_t *data; // "Backbuffer" data for this window + int pos; // Current position in the window, 0 = real time + BOOL dirty; + + char *id; // Chatter ID, NULL = main window + int num; // Window number + + char *buf; + size_t len, bufsize; + size_t chlen; +} nn_window_t; + +nn_window_t *nn_window_new(const char *); +void nn_window_free(nn_window_t *); + + +typedef struct +{ + size_t len; + char *str; +} nn_strtuple_t; + + +nn_strtuple_t *nn_strtuple_new(size_t, char *); +void nn_strtuple_free(nn_strtuple_t *); + +#endif