#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);
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);
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);
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, ...);