From 688b44914d5ccc761dcb0f97148fe292d4565836 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Tue, 11 Feb 2020 22:47:57 -0800 Subject: [PATCH] Updating a bunch of stuff. --- Makefile.am | 1 - configure.ac | 4 ++-- ke/erow.c | 1 + ke/main.c | 28 ++++++++++++++++++++++++++++ src/Makefile.am | 8 ++++---- src/dirutils.c | 2 +- src/kst/dirlist.h | 2 +- test/Makefile.am | 9 --------- tests/Makefile.am | 9 +++++++++ {test => tests}/dirlist_test.c | 0 {test => tests}/dirutils_test.c | 0 {test => tests}/iniparser_test.c | 4 +++- 12 files changed, 49 insertions(+), 19 deletions(-) delete mode 100644 test/Makefile.am create mode 100644 tests/Makefile.am rename {test => tests}/dirlist_test.c (100%) rename {test => tests}/dirutils_test.c (100%) rename {test => tests}/iniparser_test.c (98%) diff --git a/Makefile.am b/Makefile.am index 1cf9756..7764db9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,7 +6,6 @@ TESTS = tests/dirlist_test \ dist_noinst_DATA = LICENSE \ testdata \ README \ - example/ \ autobuild.sh test: check diff --git a/configure.ac b/configure.ac index b2f03e2..9944fa0 100644 --- a/configure.ac +++ b/configure.ac @@ -2,8 +2,8 @@ AC_PREREQ([2.59]) AC_INIT([kst], [1.0.0], [kyle@imap.cc], [libdirutils], [https://hg.sr.ht/~kisom/kst]) AM_INIT_AUTOMAKE([1.11 foreign subdir-objects]) -AC_CONFIG_SRCDIR([docs/srm.1]) -AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile test/Makefile]) +AC_CONFIG_SRCDIR([doc/srm.1]) +AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile tests/Makefile]) AC_PROG_CC AC_PROG_INSTALL AC_PROG_RANLIB diff --git a/ke/erow.c b/ke/erow.c index 6c65cc7..fddf82c 100644 --- a/ke/erow.c +++ b/ke/erow.c @@ -91,6 +91,7 @@ erow_insert(int at, char *s, int len) assert(editor->row != NULL); if (at < editor->nrows) { + printf("%d, %d\n", at, editor->nrows); memmove(&editor->row[at+1], &editor->row[at], sizeof(struct erow) * (editor->nrows - at + 1)); } diff --git a/ke/main.c b/ke/main.c index c644532..b4c4ec0 100644 --- a/ke/main.c +++ b/ke/main.c @@ -40,6 +40,8 @@ void editor_set_status(const char *fmt, ...); void display_refresh(); char *editor_prompt(char *, void (*cb)(char *, int16_t)); +void init_editor(); +void process_normal(int16_t c); enum KeyPress { @@ -547,6 +549,24 @@ editor_find() } +void +editor_openfile() +{ + char *filename; + + /* TODO(kyle): combine with dirutils for tab-completion */ + filename = editor_prompt("Load file: %s", NULL); + if (filename == NULL) { + return; + } + + free(editor->row); + init_editor(); + + open_file(filename); +} + + void move_cursor(int16_t c) { @@ -667,10 +687,18 @@ process_kcommand(int16_t c) case 'w': exit(save_file()); case 'd': + while ((editor->row[editor->cury].size - editor->curx) > 0) { + process_normal(DEL_KEY); + } + break; case CTRL_KEY('\\'): /* sometimes it's nice to dump core */ disable_termraw(); abort(); + case 'e': + case CTRL_KEY('e'): + editor_openfile(); + break; case 'f': editor_find(); break; diff --git a/src/Makefile.am b/src/Makefile.am index 7b5809f..2f14feb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,9 +2,9 @@ CFLAGS := -pedantic -Wall -Werror -Wextra -O2 -std=c99 -g lib_LIBRARIES := libdirutils.a libiniparser.a nobase_include_HEADERS := kst/dirutils.h \ - kst/iniparser.h \ -dist_noinst_HEADERS := kst/dirlist.h -bin_PROGRAMS := srm + kst/iniparser.h +dist_noinst_HEADERS = kst/dirlist.h +bin_PROGRAMS = srm ## programs @@ -13,7 +13,7 @@ srm_SOURCES = srm.c ## libraries libdirutils_a_SOURCES = dirutils.c dirlist.c dirwalk.c dirlist.h - +libiniparser_a_SOURCES = iniparser.c diff --git a/src/dirutils.c b/src/dirutils.c index a05baf3..433789a 100644 --- a/src/dirutils.c +++ b/src/dirutils.c @@ -147,7 +147,7 @@ _rmdirs(const char *path) char child[FILENAME_MAX + 1]; struct dirent *dp; DIR *dirp; - int fail; + int fail = EXIT_FAILURE; if (NULL == (dirp = opendir(path))) { return EXIT_FAILURE; diff --git a/src/kst/dirlist.h b/src/kst/dirlist.h index 313187a..ac4b97d 100644 --- a/src/kst/dirlist.h +++ b/src/kst/dirlist.h @@ -21,9 +21,9 @@ #define __DIRUTILS_DIRLIST_H +#include #include #include -#include "queue.h" struct dirlst { diff --git a/test/Makefile.am b/test/Makefile.am deleted file mode 100644 index 4b5b612..0000000 --- a/test/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -AM_LDFLAGS = -L/usr/local/include -lcunit -L../src/ -AM_CFLAGS = -Wall -g -I/usr/local/include -I../src -O0 - -check_PROGRAMS = dirlist_test dirutils_test -dirlist_test_CFLAGS = $(AM_CFLAGS) -dirlist_test_SOURCES = dirlist_test.c -dirutils_test_CFLAGS = $(AM_CFLAGS) -dirutils_test_SOURCES = dirutils_test.c - diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..57db808 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,9 @@ +AM_LDFLAGS = -L/usr/local/lib -lcunit +AM_CFLAGS = -Wall -g -I/usr/local/include -I../src -O0 + +check_PROGRAMS = dirlist_test dirutils_test iniparser-test +dirlist_test_SOURCES = dirlist_test.c ../src/dirlist.c +dirutils_test_SOURCES = dirutils_test.c ../src/dirlist.c ../src/dirutils.c +iniparser_test_SOURCES = iniparser_test.c ../src/iniparser.c + + diff --git a/test/dirlist_test.c b/tests/dirlist_test.c similarity index 100% rename from test/dirlist_test.c rename to tests/dirlist_test.c diff --git a/test/dirutils_test.c b/tests/dirutils_test.c similarity index 100% rename from test/dirutils_test.c rename to tests/dirutils_test.c diff --git a/test/iniparser_test.c b/tests/iniparser_test.c similarity index 98% rename from test/iniparser_test.c rename to tests/iniparser_test.c index ffa59e3..639a6c6 100644 --- a/test/iniparser_test.c +++ b/tests/iniparser_test.c @@ -45,6 +45,7 @@ main(int argc, char *argv[]) argc--; argv++; + iniparser_line_init(&line); for (i = 0; i < argc; i++) { printf("Processing %s\n", argv[i]); ret = iniparser_open(argv[i], &file); @@ -92,5 +93,6 @@ exit: iniparser_destroy(); } - return ret==0; + return ret!=0; } +