aboutsummaryrefslogtreecommitdiff
path: root/buf.c
blob: eb1655e906e6d815e18de636c42c468e78039cbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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){

}