From b9899c6cbe2f694c9db36e9d4e15c532d10b546f Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Thu, 25 Oct 2018 12:08:54 -0400 Subject: Started refactoring code Added a src/ and build/ directory Added a include/ directory Included file is smaller --- fbuf.c | 121 ----------------------------------------------------------------- 1 file changed, 121 deletions(-) delete mode 100644 fbuf.c (limited to 'fbuf.c') diff --git a/fbuf.c b/fbuf.c deleted file mode 100644 index 9ce4163..0000000 --- a/fbuf.c +++ /dev/null @@ -1,121 +0,0 @@ -#include "fbuf.h" - -void bputc(struct TMPL_buf* b,char s){ - if(b->head == NULL){ - struct LLNode* new = (struct LLNode*)malloc(sizeof(struct LLNode)); - new->length = 1; - new->data = (char*)malloc(sizeof(char)); - new->data[0] = s; - new->next = NULL; - b->total_len = 1; - b->head = new; - b->tail = new; - }else{ - struct LLNode* last = b->tail; - struct LLNode* new = (struct LLNode*)malloc(sizeof(struct LLNode)); - new->length = 1; - new->data = (char*)malloc(sizeof(char)); - new->data[0] = s; - new->next = NULL; - b->total_len += new->length; - last->next = new; - b->tail = new; - } -} - -void bputsn(struct TMPL_buf* b, char* s, size_t size){ - if(b->head == NULL){ - struct LLNode* new = (struct LLNode*)malloc(sizeof(struct LLNode)); - new->length = size; - new->data = (char*)malloc(sizeof(char)*size); - memcpy(new->data,s,size); - b->total_len = size; - b->head = new; - b->tail = new; - new->next = NULL; - }else{ - struct LLNode* last = b->tail; - struct LLNode* new = (struct LLNode*)malloc(sizeof(struct LLNode)); - new->length = size; - new->data = (char*)malloc(sizeof(char)*size); - memcpy(new->data,s,size); - last->next = new; - new->next = NULL; - b->tail = new; - b->total_len += size; - } -} - -void bputs(struct TMPL_buf* b, char* s){ - size_t len = strlen(s); - bputsn(b,s,len); -} - -struct TMPL_buf* alloc_tmpl_buf(){ - struct TMPL_buf* ret = (struct TMPL_buf*)malloc(sizeof(struct TMPL_buf)); - ret->total_len = 0; - ret->head = NULL; - ret->tail = NULL; - return ret; -} - -void free_llnodes(struct LLNode* l){ - struct LLNode* cursor = l; - struct LLNode* next; - while(cursor != NULL){ - next = cursor->next; - free(cursor->data); - free(cursor); - cursor = next; - } -} - -void free_tmpl_buf(struct TMPL_buf* b){ - free_llnodes(b->head); - free(b); -} - -void bprint(struct TMPL_buf* b){ - printf("-------------\n"); - struct LLNode* cursor = b->head; - while(cursor != NULL){ - printf("Cursor is %p\n",(void*)cursor); - printf("Length:%d\nData:",(int)cursor->length); - char* cb = cursor->data; - size_t cn; - for(cn = 0; cn < cursor->length; cn++){ - printf("%c",*cb); - cb++; - } - cursor = cursor->next; - printf("\n-------------\n"); - } - printf("Done printing\n"); - printf("-----------------------\n"); - -} - -char* bstringify(struct TMPL_buf* b, size_t* size){ - struct LLNode* cursora = b->head; - size_t cursorb = 0; - - struct LLNode* single = (struct LLNode*)malloc(sizeof(struct LLNode)); - single->length = b->total_len; - single->data = (char*)malloc(sizeof(char)*(b->total_len + 1)); - single->data[b->total_len] = '\0'; - single->next = NULL; - - while(cursora != NULL){ - memcpy(single->data + cursorb,cursora->data,cursora->length); - cursorb += cursora->length; - cursora = cursora->next; - } - - free_llnodes(b->head); - - b->head = single; - b->tail = single; - *size = b->total_len; - - return single->data; -} -- cgit v1.2.3-70-g09d2