aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor.c22
-rw-r--r--editor.h7
2 files changed, 18 insertions, 11 deletions
diff --git a/editor.c b/editor.c
index 4e40624..012f454 100644
--- a/editor.c
+++ b/editor.c
@@ -71,8 +71,20 @@ struct Editor {
};
/* prototypes */
-static void change_free(Change *c);
-
+static Buffer *buffer_alloc(Editor *ed, size_t size);
+static void buffer_free(Buffer *buf);
+static char *buffer_store(Editor *ed, char *content, size_t len);
+static Piece *piece_alloc(Editor *ed);
+static void piece_free(Piece *p);
+static void piece_init(Piece *p, Piece *prev, Piece *next, char *content, size_t len);
+static void span_init(Span *span, Piece *start, Piece *end);
+static void span_swap(Editor *ed, Span *old, Span *new);
+static Change *change_alloc(Editor *ed);
+static void change_free(Change *c);
+static Action *action_alloc(Editor *ed);
+static void action_free(Action *a);
+static void action_push(Action **stack, Action *action);
+static Action *action_pop(Action **stack);
static Buffer *buffer_alloc(Editor *ed, size_t size) {
Buffer *buf = calloc(1, sizeof(Buffer));
@@ -328,11 +340,11 @@ bool editor_redo(Editor *ed) {
return true;
}
-Iterate copy_content(void *data, size_t pos, const char *content, size_t len) {
+bool copy_content(void *data, size_t pos, const char *content, size_t len) {
char **p = (char **)data;
memcpy(*p, content, len);
*p += len;
- return CONTINUE;
+ return true;
}
int editor_save(Editor *ed, const char *filename) {
@@ -422,7 +434,7 @@ void editor_iterate(Editor *ed, void *data, size_t pos, iterator_callback_t call
return;
size_t len = p->len - loc.off;
char *content = p->content + loc.off;
- while (p && callback(data, pos, content, len) == CONTINUE) {
+ while (p && callback(data, pos, content, len)) {
pos += len;
p = p->next;
if (!p)
diff --git a/editor.h b/editor.h
index 8b1ef13..ae504f0 100644
--- a/editor.h
+++ b/editor.h
@@ -2,12 +2,7 @@
typedef struct Editor Editor;
-typedef enum {
- CONTINUE,
- BREAK,
-} Iterate;
-
-typedef Iterate (*iterator_callback_t)(void *, size_t pos, const char *content, size_t len);
+typedef bool (*iterator_callback_t)(void *, size_t pos, const char *content, size_t len);
bool editor_insert(Editor*, size_t pos, char *c);
bool editor_replace(Editor*, size_t pos, char *c);