aboutsummaryrefslogtreecommitdiff
path: root/buf.c
diff options
context:
space:
mode:
Diffstat (limited to 'buf.c')
-rw-r--r--buf.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/buf.c b/buf.c
new file mode 100644
index 0000000..eb1655e
--- /dev/null
+++ b/buf.c
@@ -0,0 +1,82 @@
+#include <stdlib.h>
+#include "buf.h"
+
+int max(int a, int b){
+ if (a > b) return a;
+ return b;
+}
+int min(int a, int b){
+ if (a < b) return a;
+ return b;
+}
+
+struct buf_node{
+ char* text;
+ size_t space;
+ struct buf_node* next;
+ struct buf_node* prev;
+};
+
+struct buf{
+ buf_node* head;
+ buf_node* tail;
+ size_t cap;
+};
+
+buf* newbuf(size_t cap){
+ buf* buffer = malloc(sizeof(buf));
+ buffer->cap = cap;
+ buffer->tail = buffer->head = newbufnode(cap);
+ return buffer;
+}
+
+buf_node* newbufnode(size_t cap){
+ buf_node* bufnode = calloc(sizeof(buf_node));
+ bufnode->text = malloc(sizeof(char)*cap);
+ return bufnode;
+}
+
+void bextendbuf(buf* buffer){
+ buffer->tail = buffer->tail->prev->next
+ = buffer->tail->prev = newbufnode();
+}
+
+void fextendbuf(buf* buffer){
+ buffer->head = buffer->head->next->prev
+ = buffer->head->next = newbufnode();
+}
+
+void addchrbuf(buf* buffer, char chr){ // front
+ buf_node* head = buffer->head
+ if (head->space < 0 || head->space == buffer->cap)
+ fextendbuf(buffer);
+ *(head->text + head->space) = chr;
+ head->space++;
+}
+void addstrbuf(buf* buffer, char* str){
+
+}
+char remchrbuf(buf* buffer){
+
+}
+char* remchrbuf(buf* buffer, int ct){
+
+}
+
+void prechrbuf(buf* buffer, char chr){ // back
+
+}
+void prestrbuf(buf* buffer, char* str){
+
+}
+char shfchrbuf(buf* buffer){
+
+}
+char* shfstrbuf(buf* buffer, int ct){
+
+}
+
+char* strpeekbuf(buf* buffer, int loc, int len){
+
+}
+