Fixed left, need to work on grow

master
Aadhavan Srinivasan 2 years ago
parent 102a0ed093
commit 0d001b550e

@ -27,13 +27,14 @@ Buffer* new_buffer(int size) {
void buffer_grow(Buffer* buffer) { void buffer_grow(Buffer* buffer) {
int start_offset = buffer->start - buffer->text; int start_offset = buffer->start - buffer->text;
buffer->size *= 2; buffer->size += 10;
buffer->text = realloc(buffer->text,buffer->size); buffer->text = realloc(buffer->text,buffer->size);
buffer->start = buffer->text + start_offset; buffer->start = buffer->text + start_offset;
buffer->gap_size = 10; buffer->gap_size = 10;
for (int i=strlen(buffer->text)-1; i > (buffer->start - buffer->text); i--) { // for (int i=strlen(buffer->text)-1; i > (buffer->start - buffer->text); i--) {
*(buffer->text + i + buffer->gap_size) = *(buffer->start + i); for (int i=0; i < (strlen(buffer->text) - start_offset); i++) {
*(buffer->start + i + buffer->gap_size) = *(buffer->start + i);
*(buffer->start + i) = 0; *(buffer->start + i) = 0;
} }
@ -99,7 +100,7 @@ int main() {
if (buffer->start != buffer->text) { /* We don't want to print the string, if the if (buffer->start != buffer->text) { /* We don't want to print the string, if the
gap starts at the first index of the string */ gap starts at the first index of the string */
while (i < strlen(buffer->text)) { while (i < buffer->size) {
addch(*(buffer->text + i)); addch(*(buffer->text + i));
i++; i++;
if ((buffer->start - buffer->text) == i) { /* If we have encountered if ((buffer->start - buffer->text) == i) { /* If we have encountered

Loading…
Cancel
Save