|
|
|
@ -26,19 +26,21 @@ Buffer* new_buffer(int size) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void buffer_grow(Buffer* buffer) {
|
|
|
|
|
|
|
|
|
|
int old_size = buffer->size;
|
|
|
|
|
int start_offset = buffer->start - buffer->text;
|
|
|
|
|
buffer->size += 10;
|
|
|
|
|
buffer->text = realloc(buffer->text,buffer->size);
|
|
|
|
|
buffer->start = buffer->text + start_offset;
|
|
|
|
|
|
|
|
|
|
buffer->gap_size = 10;
|
|
|
|
|
// for (int i=strlen(buffer->text)-1; i > (buffer->start - buffer->text); i--) {
|
|
|
|
|
for (int i=0; i < (strlen(buffer->text) - start_offset); i++) {
|
|
|
|
|
for (int i=0; i < (old_size - start_offset); i++) {
|
|
|
|
|
*(buffer->start + i + buffer->gap_size) = *(buffer->start + i);
|
|
|
|
|
*(buffer->start + i) = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffer->end = buffer->start + buffer->gap_size;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void buffer_insert(char ch, Buffer* buffer) {
|
|
|
|
@ -59,8 +61,10 @@ void buffer_delete(Buffer* buffer) {
|
|
|
|
|
|
|
|
|
|
void buffer_right(Buffer* buffer) {
|
|
|
|
|
if (buffer->end != buffer->text + buffer->size) {
|
|
|
|
|
char c = *(buffer->end);
|
|
|
|
|
buffer->start++;
|
|
|
|
|
buffer->end++;
|
|
|
|
|
*(buffer->start -1) = c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -70,6 +74,7 @@ void buffer_left(Buffer* buffer) {
|
|
|
|
|
buffer->start--;
|
|
|
|
|
buffer->end--;
|
|
|
|
|
*(buffer->end) = c;
|
|
|
|
|
*(buffer->start) = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|