Compare commits

..

4 Commits

3 changed files with 38 additions and 1 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
editor
editor.o

23
Makefile Normal file
View File

@@ -0,0 +1,23 @@
EXEC_FILE=editor
CFLAGS=
all: $(EXEC_FILE)
$(EXEC_FILE): $(EXEC_FILE).o
gcc $(CFLAGS) -o $@ $^ -lncurses
$(EXEC_FILE).o: $(EXEC_FILE).c
gcc $(CFLAGS) -c -o $@ $^
.PHONY: debug
debug: CFLAGS+=-g
debug: $(EXEC_FILE)
.PHONY: allwarn
allwarn: CFLAGS+=-Wall -Wextra -pedantic
allwarn: $(EXEC_FILE)
.PHONY: clean
clean:
rm $(EXEC_FILE)
rm $(EXEC_FILE).o

View File

@@ -27,7 +27,10 @@ Buffer* new_buffer(int size) {
void buffer_grow(Buffer* buffer) {
int old_size = buffer->size;
int old_size = buffer->size; /* I am making use of the fact that, whenever this
function is called, the strlen of the string must
equal the size of the buffer (since the gap size is zero) */
int start_offset = buffer->start - buffer->text;
buffer->size += 10;
buffer->text = realloc(buffer->text,buffer->size);
@@ -135,6 +138,15 @@ int main() {
buffer_right(buffer);
break;
case 10: /* Enter key */
buffer_insert('\n',buffer); /* Why handle this separately?
Because, by default, curses seems to send '\r\n',
which is technically two characters. I should
probably add some code to deal with this scenario
in the 'insert' method (instead of creating an
exception here), but that's a problem for another day. */
break;
default:
buffer_insert(ch,buffer);