#include #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){ }