From 8f5419f2a29b9088ad1d0db63d3016aa3c44cd27 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Tue, 11 Feb 2020 20:27:53 -0800 Subject: [PATCH] autoconfiguration --- Makefile.am | 12 ++++++++ configure.ac | 19 ++++++++++++ doc/Makefile.am | 3 ++ src/Makefile | 40 ------------------------- src/Makefile.am | 19 ++++++++++++ src/kst/dirlist.h | 42 +++++++++++++++++++++++++++ src/kst/dirutils.h | 53 ++++++++++++++++++++++++++++++++++ src/kst/iniparser.h | 51 ++++++++++++++++++++++++++++++++ test/Makefile.am | 9 ++++++ {src => test}/dirlist_test.c | 4 +-- {src => test}/dirutils_test.c | 17 +++++++---- {src => test}/iniparser_test.c | 0 12 files changed, 221 insertions(+), 48 deletions(-) create mode 100644 Makefile.am create mode 100644 configure.ac create mode 100644 doc/Makefile.am delete mode 100644 src/Makefile create mode 100644 src/Makefile.am create mode 100644 src/kst/dirlist.h create mode 100644 src/kst/dirutils.h create mode 100644 src/kst/iniparser.h create mode 100644 test/Makefile.am rename {src => test}/dirlist_test.c (98%) rename {src => test}/dirutils_test.c (96%) rename {src => test}/iniparser_test.c (100%) diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..1cf9756 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,12 @@ +SUBDIRS = src tests doc + +TESTS = tests/dirlist_test \ + tests/dirutils_test \ + tests/iniparser-test +dist_noinst_DATA = LICENSE \ + testdata \ + README \ + example/ \ + autobuild.sh + +test: check diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..b2f03e2 --- /dev/null +++ b/configure.ac @@ -0,0 +1,19 @@ +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_PROG_CC +AC_PROG_INSTALL +AC_PROG_RANLIB + +NO_CUNIT_MSG=" + ============================================== + Warning: CUnit was not found; will not be able + to run unit tests! + ============================================== +" +AC_SEARCH_LIBS([CU_initialize_registry], [cunit], + [], [AC_MSG_WARN($NO_CUNIT_MSG)]) +AC_OUTPUT diff --git a/doc/Makefile.am b/doc/Makefile.am new file mode 100644 index 0000000..47ad617 --- /dev/null +++ b/doc/Makefile.am @@ -0,0 +1,3 @@ +dist_man1_MANS = srm.1 +dist_man3_MANS = libdirutils.3 libiniparser.3 + diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index 2dc53fe..0000000 --- a/src/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -BINS := srm -EDS := ke kte -LIBS := libdirutils.a libiniparser.a - -LDFLAGS := -L. -L/usr/local/lib -CFLAGS := -pedantic -Wall -Werror -Wextra -O0 -std=c99 -g -CFLAGS += -I../include/ -I/usr/local/include/ - -.PHONY: all -all: $(BINS) $(EDS) $(LIBS) - -.PHONY: clean -clean: - rm -f $(BINS) $(EDS) $(LIBS) *.o *.core - - -ke kte: - cd ../$@ && make && cp $@ ../src - -srm: srm.c - $(CC) $(CFLAGS) -o $@ srm.c - -libiniparser.a: iniparser.o - $(AR) -rcs $@ iniparser.o - -libdirutils.a: dirlist.o dirutils.o dirwalk.o - $(AR) -rcs $@ dirlist.o dirutils.o dirwalk.o - - -.PHONY: tests -tests: iniparser-test dirlist-test dirutils-test - -iniparser-test: iniparser_test.c libiniparser.a - $(CC) $(CFLAGS) -o $@ iniparser_test.c libiniparser.a - -dirlist-test: dirlist_test.c libdirutils.a - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ dirlist_test.c libdirutils.a -lcunit - -dirutils-test: dirutils_test.c libdirutils.a - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ dirutils_test.c libdirutils.a -lcunit diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..7b5809f --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,19 @@ +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 + + +## programs +srm_SOURCES = srm.c + + +## libraries +libdirutils_a_SOURCES = dirutils.c dirlist.c dirwalk.c dirlist.h + + + + diff --git a/src/kst/dirlist.h b/src/kst/dirlist.h new file mode 100644 index 0000000..313187a --- /dev/null +++ b/src/kst/dirlist.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012 Kyle Isom + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * --------------------------------------------------------------------- + */ + + +#ifndef __DIRUTILS_DIRLIST_H +#define __DIRUTILS_DIRLIST_H + + +#include +#include +#include "queue.h" + + +struct dirlst { + char path[FILENAME_MAX + 1]; + TAILQ_ENTRY(dirlst) dirs; +}; +TAILQ_HEAD(tq_dirlst, dirlst); + + +struct tq_dirlst *dirlst_create(const char *, size_t); +int dirlst_push(struct tq_dirlst *, const char *, size_t); +struct dirlst *dirlst_pop(struct tq_dirlst *); +int dirlst_destroy(struct tq_dirlst **); + + +#endif diff --git a/src/kst/dirutils.h b/src/kst/dirutils.h new file mode 100644 index 0000000..be2a78f --- /dev/null +++ b/src/kst/dirutils.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2012 Kyle Isom + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * --------------------------------------------------------------------- + */ + + +#ifndef __DIRUTILS_DIRUTILS_H +#define __DIRUTILS_DIRUTILS_H + + +#include +#include +#include + +enum E_EXISTS_STATUS { + EXISTS_ERROR, + EXISTS_NOENT, + EXISTS_NOPERM, + EXISTS_DIR, + EXISTS_FILE, + EXISTS_OTHER +}; +typedef enum E_EXISTS_STATUS EXISTS_STATUS; + + +typedef int (*dirwalk_action)(const char *); + + +extern const unsigned char FT_ANY; +extern const unsigned char FT_STD; +extern const unsigned char FT_NODESCEND; + + +int makedirs(const char *); +int rmdirs(const char *); +EXISTS_STATUS path_exists(const char *); +int walkdir(const char *, dirwalk_action, unsigned char); + + +#endif diff --git a/src/kst/iniparser.h b/src/kst/iniparser.h new file mode 100644 index 0000000..55f819f --- /dev/null +++ b/src/kst/iniparser.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 Kyle Isom + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __LIBINIPARSER_INIPARSER_H +#define __LIBINIPARSER_INIPARSER_H + + +typedef struct { + FILE *source; + char *lineptr; + size_t linelen; + ssize_t readlen; +} iniparser_file_s; + +typedef struct { + uint8_t is_section; + uint8_t is_set; + char *name; + char *value; +} iniparser_line_s; + + +int iniparser_init(void); +void iniparser_destroy(void); +int iniparser_open(const char *, iniparser_file_s **); +int iniparser_close(iniparser_file_s *); +int iniparser_readline(iniparser_file_s *, iniparser_line_s *); +void iniparser_line_init(iniparser_line_s *); +void iniparser_line_destroy(iniparser_line_s *); + + +#endif diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..4b5b612 --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,9 @@ +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/src/dirlist_test.c b/test/dirlist_test.c similarity index 98% rename from src/dirlist_test.c rename to test/dirlist_test.c index 2f2eb1b..8c9ffd4 100644 --- a/src/dirlist_test.c +++ b/test/dirlist_test.c @@ -26,7 +26,7 @@ #include #include -#include +#include /* @@ -179,7 +179,7 @@ main(void) return EXIT_FAILURE; } - tsuite = CU_add_suite(TEST_SUITE, init_test, cleanup_test); + tsuite = CU_add_suite("dirlist_test", init_test, cleanup_test); if (NULL == tsuite) fireball(); diff --git a/src/dirutils_test.c b/test/dirutils_test.c similarity index 96% rename from src/dirutils_test.c rename to test/dirutils_test.c index 2a12e07..db081a9 100644 --- a/src/dirutils_test.c +++ b/test/dirutils_test.c @@ -29,7 +29,7 @@ #include #include -#include +#include static int test_write_file_helper(const char *, const char *); static int test_touch_file_helper(const char *); @@ -44,7 +44,7 @@ test_exists(void) char testfil[] = "testdata/testfile"; char testnot[] = "testdata/nosuchfile"; EXISTS_STATUS ftype; - + ftype = path_exists(testdir); CU_ASSERT(EXISTS_DIR == ftype); @@ -176,13 +176,18 @@ test_write_file_helper(const char *path, const char *data) fail = EXIT_SUCCESS; data_len = strlen(data); fd = open(path, O_WRONLY|O_CREAT, S_IRUSR| S_IWUSR); - if (-1 == fd) + if (-1 == fd) { return EXIT_FAILURE; + } wrsz = write(fd, data, data_len); - if (wrsz != data_len) + if (wrsz == -1) { + fail = EXIT_FAILURE; + } else if ((size_t)wrsz != data_len) { fail = EXIT_FAILURE; - if (-1 == close(fd)) + } + if (-1 == close(fd)) { fail = EXIT_FAILURE; + } return fail; } @@ -238,7 +243,7 @@ main(void) return EXIT_FAILURE; } - tsuite = CU_add_suite(TEST_SUITE, init_test, cleanup_test); + tsuite = CU_add_suite("dirutils_test", init_test, cleanup_test); if (NULL == tsuite) fireball(); diff --git a/src/iniparser_test.c b/test/iniparser_test.c similarity index 100% rename from src/iniparser_test.c rename to test/iniparser_test.c