commit 78db499bbb1371ff05d832c65ea3da4466567007
parent 9b76662831fccb39c45ec4cc5e2223fe150a0fbd
Author: gearsix <gearsix@tuta.io>
Date: Tue, 21 Jun 2022 17:51:12 +0100
bufins, pfree
Diffstat:
M | buf.c | | | 28 | +++++++++++++++++++++++++++- |
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/buf.c b/buf.c
@@ -17,6 +17,11 @@ Piece *palloc()
return &pieceblk[npieces++];
}
+void pfree(Piece *p)
+{
+
+}
+
Piece *psplit(Piece *p, long int offset)
{
Piece *q = palloc();
@@ -86,6 +91,27 @@ Piece *bufidx(Buf *b, size_t pos)
return b->pos;
}
-void bufins(Buf *b, size_t pos, const char *buf)
+void bufins(Buf *b, size_t pos, const char *s)
{
+ const size_t slen = strlen(s);
+ Piece *p = palloc();
+
+ bufidx(pos);
+
+ p->f = b->append;
+ p->off = ftell(b->append);
+ p->len = strlen(buf);
+/* p->undo = ?? */
+ p->redo = NULL;
+ p->prev = b->pos->prev;
+ p->next = b->pos->next;
+ b->pos->next = p;
+
+ fprintf(b->append, "%s", buf);
+ if (ferror(b->append)) {
+ perror("failed to write to append file");
+ --npieces;
+ memset(ins, 0, sizeof(Piece));
+ }
+ return (ins->f == 0) ? b->size : (b->size += slen);
}