]> Pileus Git - ~andy/lamechat/blobdiff - util.h
Make logfile optional.
[~andy/lamechat] / util.h
diff --git a/util.h b/util.h
index 6310a90580e79e86b8ea73021fc4c7b19b601036..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)(void *data);
 
@@ -46,20 +53,36 @@ typedef struct {
        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 free0(void *ptr);
 void append(buf_t *buf, const char *data, int len);
 void release(buf_t *buf);
 const char *reset(buf_t *buf);
@@ -71,9 +94,9 @@ int base64(const void *in, int ilen, void *out, int olen);
 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);
 
@@ -81,6 +104,16 @@ void poll_quit(void);
 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, ...);