aboutsummaryrefslogtreecommitdiffstats
path: root/buffer.c
diff options
context:
space:
mode:
authornytpu <alex@nytpu.com>2021-05-31 15:45:37 -0600
committernytpu <alex@nytpu.com>2021-05-31 18:23:39 -0600
commit1f5d4354ad79468ca9ec776fbd7a07aeaef1764a (patch)
treeb632eb1ec79858cb7d1dfa1a171e490940dbcace /buffer.c
parentadd editor_deinit() (diff)
downloaded-1f5d4354ad79468ca9ec776fbd7a07aeaef1764a.tar.bz2
ed-1f5d4354ad79468ca9ec776fbd7a07aeaef1764a.zip
major refactor, struct Buffer and struct Options merged into one Editor state struct
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/buffer.c b/buffer.c
index 107ed17..7005651 100644
--- a/buffer.c
+++ b/buffer.c
@@ -10,40 +10,38 @@
#include <stdlib.h>
#include <string.h>
-struct Buffer B;
-
void
insert_row(RowNum at, char *r, size_t len)
{
- if (at > B.numrows) return;
- B.rows = realloc(B.rows, (B.numrows+1) * sizeof(struct Row));
- if (at != B.numrows) {
- memmove(&B.rows[at+1], &B.rows[at], (B.numrows-at) * sizeof(struct Row));
- for (RowNum i = at+1; i <= B.numrows; ++i) ++B.rows[i].idx;
+ if (at > E.numrows) return;
+ E.rows = realloc(E.rows, (E.numrows+1) * sizeof(struct Row));
+ if (at != E.numrows) {
+ memmove(&E.rows[at+1], &E.rows[at], (E.numrows-at) * sizeof(struct Row));
+ for (RowNum i = at+1; i <= E.numrows; ++i) ++E.rows[i].idx;
}
- B.rows[at].size = len;
- B.rows[at].chars = malloc(len + 1);
- memcpy(B.rows[at].chars, r, len);
- B.rows[at].chars[len] = '\0';
- ++B.numrows;
- B.dirty = true;
+ E.rows[at].size = len;
+ E.rows[at].chars = malloc(len + 1);
+ memcpy(E.rows[at].chars, r, len);
+ E.rows[at].chars[len] = '\0';
+ ++E.numrows;
+ E.dirty = true;
}
void
delete_row(RowNum at)
{
- if (at >= B.numrows) return;
- free(B.rows[at].chars);
- memmove(&B.rows[at], &B.rows[at+1], (B.numrows-at-1) * sizeof(struct Row));
- for (RowNum i = at; i < B.numrows; ++i) --B.rows[i].idx;
- --B.numrows;
- B.dirty = true;
+ if (at >= E.numrows) return;
+ free(E.rows[at].chars);
+ memmove(&E.rows[at], &E.rows[at+1], (E.numrows-at-1) * sizeof(struct Row));
+ for (RowNum i = at; i < E.numrows; ++i) --E.rows[i].idx;
+ --E.numrows;
+ E.dirty = true;
}
void
delete_rows(RowNum from, RowNum to)
{
- if (from < 0 || to >= B.numrows) return;
+ if (from < 0 || to >= E.numrows) return;
for (; from != to; ++from) delete_row(from);
}