From ba6c249454cb8935921eb32ae6452527fa968bd1 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Sat, 15 Feb 2020 01:17:09 +0200 Subject: [PATCH] Computers, how do they even? --- ke/Makefile | 57 ---------------------------------------- ke/config.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ke/main.c | 3 +-- 3 files changed, 74 insertions(+), 59 deletions(-) delete mode 100644 ke/Makefile create mode 100755 ke/config.sh diff --git a/ke/Makefile b/ke/Makefile deleted file mode 100644 index 2a26dca..0000000 --- a/ke/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -VERSION := 0.9.2 -CC ?= gcc -TARGET := ke -OBJS := main.o -LIBS := -lefence - -PREFIX ?= /usr/local -MANDIR ?= /usr/local/man - -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) - -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/config.sh b/ke/config.sh new file mode 100755 index 0000000..47005f7 --- /dev/null +++ b/ke/config.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +TARGET="$(cat Makefile.in | grep 'TARGET :=' | awk -F' ' '{ print $3; }')" +echo "configuring ${TARGET}" + +which sed 2>/dev/null 1>/dev/null +if [ $? -ne 0 ] +then + echo "cannot find sed!" 1>&2 +fi + +OPSYS=$(uname -s) + +echo "Configuring for ${OPSYS}..." +if [ "x${OPSYS}" = "xLinux" ] +then + OS_CFLAGS="-D_DEFAULT_SOURCE -D_XOPEN_SOURCE" + OS_LIBS="-lbsd" + if [ "x${CC}" = "xclang" ]; then + OS_CFLAGS="${OS_CFLAGS} -fsanitize=memory" + fi + if [ -e "/usr/lib/libefence.a" ] + then + OS_LIBS="${OS_LIBS} -lefence" + fi +else + OS_CFLAGS="" + OS_LIBS="" +fi + +if [ -z "${OS_CFLAGS}" ] +then + echo "${OPSYS} requires no extra build flags." +else + echo "${OPSYS} requires build flags ${OS_CFLAGS}" +fi + +if [ -z "${OS_LIBS}" ] +then + echo "${OPSYS} requires no extra linkages." +else + echo "${OPSYS} requires linking with ${OS_LIBS}." +fi + +if [ -z "${PREFIX}" ]; then + PREFIX="/usr/local" +fi + +if [ "${PREFIX}" = "/usr" ] +then + MANDIR="$(PREFIX)/share/man" +elif [ "${PREFIX}" = "/usr/local" ] +then + if [ "${OPSYS}" = "Darwin" ] + then + MANDIR="${PREFIX}/share/man" + else + MANDIR="${PREFIX}/man" + fi +else + MANDIR="${PREFIX}/man" +fi + +echo "prefix: ${PREFIX}" +echo "mandir: ${MANDIR}" + +echo "writing new Makefile" +cat Makefile.in | sed -e "s|OS_CFLAGS|${OS_CFLAGS}|" | \ + sed -e "s|OS_LIBS|${OS_LIBS}|" | \ + sed -e "s|\$PREFIX|${PREFIX}|" | \ + sed -e "s|\$MANDIR|${MANDIR}|" > Makefile + +echo "done." diff --git a/ke/main.c b/ke/main.c index 949279d..c722e66 100644 --- a/ke/main.c +++ b/ke/main.c @@ -427,7 +427,7 @@ row_delete_ch(struct erow *row, int at) if (at < 0 || at >= row->size) { return; } - memmove(&row->line[at], &row->line[at+1], row->size+1); + memmove(&row->line[at], &row->line[at+1], row->size-at); row->size--; erow_update(row); editor.dirty++; @@ -660,7 +660,6 @@ get_keypress() if (seq[2] == '~') { switch (seq[1]) { case '1': return HOME_KEY; - case '2': return /* INS_KEY */ c; case '3': return DEL_KEY; case '4': return END_KEY; case '5': return PG_UP;