]> Pileus Git - ~andy/lamechat/blobdiff - util.h
Make logfile optional.
[~andy/lamechat] / util.h
diff --git a/util.h b/util.h
index 0e876ea3f4cb58b6a294a13e2b7814f16dafd9dd..9ce35943d0e8f7d2b942c269a66e6633b5bbe8e4 100644 (file)
--- a/util.h
+++ b/util.h
 
 #define new0(type) alloc0(sizeof(type))
 
+#define MATCH_NONE  0b000
+#define MATCH_START 0b001
+#define MATCH_STOP  0b010
+#define MATCH_BOTH  0b011
+#define MATCH_HERE  0b100
+#define MATCH_STR   " <>^-"
+
 /* Types */
-typedef void (*cb_t)(int fd, void *data);
+typedef void (*cb_t)(void *data);
 
 typedef struct {
-       void *data;
+       char *data;
        int   len;
        int   max;
 } buf_t;
@@ -40,29 +47,73 @@ typedef struct {
        void *data;
 } poll_t;
 
+typedef struct {
+       poll_t    poll;
+       cb_t      timer;
+       void     *data;
+} idle_t;
+
+typedef struct {
+       char     *pattern; // regex string
+       void     *regex;   // compiled regex
+       int       count;   // number of matches
+       int       index;   // cached match position
+       int       size;    // max number of matches
+       int      *start;   // start pos of each match
+       int      *stop;    // end pos of each match
+} reg_t;
+
 /* Debug functions */
 void util_init(void);
+void util_exit(void);
+void util_config(const char *group, const char *name, const char *key, const char *value);
 
-/* Stirng functions */
+/* String functions */
 void strsub(char *str, char find, char repl);
 char *strcopy(const char *str);
+void strset(char **old, const char *str);
+int compare(const char *a, const char *b);
 int match(const char *a, const char *b);
+int starts(const char *prefix, const char *str);
+int prefix(const char *str, const char *prefix, const char **suffix);
+int suffix(const char *str, const char *prefix, const char **suffix);
+char *despace(char *text);
+void escape(char *dst, const char *src, int len);
 
 /* Memory functions */
 void *alloc0(int size);
-void append(buf_t *buf, const void *data, int len);
+void free0(void *ptr);
+void append(buf_t *buf, const char *data, int len);
 void release(buf_t *buf);
+const char *reset(buf_t *buf);
+
+/* Data functions */
+int base64(const void *in, int ilen, void *out, int olen);
 
 /* File functions */
 char *read_file(const char *path, int *len);
 
 /* Polling functions */
-int poll_add(poll_t *poll, int fd, cb_t cb, void *data);
-int poll_ctl(poll_t *poll, int in, int out, int err);
-int poll_del(poll_t *poll);
+void poll_add(poll_t *poll, int fd, cb_t cb, void *data);
+void poll_ctl(poll_t *poll, int in, int out, int err);
+void poll_del(poll_t *poll);
 int poll_run(int timeout);
 void poll_quit(void);
 
+/* Idle functions */
+void idle_add(idle_t *idle);
+void idle_set(idle_t *idle, int first, int next);
+
+/* Regex functions */
+void reg_set(reg_t *reg, const char *pattern, int flags);
+void reg_clr(reg_t *reg);
+int reg_match(reg_t *reg, const char *text);
+int reg_check(reg_t *reg, int pos);
+
+/* Spell functions */
+int spell_check(const char *word, const char **fixes);
+
 /* Debug functions */
+void notice(char *fmt, ...);
 void debug(char *fmt, ...);
 void error(char *fmt, ...);