autoconfiguration

This commit is contained in:
Kyle Isom 2020-02-11 20:27:53 -08:00
parent 0d8053dc20
commit 8f5419f2a2
12 changed files with 221 additions and 48 deletions

12
Makefile.am Normal file
View File

@ -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

19
configure.ac Normal file
View File

@ -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

3
doc/Makefile.am Normal file
View File

@ -0,0 +1,3 @@
dist_man1_MANS = srm.1
dist_man3_MANS = libdirutils.3 libiniparser.3

View File

@ -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

19
src/Makefile.am Normal file
View File

@ -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

42
src/kst/dirlist.h Normal file
View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2012 Kyle Isom <kyle@tyrfingr.is>
*
* 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 <stdio.h>
#include <dirent.h>
#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

53
src/kst/dirutils.h Normal file
View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2012 Kyle Isom <kyle@tyrfingr.is>
*
* 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 <sys/queue.h>
#include <dirent.h>
#include <stdio.h>
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

51
src/kst/iniparser.h Normal file
View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2015 Kyle Isom <kyle@tyrfingr.is>
*
* 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

9
test/Makefile.am Normal file
View File

@ -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

View File

@ -26,7 +26,7 @@
#include <string.h> #include <string.h>
#include <sysexits.h> #include <sysexits.h>
#include <dirlist.h> #include <kst/dirlist.h>
/* /*
@ -179,7 +179,7 @@ main(void)
return EXIT_FAILURE; 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) if (NULL == tsuite)
fireball(); fireball();

View File

@ -29,7 +29,7 @@
#include <sysexits.h> #include <sysexits.h>
#include <unistd.h> #include <unistd.h>
#include <dirutils.h> #include <kst/dirutils.h>
static int test_write_file_helper(const char *, const char *); static int test_write_file_helper(const char *, const char *);
static int test_touch_file_helper(const char *); static int test_touch_file_helper(const char *);
@ -176,13 +176,18 @@ test_write_file_helper(const char *path, const char *data)
fail = EXIT_SUCCESS; fail = EXIT_SUCCESS;
data_len = strlen(data); data_len = strlen(data);
fd = open(path, O_WRONLY|O_CREAT, S_IRUSR| S_IWUSR); fd = open(path, O_WRONLY|O_CREAT, S_IRUSR| S_IWUSR);
if (-1 == fd) if (-1 == fd) {
return EXIT_FAILURE; return EXIT_FAILURE;
}
wrsz = write(fd, data, data_len); 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; fail = EXIT_FAILURE;
if (-1 == close(fd)) }
if (-1 == close(fd)) {
fail = EXIT_FAILURE; fail = EXIT_FAILURE;
}
return fail; return fail;
} }
@ -238,7 +243,7 @@ main(void)
return EXIT_FAILURE; 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) if (NULL == tsuite)
fireball(); fireball();