Compare commits
4 Commits
f19eb3becc
...
68305de7f6
Author | SHA1 | Date | |
---|---|---|---|
68305de7f6 | |||
bb8917645e | |||
438bd61c0d | |||
da0f6fdf32 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
editor
|
||||||
|
editor.o
|
23
Makefile
Normal file
23
Makefile
Normal 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
|
14
editor.c
14
editor.c
@@ -27,7 +27,10 @@ Buffer* new_buffer(int size) {
|
|||||||
|
|
||||||
void buffer_grow(Buffer* buffer) {
|
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;
|
int start_offset = buffer->start - buffer->text;
|
||||||
buffer->size += 10;
|
buffer->size += 10;
|
||||||
buffer->text = realloc(buffer->text,buffer->size);
|
buffer->text = realloc(buffer->text,buffer->size);
|
||||||
@@ -135,6 +138,15 @@ int main() {
|
|||||||
buffer_right(buffer);
|
buffer_right(buffer);
|
||||||
break;
|
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:
|
default:
|
||||||
buffer_insert(ch,buffer);
|
buffer_insert(ch,buffer);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user