From e999245c8e8a9f6dd33063fc5d9f20f16b5948d9 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Thu, 13 Feb 2020 16:02:53 +0000 Subject: [PATCH] switching to config build sys lunix is why we can't have nice things --- ke/Makefile | 85 +++++++++++++++++++++++++++----------------------- ke/Makefile.in | 57 +++++++++++++++++++++++++++++++++ ke/main.c | 43 ++++++++++++++----------- 3 files changed, 127 insertions(+), 58 deletions(-) create mode 100644 ke/Makefile.in diff --git a/ke/Makefile b/ke/Makefile index 6445b27..2a26dca 100644 --- a/ke/Makefile +++ b/ke/Makefile @@ -1,50 +1,57 @@ -BIN := ke -OBJS := main.o -INSTROOT := $(HOME) VERSION := 0.9.2 +CC ?= gcc +TARGET := ke +OBJS := main.o +LIBS := -lefence -LDFLAGS := -CFLAGS := -pedantic -Wall -Werror -Wextra -O2 -std=c99 -g -CFLAGS += -fno-builtin-memmove -DKE_VERSION="\"$(VERSION)\"" +PREFIX ?= /usr/local +MANDIR ?= /usr/local/man -.PHONY: all -all: build +CFLAGS += -Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g +CFLAGS += -DKE_VERSION="\"$(TARGET) version $(VERSION)\"" +CFLAGS += -D_DEFAULT_SOURCE -D_POSIX_SOURCE -D_XOPEN_SOURCE +all: $(TARGET) -.PHONY: build -build: $(BIN) - -$(BIN): $(OBJS) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) - -$(BIN).1.txt: $(BIN).1 - mandoc -Tutf8 $(BIN).1 > $@ - -.PHONY: clean clean: - rm -f $(BIN) $(OBJS) *.core keypress + -rm -f .?*.* *.core *.o *.html tags $(TARGET) $(OBJS) + -rm -rf security + -rm -rf $(TARGET)-$(VERSION) + -rm -f $(TARGET)-$(VERSION).tgz -.PHONY: run -run: $(BIN) - reset - ./$(BIN) hello.txt +$(TARGET): $(OBJS) + ${CC} -o $(TARGET) ${CFLAGS} ${LDFLAGS} $(LIBS) $(OBJS) -keypress: keypress.c - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ keypress.c +install: $(TARGET) + install -m 0755 $(TARGET) $(PREFIX)/bin/$(TARGET) + install -m 0755 -d $(MANDIR)/man1 + install -m 0444 $(TARGET).1 $(MANDIR)/man1/$(TARGET).1 -.PHONY: install -install: $(BIN) $(BIN).1 - install -d $(INSTROOT)/bin/ - install -d $(INSTROOT)/share/man/man1 - install -C $(BIN) $(INSTROOT)/bin/ - install -C $(BIN).1 $(INSTROOT)/share/man/man1/$(BIN).1 +uninstall: + -rm -f $(PREFIX)/bin/$(TARGET) + -rm -f $(MANDIR)/man1/$(TARGET).1 -.PHONY: upload -upload: $(BIN).1.txt - scp main.c p.kyleisom.net:/var/www/sites/p/ke/$(BIN)_$(VERSION).c.txt - scp $(BIN).1.txt p.kyleisom.net:/var/www/sites/p/ke/$(BIN).1.txt +lint: + -mkdir security + -rats -w 3 $(TARGET).[ch] > security/rats.out + -lint -fhrs $(TARGET).c > security/lint.out + -splint +posixlib $(TARGET).[ch] > security/splint.out -.PHONY: cloc -cloc: - cloc main.c +dist: clean + -mkdir $(TARGET)-$(VERSION) + -cp * $(TARGET)-$(VERSION) + -cd $(TARGET)-$(VERSION) && make distclean && cd .. + -tar czf $(TARGET)-$(VERSION).tgz $(TARGET)-$(VERSION) -%.o: %.c +distclean: clean + -rm -f Makefile + +htmldoc: + -mandoc -Thtml $(TARGET).1 > $(TARGET).1.html + +tags: + ctags *.[ch] + +.c.o: + $(CC) -c ${CFLAGS} $? + +.PHONY: clean all install lint uninstall dist distclean htmldoc tags diff --git a/ke/Makefile.in b/ke/Makefile.in new file mode 100644 index 0000000..2ad0c3a --- /dev/null +++ b/ke/Makefile.in @@ -0,0 +1,57 @@ +VERSION := 0.9.2 +CC ?= gcc +TARGET := ke +OBJS := main.o +LIBS := + +PREFIX ?= $PREFIX +MANDIR ?= $MANDIR + +CFLAGS += -Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g +CFLAGS += -DKE_VERSION="\"$(TARGET) version $(VERSION)\"" +CFLAGS += OS_CFLAGS +all: $(TARGET) + +clean: + -rm -f .?*.* *.core *.o *.html tags $(TARGET) $(OBJS) + -rm -rf security + -rm -rf $(TARGET)-$(VERSION) + -rm -f $(TARGET)-$(VERSION).tgz + +$(TARGET): $(OBJS) + ${CC} -o $(TARGET) ${CFLAGS} ${LDFLAGS} $(LIBS) $(OBJS) + +install: $(TARGET) + install -m 0755 $(TARGET) $(PREFIX)/bin/$(TARGET) + install -m 0755 -d $(MANDIR)/man1 + install -m 0444 $(TARGET).1 $(MANDIR)/man1/$(TARGET).1 + +uninstall: + -rm -f $(PREFIX)/bin/$(TARGET) + -rm -f $(MANDIR)/man1/$(TARGET).1 + +lint: + -mkdir security + -rats -w 3 $(TARGET).[ch] > security/rats.out + -lint -fhrs $(TARGET).c > security/lint.out + -splint +posixlib $(TARGET).[ch] > security/splint.out + +dist: clean + -mkdir $(TARGET)-$(VERSION) + -cp * $(TARGET)-$(VERSION) + -cd $(TARGET)-$(VERSION) && make distclean && cd .. + -tar czf $(TARGET)-$(VERSION).tgz $(TARGET)-$(VERSION) + +distclean: clean + -rm -f Makefile + +htmldoc: + -mandoc -Thtml $(TARGET).1 > $(TARGET).1.html + +tags: + ctags *.[ch] + +.c.o: + $(CC) -c ${CFLAGS} $? + +.PHONY: clean all install lint uninstall dist distclean htmldoc tags diff --git a/ke/main.c b/ke/main.c index 2392403..949279d 100644 --- a/ke/main.c +++ b/ke/main.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -77,44 +78,43 @@ void editor_set_status(const char *fmt, ...); /* miscellaneous */ void die(const char *s); int get_winsz(int *rows, int *cols); -void goto_line(); +void goto_line(void); void delete_row(int at); void row_append_row(struct erow *row, char *s, int len); void row_insert_ch(struct erow *row, int at, int16_t c); void row_delete_ch(struct erow *row, int at); void insertch(int16_t c); -void deletech(); +void deletech(void); void open_file(const char *filename); char *rows_to_buffer(int *buflen); -int save_file(); +int save_file(void); uint16_t is_arrow_key(int16_t c); -int16_t get_keypress(); -void display_refresh(); +int16_t get_keypress(void); +void display_refresh(void); void editor_find_callback(char *query, int16_t c); -void editor_find(); +void editor_find(void); char *editor_prompt(char *, void (*cb)(char *, int16_t)); -void editor_openfile(); +void editor_openfile(void); void move_cursor(int16_t c); -void newline(); +void newline(void); void process_kcommand(int16_t c); void process_normal(int16_t c); void process_escape(int16_t c); -int process_keypress(); -void enable_termraw(); +int process_keypress(void); +void enable_termraw(void); void display_clear(struct abuf *ab); -void disable_termraw(); -void setup_terminal(); +void disable_termraw(void); +void setup_terminal(void); void draw_rows(struct abuf *ab); -char status_mode_char(); +char status_mode_char(void); void draw_status_bar(struct abuf *ab); void draw_message_line(struct abuf *ab); -void scroll(); -void display_refresh(); +void scroll(void); +void display_refresh(void); void editor_set_status(const char *fmt, ...); -void loop(); -void init_editor(); +void loop(void); +void init_editor(void); void process_normal(int16_t c); -void disable_termraw(); enum KeyPress { @@ -133,6 +133,10 @@ enum KeyPress { }; +/* + * editor is the global editor state; it should be broken out + * to buffers and screen state, probably. + */ struct editor_t { struct termios entry_term; int rows, cols; @@ -172,7 +176,6 @@ ab_free(struct abuf *buf) buf->b = NULL; } - char nibble_to_hex(char c) { @@ -899,6 +902,8 @@ move_cursor(int16_t c) while (--reps) { move_cursor(c == PG_UP ? ARROW_UP : ARROW_DOWN); } + + break; } case HOME_KEY: