Browse Source

faux: Remove local version of faux library

Serj Kalichev 3 years ago
parent
commit
a2fa169e75

+ 0 - 48
faux/Makefile.am

@@ -1,48 +0,0 @@
-lib_LTLIBRARIES += libfaux.la
-libfaux_la_SOURCES =
-libfaux_la_LIBADD =
-
-nobase_include_HEADERS += \
-	faux/faux.h \
-	faux/ctype.h \
-	faux/str.h \
-	faux/sysdb.h \
-	faux/conv.h \
-	faux/log.h \
-	faux/list.h \
-	faux/ini.h \
-	faux/file.h
-
-#	faux/argv.h \
-#	faux/dump.h \
-#	faux/system.h
-
-EXTRA_DIST += \
-	faux/base/Makefile.am \
-	faux/ctype/Makefile.am \
-	faux/str/Makefile.am \
-	faux/sysdb/Makefile.am \
-	faux/conv/Makefile.am \
-	faux/log/Makefile.am \
-	faux/list/Makefile.am \
-	faux/ini/Makefile.am \
-	faux/file/Makefile.am
-
-#	faux/argv/Makefile.am \
-#	faux/dump/Makefile.am \
-#	faux/system/Makefile.am \
-#	faux/README
-
-include $(top_srcdir)/faux/base/Makefile.am
-include $(top_srcdir)/faux/ctype/Makefile.am
-include $(top_srcdir)/faux/str/Makefile.am
-include $(top_srcdir)/faux/sysdb/Makefile.am
-include $(top_srcdir)/faux/conv/Makefile.am
-include $(top_srcdir)/faux/log/Makefile.am
-include $(top_srcdir)/faux/list/Makefile.am
-include $(top_srcdir)/faux/ini/Makefile.am
-include $(top_srcdir)/faux/file/Makefile.am
-
-if TESTC
-include $(top_srcdir)/faux/testc_module/Makefile.am
-endif

+ 0 - 11
faux/README

@@ -1,11 +0,0 @@
-/**
-\defgroup lub "Little Useful Bits" Library
-@{
-
-\brief This is a general purpose library of small utilities. 
-
-The design and implementation are intended for embedded devices,
-ie. minimise footprint and maximise performance.
-
-@}
-*/

+ 0 - 79
faux/argv.h

@@ -1,79 +0,0 @@
-/*
- * argv.h
- */
-/**
-\ingroup lub
-\defgroup lub_argv argv
-@{
-
-\brief This utility provides a simple means of manipulating a vector of 
-command textual words.
-
-A word is either separated by whitespace, or if quotes are used a word is
-defined by the scope of the quotes.
-
-e.g.
-\verbatim
-one two "this is the third word" four
-\endverbatim
-contains four "words" the third of which is a string.
-
-*/
-#ifndef _lub_argv_h
-#define _lub_argv_h
-
-#include <stddef.h>
-
-#include "c_decl.h"
-#include "faux.h"
-
-_BEGIN_C_DECL
-/**
- * This type is used to reference an instance of an argument vector
- */
-typedef struct lub_argv_s lub_argv_t;
-
-/*=====================================
- * ARGV INTERFACE
- *===================================== */
-/**
- *  This operation is used to construct an instance of this class. The client
- * species a string and an offset within that string, from which to start
- * collecting "words" to place into the vector instance.
- *
- * \pre
- * - none
- *
- * \return
- * - A instance of an argument vector, which represents the words contained in
- * the provided string.
- * - NULL if there is insuffcient resource
- *
- * \post
- * - The client becomes resposible for releasing the instance when they are
- *   finished with it, by calling lub_argv_delete()
- */
-lub_argv_t *lub_argv_new(
-	/**
-         * The string to analyse
-         */
-	const char *line,
-	/**
-         * The offset in the string to start from
-         */
-	size_t offset);
-
-void lub_argv_delete(lub_argv_t * instance);
-unsigned lub_argv__get_count(const lub_argv_t * instance);
-const char *lub_argv__get_arg(const lub_argv_t * instance, unsigned index);
-size_t lub_argv__get_offset(const lub_argv_t * instance, unsigned index);
-bool_t lub_argv__get_quoted(const lub_argv_t * instance, unsigned index);
-void lub_argv__set_arg(lub_argv_t * instance, unsigned index, const char *arg);
-char **lub_argv__get_argv(const lub_argv_t * instance, const char *argv0);
-void lub_argv__free_argv(char **argv);
-char *lub_argv__get_line(const lub_argv_t * instance);
-void lub_argv_add(lub_argv_t * instance, const char *text);
-
-_END_C_DECL
-#endif				/* _lub_argv_h */
-/** @} lub_argv */

+ 0 - 199
faux/argv/argv.c

@@ -1,199 +0,0 @@
-/*
- * argv.c
- */
-#include "private.h"
-#include "lub/string.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <ctype.h>
-
-/*--------------------------------------------------------- */
-static void lub_argv_init(lub_argv_t * this, const char *line, size_t offset)
-{
-	size_t len;
-	const char *word;
-	lub_arg_t *arg;
-	size_t quoted;
-
-	this->argv = NULL;
-	this->argc = 0;
-	if (!line)
-		return;
-	/* first of all count the words in the line */
-	this->argc = lub_string_wordcount(line);
-	if (0 == this->argc)
-		return;
-	/* allocate space to hold the vector */
-	arg = this->argv = faux_zmalloc(sizeof(lub_arg_t) * this->argc);
-	assert(arg);
-
-	/* then fill out the array with the words */
-	for (word = lub_string_nextword(line, &len, &offset, &quoted);
-		*word || quoted;
-		word = lub_string_nextword(word + len, &len, &offset, &quoted)) {
-		(*arg).arg = lub_string_ndecode(word, len);
-		(*arg).offset = offset;
-		(*arg).quoted = quoted ? BOOL_TRUE : BOOL_FALSE;
-
-		offset += len;
-
-		if (quoted) {
-			len += quoted - 1; /* account for terminating quotation mark */
-			offset += quoted; /* account for quotation marks */
-		}
-		arg++;
-	}
-}
-
-/*--------------------------------------------------------- */
-lub_argv_t *lub_argv_new(const char *line, size_t offset)
-{
-	lub_argv_t *this;
-
-	this = faux_zmalloc(sizeof(lub_argv_t));
-	if (this)
-		lub_argv_init(this, line, offset);
-
-	return this;
-}
-
-/*--------------------------------------------------------- */
-void lub_argv_add(lub_argv_t * this, const char *text)
-{
-	lub_arg_t * arg;
-
-	if (!text)
-		return;
-
-	/* allocate space to hold the vector */
-	arg = realloc(this->argv, sizeof(lub_arg_t) * (this->argc + 1));
-	assert(arg);
-	this->argv = arg;
-	(this->argv[this->argc++]).arg = strdup(text);
-}
-
-/*--------------------------------------------------------- */
-static void lub_argv_fini(lub_argv_t * this)
-{
-	unsigned i;
-
-	for (i = 0; i < this->argc; i++)
-		faux_free(this->argv[i].arg);
-	faux_free(this->argv);
-	this->argv = NULL;
-}
-
-/*--------------------------------------------------------- */
-void lub_argv_delete(lub_argv_t * this)
-{
-	lub_argv_fini(this);
-	faux_free(this);
-}
-
-/*--------------------------------------------------------- */
-char *lub_argv__get_line(const lub_argv_t * this)
-{
-	int space = 0;
-	const char *p;
-	unsigned i;
-	char *line = NULL;
-
-	for (i = 0; i < this->argc; i++) {
-		if (i != 0)
-			lub_string_cat(&line, " ");
-		space = 0;
-		/* Search for spaces */
-		for (p = this->argv[i].arg; *p; p++) {
-			if (isspace(*p)) {
-				space = 1;
-				break;
-			}
-		}
-		if (space)
-			lub_string_cat(&line, "\"");
-		lub_string_cat(&line, this->argv[i].arg);
-		if (space)
-			lub_string_cat(&line, "\"");
-	}
-
-	return line;
-}
-
-/*--------------------------------------------------------- */
-char **lub_argv__get_argv(const lub_argv_t * this, const char *argv0)
-{
-	char **result = NULL;
-	unsigned i;
-	unsigned a = 0;
-
-	if (argv0)
-		a = 1;
-
-	result = faux_zmalloc(sizeof(char *) * (this->argc + 1 + a));
-
-	if (argv0)
-		result[0] = strdup(argv0);
-	for (i = 0; i < this->argc; i++)
-		result[i + a] = strdup(this->argv[i].arg);
-	result[i + a] = NULL;
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-void lub_argv__free_argv(char **argv)
-{
-	unsigned i;
-
-	if (!argv)
-		return;
-
-	for (i = 0; argv[i]; i++)
-		faux_free(argv[i]);
-	faux_free(argv);
-}
-
-/*--------------------------------------------------------- */
-const char *lub_argv__get_arg(const lub_argv_t *this, unsigned int index)
-{
-	const char *result = NULL;
-
-	if (!this)
-		return NULL;
-	if (this->argc > index)
-		result = this->argv[index].arg;
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-unsigned lub_argv__get_count(const lub_argv_t * this)
-{
-	return this->argc;
-}
-
-/*--------------------------------------------------------- */
-size_t lub_argv__get_offset(const lub_argv_t * this, unsigned index)
-{
-	size_t result = 0;
-
-	if (this->argc > index)
-		result = this->argv[index].offset;
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_argv__get_quoted(const lub_argv_t * this, unsigned index)
-{
-	bool_t result = BOOL_FALSE;
-
-	if (this->argc > index)
-		result = this->argv[index].quoted;
-
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 6
faux/argv/module.am

@@ -1,6 +0,0 @@
-liblub_la_SOURCES += \
-	lub/argv/argv.c \
-	lub/argv/private.h
-
-
-

+ 0 - 19
faux/argv/private.h

@@ -1,19 +0,0 @@
-/*
- * private.h
- *
- * Class to deal with splitting a command line into multiple arguments.
- * This class deals with full quoted text "like this" as a single argument.
- */
-#include "lub/argv.h"
-
-typedef struct lub_arg_s lub_arg_t;
-struct lub_arg_s {
-	char *arg;
-	size_t offset;
-	bool_t quoted;
-};
-
-struct lub_argv_s {
-	unsigned argc;
-	lub_arg_t *argv;
-};

+ 0 - 3
faux/base/Makefile.am

@@ -1,3 +0,0 @@
-libfaux_la_SOURCES += \
-	faux/base/base.c
-

+ 0 - 88
faux/base/base.c

@@ -1,88 +0,0 @@
-/** @file base.c
- * @brief Base faux functions.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "faux/faux.h"
-
-
-/** Portable implementation of free() function.
- *
- * The POSIX standard says the free() must check pointer for NULL value
- * and must not try to free NULL pointer. I.e. it do nothing in a case of NULL.
- * The Linux glibc do so. But some non-fully POSIX compatible systems don't.
- * For these systems our implementation of free() must check for NULL itself.
- *
- * For now function simply call free() but it can be changed while working on
- * portability.
- *
- * @param [in] ptr Memory pointer to free.
- * @sa free()
- */
-void faux_free(void *ptr) {
-
-#if 0
-	if (ptr)
-#endif
-	free(ptr);
-}
-
-
-/** Portable implementation of malloc() function.
- *
- * The faux library implements its own free() function (called faux_free()) so
- * it's suitable to implement their own complementary malloc() function.
- * The behaviour when the size is 0 must be strictly defined. This function
- * will assert() and return NULL when size is 0.
- *
- * @param [in] size Memory size to allocate.
- * @return Allocated memory or NULL on error.
- * @sa malloc()
- */
-void *faux_malloc(size_t size) {
-
-	assert(size != 0);
-	if (0 == size)
-		return NULL;
-
-	return malloc(size);
-}
-
-/** Portable implementation of bzero().
- *
- * The POSIX standard says the bzero() is legacy now. It recommends to use
- * memset() instead it. But bzero() is easier to use. So bzero() can be
- * implemented using memset().
- *
- * @param [in] ptr Pointer
- * @param [in] size Size of memory (in bytes) to zero it.
- * @sa bzero()
- */
-void faux_bzero(void *ptr, size_t size) {
-
-	memset(ptr, '\0', size);
-}
-
-
-/** The malloc() implementation with writing zeroes to allocated buffer.
- *
- * The POSIX defines calloc() function to allocate memory and write zero bytes
- * to the whole buffer. But calloc() has strange set of arguments. This function
- * is simply combination of malloc() and bzero().
- *
- * @param [in] size Memory size to allocate.
- * @return Allocated zeroed memory or NULL on error.
- */
-void *faux_zmalloc(size_t size) {
-
-	void *ptr = NULL;
-
-	ptr = faux_malloc(size);
-	if (ptr)
-		faux_bzero(ptr, size);
-
-	return ptr;
-}

+ 0 - 29
faux/conv.h

@@ -1,29 +0,0 @@
-/** @file conv.h
- * @brief Public interface for faux convert functions.
- */
-
-#ifndef _faux_conv_h
-#define _faux_conv_h
-
-#include "faux/faux.h"
-
-C_DECL_BEGIN
-
-int lub_conv_atol(const char *str, long int *val, int base);
-int lub_conv_atoul(const char *str, unsigned long int *val, int base);
-
-int lub_conv_atoll(const char *str, long long int *val, int base);
-int lub_conv_atoull(const char *str, unsigned long long int *val, int base);
-
-int lub_conv_atoi(const char *str, int *val, int base);
-int lub_conv_atoui(const char *str, unsigned int *val, int base);
-
-int lub_conv_atos(const char *str, short *val, int base);
-int lub_conv_atous(const char *str, unsigned short *val, int base);
-
-int lub_conv_atoc(const char *str, short *val, int base);
-int lub_conv_atouc(const char *str, unsigned short *val, int base);
-
-C_DECL_END
-
-#endif

+ 0 - 3
faux/conv/Makefile.am

@@ -1,3 +0,0 @@
-libfaux_la_SOURCES += \
-	faux/conv/conv.c
-

+ 0 - 281
faux/conv/conv.c

@@ -1,281 +0,0 @@
-/** @file conv.c
- * @brief Functions to convert from string to integer.
- */
-
-#include <stdlib.h>
-#include <errno.h>
-#include <limits.h>
-
-#include "faux/conv.h"
-
-
-/** @brief Converts string to long int
- *
- * Converts string to long int and check for overflow and valid
- * input values. Function indicates error by return value. It
- * returns the convertion result by second argument.
- *
- * @param [in] str Input string to convert.
- * @param [out] val Pointer to result value.
- * @param [in] base Base to convert.
- * @return 0 - success, < 0 - error
- */
-int faux_conv_atol(const char *str, long int *val, int base) {
-
-	char *endptr = NULL;
-	long int res = 0;
-
-	errno = 0; // man recommends to do so
-	res = strtol(str, &endptr, base);
-	// Check for overflow
-	if (((LONG_MIN == res) || (LONG_MAX == res)) && (ERANGE == errno))
-		return -1;
-	// No valid digits at all
-	if ((0 == res) && ((endptr == str) || (errno != 0)))
-		return -1;
-	*val = res;
-
-	return 0;
-}
-
-
-/** @brief Converts string to unsigned long int
- *
- * Converts string to unsigned long int and check for overflow and valid
- * input values. Function indicates error by return value. It
- * returns the convertion result by second argument.
- *
- * @param [in] str Input string to convert.
- * @param [out] val Pointer to result value.
- * @param [in] base Base to convert.
- * @return 0 - success, < 0 - error
- */
-int faux_conv_atoul(const char *str, unsigned long int *val, int base) {
-
-	char *endptr = NULL;
-	unsigned long int res = 0;
-
-	errno = 0; // man recommends to do so
-	res = strtoul(str, &endptr, base);
-	// Check for overflow
-	if ((ULONG_MAX == res) && (ERANGE == errno))
-		return -1;
-	// No valid digits at all
-	if ((0 == res) && ((endptr == str) || (errno != 0)))
-		return -1;
-	*val = res;
-
-	return 0;
-}
-
-
-/** @brief Converts string to long long int
- *
- * Converts string to long long int and check for overflow and valid
- * input values. Function indicates error by return value. It
- * returns the convertion result by second argument.
- *
- * @param [in] str Input string to convert.
- * @param [out] val Pointer to result value.
- * @param [in] base Base to convert.
- * @return 0 - success, < 0 - error
- */
-int faux_conv_atoll(const char *str, long long int *val, int base) {
-
-	char *endptr = NULL;
-	long long int res = 0;
-
-	errno = 0; // man recommends to do so
-	res = strtoll(str, &endptr, base);
-	// Check for overflow
-	if (((LLONG_MIN == res) || (LLONG_MAX == res)) && (ERANGE == errno))
-		return -1;
-	// No valid digits at all
-	if ((0 == res) && ((endptr == str) || (errno != 0)))
-		return -1;
-	*val = res;
-
-	return 0;
-}
-
-
-/** @brief Converts string to unsigned long long int
- *
- * Converts string to unsigned long long int and check for overflow and valid
- * input values. Function indicates error by return value. It
- * returns the convertion result by second argument.
- *
- * @param [in] str Input string to convert.
- * @param [out] val Pointer to result value.
- * @param [in] base Base to convert.
- * @return 0 - success, < 0 - error
- */
-int faux_conv_atoull(const char *str, unsigned long long int *val, int base) {
-
-	char *endptr = NULL;
-	unsigned long long int res = 0;
-
-	errno = 0; // man recommends to do so
-	res = strtoull(str, &endptr, base);
-	// Check for overflow
-	if ((ULLONG_MAX == res) && (ERANGE == errno))
-		return -1;
-	// No valid digits at all
-	if ((0 == res) && ((endptr == str) || (errno != 0)))
-		return -1;
-	*val = res;
-
-	return 0;
-}
-
-
-/** @brief Converts string to int
- *
- * Converts string to int and check for overflow and valid
- * input values. Function indicates error by return value. It
- * returns the convertion result by second argument.
- *
- * @param [in] str Input string to convert.
- * @param [out] val Pointer to result value.
- * @param [in] base Base to convert.
- * @return 0 - success, < 0 - error
- */
-int faux_conv_atoi(const char *str, int *val, int base) {
-
-	long int tmp = 0;
-
-	// Use existent func. The long int is longer or equal to int.
-	if (faux_conv_atol(str, &tmp, base) < 0)
-		return -1;
-	if ((tmp < INT_MIN) || (tmp > INT_MAX)) // Overflow
-		return -1;
-	*val = tmp;
-
-	return 0;
-}
-
-
-/** @brief Converts string to unsigned int
- *
- * Converts string to unsigned int and check for overflow and valid
- * input values. Function indicates error by return value. It
- * returns the convertion result by second argument.
- *
- * @param [in] str Input string to convert.
- * @param [out] val Pointer to result value.
- * @param [in] base Base to convert.
- * @return 0 - success, < 0 - error
- */
-int faux_conv_atoui(const char *str, unsigned int *val, int base) {
-
-	unsigned long int tmp = 0;
-
-	// Use existent func. The long int is longer or equal to int.
-	if (faux_conv_atoul(str, &tmp, base) < 0)
-		return -1;
-	if (tmp > UINT_MAX) // Overflow
-		return -1;
-	*val = tmp;
-
-	return 0;
-}
-
-
-/** @brief Converts string to short
- *
- * Converts string to short and check for overflow and valid
- * input values. Function indicates error by return value. It
- * returns the convertion result by second argument.
- *
- * @param [in] str Input string to convert.
- * @param [out] val Pointer to result value.
- * @param [in] base Base to convert.
- * @return 0 - success, < 0 - error
- */
-int faux_conv_atos(const char *str, short *val, int base) {
-
-	long int tmp = 0;
-
-	if (faux_conv_atol(str, &tmp, base) < 0)
-		return -1;
-	if ((tmp < SHRT_MIN) || (tmp > SHRT_MAX)) // Overflow
-		return -1;
-	*val = tmp;
-
-	return 0;
-}
-
-
-/** @brief Converts string to unsigned short
- *
- * Converts string to unsigned short and check for overflow and valid
- * input values. Function indicates error by return value. It
- * returns the convertion result by second argument.
- *
- * @param [in] str Input string to convert.
- * @param [out] val Pointer to result value.
- * @param [in] base Base to convert.
- * @return 0 - success, < 0 - error
- */
-int faux_conv_atous(const char *str, unsigned short *val, int base) {
-
-	unsigned long int tmp = 0;
-
-	if (faux_conv_atoul(str, &tmp, base) < 0)
-		return -1;
-	if (tmp > USHRT_MAX) // Overflow
-		return -1;
-	*val = tmp;
-
-	return 0;
-}
-
-
-/** @brief Converts string to char
- *
- * Converts string to char and check for overflow and valid
- * input values. Function indicates error by return value. It
- * returns the convertion result by second argument.
- *
- * @param [in] str Input string to convert.
- * @param [out] val Pointer to result value.
- * @param [in] base Base to convert.
- * @return 0 - success, < 0 - error
- */
-int faux_conv_atoc(const char *str, char *val, int base) {
-
-	long int tmp = 0;
-
-	if (faux_conv_atol(str, &tmp, base) < 0)
-		return -1;
-	if ((tmp < CHAR_MIN) || (tmp > CHAR_MAX)) // Overflow
-		return -1;
-	*val = tmp;
-
-	return 0;
-}
-
-
-/** @brief Converts string to unsigned char
- *
- * Converts string to unsigned char and check for overflow and valid
- * input values. Function indicates error by return value. It
- * returns the convertion result by second argument.
- *
- * @param [in] str Input string to convert.
- * @param [out] val Pointer to result value.
- * @param [in] base Base to convert.
- * @return 0 - success, < 0 - error
- */
-int faux_conv_atouc(const char *str, unsigned char *val, int base) {
-
-	unsigned long int tmp = 0;
-
-	if (faux_conv_atoul(str, &tmp, base) < 0)
-		return -1;
-	if (tmp > UCHAR_MAX) // Overflow
-		return -1;
-	*val = tmp;
-
-	return 0;
-}

+ 0 - 24
faux/ctype.h

@@ -1,24 +0,0 @@
-/** @file ctype.h
- * @brief Public interface for faux ctype functions.
- */
-
-#ifndef _faux_ctype_h
-#define _faux_ctype_h
-
-#include <ctype.h>
-
-#include "faux/faux.h"
-
-C_DECL_BEGIN
-
-// Classify functions
-bool_t faux_ctype_isdigit(char c);
-bool_t faux_ctype_isspace(char c);
-
-// Convert functions
-char faux_ctype_tolower(char c);
-char faux_ctype_toupper(char c);
-
-C_DECL_END
-
-#endif /* _faux_ctype_h */

+ 0 - 3
faux/ctype/Makefile.am

@@ -1,3 +0,0 @@
-libfaux_la_SOURCES += \
-	faux/ctype/ctype.c
-

+ 0 - 71
faux/ctype/ctype.c

@@ -1,71 +0,0 @@
-/** @file ctype.c
- * @brief The ctype functions
- *
- * Some ctype functions are not compatible among different OSes.
- * So faux library functions use their own versions of some
- * ctype functions to unify the behaviour. Really for now all
- * faux ctype functions are only a wrappers for standard functions.
- * But it can be changed in future for portability purposes.
- */
-
-#include <ctype.h>
-
-#include "faux/ctype.h"
-
-/** @brief Checks for a digit
- *
- * The function is same as standard isdigit() but gets char type
- * as an argument.
- *
- * @param [in] c Character to classify.
- * @return BOOL_TRUE if char is digit and BOOL_FALSE else.
- */
-bool_t faux_ctype_isdigit(char c) {
-
-	// isdigit() man says that argument must be unsigned char
-	return isdigit((unsigned char)c) ? BOOL_TRUE : BOOL_FALSE;
-}
-
-
-/** @brief Checks for a white space
- *
- * The function is same as standard isspace() but gets char type
- * as an argument.
- *
- * @param [in] c Character to classify.
- * @return BOOL_TRUE if char is space and BOOL_FALSE else.
- */
-bool_t faux_ctype_isspace(char c) {
-
-	// isspace() man says that argument must be unsigned char
-	return isspace((unsigned char)c) ? BOOL_TRUE : BOOL_FALSE;
-}
-
-
-/** @brief Converts uppercase characters to lowercase
- *
- * The function is same as standard tolower() but gets char type
- * as an argument.
- *
- * @param [in] c Character to convert.
- * @return Converted character.
- */
-char faux_ctype_tolower(char c) {
-
-	// tolower() man says that argument must be unsigned char
-	return tolower((unsigned char)c);
-}
-
-/** @brief Converts lowercase characters to uppercase
- *
- * The function is same as standard toupper() but gets char type
- * as an argument.
- *
- * @param [in] c Character to convert.
- * @return Converted character.
- */
-char faux_ctype_toupper(char c) {
-
-	// toupper() man says that argument must be unsigned char
-	return toupper((unsigned char)c);
-}

+ 0 - 75
faux/dump.h

@@ -1,75 +0,0 @@
-/*
- * dump.h
- */
-/**
-\ingroup lub
-\defgroup lub_dump dump
-@{
-
-\brief This utility provides a simple hierachical debugging mechanism.
-
-By indenting and undenting the output, printing nested debug messages is made
-easy.
-*/
-#ifndef _lub_dump_h
-#define _lub_dump_h
-
-#define LUB_DUMP_NULL "(null)"
-#define LUB_DUMP_STR(str) ( str ? str : LUB_DUMP_NULL )
-#define LUB_DUMP_BOOL(val) ( val ? "true" : "false" )
-
-#include <stdarg.h>
-/*=====================================
- * DUMP INTERFACE
- *===================================== */
-/**
- * This operation behaves identically to the standard printf() function
- * with the exception that the offset at the begining of the line is 
- * determined by the current indent settings.
- * \pre 
- * - none
- *
- * \return
- * The number of characters sent to stdout.
- *
- * \post
- * - The formatted message will be sent to stdout.
- */
- /*lint -esym(534,lub_dump_printf) Ignoring return value of function */
-int lub_dump_printf(
-	    /**
-             * printf-like format string
-             */
-			   const char *fmt, ...
-    );
-/**
- * This operation indicates that the offset for messages should be increased by
- * one level.
- *
- * \pre 
- * - none
- *
- * \post
- * - An indentation divider will be sent to stdout to emphasise the change
- *   in offset.
- * - Subsequent calls to lub_dump_printf() will output at this new offset.
- * - Client may call lub_undent() to restore offset.
- */
-void lub_dump_indent(void);
-/**
- * This operation indicates that the offset for messages should be decreased by
- * one level.
- *
- * \pre 
- * - lub_dump_indent() should have been called at least one more time than
- *   this function.
- *
- * \post
- * - An indentation divider will be sent to stdout to emphasise the change
- *   in offset.
- * - Subsequent calls to lub_dump_printf() will output at this new offset.
- */
-void lub_dump_undent(void);
-
-#endif				/* _lub_dump_h */
-/** @} lub_dump */

+ 0 - 53
faux/dump/dump.c

@@ -1,53 +0,0 @@
-/*
- * dump.c
- * Provides indented printf functionality
- */
-#include "private.h"
-
-#include <stdio.h>
-#include <stdarg.h>
-
-static int indent = 0;
-
-/*--------------------------------------------------------- */
-int lub_dump_printf(const char *fmt, ...)
-{
-	va_list args;
-	int len;
-
-	va_start(args, fmt);
-	fprintf(stderr, "%*s", indent, "");
-	len = vfprintf(stderr, fmt, args);
-	va_end(args);
-
-	return len;
-}
-
-/*--------------------------------------------------------- */
-static void lub_dump_divider(char c)
-{
-	int i;
-
-	lub_dump_printf("");
-	for (i = 0; i < (80 - indent); i++) {
-		fputc(c, stderr);
-	}
-	fputc('\n', stderr);
-}
-
-/*--------------------------------------------------------- */
-void lub_dump_indent(void)
-{
-	indent += 2;
-	lub_dump_divider('_');
-}
-
-/*--------------------------------------------------------- */
-void lub_dump_undent(void)
-{
-	lub_dump_divider('^');
-
-	indent -= 2;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 2
faux/dump/module.am

@@ -1,2 +0,0 @@
-liblub_la_SOURCES +=	lub/dump/dump.c		\
-			lub/dump/private.h

+ 0 - 4
faux/dump/private.h

@@ -1,4 +0,0 @@
-/*
- * private.h
- */
-#include "lub/dump.h"

+ 0 - 68
faux/faux.h

@@ -1,68 +0,0 @@
-/** @file faux.h
- * @brief Additional usefull data types and base functions.
- */
-
-#ifndef _faux_types_h
-#define _faux_types_h
-
-#include <stdlib.h>
-
-/**
- * A standard boolean type. The possible values are
- * BOOL_FALSE and BOOL_TRUE.
- */
-typedef enum {
-	BOOL_FALSE = 0,
-	BOOL_TRUE = 1
-} bool_t;
-
-
-/** @def C_DECL_BEGIN
- * This macro can be used instead standard preprocessor
- * directive like this:
- * @code
- * #ifdef __cplusplus
- * extern "C" {
- * #endif
- *
- * int foobar(void);
- *
- * #ifdef __cplusplus
- * }
- * #endif
- * @endcode
- * It make linker to use C-style linking for functions.
- * Use C_DECL_BEGIN before functions declaration and C_DECL_END
- * after declaration:
- * @code
- * C_DECL_BEGIN
- *
- * int foobar(void);
- *
- * C_DECL_END
- * @endcode
- */
-
-/** @def C_DECL_END
- * See the macro C_DECL_BEGIN.
- * @sa C_DECL_BEGIN
- */
-
-#ifdef __cplusplus
-#define C_DECL_BEGIN extern "C" {
-#define C_DECL_END }
-#else
-#define C_DECL_BEGIN
-#define C_DECL_END
-#endif
-
-C_DECL_BEGIN
-
-void faux_free(void *ptr);
-void *faux_malloc(size_t size);
-void faux_bzero(void *ptr, size_t size);
-void *faux_zmalloc(size_t size);
-
-C_DECL_END
-
-#endif /* _faux_types_h */

+ 0 - 29
faux/file.h

@@ -1,29 +0,0 @@
-/** @file file.h
- * @brief Public interface to work with files.
- */
-
-#ifndef _faux_file_h
-#define _faux_file_h
-
-// For macros definition
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#include "faux/faux.h"
-
-typedef struct faux_file_s faux_file_t;
-
-C_DECL_BEGIN
-
-faux_file_t *faux_file_fdopen(int fd);
-faux_file_t *faux_file_open(const char *pathname, int flags, mode_t mode);
-int faux_file_close(faux_file_t *file);
-int faux_file_fileno(faux_file_t *file);
-bool_t faux_file_eof(const faux_file_t *file);
-char *faux_file_getline(faux_file_t *file);
-ssize_t faux_file_write(faux_file_t *file, const void *buf, size_t n);
-
-C_DECL_END
-
-#endif				/* _faux_file_h */

+ 0 - 3
faux/file/Makefile.am

@@ -1,3 +0,0 @@
-libfaux_la_SOURCES += \
-	faux/file/file.c \
-	faux/file/private.h

+ 0 - 371
faux/file/file.c

@@ -1,371 +0,0 @@
-/** @file file.c
- * @brief Functions for working with files.
- *
- * This library was created to exclude glibc's file stream operations like
- * fopen(), fgets() etc. These functions use glibc internal buffer. To work
- * with buffer glibc has its own fflush() function and special behaviour while
- * fclose(). It brings a problems with stream file objects and system file
- * descriptors while fork(). The file streams and system file descriptors can't
- * be used interchangeably. So faux file library uses standard system file
- * operations like open(), read() and emulate some usefull stream function like
- * getline(). The faux file object has own buffer and doesn't use glibc's one.
- * The faux_file_close() doesn't lseek() file descriptor as fclose() can do.
- * You can use faux file object and standard file operation in the same time.
- * The only thing to remember is internal buffer that can contain already
- * readed bytes.
- */
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <assert.h>
-#include <errno.h>
-
-#include "private.h"
-#include "faux/faux.h"
-#include "faux/file.h"
-#include "faux/str.h"
-
-
-/** @brief Create file object using existent fd.
- *
- * Create file object and link it to existent file descriptor.
- *
- * @param [in] fd Already opened file descriptor.
- * @return Allocated and initialized file object or NULL on error.
- */
-faux_file_t *faux_file_fdopen(int fd) {
-
-	struct stat stat_struct = {};
-	faux_file_t *f = NULL;
-
-	// Before object creation check is fd valid.
-	// Try to get stat().
-	if (fstat(fd, &stat_struct) < 0)
-		return NULL; // Illegal fd
-
-	f = faux_zmalloc(sizeof(*f));
-	assert(f);
-	if (!f)
-		return NULL;
-
-	// Init
-	f->fd = fd;
-	f->buf_size = FAUX_FILE_CHUNK_SIZE;
-	f->buf = faux_zmalloc(f->buf_size);
-	assert(f->buf);
-	if (!f->buf) {
-		faux_free(f);
-		return NULL;
-	}
-	f->len = 0;
-	f->eof = BOOL_FALSE;
-
-	return f;
-}
-
-
-/** @brief Create file object and open correspondent file.
- *
- * Function opens specified file using flags and create file object based
- * on this opened file. The object must be freed and file must be closed
- * later by the faux_file_close().
- *
- * @warning The faux_file_close() must be executed later to free file object.
- *
- * @param [in] pathname File name.
- * @param [in] flags Flags to open file (like O_RDONLY etc).
- * @param [in] mode File permissions if file will be created.
- * @return File object or NULL on error.
- */
-faux_file_t *faux_file_open(const char *pathname, int flags, mode_t mode) {
-
-	int fd = -1;
-
-	assert(pathname);
-	if (!pathname)
-		return NULL;
-
-	fd = open(pathname, flags, mode);
-	if (fd < 0)
-		return NULL;
-
-	return faux_file_fdopen(fd);
-}
-
-
-/** @brief Closes file and frees file object.
- *
- * Function closes previously opened (by faux_file_open() or faux_file_fdopen())
- * file and frees file object structures.
- *
- * @param [in] f File object to close and free.
- * @return 0 - success, < 0 - error
- */
-int faux_file_close(faux_file_t *f) {
-
-	int fd = -1;
-
-	assert(f);
-	if (!f)
-		return -1;
-
-	fd = f->fd;
-	faux_free(f->buf);
-	faux_free(f);
-
-	return close(fd);
-}
-
-
-/** @brief Returns file descriptor from file object.
- *
- * Works like fileno() function for stream objects.
- *
- * @param [in] f File object.
- * @return Linked file descriptor.
- */
-int faux_file_fileno(faux_file_t *f) {
-
-	assert(f);
-	if (!f)
-		return -1;
-
-	return f->fd;
-}
-
-
-/** @brief Returns EOF flag.
- *
- * @param [in] f File object
- * @return BOOL_TRUE if it's end of file and BOOL_FALSE else.
- */
-bool_t faux_file_eof(const faux_file_t *f) {
-
-	assert(f);
-	if (!f)
-		return BOOL_FALSE;
-
-	return f->eof;
-}
-
-
-/** @brief Service static function to take away data block from internal buffer.
- *
- * Returns allocated data block in a form of C-string i.e. adds '\0' at the end
- * of data. Additionally function can drop some bytes from internal buffer.
- * It's usefull when it's necessary to get text string from the buffer and
- * drop trailing end of line.
- *
- * @warning Returned pointer must be freed by faux_str_free() later.
- *
- * @param [in] f File object.
- * @param [in] bytes_get Number of bytes to get from internal buffer.
- * @param [in] bytes_drop Number of bytes to drop. Actually
- * (bytes_drop + bytes_get) bytes will be removed from internal buffer.
- * @return Allocated string (with trailing '\0') with data to get.
- */
-static char *faux_file_takeaway(faux_file_t *f,
-	size_t bytes_get, size_t bytes_drop) {
-
-	size_t remove_len = 0;
-	char *line = NULL;
-
-	assert(f);
-	if (!f)
-		return NULL;
-
-	remove_len = bytes_get + bytes_drop;
-	// Try to take away more bytes than buffer contain
-	if ((remove_len > f->len) || (0 == remove_len))
-		return NULL;
-
-	line = faux_zmalloc(bytes_get + 1); // One extra byte for '\0'
-	assert(line);
-	if (!line)
-		return NULL; // Memory problems
-	memcpy(line, f->buf, bytes_get);
-
-	// Remove block from the internal buffer
-	f->len = f->len - remove_len;
-	memmove(f->buf, f->buf + remove_len, f->len);
-
-	return line;
-}
-
-
-/** @brief Service static function to get all data from buf as single C-string.
- *
- * Gets all the data from internal buffer as a single C-string (i.e. ends with
- * '\0'). This data will be removed from internal buffer.
- *
- * @warning Returned pointer must be freed by faux_str_free() later.
- *
- * @param [in] f File object.
- * @return Allocated string (with trailing '\0') with data to get.
- */
-static char *faux_file_takeaway_rest(faux_file_t *f) {
-
-	assert(f);
-	if (!f)
-		return NULL;
-
-	return faux_file_takeaway(f, f->len, 0);
-}
-
-
-/** @brief Service static function to get line from buf as single C-string.
- *
- * Gets line (data ends with EOL) from internal buffer as a single C-string
- * (i.e. ends with '\0'). The resulting line will not contain trailing EOL but
- * EOL will be removed from internal buffer together with line.
- *
- * @warning Returned pointer must be freed by faux_str_free() later.
- *
- * @param [in] f File object.
- * @return Allocated string (with trailing '\0') with line.
- */
-static char *faux_file_takeaway_line(faux_file_t *f) {
-
-	char *find = NULL;
-	const char *eol = "\n\r";
-	size_t line_len = 0;
-
-	assert(f);
-	if (!f)
-		return NULL;
-
-	// Search buffer for EOL
-	find = faux_str_charsn(f->buf, eol, f->len);
-	if (!find)
-		return NULL; // End of line is not found
-	line_len = find - f->buf;
-
-	// Takeaway line without trailing EOL. So drop one last byte
-	return faux_file_takeaway(f, line_len, 1);
-}
-
-
-/** @brief Service static function to enlarge internal buffer.
- *
- * The initial size of internal buffer is 128 bytes. Each function execution
- * enlarges buffer by chunk of 128 bytes.
- *
- * @param [in] f File objects.
- * @return 0 - success, < 0 - error
- */
-static int faux_file_enlarge_buffer(faux_file_t *f) {
-
-	size_t new_size = 0;
-	char *new_buf = NULL;
-
-	assert(f);
-	if (!f)
-		return -1;
-
-	new_size = f->buf_size + FAUX_FILE_CHUNK_SIZE;
-	new_buf = realloc(f->buf, new_size);
-	assert(new_buf);
-	if (!new_buf)
-		return -1;
-	// NULLify newly allocated memory
-	faux_bzero(new_buf + f->buf_size, new_size - f->buf_size);
-	f->buf = new_buf;
-	f->buf_size = new_size;
-
-	return 0;
-}
-
-
-/** @brief Read line from file.
- *
- * Actually function searches for line within internal buffer. If line is not
- * found then function reads new data from file and searches for the line again.
- * The last line in file (without trailing EOL) is considered as line too.
- *
- * @warning Returned pointer must be freed by faux_str_free() later.
- *
- * @param [in] f File object.
- * @return Line pointer or NULL on error.
- */
-char *faux_file_getline(faux_file_t *f) {
-
-	ssize_t bytes_readed = 0;
-
-	assert(f);
-	if (!f)
-		return NULL;
-
-	do {
-		char *find = NULL;
-
-		// May be buffer already contain line
-		find = faux_file_takeaway_line(f);
-		if (find)
-			return find;
-
-		if (f->buf_size == f->len) { // Buffer is full but doesn't contain line
-			if (faux_file_enlarge_buffer(f) < 0) // Make buffer larger
-				return NULL; // Memory problem
-		}
-
-		// Read new data from file
-		do {
-			bytes_readed = read(f->fd, f->buf + f->len, f->buf_size - f->len);
-			if ((bytes_readed < 0) && (errno != EINTR))
-				return NULL; // Some file error
-		} while (bytes_readed < 0); // i.e. EINTR
-		f->len += bytes_readed;
-
-	} while (bytes_readed > 0);
-
-	// EOF (here bytes_readed == 0)
-	f->eof = BOOL_TRUE;
-
-	// The last line can be without eol. Consider it as a line too
-	return faux_file_takeaway_rest(f);
-}
-
-
-/** @brief Writes data to file.
- *
- * The system write() can be interrupted by signal or can write less bytes
- * than specified. This function will continue to write data until all data
- * will be written or error occured.
- *
- * @param [in] f File object.
- * @param [in] buf Buffer to write.
- * @param [in] n Number of bytes to write.
- * @return Number of bytes written or NULL on error.
- */
-ssize_t faux_file_write(faux_file_t *f, const void *buf, size_t n) {
-
-	ssize_t bytes_written = 0;
-	size_t left = n;
-	const void *data = buf;
-
-	assert(f);
-	assert(buf);
-	if (!f || !buf)
-		return -1;
-	if (0 == n)
-		return 0;
-
-	do {
-		bytes_written = write(f->fd, data, left);
-		if (bytes_written < 0) {
-			if (EINTR == errno)
-				continue;
-			return -1;
-		}
-		if (0 == bytes_written) // Insufficient space
-			return -1;
-		data += bytes_written;
-		left = left - bytes_written;
-	} while (left > 0);
-
-	return n;
-}

+ 0 - 13
faux/file/private.h

@@ -1,13 +0,0 @@
-#include "faux/faux.h"
-#include "faux/file.h"
-
-/** @brief Chunk size to allocate buffer */
-#define FAUX_FILE_CHUNK_SIZE 128
-
-struct faux_file_s {
-	int fd; // File descriptor
-	char *buf; // Data buffer
-	size_t buf_size; // Current buffer size
-	size_t len; // Current data length
-	bool_t eof; // EOF flag
-};

+ 0 - 39
faux/ini.h

@@ -1,39 +0,0 @@
-/** @file ini.h
- * @brief Public interface to work with ini files and strings.
- */
-
-#ifndef _faux_ini_h
-#define _faux_ini_h
-
-#include "faux/faux.h"
-#include "faux/list.h"
-
-typedef struct faux_pair_s faux_pair_t;
-typedef struct faux_ini_s faux_ini_t;
-typedef faux_list_node_t faux_ini_node_t;
-
-C_DECL_BEGIN
-
-// Pair
-const char *faux_pair_name(const faux_pair_t *pair);
-const char *faux_pair_value(const faux_pair_t *pair);
-
-// Ini
-faux_ini_t *faux_ini_new(void);
-void faux_ini_free(faux_ini_t *ini);
-
-const faux_pair_t *faux_ini_set(faux_ini_t *ini, const char *name, const char *value);
-void faux_ini_unset(faux_ini_t *ini, const char *name);
-
-const faux_pair_t *faux_ini_find_pair(const faux_ini_t *ini, const char *name);
-const char *faux_ini_find(const faux_ini_t *ini, const char *name);
-faux_ini_node_t *faux_ini_iter(const faux_ini_t *ini);
-const faux_pair_t *faux_ini_each(faux_ini_node_t **iter);
-
-int faux_ini_parse_str(faux_ini_t *ini, const char *str);
-int faux_ini_parse_file(faux_ini_t *ini, const char *fn);
-int faux_ini_write_file(const faux_ini_t *ini, const char *fn);
-
-C_DECL_END
-
-#endif				/* _faux_ini_h */

+ 0 - 8
faux/ini/Makefile.am

@@ -1,8 +0,0 @@
-libfaux_la_SOURCES += \
-	faux/ini/pair.c \
-	faux/ini/ini.c \
-	faux/ini/private.h
-
-if TESTC
-libfaux_la_SOURCES += faux/ini/testc_ini.c
-endif

+ 0 - 465
faux/ini/ini.c

@@ -1,465 +0,0 @@
-/** @file ini.c
- * @brief Functions for working with INI files.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <ctype.h>
-
-#include "private.h"
-#include "faux/faux.h"
-#include "faux/str.h"
-#include "faux/file.h"
-#include "faux/ini.h"
-
-
-/** @brief Allocates new INI object.
- *
- * Before working with INI object it must be allocated and initialized.
- *
- * @return Allocated and initialized INI object or NULL on error.
- */
-faux_ini_t *faux_ini_new(void) {
-
-	faux_ini_t *ini;
-
-	ini = faux_zmalloc(sizeof(*ini));
-	if (!ini)
-		return NULL;
-
-	// Init
-	ini->list = faux_list_new(BOOL_TRUE, BOOL_TRUE, 
-		faux_pair_compare, faux_pair_kcompare, faux_pair_free);
-
-	return ini;
-}
-
-
-/** @brief Frees the INI object.
- *
- * After using the INI object must be freed. Function frees INI objecr itself
- * and all pairs 'name/value' stored within INI object.
- */
-void faux_ini_free(faux_ini_t *ini) {
-
-	assert(ini);
-	if (!ini)
-		return;
-
-	faux_list_free(ini->list);
-	faux_free(ini);
-}
-
-
-/** @brief Adds pair 'name/value' to INI object.
- *
- * The 'name' field is a key. The key must be unique. Each key has its
- * correspondent value.
- *
- * If key is new for the INI object then the pair 'name/value' will be added
- * to it. If INI object already contain the same key then value of this pair
- * will be replaced by newer one. If new specified value is NULL then the
- * entry with the correspondent key will be removed from the INI object.
- *
- * @param [in] ini Allocated and initialized INI object.
- * @param [in] name Name field for pair 'name/value'.
- * @param [in] value Value field for pair 'name/value'.
- * @return
- * Newly created pair object.
- * NULL if entry was removed (value == NULL)
- * NULL on error
- */
-const faux_pair_t *faux_ini_set(
-	faux_ini_t *ini, const char *name, const char *value) {
-
-	faux_pair_t *pair = NULL;
-	faux_list_node_t *node = NULL;
-	faux_pair_t *found_pair = NULL;
-
-	assert(ini);
-	assert(name);
-	if (!ini || !name)
-		return NULL;
-
-	// NULL 'value' means: remove entry from list
-	if (!value) {
-		node = faux_list_kfind_node(ini->list, name);
-		if (node)
-			faux_list_del(ini->list, node);
-		return NULL;
-	}
-
-	pair = faux_pair_new(name, value);
-	assert(pair);
-	if (!pair)
-		return NULL;
-
-	// Try to add new entry or find existent entry with the same 'name'
-	node = faux_list_add_find(ini->list, pair);
-	if (!node) { // Something went wrong
-		faux_pair_free(pair);
-		return NULL;
-	}
-	found_pair = faux_list_data(node);
-	if (found_pair != pair) { // Item already exists so use existent
-		faux_pair_free(pair);
-		faux_pair_set_value(
-			found_pair, value); // Replace value by new one
-		return found_pair;
-	}
-
-	// The new entry was added
-	return pair;
-}
-
-
-/** @brief Removes pair 'name/value' from INI object.
- *
- * Function search for the pair with specified name within INI object and
- * removes it.
- *
- * @param [in] ini Allocated and initialized INI object.
- * @param [in] name Name field to search for the entry.
- */
-void faux_ini_unset(faux_ini_t *ini, const char *name) {
-
-	faux_ini_set(ini, name, NULL);
-}
-
-
-/** @brief Searches for pair by name.
- *
- * The name field is a key to search INI object for pair 'name/value'.
- *
- * @param [in] ini Allocated and initialized INI object.
- * @param [in] name Name field to search for.
- * @return
- * Found pair 'name/value'.
- * NULL on errror.
- */
-const faux_pair_t *faux_ini_find_pair(const faux_ini_t *ini, const char *name) {
-
-	assert(ini);
-	assert(name);
-	if (!ini || !name)
-		return NULL;
-
-	return faux_list_kfind(ini->list, name);
-}
-
-
-/** @brief Searches for pair by name and returns correspondent value.
- *
- * The name field is a key to search INI object for pair 'name/value'.
- *
- * @param [in] ini Allocated and initialized INI object.
- * @param [in] name Name field to search for.
- * @return
- * Found value field.
- * NULL on errror.
- */
-const char *faux_ini_find(const faux_ini_t *ini, const char *name) {
-
-	const faux_pair_t *pair = faux_ini_find_pair(ini, name);
-
-	if (!pair)
-		return NULL;
-
-	return faux_pair_value(pair);
-}
-
-
-/** @brief Initializes iterator to iterate through the entire INI object.
- *
- * Before iterating with the faux_ini_each() function the iterator must be
- * initialized. This function do it.
- *
- * @param [in] ini Allocated and initialized INI object.
- * @return Initialized iterator.
- * @sa faux_ini_each()
- */
-faux_ini_node_t *faux_ini_iter(const faux_ini_t *ini) {
-
-	assert(ini);
-	if (!ini)
-		return NULL;
-
-	return (faux_ini_node_t *)faux_list_head(ini->list);
-}
-
-
-/** @brief Iterate entire INI object for pairs 'name/value'.
- *
- * Before iteration the iterator must be initialized by faux_ini_iter()
- * function. Doesn't use faux_ini_each() with uninitialized iterator.
- *
- * On each call function returns pair 'name/value' and modify iterator.
- * Stop iteration when function returns NULL.
- *
- * @param [in,out] iter Iterator.
- * @return Pair 'name/value'.
- * @sa faux_ini_iter()
- */
-const faux_pair_t *faux_ini_each(faux_ini_node_t **iter) {
-
-	return (const faux_pair_t *)faux_list_each((faux_list_node_t **)iter);
-}
-
-
-/** Service function to purify (clean out spaces, quotes) word.
- *
- * The 'word' in this case is a string without prepending or trailing spaces.
- * If 'word' is quoted then it can contain spaces within quoting. The qoutes
- * itself is not part of the 'word'. If 'word' is not quoted then it can't
- * contain spaces, so the end of 'word' is a first space after non-space
- * characters. The function searchs for the first occurence of 'word' within
- * specified string, allocates memory and returns purified copy of the word.
- * The return value must be faux_str_free()-ed later.
- *
- * Now the unclosed quoting is not an error. Suppose the end of the line can
- * close quoting.
- *
- * @param [in] str String to find word in it.
- * @return Purified copy of word or NULL.
- */
-static char *faux_ini_purify_word(const char *str) {
-	const char *word;
-	const char *string = str;
-	bool_t quoted = BOOL_FALSE;
-	size_t len = 0;
-
-	assert(str);
-	if (!str)
-		return NULL;
-
-	// Find the start of a word
-	while (*string != '\0' && isspace(*string)) {
-		string++;
-	}
-	// Is this the start of a quoted string?
-	if ('"' == *string) {
-		quoted = BOOL_TRUE;
-		string++;
-	}
-	word = string; // Begin of purified word
-
-	// Find the end of the word
-	while (*string != '\0') {
-		if ('\\' == *string) {
-			string++;
-			if ('\0' == *string) // Unfinished escaping
-				break; // Don't increment 'len'
-			len++;
-			// Skip escaped char
-			string++;
-			len++;
-			continue;
-		}
-		// End of word
-		if (!quoted && isspace(*string))
-			break;
-		if ('"' == *string) {
-			// End of a quoted string
-			break;
-		}
-		string++;
-		len++;
-	}
-
-	if (len == 0)
-		return NULL;
-
-	return faux_str_dupn(word, len);
-}
-
-
-/** @brief Parse string for pairs 'name/value'.
- *
- * String can contain an `name/value` pairs in following format:
- * @code
- * var1=value1
- * var2 = "value 2"
- * @endcode
- * Function parses that string and stores 'name/value' pairs to
- * the INI object.
- *
- * @param [in] ini Allocated and initialized INI object.
- * @param [in] string String to parse.
- * @return 0 - succes, < 0 - error
- */
-int faux_ini_parse_str(faux_ini_t *ini, const char *string) {
-
-	char *buffer = NULL;
-	char *saveptr = NULL;
-	char *line = NULL;
-
-	assert(ini);
-	if (!ini)
-		return -1;
-	if (!string)
-		return 0;
-
-	buffer = faux_str_dup(string);
-	// Now loop though each line
-	for (line = strtok_r(buffer, "\n\r", &saveptr); line;
-		line = strtok_r(NULL, "\n\r", &saveptr)) {
-
-		// Now 'line' contain one 'name/value' pair. Single line.
-		char *str = NULL;
-		char *name = NULL;
-		char *value = NULL;
-		char *savestr = NULL;
-		char *rname = NULL;
-		char *rvalue = NULL;
-
-		while ((*line != '\0') && isspace(*line)) // Skip spaces
-			line++;
-		if ('\0' == *line) // Empty line
-			continue;
-		if ('#' == *line) // Comment. Skip it.
-			continue;
-		str = faux_str_dup(line);
-
-		// Find out name
-		name = strtok_r(str, "=", &savestr);
-		if (!name) {
-			faux_str_free(str);
-			continue;
-		}
-		rname = faux_ini_purify_word(name);
-		if (!rname) {
-			faux_str_free(str);
-			continue;
-		}
-
-		// Find out value
-		value = strtok_r(NULL, "=", &savestr);
-		if (!value) { // Empty value
-			rvalue = NULL;
-		} else {
-			rvalue = faux_ini_purify_word(value);
-		}
-
-		faux_ini_set(ini, rname, rvalue);
-		faux_str_free(rname);
-		faux_str_free(rvalue);
-		faux_str_free(str);
-	}
-	faux_str_free(buffer);
-
-	return 0;
-}
-
-
-/** @brief Parse file for pairs 'name/value'.
- *
- * File can contain an `name/value` pairs in following format:
- * @code
- * var1=value1
- * var2 = "value 2"
- * @endcode
- * Function parses file and stores 'name/value' pairs to
- * the INI object.
- *
- * @param [in] ini Allocated and initialized INI object.
- * @param [in] string String to parse.
- * @return 0 - succes, < 0 - error
- * @sa faux_ini_parse_str()
- */
-int faux_ini_parse_file(faux_ini_t *ini, const char *fn) {
-
-	bool_t eof = BOOL_FALSE;
-	faux_file_t *f = NULL;
-	char *buf = NULL;
-
-	assert(ini);
-	assert(fn);
-	if (!ini)
-		return -1;
-	if (!fn || '\0' == *fn)
-		return -1;
-
-	f = faux_file_open(fn, O_RDONLY, 0);
-	if (!f)
-		return -1;
-
-	while ((buf = faux_file_getline(f))) {
-		// Don't analyze retval because it's not obvious what
-		// to do on error. May be next string will be ok.
-		faux_ini_parse_str(ini, buf);
-		faux_str_free(buf);
-	}
-
-	eof = faux_file_eof(f);
-	faux_file_close(f);
-	if (!eof) // File reading was interrupted before EOF
-		return -1;
-
-	return 0;
-}
-
-
-/** Writes INI file using INI object.
- *
- * Write pairs 'name/value' to INI file. The source of pairs is an INI object.
- * It's complementary operation to faux_ini_parse_file().
- *
- * @param [in] ini Allocated and initialized INI object.
- * @param [in] fn File name to write to.
- * @return 0 - success, < 0 - error
- */
-int faux_ini_write_file(const faux_ini_t *ini, const char *fn) {
-
-	faux_file_t *f = NULL;
-	faux_ini_node_t *iter = NULL;
-	const faux_pair_t *pair = NULL;
-	const char *spaces = " \t"; // String with spaces needs quotes
-
-	assert(ini);
-	assert(fn);
-	if (!ini)
-		return -1;
-	if (!fn || '\0' == *fn)
-		return -1;
-
-	f = faux_file_open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0644);
-	if (!f)
-		return -1;
-
-	iter = faux_ini_iter(ini);
-	while ((pair = faux_ini_each(&iter))) {
-		char *quote_name = NULL;
-		char *quote_value = NULL;
-		const char *name = faux_pair_name(pair);
-		const char *value = faux_pair_value(pair);
-		char *line = NULL;
-		ssize_t bytes_written = 0;
-
-		// Word with spaces needs quotes
-		quote_name = faux_str_chars(name, spaces) ? "\"" : "";
-		quote_value = faux_str_chars(value, spaces) ? "\"" : "";
-
-		// Prepare INI line
-		line = faux_str_sprintf("%s%s%s=%s%s%s\n",
-			quote_name, name, quote_name,
-			quote_value, value, quote_value);
-		if (!line) {
-			faux_file_close(f);
-			return -1;
-		}
-
-		// Write to file
-		bytes_written = faux_file_write(f, line, strlen(line));
-		faux_str_free(line);
-		if (bytes_written < 0) { // Can't write to file
-			faux_file_close(f);
-			return -1;
-		}
-	}
-
-	faux_file_close(f);
-
-	return 0;
-}

+ 0 - 100
faux/ini/pair.c

@@ -1,100 +0,0 @@
-/** @file pair.c
- * Ini file pairs key/value.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "private.h"
-#include "faux/str.h"
-#include "faux/ini.h"
-
-int faux_pair_compare(const void *first, const void *second) {
-
-	const faux_pair_t *f = (const faux_pair_t *)first;
-	const faux_pair_t *s = (const faux_pair_t *)second;
-
-	return strcmp(f->name, s->name);
-}
-
-
-int faux_pair_kcompare(const void *key, const void *list_item) {
-
-	const char *f = (const char *)key;
-	const faux_pair_t *s = (const faux_pair_t *)list_item;
-
-	return strcmp(f, s->name);
-}
-
-
-faux_pair_t *faux_pair_new(const char *name, const char *value) {
-
-	faux_pair_t *pair = NULL;
-
-	pair = faux_zmalloc(sizeof(*pair));
-	assert(pair);
-	if (!pair)
-		return NULL;
-
-	// Initialize
-	pair->name = faux_str_dup(name);
-	pair->value = faux_str_dup(value);
-
-	return pair;
-}
-
-
-void faux_pair_free(void *ptr) {
-
-	faux_pair_t *pair = (faux_pair_t *)ptr;
-
-	assert(pair);
-	if (!pair)
-		return;
-	faux_str_free(pair->name);
-	faux_str_free(pair->value);
-	faux_free(pair);
-}
-
-
-const char *faux_pair_name(const faux_pair_t *pair) {
-
-	assert(pair);
-	if (!pair)
-		return NULL;
-
-	return pair->name;
-}
-
-
-void faux_pair_set_name(faux_pair_t *pair, const char *name) {
-
-	assert(pair);
-	if (!pair)
-		return;
-
-	faux_str_free(pair->name);
-	pair->name = faux_str_dup(name);
-}
-
-
-const char *faux_pair_value(const faux_pair_t *pair) {
-
-	assert(pair);
-	if (!pair)
-		return NULL;
-
-	return pair->value;
-}
-
-
-void faux_pair_set_value(faux_pair_t *pair, const char *value) {
-
-	assert(pair);
-	if (!pair)
-		return;
-
-	faux_str_free(pair->value);
-	pair->value = faux_str_dup(value);
-}

+ 0 - 24
faux/ini/private.h

@@ -1,24 +0,0 @@
-#include "faux/faux.h"
-#include "faux/list.h"
-#include "faux/ini.h"
-
-struct faux_pair_s {
-	char *name;
-	char *value;
-};
-
-struct faux_ini_s {
-	faux_list_t *list;
-};
-
-C_DECL_BEGIN
-
-int faux_pair_compare(const void *first, const void *second);
-int faux_pair_kcompare(const void *key, const void *list_item);
-faux_pair_t *faux_pair_new(const char *name, const char *value);
-void faux_pair_free(void *pair);
-
-void faux_pair_set_name(faux_pair_t *pair, const char *name);
-void faux_pair_set_value(faux_pair_t *pair, const char *value);
-
-C_DECL_END

+ 0 - 26
faux/ini/testc_ini.c

@@ -1,26 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-
-int testc_faux_ini_good(void) {
-
-	char *path = NULL;
-
-	path = getenv("FAUX_INI_PATH");
-	if (path)
-		printf("Env var is [%s]\n", path);
-	return 0;
-}
-
-
-int testc_faux_ini_bad(void) {
-
-	return -1;
-}
-
-int testc_faux_ini_signal(void) {
-
-	char *p = NULL;
-
-	printf("%s\n", p);
-	return -1;
-}

+ 0 - 67
faux/list.h

@@ -1,67 +0,0 @@
-/** @file list.h
- * @brief Public interface for a bidirectional list.
- */
-
-#ifndef _faux_list_h
-#define _faux_list_h
-
-#include <stddef.h>
-
-#include "faux.h"
-
-typedef struct faux_list_node_s faux_list_node_t;
-typedef struct faux_list_s faux_list_t;
-
-typedef int (*faux_list_cmp_fn)(const void *new_item, const void *list_item);
-typedef int (*faux_list_kcmp_fn)(const void *key, const void *list_item);
-typedef void (*faux_list_free_fn)(void *list_item);
-
-C_DECL_BEGIN
-
-// list_node_t methods
-faux_list_node_t *faux_list_prev_node(const faux_list_node_t *node);
-faux_list_node_t *faux_list_next_node(const faux_list_node_t *node);
-void *faux_list_data(const faux_list_node_t *node);
-faux_list_node_t *faux_list_each_node(faux_list_node_t **iter);
-faux_list_node_t *faux_list_eachr_node(faux_list_node_t **iter);
-void *faux_list_each(faux_list_node_t **iter);
-void *faux_list_eachr(faux_list_node_t **iter);
-
-// list_t methods
-faux_list_t *faux_list_new(bool_t sorted, bool_t unique,
-	faux_list_cmp_fn cmpFn, faux_list_kcmp_fn kcmpFn,
-	faux_list_free_fn freeFn);
-void faux_list_free(faux_list_t *list);
-
-faux_list_node_t *faux_list_head(const faux_list_t *list);
-faux_list_node_t *faux_list_tail(const faux_list_t *list);
-size_t faux_list_len(const faux_list_t *list);
-
-faux_list_node_t *faux_list_add(faux_list_t *list, void *data);
-faux_list_node_t *faux_list_add_find(faux_list_t *list, void *data);
-void *faux_list_takeaway(faux_list_t *list, faux_list_node_t *node);
-int faux_list_del(faux_list_t *list, faux_list_node_t *node);
-
-faux_list_node_t *faux_list_match_node(const faux_list_t *list,
-	faux_list_kcmp_fn matchFn, const void *userkey,
-	faux_list_node_t **saveptr);
-faux_list_node_t *faux_list_kmatch_node(const faux_list_t *list,
-	const void *userkey, faux_list_node_t **saveptr);
-void *faux_list_match(const faux_list_t *list,
-	faux_list_kcmp_fn matchFn, const void *userkey,
-	faux_list_node_t **saveptr);
-void *faux_list_kmatch(const faux_list_t *list,
-	const void *userkey, faux_list_node_t **saveptr);
-faux_list_node_t *faux_list_find_node(const faux_list_t *list,
-	faux_list_kcmp_fn matchFn, const void *userkey);
-faux_list_node_t *faux_list_kfind_node(const faux_list_t *list,
-	const void *userkey);
-void *faux_list_find(const faux_list_t *list,
-	faux_list_kcmp_fn matchFn, const void *userkey);
-void *faux_list_kfind(const faux_list_t *list,
-	const void *userkey);
-
-C_DECL_END
-
-#endif				/* _faux_list_h */
-

+ 0 - 3
faux/list/Makefile.am

@@ -1,3 +0,0 @@
-libfaux_la_SOURCES += \
-	faux/list/list.c \
-	faux/list/private.h

+ 0 - 659
faux/list/list.c

@@ -1,659 +0,0 @@
-/** @file list.c
- * @brief Implementation of a bidirectional list.
- *
- * Bidirectional List stores special structures (nodes) as its elements.
- * Nodes are linked to each other. Node stores abstract user data (i.e. void *).
- *
- * List can be sorted or unsorted. To sort list user provides special callback
- * function to compare two nodes. The list will be sorted
- * due to this function return value that indicates "less than",
- * "equal", "greater than". Additionally user may provide another callback
- * function to free user defined data on list freeing.
- */
-
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-
-#include "private.h"
-#include "faux/list.h"
-
-
-/** @brief Allocates and initializes new list node instance.
- *
- * @param [in] data User defined data to store within node.
- * @return Newly created list node instance or NULL on error.
- */
-static faux_list_node_t *faux_list_new_node(void *data) {
-
-	faux_list_node_t *node = NULL;
-
-	node = faux_zmalloc(sizeof(*node));
-	assert(node);
-	if (!node)
-		return NULL;
-
-	// Initialize
-	node->prev = NULL;
-	node->next = NULL;
-	node->data = data;
-
-	return node;
-}
-
-
-/** @brief Free list node instance.
- *
- * @param [in] node List node instance.
- */
-static void faux_list_free_node(faux_list_node_t *node) {
-
-	assert(node);
-	faux_free(node);
-}
-
-
-/** @brief Gets previous list node.
- *
- * @param [in] this List node instance.
- * @return List node previous in list.
- */
-faux_list_node_t *faux_list_prev_node(const faux_list_node_t *node) {
-
-	assert(node);
-	if (!node)
-		return NULL;
-
-	return node->prev;
-}
-
-
-/** @brief Gets next list node.
- *
- * @param [in] this List node instance.
- * @return List node next in list.
- */
-faux_list_node_t *faux_list_next_node(const faux_list_node_t *node) {
-
-	assert(node);
-	if (!node)
-		return NULL;
-
-	return node->next;
-}
-
-
-/** @brief Gets user data from list node.
- *
- * @param [in] this List node instance.
- * @return User data stored within specified list node.
- */
-void *faux_list_data(const faux_list_node_t *node) {
-
-	assert(node);
-	if (!node)
-		return NULL;
-
-	return node->data;
-}
-
-
-/** @brief Iterate through each list node.
- *
- * On each call to this function the iterator will change its value.
- * Before function using the iterator must be initialised by list head node.
- *
- * @param [in,out] iter List node ptr used as an iterator.
- * @return List node or NULL if list elements are over.
- */
-faux_list_node_t *faux_list_each_node(faux_list_node_t **iter) {
-
-	faux_list_node_t *current_node = *iter;
-
-	// No assert() on current_node. NULL iterator is normal
-	if (!current_node)
-		return NULL;
-	*iter = faux_list_next_node(current_node);
-
-	return current_node;
-}
-
-
-/** @brief Iterate through each list node. Reverse order.
- *
- * On each call to this function the iterator will change its value.
- * Before function using the iterator must be initialised by list tail node.
- *
- * @param [in,out] iter List node ptr used as an iterator.
- * @return List node or NULL if list elements are over.
- */
-faux_list_node_t *faux_list_eachr_node(faux_list_node_t **iter) {
-
-	faux_list_node_t *current_node = *iter;
-
-	// No assert() on current_node. NULL iterator is normal
-	if (!current_node)
-		return NULL;
-	*iter = faux_list_prev_node(current_node);
-
-	return current_node;
-}
-
-
-/** @brief Iterate through each list node and returns user data.
- *
- * On each call to this function the iterator will change its value.
- * Before function using the iterator must be initialised by list head node.
- *
- * @param [in,out] iter List node ptr used as an iterator.
- * @return User data or NULL if list elements are over.
- */
-void *faux_list_each(faux_list_node_t **iter) {
-
-	faux_list_node_t *current_node = NULL;
-
-	// No assert() on current_node. NULL iterator is normal
-	if (!*iter)
-		return NULL;
-	current_node = faux_list_each_node(iter);
-
-	return faux_list_data(current_node);
-}
-
-
-/** @brief Iterate (reverse order) through each list node and returns user data.
- *
- * On each call to this function the iterator will change its value.
- * Before function using the iterator must be initialised by list head node.
- *
- * @param [in,out] iter List node ptr used as an iterator.
- * @return User data or NULL if list elements are over.
- */
-void *faux_list_eachr(faux_list_node_t **iter) {
-
-	faux_list_node_t *current_node = NULL;
-
-	// No assert() on current_node. NULL iterator is normal
-	if (!*iter)
-		return NULL;
-	current_node = faux_list_eachr_node(iter);
-
-	return faux_list_data(current_node);
-}
-
-
-/** @brief Allocate and initialize bidirectional list.
- *
- * Prototypes for callback functions:
- * @code
- * int (*faux_list_cmp_fn)(const void *new_item, const void *list_item);
- * void faux_list_free_fn(void *data);
- * @endcode
- *
- * @param [in] sorted If list is sorted - BOOL_TRUE, unsorted - BOOL_FALSE.
- * @param [in] unique If list entry is unique - BOOL_TRUE, else - BOOL_FALSE.
- * @param [in] compareFn Callback function to compare two user data instances
- * to sort list.
- * @param [in] freeFn Callback function to free user data.
- * @return Newly created bidirectional list or NULL on error.
- */
-faux_list_t *faux_list_new(bool_t sorted, bool_t unique,
-	faux_list_cmp_fn cmpFn, faux_list_kcmp_fn kcmpFn,
-	faux_list_free_fn freeFn) {
-
-	faux_list_t *list = NULL;
-
-	// Sorted list must have cmpFn
-	if (sorted && !cmpFn)
-		return NULL;
-
-	// Unique list must have cmpFn
-	if (unique && !cmpFn)
-		return NULL;
-
-	list = faux_zmalloc(sizeof(*list));
-	assert(list);
-	if (!list)
-		return NULL;
-
-	// Initialize
-	list->head = NULL;
-	list->tail = NULL;
-	list->sorted = sorted;
-	list->unique = unique;
-	list->cmpFn = cmpFn;
-	list->kcmpFn = kcmpFn;
-	list->freeFn = freeFn;
-	list->len = 0;
-
-	return list;
-}
-
-
-/** @brief Free bidirectional list
- *
- * Free all nodes and user data from list and finally
- * free the list itself. It uses special callback
- * function specified by user (while faux_list_new()) to free the abstract
- * user data.
- *
- * @param [in] list List to free.
- */
-void faux_list_free(faux_list_t *list) {
-
-	faux_list_node_t *iter = NULL;
-
-	if (!list)
-		return;
-
-	while ((iter = faux_list_head(list))) {
-		faux_list_del(list, iter);
-	}
-	faux_free(list);
-}
-
-
-/** @brief Gets head of list.
- *
- * @param [in] list List.
- * @return List node first in list.
- */
-faux_list_node_t *faux_list_head(const faux_list_t *list) {
-
-	assert(list);
-	if (!list)
-		return NULL;
-
-	return list->head;
-}
-
-
-/** @brief Gets tail of list.
- *
- * @param [in] list List.
- * @return List node last in list.
- */
-faux_list_node_t *faux_list_tail(const faux_list_t *list) {
-
-	assert(list);
-	if (!list)
-		return NULL;
-
-	return list->tail;
-}
-
-
-/** @brief Gets current length of list.
- *
- * @param [in] list List.
- * @return Current length of list.
- */
-size_t faux_list_len(const faux_list_t *list) {
-
-	assert(list);
-	if (!list)
-		return 0;
-
-	return list->len;
-}
-
-
-/** @brief Generic static function for adding new list nodes.
- *
- * @param [in] list List to add node to.
- * @param [in] data User data for new list node.
- * key (when the cmpFn() returns 0)
- * @param [in] find - true/false Function returns list node if there is
- * identical entry. Or NULL if find is false.
- * @return Newly added list node.
- */
-static faux_list_node_t *faux_list_add_generic(
-	faux_list_t *list, void *data, bool_t find) {
-
-	faux_list_node_t *node = NULL;
-	faux_list_node_t *iter = NULL;
-
-	assert(list);
-	assert(data);
-	if (!list || !data)
-		return NULL;
-
-	node = faux_list_new_node(data);
-	if (!node)
-		return NULL;
-
-	// Empty list
-	if (!list->head) {
-		list->head = node;
-		list->tail = node;
-		list->len++;
-		return node;
-	}
-
-	// Non-sorted: Insert to tail
-	if (!list->sorted) {
-		// Unique: Search through whole list
-		if (list->unique) {
-			iter = list->tail;
-			while (iter) {
-				int res = list->cmpFn(node->data, iter->data);
-				if (0 == res) { // Already in list
-					faux_list_free_node(node);
-					return (find ? iter : NULL);
-				}
-				iter = iter->prev;
-			}
-		}
-		// Add entry to the tail
-		node->prev = list->tail;
-		node->next = NULL;
-		if (list->tail)
-			list->tail->next = node;
-		list->tail = node;
-		list->len++;
-		return node;
-	}
-
-	// Sorted: Insert from tail
-	iter = list->tail;
-	while (iter) {
-		int res = list->cmpFn(node->data, iter->data);
-		// Unique: Already exists
-		if (list->unique && (0 == res)) {
-			faux_list_free_node(node);
-			return (find ? iter : NULL);
-		}
-		// Non-unique: Entry will be inserted after existent one
-		if (res >= 0) {
-			node->next = iter->next;
-			node->prev = iter;
-			iter->next = node;
-			if (node->next)
-				node->next->prev = node;
-			break;
-		}
-		iter = iter->prev;
-	}
-	// Insert node into the list head
-	if (!iter) {
-		node->next = list->head;
-		node->prev = NULL;
-		list->head->prev = node;
-		list->head = node;
-	}
-	if (!node->next)
-		list->tail = node;
-	list->len++;
-
-	return node;
-}
-
-
-/** @brief Adds user data to the list.
- *
- * The user data is not unique. It means that two equal user data instances
- * can be added to the list.
- *
- * @param [in] list List to add entry to.
- * @param [in] data User data.
- * @return Newly created list node or NULL on error.
- */
-faux_list_node_t *faux_list_add(faux_list_t *list, void *data) {
-
-	return faux_list_add_generic(list, data, BOOL_FALSE);
-}
-
-
-/** @brief Adds user data (unique) to the list or return equal existent node.
- *
- * The user data must be unique in this case. Function compares list nodes
- * with the new one. If equal node is already in the list then function
- * returns this node. Else new unique node will be added to the list.
- *
- * @param [in] list List to add entry to.
- * @param [in] data User data.
- * @return Newly created list node, existent equal node or NULL on error.
- */
-faux_list_node_t *faux_list_add_find(faux_list_t *list, void *data) {
-
-	assert(list);
-	if (!list)
-		return NULL;
-
-	// Function add_find has no meaning for non-unique list. What is the
-	// function behaviour? It found entry. Must it return existent entry or
-	// add new non-unique entry?
-	if (!list->unique)
-		return NULL;
-
-	return faux_list_add_generic(list, data, BOOL_TRUE);
-}
-
-
-/** Takes away list node from the list.
- *
- * Function removes list node from the list and returns user data
- * stored in this node.
- *
- * @param [in] list List to take away node from.
- * @param [in] node List node to take away.
- * @return User data from removed node or NULL on error.
- */
-void *faux_list_takeaway(faux_list_t *list, faux_list_node_t *node) {
-
-	void *data = NULL;
-
-	assert(list);
-	assert(node);
-	if (!list || !node)
-		return NULL;
-
-	if (node->prev)
-		node->prev->next = node->next;
-	else
-		list->head = node->next;
-	if (node->next)
-		node->next->prev = node->prev;
-	else
-		list->tail = node->prev;
-	list->len--;
-
-	data = faux_list_data(node);
-	faux_list_free_node(node);
-
-	return data;
-}
-
-
-/** @brief Deletes list node from the list.
- *
- * Functions removes node from the list and free user data memory if
- * freeFn callback was defined while list creation. If freeFn callback
- * is not defined then function is the same as faux_list_takeaway().
- *
- * @param [in] list List to delete node from.
- * @param [in] node List node to delete.
- * @return 0 on success, < 0 on error.
- */
-int faux_list_del(faux_list_t *list, faux_list_node_t *node) {
-
-	void *data = NULL;
-
-	assert(list);
-	assert(node);
-	if (!list || !node)
-		return -1;
-
-	data = faux_list_takeaway(list, node);
-	assert(data);
-	if (!data) // Illegal case
-		return -1;
-	if (list->freeFn)
-		list->freeFn(data);
-
-	return 0;
-}
-
-
-/** @brief Search list for matching (match function).
- *
- * Function iterates through the list and executes special matching user defined
- * callback function matchFn for every list node. User can provide "userkey" -
- * the data that matchFn can use how it wants. The matchFn is arbitrary
- * argument. The userkey argument can be NULL. The function will immediately
- * return matched list node. To continue searching the saveptr argument contains
- * current iterator. So user can call to faux_list_match_node() for several
- * times and gets all matched nodes from list.
- *
- * Prototype for matchFn callback function:
- * @code
- * int (*faux_list_kcmp_fn)(const void *key, const void *list_item);
- * @endcode
- *
- * @param [in] list List.
- * @param [in] matchFn User defined matching callback function.
- * @param [in] userkey User defined data to use in matchFn function.
- * @param [in,out] saveptr Ptr to save iterator.
- * @return Matched list node.
- */
-faux_list_node_t *faux_list_match_node(const faux_list_t *list,
-	faux_list_kcmp_fn matchFn, const void *userkey,
-	faux_list_node_t **saveptr) {
-
-	faux_list_node_t *iter = NULL;
-
-	assert(list);
-	assert(matchFn);
-	if (!list || !matchFn || !list->head)
-		return NULL;
-
-	if (saveptr)
-		iter = *saveptr;
-	if (!iter)
-		iter = list->head;
-	while (iter) {
-		int res = 0;
-		faux_list_node_t *node = iter;
-
-		iter = faux_list_next_node(node);
-		if (saveptr)
-			*saveptr = iter;
-		res = matchFn(userkey, faux_list_data(node));
-		if (0 == res)
-			return node;
-		if (list->sorted && (res < 0)) // No chances to find match
-			return NULL;
-	}
-
-	return NULL;
-}
-
-
-/** @brief Search list for matching (key cmp function).
- *
- * Same as faux_list_match_node() but uses userkey compare function defined
- * while faux_list_new() function call.
- *
- * @sa faux_list_match_node()
- */
-faux_list_node_t *faux_list_kmatch_node(const faux_list_t *list,
-	const void *userkey, faux_list_node_t **saveptr) {
-
-	assert(list);
-	if (!list)
-		return NULL;
-
-	return faux_list_match_node(list, list->kcmpFn, userkey, saveptr);
-}
-
-
-/** @brief Search list for matching (match function) and returns user data.
- *
- * Same as faux_list_match_node() but returns user data structure.
- *
- * @sa faux_list_match_node()
- */
-void *faux_list_match(const faux_list_t *list, faux_list_kcmp_fn matchFn,
-	const void *userkey, faux_list_node_t **saveptr) {
-
-	faux_list_node_t *res =
-		faux_list_match_node(list, matchFn, userkey, saveptr);
-	if (!res)
-		return NULL;
-
-	return faux_list_data(res);
-}
-
-
-/** @brief Search list for matching (key cmp function) and returns user data.
- *
- * Same as faux_list_match() but uses userkey compare function defined
- * while faux_list_new() function call.
- *
- * @sa faux_list_match_node()
- */
-void *faux_list_kmatch(const faux_list_t *list, const void *userkey,
-	faux_list_node_t **saveptr) {
-
-	assert(list);
-	if (!list)
-		return NULL;
-
-	return faux_list_match(list, list->kcmpFn, userkey, saveptr);
-}
-
-
-/** @brief Search list for first matching (match function).
- *
- * Same as faux_list_match_node() but search for the fisrt matching.
- * Doesn't use saveptr iterator.
- *
- * @sa faux_list_match_node()
- */
-faux_list_node_t *faux_list_find_node(const faux_list_t *list,
-	faux_list_kcmp_fn matchFn, const void *userkey) {
-
-	return faux_list_match_node(list, matchFn, userkey, NULL);
-}
-
-
-/** @brief Search list for first matching (key cmp function).
- *
- * Same as faux_list_find_node() but uses userkey compare function defined
- * while faux_list_new() function call.
- *
- * @sa faux_list_match_node()
- */
-faux_list_node_t *faux_list_kfind_node(const faux_list_t *list,
-	const void *userkey) {
-
-	return faux_list_find_node(list, list->kcmpFn, userkey);
-}
-
-
-/** @brief Search list for first matching (match function) and returns user data.
- *
- * Same as faux_list_match_node() but returns user data structure and search
- * only for the first matching. Doesn't use saveptr iterator.
- *
- * @sa faux_list_match_node()
- */
-void *faux_list_find(const faux_list_t *list, faux_list_kcmp_fn matchFn,
-	const void *userkey) {
-
-	return faux_list_match(list, matchFn, userkey, NULL);
-}
-
-
-/** @brief Search list for first matching (key cmp function). Returns user data.
- *
- * Same as faux_list_find() but uses userkey compare function defined
- * while faux_list_new() function call.
- *
- * @sa faux_list_match_node()
- */
-void *faux_list_kfind(const faux_list_t *list,
-	const void *userkey) {
-
-	return faux_list_find(list, list->kcmpFn, userkey);
-}

+ 0 - 18
faux/list/private.h

@@ -1,18 +0,0 @@
-#include "faux/list.h"
-
-struct faux_list_node_s {
-	faux_list_node_t *prev;
-	faux_list_node_t *next;
-	void *data;
-};
-
-struct faux_list_s {
-	faux_list_node_t *head;
-	faux_list_node_t *tail;
-	bool_t sorted;
-	bool_t unique;
-	faux_list_cmp_fn cmpFn; // Function to compare two list elements
-	faux_list_kcmp_fn kcmpFn; // Function to compare key and list element
-	faux_list_free_fn freeFn; // Function to properly free data field
-	size_t len;
-};

+ 0 - 16
faux/log.h

@@ -1,16 +0,0 @@
-/** @file log.h
- * @brief Public interface for faux log functions.
- */
-
-#ifndef _faux_log_h
-#define _faux_log_h
-
-#include "faux/faux.h"
-
-C_DECL_BEGIN
-
-int faux_log_facility(const char *str, int *facility);
-
-C_DECL_END
-
-#endif

+ 0 - 2
faux/log/Makefile.am

@@ -1,2 +0,0 @@
-libfaux_la_SOURCES += \
-	faux/log/log.c

+ 0 - 74
faux/log/log.c

@@ -1,74 +0,0 @@
-/** @file log.c
- * @brief Helpers for logging
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <assert.h>
-#include <syslog.h>
-
-#include "faux/str.h"
-#include "faux/log.h"
-
-struct log_name {
-	const char *name;
-	int facility;
-};
-
-static struct log_name log_names[] = {
-	{"local0", LOG_LOCAL0},
-	{"local1", LOG_LOCAL1},
-	{"local2", LOG_LOCAL2},
-	{"local3", LOG_LOCAL3},
-	{"local4", LOG_LOCAL4},
-	{"local5", LOG_LOCAL5},
-	{"local6", LOG_LOCAL6},
-	{"local7", LOG_LOCAL7},
-	{"auth", LOG_AUTH},
-#ifdef LOG_AUTHPRIV
-	{"authpriv", LOG_AUTHPRIV},
-#endif
-	{"cron", LOG_CRON},
-	{"daemon", LOG_DAEMON},
-#ifdef LOG_FTP
-	{"ftp", LOG_FTP},
-#endif
-	{"kern", LOG_KERN},
-	{"lpr", LOG_LPR},
-	{"mail", LOG_MAIL},
-	{"news", LOG_NEWS},
-	{"syslog", LOG_SYSLOG},
-	{"user", LOG_USER},
-	{"uucp", LOG_UUCP},
-	{NULL, 0}, // end of list
-};
-
-/** @brief Parses syslog facility string and returns the facility id.
- *
- * Gets syslog facility string, parse it and finds out the facility
- * id in digital form. Usefull config or command line options parsing.
- *
- * @param [in] str Facility string.
- * @param [out] facility Facility in digital form.
- * @returns 0 - success, < 0 - parsing error
- */
-int faux_log_facility(const char *str, int *facility) {
-
-	int i = 0;
-
-	assert(facility);
-	assert(str);
-	if (!str || !facility)
-		return -1;
-
-	for (i = 0; log_names[i].name; i++) {
-		if (faux_str_casecmp(str, log_names[i].name) == 0) {
-			*facility = log_names[i].facility;
-			return 0;
-		}
-	}
-
-	return -1;
-}

+ 0 - 63
faux/str.h

@@ -1,63 +0,0 @@
-/** @file str.h
- * @brief Public interface for faux string functions.
- */
-
-#ifndef _faux_str_h
-#define _faux_str_h
-
-#include <stddef.h>
-
-#include "faux/faux.h"
-
-#define UTF8_MASK 0xC0
-#define UTF8_7BIT_MASK 0x80 // One byte or multibyte
-#define UTF8_11   0xC0 // First UTF8 byte
-#define UTF8_10   0x80 // Next UTF8 bytes
-
-C_DECL_BEGIN
-
-void faux_str_free(char *str);
-
-char *faux_str_dupn(const char *str, size_t n);
-char *faux_str_dup(const char *str);
-
-char *faux_str_catn(char **str, const char *text, size_t n);
-char *faux_str_cat(char **str, const char *text);
-char *faux_str_vcat(char **str, ...);
-char *faux_str_sprintf(const char *fmt, ...);
-
-char *faux_str_tolower(const char *str);
-char *faux_str_toupper(const char *str);
-
-int faux_str_casecmpn(const char *str1, const char *str2, size_t n);
-int faux_str_casecmp(const char *str1, const char *str2);
-char *faux_str_casestr(const char *haystack, const char *needle);
-char *faux_str_charsn(const char *str, const char *chars_to_search, size_t n);
-char *faux_str_chars(const char *str, const char *chars_to_search);
-
-
-//const char *faux_str_suffix(const char *string);
-/*
- * These are the escape characters which are used by default when 
- * expanding variables. These characters will be backslash escaped
- * to prevent them from being interpreted in a script.
- *
- * This is a security feature to prevent users from arbitarily setting
- * parameters to contain special sequences.
- */
-//extern const char *faux_str_esc_default;
-//extern const char *faux_str_esc_regex;
-//extern const char *faux_str_esc_quoted;
-
-//char *faux_str_decode(const char *string);
-//char *faux_str_ndecode(const char *string, unsigned int len);
-//char *faux_str_encode(const char *string, const char *escape_chars);
-//unsigned int faux_str_equal_part(const char *str1, const char *str2,
-//	bool_t utf8);
-//const char *faux_str_nextword(const char *string,
-//	size_t *len, size_t *offset, size_t *quoted);
-//unsigned int faux_str_wordcount(const char *line);
-
-C_DECL_END
-
-#endif				/* _faux_str_h */

+ 0 - 3
faux/str/Makefile.am

@@ -1,3 +0,0 @@
-libfaux_la_SOURCES += \
-	faux/str/str.c
-

+ 0 - 739
faux/str/str.c

@@ -1,739 +0,0 @@
-/** @file str.c
- * @brief String related functions
- *
- * This file implements some often used string functions.
- * Some functions are more portable versions of standard
- * functions but others are original ones.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdarg.h>
-
-#include "faux/ctype.h"
-#include "faux/str.h"
-
-/* TODO: Are that vars really needed? */
-//const char *lub_string_esc_default = "`|$<>&()#;\\\"!";
-//const char *lub_string_esc_regex = "^$.*+[](){}";
-//const char *lub_string_esc_quoted = "\\\"";
-
-
-/** @brief Free the memory allocated for the string.
- *
- * Safely free the memory allocated for the string. You can use NULL
- * pointer with this function. POSIX's free() checks for the NULL pointer
- * but not all systems do so.
- *
- * @param [in] str String to free
- */
-void faux_str_free(char *str) {
-
-	faux_free(str);
-}
-
-
-/** @brief Duplicates the string.
- *
- * Duplicates the string. Same as standard strdup() function. Allocates
- * memory with malloc(). Checks for NULL pointer.
- *
- * @warning Resulting string must be freed by faux_str_free().
- *
- * @param [in] str String to duplicate.
- * @return Pointer to allocated string or NULL.
- */
-char *faux_str_dup(const char *str) {
-
-	if (!str)
-		return NULL;
-	return strdup(str);
-}
-
-
-/** @brief Duplicates the first n bytes of the string.
- *
- * Duplicates at most n bytes of the string. Allocates
- * memory with malloc(). Checks for NULL pointer. Function will allocate
- * n + 1 bytes to store string and terminating null byte.
- *
- * @warning Resulting string must be freed by faux_str_free().
- *
- * @param [in] str String to duplicate.
- * @param [in] n Number of bytes to copy.
- * @return Pointer to allocated string or NULL.
- */
-char *faux_str_dupn(const char *str, size_t n) {
-
-	char *res = NULL;
-	size_t len = 0;
-
-	if (!str)
-		return NULL;
-	len = strlen(str);
-	len = (len < n) ? len : n;
-	res = faux_zmalloc(len + 1);
-	if (!res)
-		return NULL;
-	strncpy(res, str, len);
-	res[len] = '\0';
-
-	return res;
-}
-
-
-/** @brief Generates lowercase copy of input string.
- *
- * Allocates the copy of input string and convert that copy to lowercase.
- *
- * @warning Resulting string must be freed by faux_str_free().
- *
- * @param [in] str String to convert.
- * @return Pointer to lowercase string copy or NULL.
- */
-char *faux_str_tolower(const char *str) {
-
-	char *res = faux_str_dup(str);
-	char *p = res;
-
-	if (!res)
-		return NULL;
-
-	while (*p) {
-		*p = faux_ctype_tolower(*p);
-		p++;
-	}
-
-	return res;
-}
-
-
-/** @brief Generates uppercase copy of input string.
- *
- * Allocates the copy of input string and convert that copy to uppercase.
- *
- * @warning Resulting string must be freed by faux_str_free().
- *
- * @param [in] str String to convert.
- * @return Pointer to lowercase string copy or NULL.
- */
-char *faux_str_toupper(const char *str) {
-
-	char *res = faux_str_dup(str);
-	char *p = res;
-
-	if (!res)
-		return NULL;
-
-	while (*p) {
-		*p = faux_ctype_toupper(*p);
-		p++;
-	}
-
-	return res;
-}
-
-
-/** @brief Add n bytes of text to existent string.
- *
- * Concatenate two strings. Add n bytes of second string to the end of the
- * first one. The first argument is address of string pointer. The pointer
- * can be changed due to realloc() features. The first pointer can be NULL.
- * In this case the memory will be malloc()-ed and stored to the first pointer.
- *
- * @param [in,out] str Address of first string pointer.
- * @param [in] text Text to add to the first string.
- * @param [in] n Number of bytes to add.
- * @return Pointer to resulting string or NULL.
- */
-char *faux_str_catn(char **str, const char *text, size_t n) {
-
-	size_t str_len = 0;
-	size_t text_len = 0;
-	char *res = NULL;
-	char *p = NULL;
-
-	if (!text)
-		return *str;
-
-	str_len = (*str) ? strlen(*str) : 0;
-	text_len = strlen(text);
-	text_len = (text_len < n) ? text_len : n;
-
-	res = realloc(*str, str_len + text_len + 1);
-	if (!res)
-		return NULL;
-	p = res + str_len;
-	strncpy(p, text, text_len);
-	p[text_len] = '\0';
-	*str = res;
-
-	return res;
-}
-
-
-/** @brief Add some text to existent string.
- *
- * Concatenate two strings. Add second string to the end of the first one.
- * The first argument is address of string pointer. The pointer can be
- * changed due to realloc() features. The first pointer can be NULL. In this
- * case the memory will be malloc()-ed and stored to the first pointer.
- *
- * @param [in,out] str Address of first string pointer.
- * @param [in] text Text to add to the first string.
- * @return Pointer to resulting string or NULL.
- */
-char *faux_str_cat(char **str, const char *text) {
-
-	size_t len = 0;
-
-	if (!text)
-		return *str;
-	len = strlen(text);
-
-	return faux_str_catn(str, text, len);
-}
-
-/** @brief Add multiply text strings to existent string.
- *
- * Concatenate multiply strings. Add next string to the end of the previous one.
- * The first argument is address of string pointer. The pointer can be
- * changed due to realloc() features. The first pointer can be NULL. In this
- * case the memory will be malloc()-ed and stored to the first pointer.
- * The last argument must be 'NULL'. It marks the last argument within
- * variable arguments list.
- *
- * @warning If last argument is not 'NULL' then behaviour is undefined.
- *
- * @param [in,out] str Address of first string pointer.
- * @param [in] text Text to add to the first string.
- * @return Pointer to resulting string or NULL.
- */
-char *faux_str_vcat(char **str, ...) {
-
-	va_list ap;
-	const char *arg = NULL;
-	char *retval = *str;
-
-	va_start(ap, str);
-	while ((arg = va_arg(ap, const char *))) {
-		retval = faux_str_cat(str, arg);
-	}
-	va_end(ap);
-
-	return retval;
-}
-
-
-/** @brief Allocates memory and sprintf() to it.
- *
- * Function tries to find out necessary amount of memory for specified format
- * string and arguments. Format is same as for sprintf() function. Then
- * function allocates memory for resulting string and sprintf() to it. So
- * user doesn't need to allocate buffer himself. Function returns allocated
- * string that need to be freed by faux_str_free() function later.
- *
- * @warning The returned pointer must be free by faux_str_free().
- *
- * @param [in] fmt Format string like the sprintf()'s fmt.
- * @param [in] arg Number of arguments.
- * @return Allocated resulting string or NULL on error.
- */
-char *faux_str_sprintf(const char *fmt, ...) {
-
-	int size = 1;
-	char calc_buf[1] = "";
-	char *line = NULL;
-	va_list ap;
-
-	// Calculate buffer size
-	va_start(ap, fmt);
-	size = vsnprintf(calc_buf, size, fmt, ap);
-	va_end(ap);
-	// The snprintf() prior to 2.0.6 glibc version returns -1 if string
-	// was truncated. The later glibc returns required buffer size.
-	// The calc_buf can be NULL and size can be 0 for recent glibc but
-	// probably some exotic implementations can break on it. So use
-	// minimal buffer with length = 1.
-	if (size < 0)
-		return NULL;
-
-	size++; // Additional byte for '\0'
-	line = faux_zmalloc(size);
-	if (!line) // Memory problems
-		return NULL;
-
-	// Format real string
-	va_start(ap, fmt);
-	size = vsnprintf(line, size, fmt, ap);
-	va_end(ap);
-	if (size < 0) { // Some problems
-		faux_str_free(line);
-		return NULL;
-	}
-
-	return line;
-}
-
-
-/** @brief Service function to compare to chars in right way.
- *
- * The problem is char type can be signed or unsigned on different
- * platforms. So stright comparision can return different results.
- *
- * @param [in] char1 First char
- * @param [in] char2 Second char
- * @return
- * < 0 if char1 < char2
- * = 0 if char1 = char2
- * > 0 if char1 > char2
- */
-static int faux_str_cmp_chars(char char1, char char2) {
-
-	unsigned char ch1 = (unsigned char)char1;
-	unsigned char ch2 = (unsigned char)char2;
-
-	return (int)ch1 - (int)ch2;
-}
-
-
-/** @brief Compare n first characters of two strings ignoring case.
- *
- * The difference beetween this function an standard strncasecmp() is
- * faux function uses faux ctype functions. It can be important for
- * portability.
- *
- * @param [in] str1 First string to compare.
- * @param [in] str2 Second string to compare.
- * @param [in] n Number of characters to compare.
- * @return < 0, 0, > 0, see the strcasecmp().
- */
-int faux_str_casecmpn(const char *str1, const char *str2, size_t n) {
-
-	const char *p1 = str1;
-	const char *p2 = str2;
-	size_t num = n;
-
-	while (*p1 != '\0' && *p2 != '\0' && num != 0) {
-		int res = faux_str_cmp_chars(
-			faux_ctype_tolower(*p1), faux_ctype_tolower(*p2));
-		if (res != 0)
-			return res;
-		p1++;
-		p2++;
-		num--;
-	}
-
-	if (0 == n) // It means n first characters are equal.
-		return 0;
-
-	return faux_str_cmp_chars(
-		faux_ctype_tolower(*p1), faux_ctype_tolower(*p2));
-}
-
-
-/** @brief Compare two strings ignoring case.
- *
- * The difference beetween this function an standard strcasecmp() is
- * faux function uses faux ctype functions. It can be important for
- * portability.
- *
- * @param [in] str1 First string to compare.
- * @param [in] str2 Second string to compare.
- * @return < 0, 0, > 0, see the strcasecmp().
- */
-int faux_str_casecmp(const char *str1, const char *str2) {
-
-	const char *p1 = str1;
-	const char *p2 = str2;
-
-	while (*p1 != '\0' && *p2 != '\0') {
-		int res = faux_str_cmp_chars(
-			faux_ctype_tolower(*p1), faux_ctype_tolower(*p2));
-		if (res != 0)
-			return res;
-		p1++;
-		p2++;
-	}
-
-	return faux_str_cmp_chars(
-		faux_ctype_tolower(*p1), faux_ctype_tolower(*p2));
-}
-
-
-/** @brief Finds the first occurrence of the substring in the string
- *
- * Function is a faux version of strcasestr() function.
- *
- * @param [in] haystack String to find substring in it.
- * @param [in] needle Substring to find.
- * @return
- * Pointer to first occurence of substring in the string.
- * NULL on error
- */
-char *faux_str_casestr(const char *haystack, const char *needle) {
-
-	const char *ptr = haystack;
-	size_t ptr_len = 0;
-	size_t needle_len = 0;
-
-	assert(haystack);
-	assert(needle);
-	if (!haystack || !needle)
-		return NULL;
-
-	ptr_len = strlen(haystack);
-	needle_len = strlen(needle);
-
-	while ((*ptr != '\0') && (ptr_len >= needle_len)) {
-		int res = faux_str_casecmpn(ptr, needle, needle_len);
-		if (0 == res)
-			return (char *)ptr;
-		ptr++;
-		ptr_len--;
-	}
-
-	return NULL; // Not found
-}
-
-
-/** Prepare string for embedding to C-code (make escaping).
- *
- * @warning The returned pointer must be freed by faux_str_free().
- * @param [in] src String for escaping.
- * @return Escaped string or NULL on error.
- */
-char *faux_str_c_esc(const char *src) {
-
-	const char *src_ptr = src;
-	char *dst = NULL;
-	char *dst_ptr = NULL;
-	char *escaped = NULL;
-	size_t src_len = 0;
-	size_t dst_len = 0;
-
-	assert(src);
-	if (!src)
-		return NULL;
-
-	src_len = strlen(src);
-	// Calculate max destination string size.
-	// The worst case is when each src character will be replaced by
-	// something like '\xff'. So it's 4 dst chars for 1 src one.
-	dst_len = (src_len * 4) + 1; // one byte for '\0'
-	dst = faux_zmalloc(dst_len);
-	assert(dst);
-	if (!dst)
-		return NULL;
-	dst_ptr = dst;
-
-	while (*src_ptr != '\0') {
-		char *esc = NULL; // escaped replacement
-		char buf[5]; // longest 'char' (4 bytes) + '\0'
-		size_t len = 0;
-
-		switch (*src_ptr) {
-		case '\n':
-			esc = "\\n";
-			break;
-		case '\"':
-			esc = "\\\"";
-			break;
-		case '\\':
-			esc = "\\\\";
-			break;
-		case '\'':
-			esc = "\\\'";
-			break;
-		case '\r':
-			esc = "\\r";
-			break;
-		case '\t':
-			esc = "\\t";
-			break;
-		default:
-			// Check is the symbol control character. Control
-			// characters has codes from 0x00 to 0x1f.
-			if (((unsigned char)*src_ptr & 0xe0) == 0) { // control
-				snprintf(buf, sizeof(buf), "\\x%02x",
-					(unsigned char)*src_ptr);
-				buf[4] = '\0'; // for safety
-			} else {
-				buf[0] = *src_ptr; // Common character
-				buf[1] = '\0';
-			}
-			esc = buf;
-			break;
-		}
-
-		len = strlen(esc);
-		memcpy(dst_ptr, esc, len); // zmalloc() nullify the rest
-		dst_ptr += len;
-		src_ptr++;
-	}
-
-	escaped = faux_str_dup(dst); // Free some memory
-	faux_str_free(dst); // 'dst' size >= 'escaped' size
-
-	return escaped;
-}
-
-
-/** @brief Search the n-th chars of string for one of the specified chars.
- *
- * The function search for any of specified characters within string.
- * The search is limited to first n characters of the string. If
- * terminating '\0' is before n-th character then search will stop on
- * it. Can be used with raw memory block.
- *
- * @param [in] str String (or memory block) to search in.
- * @param [in] chars_to_string Chars enumeration to search for.
- * @param [in] n Maximum number of bytes to search within.
- * @return Pointer to the first occurence of one of specified chars.
- * NULL on error.
- */
-char *faux_str_charsn(const char *str, const char *chars_to_search, size_t n) {
-
-	const char *current_char = str;
-	size_t len = n;
-
-	assert(str);
-	assert(chars_to_search);
-	if (!str || !chars_to_search)
-		return NULL;
-
-	while ((*current_char != '\0') && (len > 0)) {
-		if (strchr(chars_to_search, *current_char))
-			return (char *)current_char;
-		current_char++;
-		len--;
-	}
-
-	return NULL;
-}
-
-
-/** @brief Search string for one of the specified chars.
- *
- * The function search for any of specified characters within string.
- *
- * @param [in] str String to search in.
- * @param [in] chars_to_string Chars enumeration to search for.
- * @return Pointer to the first occurence of one of specified chars.
- * NULL on error.
- */
-char *faux_str_chars(const char *str, const char *chars_to_search) {
-
-	assert(str);
-	if (!str)
-		return NULL;
-
-	return faux_str_charsn(str, chars_to_search, strlen(str));
-}
-
-/* TODO: If it nedeed?
-const char *faux_str_nextword(const char *string,
-	size_t *len, size_t *offset, size_t *quoted)
-{
-	const char *word;
-
-	*quoted = 0;
-
-	// Find the start of a word (not including an opening quote)
-	while (*string && isspace(*string)) {
-		string++;
-		(*offset)++;
-	}
-	// Is this the start of a quoted string ?
-	if (*string == '"') {
-		*quoted = 1;
-		string++;
-	}
-	word = string;
-	*len = 0;
-
-	// Find the end of the word
-	while (*string) {
-		if (*string == '\\') {
-			string++;
-			(*len)++;
-			if (*string) {
-				(*len)++;
-				string++;
-			}
-			continue;
-		}
-		// End of word
-		if (!*quoted && isspace(*string))
-			break;
-		if (*string == '"') {
-			// End of a quoted string
-			*quoted = 2;
-			break;
-		}
-		(*len)++;
-		string++;
-	}
-
-	return word;
-}
-*/
-
-// TODO: Is it needed?
-/*
-char *lub_string_ndecode(const char *string, unsigned int len)
-{
-	const char *s = string;
-	char *res, *p;
-	int esc = 0;
-
-	if (!string)
-		return NULL;
-
-	p = res = faux_zmalloc(len + 1);
-
-	while (*s && (s < (string +len))) {
-		if (!esc) {
-			if ('\\' == *s)
-				esc = 1;
-			else
-				*p = *s;
-		} else {
-//			switch (*s) {
-//			case 'r':
-//			case 'n':
-//				*p = '\n';
-//				break;
-//			case 't':
-//				*p = '\t';
-//				break;
-//			default:
-//				*p = *s;
-//				break;
-//			}
-//			*p = *s;
-			esc = 0;
-		}
-		if (!esc)
-			p++;
-		s++;
-	}
-	*p = '\0';
-
-	return res;
-}
-*/
-
-// TODO: Is it needed?
-/*
-inline char *lub_string_decode(const char *string)
-{
-	return lub_string_ndecode(string, strlen(string));
-}
-*/
-
-// TODO: Is it needed?
-/*----------------------------------------------------------- */
-/*
- * This needs to escape any dangerous characters within the command line
- * to prevent gaining access to the underlying system shell.
- */
-/*
-char *lub_string_encode(const char *string, const char *escape_chars)
-{
-	char *result = NULL;
-	const char *p;
-
-	if (!escape_chars)
-		return lub_string_dup(string);
-	if (string && !(*string)) // Empty string
-		return lub_string_dup(string);
-
-	for (p = string; p && *p; p++) {
-		// find any special characters and prefix them with '\'
-		size_t len = strcspn(p, escape_chars);
-		lub_string_catn(&result, p, len);
-		p += len;
-		if (*p) {
-			lub_string_catn(&result, "\\", 1);
-			lub_string_catn(&result, p, 1);
-		} else {
-			break;
-		}
-	}
-	return result;
-}
-*/
-
-
-// TODO: Is it needed?
-/*--------------------------------------------------------- */
-/*
-unsigned int lub_string_equal_part(const char *str1, const char *str2,
-	bool_t utf8)
-{
-	unsigned int cnt = 0;
-
-	if (!str1 || !str2)
-		return cnt;
-	while (*str1 && *str2) {
-		if (*str1 != *str2)
-			break;
-		cnt++;
-		str1++;
-		str2++;
-	}
-	if (!utf8)
-		return cnt;
-
-	// UTF8 features
-	if (cnt && (UTF8_11 == (*(str1 - 1) & UTF8_MASK)))
-		cnt--;
-
-	return cnt;
-}
-*/
-
-// TODO: Is it needed?
-
-/*--------------------------------------------------------- */
-/*
-const char *lub_string_suffix(const char *string)
-{
-	const char *p1, *p2;
-	p1 = p2 = string;
-	while (*p1) {
-		if (faux_ctype_isspace(*p1)) {
-			p2 = p1;
-			p2++;
-		}
-		p1++;
-	}
-	return p2;
-}
-*/
-
-
-// TODO: Is it needed?
-/*--------------------------------------------------------- */
-/*
-unsigned int lub_string_wordcount(const char *line)
-{
-	const char *word;
-	unsigned int result = 0;
-	size_t len = 0, offset = 0;
-	size_t quoted;
-
-	for (word = lub_string_nextword(line, &len, &offset, &quoted);
-		*word || quoted;
-		word = lub_string_nextword(word + len, &len, &offset, &quoted)) {
-		// account for the terminating quotation mark
-		len += quoted ? quoted - 1 : 0;
-		result++;
-	}
-
-	return result;
-}
-*/

+ 0 - 37
faux/sysdb.h

@@ -1,37 +0,0 @@
-/** @file sysdb.h
- * @brief Public interface for faux system database (passwd, group etc) functions.
- */
-
-#ifndef _faux_sysdb_h
-#define _faux_sysdb_h
-
-#include <stddef.h>
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#ifdef HAVE_PWD_H
-#include <pwd.h>
-#endif
-#ifdef HAVE_GRP_H
-#include <grp.h>
-#endif
-
-#include "faux/faux.h"
-
-C_DECL_BEGIN
-
-// Wrappers for ugly getpwnam_r()-like functions
-#ifdef HAVE_PWD_H
-struct passwd *faux_sysdb_getpwnam(const char *name);
-struct passwd *faux_sysdb_getpwuid(uid_t uid);
-#endif
-#ifdef HAVE_GRP_H
-struct group *faux_sysdb_getgrnam(const char *name);
-struct group *faux_sysdb_getgrgid(gid_t gid);
-#endif
-
-C_DECL_END
-
-#endif

+ 0 - 2
faux/sysdb/Makefile.am

@@ -1,2 +0,0 @@
-libfaux_la_SOURCES += \
-	faux/sysdb/sysdb.c

+ 0 - 180
faux/sysdb/sysdb.c

@@ -1,180 +0,0 @@
-/** @file sysdb.c
- * @brief Wrappers for system database functions like getpwnam(), getgrnam().
- */
-
-// It must be here to include config.h before another headers
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <pwd.h>
-#include <grp.h>
-#include <unistd.h>
-
-#include "faux/faux.h"
-#include "faux/sysdb.h"
-
-#define DEFAULT_GETPW_R_SIZE_MAX 1024
-
-/** @brief Wrapper for ugly getpwnam_r() function.
- *
- * Gets passwd structure by user name. Easy to use.
- *
- * @param [in] name User name.
- * @return Pointer to allocated passwd structure.
- * @warning The resulting pointer (return value) must be freed by faux_free().
- */
-struct passwd *faux_sysdb_getpwnam(const char *name) {
-
-	long int size = 0;
-	char *buf = NULL;
-	struct passwd *pwbuf = NULL;
-	struct passwd *pw = NULL;
-	int res = 0;
-
-#ifdef _SC_GETPW_R_SIZE_MAX
-	if ((size = sysconf(_SC_GETPW_R_SIZE_MAX)) < 0)
-		size = DEFAULT_GETPW_R_SIZE_MAX;
-#else
-	size = DEFAULT_GETPW_R_SIZE_MAX;
-#endif
-	pwbuf = faux_zmalloc(sizeof(*pwbuf) + size);
-	if (!pwbuf)
-		return NULL;
-	buf = (char *)pwbuf + sizeof(*pwbuf);
-
-	res = getpwnam_r(name, pwbuf, buf, size, &pw);
-	if ((res != 0) || !pw) {
-		faux_free(pwbuf);
-		if (res != 0)
-			errno = res;
-		else
-			errno = ENOENT;
-		return NULL;
-	}
-
-	return pwbuf;
-}
-
-/** @brief Wrapper for ugly getpwuid_r() function.
- *
- * Gets passwd structure by UID. Easy to use.
- *
- * @param [in] uid UID.
- * @return Pointer to allocated passwd structure.
- * @warning The resulting pointer (return value) must be freed by faux_free().
- */
-struct passwd *faux_sysdb_getpwuid(uid_t uid) {
-
-	long int size = 0;
-	char *buf = NULL;
-	struct passwd *pwbuf = NULL;
-	struct passwd *pw = NULL;
-	int res = 0;
-
-#ifdef _SC_GETPW_R_SIZE_MAX
-	if ((size = sysconf(_SC_GETPW_R_SIZE_MAX)) < 0)
-		size = DEFAULT_GETPW_R_SIZE_MAX;
-#else
-	size = DEFAULT_GETPW_R_SIZE_MAX;
-#endif
-	pwbuf = faux_zmalloc(sizeof(*pwbuf) + size);
-	if (!pwbuf)
-		return NULL;
-	buf = (char *)pwbuf + sizeof(*pwbuf);
-
-	res = getpwuid_r(uid, pwbuf, buf, size, &pw);
-	if (!pw) {
-		faux_free(pwbuf);
-		if (res != 0)
-			errno = res;
-		else
-			errno = ENOENT;
-		return NULL;
-	}
-
-	return pwbuf;
-}
-
-/** @brief Wrapper for ugly getgrnam_r() function.
- *
- * Gets group structure by group name. Easy to use.
- *
- * @param [in] name Group name.
- * @return Pointer to allocated group structure.
- * @warning The resulting pointer (return value) must be freed by faux_free().
- */
-struct group *faux_sysdb_getgrnam(const char *name) {
-
-	long int size;
-	char *buf;
-	struct group *grbuf;
-	struct group *gr = NULL;
-	int res = 0;
-
-#ifdef _SC_GETGR_R_SIZE_MAX
-	if ((size = sysconf(_SC_GETGR_R_SIZE_MAX)) < 0)
-		size = DEFAULT_GETPW_R_SIZE_MAX;
-#else
-	size = DEFAULT_GETPW_R_SIZE_MAX;
-#endif
-	grbuf = faux_zmalloc(sizeof(*grbuf) + size);
-	if (!grbuf)
-		return NULL;
-	buf = (char *)grbuf + sizeof(*grbuf);
-
-	res = getgrnam_r(name, grbuf, buf, size, &gr);
-	if (!gr) {
-		faux_free(grbuf);
-		if (res != 0)
-			errno = res;
-		else
-			errno = ENOENT;
-		return NULL;
-	}
-
-	return grbuf;
-}
-
-/** @brief Wrapper for ugly getgrgid_r() function.
- *
- * Gets group structure by GID. Easy to use.
- *
- * @param [in] gid GID.
- * @return Pointer to allocated group structure.
- * @warning The resulting pointer (return value) must be freed by faux_free().
- */
-struct group *faux_sysdb_getgrgid(gid_t gid) {
-
-	long int size;
-	char *buf;
-	struct group *grbuf;
-	struct group *gr = NULL;
-	int res = 0;
-
-#ifdef _SC_GETGR_R_SIZE_MAX
-	if ((size = sysconf(_SC_GETGR_R_SIZE_MAX)) < 0)
-		size = DEFAULT_GETPW_R_SIZE_MAX;
-#else
-	size = DEFAULT_GETPW_R_SIZE_MAX;
-#endif
-	grbuf = faux_zmalloc(sizeof(struct group) + size);
-	if (!grbuf)
-		return NULL;
-	buf = (char *)grbuf + sizeof(struct group);
-
-	res = getgrgid_r(gid, grbuf, buf, size, &gr);
-	if (!gr) {
-		faux_free(grbuf);
-		if (res != 0)
-			errno = res;
-		else
-			errno = ENOENT;
-		return NULL;
-	}
-
-	return grbuf;
-}

+ 0 - 20
faux/system.h

@@ -1,20 +0,0 @@
-/*
- * system.h
- *
- */
-#ifndef _lub_system_h
-#define _lub_system_h
-
-#include <stddef.h>
-
-#include "lub/c_decl.h"
-#include "lub/types.h"
-#include "lub/argv.h"
-
-_BEGIN_C_DECL bool_t lub_system_test(int argc, char **argv);
-bool_t lub_system_argv_test(const lub_argv_t * argv);
-bool_t lub_system_line_test(const char *line);
-char *lub_system_tilde_expand(const char *path);
-
-_END_C_DECL
-#endif				/* _lub_system_h */

+ 0 - 5
faux/system/module.am

@@ -1,5 +0,0 @@
-liblub_la_SOURCES +=	lub/system/test.c \
-			lub/system/system_test.c \
-			lub/system/system_file.c \
-			lub/system/private.h
-

+ 0 - 8
faux/system/private.h

@@ -1,8 +0,0 @@
-/*
- * private.h
- */
-#include "lub/types.h"
-#include "lub/argv.h"
-#include "lub/system.h"
-
-int testcmd(int argc, char *argv[]);

+ 0 - 29
faux/system/system_file.c

@@ -1,29 +0,0 @@
-/*
- * system_file.c
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "private.h"
-#include "lub/string.h"
-
-/*-------------------------------------------------------- */
-/* perform a simple tilde substitution for the home directory
- * defined in HOME
- */
-char *lub_system_tilde_expand(const char *path)
-{
-	char *home_dir = getenv("HOME");
-	char *result = NULL;
-	char *tilde;
-
-	while ((tilde = strchr(path, '~'))) {
-		lub_string_catn(&result, path, tilde - path);
-		lub_string_cat(&result, home_dir);
-		path = tilde + 1;
-	}
-	lub_string_cat(&result, path);
-
-	return result;
-}

+ 0 - 46
faux/system/system_test.c

@@ -1,46 +0,0 @@
-/*
- * system_test.c
- */
-
-#include <stdlib.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-bool_t lub_system_test(int argc, char **argv)
-{
-	return testcmd(argc, argv) ? BOOL_FALSE : BOOL_TRUE;
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_system_line_test(const char *line)
-{
-	bool_t res;
-	lub_argv_t *argv;
-
-	argv = lub_argv_new(line, 0);
-	res = lub_system_argv_test(argv);
-	lub_argv_delete(argv);
-
-	return res;
-}
-
-/*--------------------------------------------------------- */
-bool_t lub_system_argv_test(const lub_argv_t * argv)
-{
-	bool_t res;
-	char **str_argv;
-	int str_argc;
-
-	/* Make args */
-	str_argv = lub_argv__get_argv(argv, "");
-	str_argc = lub_argv__get_count(argv) + 1;
-
-	/* Test it */
-	res = lub_system_test(str_argc, str_argv);
-	lub_argv__free_argv(str_argv);
-
-	return res;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 486
faux/system/test.c

@@ -1,486 +0,0 @@
-/*	$OpenBSD: test.c,v 1.11 2009/10/27 23:59:22 deraadt Exp $	*/
-/*	$NetBSD: test.c,v 1.15 1995/03/21 07:04:06 cgd Exp $	*/
-
-/*
- * test(1); version 7-like  --  author Erik Baalbergen
- * modified by Eric Gisin to be used as built-in.
- * modified by Arnold Robbins to add SVR3 compatibility
- * (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
- * modified by J.T. Conklin for NetBSD.
- *
- * This program is in the Public Domain.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <err.h>
-
-#ifndef __dead
-#define __dead __attribute__((noreturn))
-#endif
-
-#define main testcmd
-
-/* test(1) accepts the following grammar:
-	oexpr	::= aexpr | aexpr "-o" oexpr ;
-	aexpr	::= nexpr | nexpr "-a" aexpr ;
-	nexpr	::= primary | "!" primary
-	primary	::= unary-operator operand
-		| operand binary-operator operand
-		| operand
-		| "(" oexpr ")"
-		;
-	unary-operator ::= "-r"|"-w"|"-x"|"-f"|"-d"|"-c"|"-b"|"-p"|
-		"-u"|"-g"|"-k"|"-s"|"-t"|"-z"|"-n"|"-o"|"-O"|"-G"|"-L"|"-S";
-
-	binary-operator ::= "="|"!="|"-eq"|"-ne"|"-ge"|"-gt"|"-le"|"-lt"|
-			"-nt"|"-ot"|"-ef";
-	operand ::= <any legal UNIX file name>
-*/
-
-enum token {
-	EOI,
-	FILRD,
-	FILWR,
-	FILEX,
-	FILEXIST,
-	FILREG,
-	FILDIR,
-	FILCDEV,
-	FILBDEV,
-	FILFIFO,
-	FILSOCK,
-	FILSYM,
-	FILGZ,
-	FILTT,
-	FILSUID,
-	FILSGID,
-	FILSTCK,
-	FILNT,
-	FILOT,
-	FILEQ,
-	FILUID,
-	FILGID,
-	STREZ,
-	STRNZ,
-	STREQ,
-	STRNE,
-	STRLT,
-	STRGT,
-	INTEQ,
-	INTNE,
-	INTGE,
-	INTGT,
-	INTLE,
-	INTLT,
-	UNOT,
-	BAND,
-	BOR,
-	LPAREN,
-	RPAREN,
-	OPERAND
-};
-
-enum token_types {
-	UNOP,
-	BINOP,
-	BUNOP,
-	BBINOP,
-	PAREN
-};
-
-struct t_op {
-	const char *op_text;
-	short op_num, op_type;
-} const ops[] = {
-	{"-r", FILRD, UNOP},
-	{"-w", FILWR, UNOP},
-	{"-x", FILEX, UNOP},
-	{"-e", FILEXIST, UNOP},
-	{"-f", FILREG, UNOP},
-	{"-d", FILDIR, UNOP},
-	{"-c", FILCDEV, UNOP},
-	{"-b", FILBDEV, UNOP},
-	{"-p", FILFIFO, UNOP},
-	{"-u", FILSUID, UNOP},
-	{"-g", FILSGID, UNOP},
-	{"-k", FILSTCK, UNOP},
-	{"-s", FILGZ, UNOP},
-	{"-t", FILTT, UNOP},
-	{"-z", STREZ, UNOP},
-	{"-n", STRNZ, UNOP},
-	{"-h", FILSYM, UNOP},	/* for backwards compat */
-	{"-O", FILUID, UNOP},
-	{"-G", FILGID, UNOP},
-	{"-L", FILSYM, UNOP},
-	{"-S", FILSOCK, UNOP},
-	{"=", STREQ, BINOP},
-	{"!=", STRNE, BINOP},
-	{"<", STRLT, BINOP},
-	{">", STRGT, BINOP},
-	{"-eq", INTEQ, BINOP},
-	{"-ne", INTNE, BINOP},
-	{"-ge", INTGE, BINOP},
-	{"-gt", INTGT, BINOP},
-	{"-le", INTLE, BINOP},
-	{"-lt", INTLT, BINOP},
-	{"-nt", FILNT, BINOP},
-	{"-ot", FILOT, BINOP},
-	{"-ef", FILEQ, BINOP},
-	{"!", UNOT, BUNOP},
-	{"-a", BAND, BBINOP},
-	{"-o", BOR, BBINOP},
-	{"(", LPAREN, PAREN},
-	{")", RPAREN, PAREN},
-	{0, 0, 0}
-};
-
-char **t_wp;
-struct t_op const *t_wp_op;
-
-static enum token t_lex(char *);
-static enum token_types t_lex_type(char *);
-static int oexpr(enum token n);
-static int aexpr(enum token n);
-static int nexpr(enum token n);
-static int binop(void);
-static int primary(enum token n);
-static int filstat(char *nm, enum token mode);
-static int getn(const char *s);
-static int newerf(const char *, const char *);
-static int olderf(const char *, const char *);
-static int equalf(const char *, const char *);
-
-#define syntax(op,msg) {return 2;}
-
-int main(int argc, char *argv[])
-{
-	int res;
-
-	if (strcmp(argv[0], "[") == 0) {
-		if (strcmp(argv[--argc], "]"))
-			syntax(NULL, "missing ]");
-		argv[argc] = NULL;
-	}
-
-	/* Implement special cases from POSIX.2, section 4.62.4 */
-	switch (argc) {
-	case 1:
-		return 1;
-	case 2:
-		return (*argv[1] == '\0');
-	case 3:
-		if (argv[1][0] == '!' && argv[1][1] == '\0') {
-			return !(*argv[2] == '\0');
-		}
-		break;
-	case 4:
-		if (argv[1][0] != '!' || argv[1][1] != '\0') {
-			if (t_lex(argv[2]),
-			    t_wp_op && t_wp_op->op_type == BINOP) {
-				t_wp = &argv[1];
-				return (binop() == 0);
-			}
-		}
-		break;
-	case 5:
-		if (argv[1][0] == '!' && argv[1][1] == '\0') {
-			if (t_lex(argv[3]),
-			    t_wp_op && t_wp_op->op_type == BINOP) {
-				t_wp = &argv[2];
-				return !(binop() == 0);
-			}
-		}
-		break;
-	}
-
-	t_wp = &argv[1];
-	res = !oexpr(t_lex(*t_wp));
-
-	if (*t_wp != NULL && *++t_wp != NULL)
-		syntax(*t_wp, "unknown operand");
-
-	return res;
-}
-
-static int oexpr(enum token n)
-{
-	int res;
-
-	res = aexpr(n);
-	if (t_lex(*++t_wp) == BOR)
-		return oexpr(t_lex(*++t_wp)) || res;
-	t_wp--;
-	return res;
-}
-
-static int aexpr(enum token n)
-{
-	int res;
-
-	res = nexpr(n);
-	if (t_lex(*++t_wp) == BAND)
-		return aexpr(t_lex(*++t_wp)) && res;
-	t_wp--;
-	return res;
-}
-
-static int nexpr(enum token n)
-{
-	if (n == UNOT)
-		return !nexpr(t_lex(*++t_wp));
-	return primary(n);
-}
-
-static int primary(enum token n)
-{
-	int res;
-
-	if (n == EOI)
-		syntax(NULL, "argument expected");
-	if (n == LPAREN) {
-		res = oexpr(t_lex(*++t_wp));
-		if (t_lex(*++t_wp) != RPAREN)
-			syntax(NULL, "closing paren expected");
-		return res;
-	}
-	/*
-	 * We need this, if not binary operations with more than 4
-	 * arguments will always fall into unary.
-	 */
-	if (t_lex_type(t_wp[1]) == BINOP) {
-		t_lex(t_wp[1]);
-		if (t_wp_op && t_wp_op->op_type == BINOP)
-			return binop();
-	}
-
-	if (t_wp_op && t_wp_op->op_type == UNOP) {
-		/* unary expression */
-		if (*++t_wp == NULL)
-			syntax(t_wp_op->op_text, "argument expected");
-		switch (n) {
-		case STREZ:
-			return strlen(*t_wp) == 0;
-		case STRNZ:
-			return strlen(*t_wp) != 0;
-		case FILTT:
-			return isatty(getn(*t_wp));
-		default:
-			return filstat(*t_wp, n);
-		}
-	}
-
-	return strlen(*t_wp) > 0;
-}
-
-static int binop(void)
-{
-	const char *opnd1, *opnd2;
-	struct t_op const *op;
-
-	opnd1 = *t_wp;
-	(void)t_lex(*++t_wp);
-	op = t_wp_op;
-
-	if (!op)
-		return 1;
-
-	if ((opnd2 = *++t_wp) == NULL)
-		syntax(op->op_text, "argument expected");
-
-	switch (op->op_num) {
-	case STREQ:
-		return strcmp(opnd1, opnd2) == 0;
-	case STRNE:
-		return strcmp(opnd1, opnd2) != 0;
-	case STRLT:
-		return strcmp(opnd1, opnd2) < 0;
-	case STRGT:
-		return strcmp(opnd1, opnd2) > 0;
-	case INTEQ:
-		return getn(opnd1) == getn(opnd2);
-	case INTNE:
-		return getn(opnd1) != getn(opnd2);
-	case INTGE:
-		return getn(opnd1) >= getn(opnd2);
-	case INTGT:
-		return getn(opnd1) > getn(opnd2);
-	case INTLE:
-		return getn(opnd1) <= getn(opnd2);
-	case INTLT:
-		return getn(opnd1) < getn(opnd2);
-	case FILNT:
-		return newerf(opnd1, opnd2);
-	case FILOT:
-		return olderf(opnd1, opnd2);
-	case FILEQ:
-		return equalf(opnd1, opnd2);
-	}
-	/* NOTREACHED */
-	return 1;		/* to make compiler happy */
-}
-
-static enum token_types t_lex_type(char *s)
-{
-	struct t_op const *op = ops;
-
-	if (s == NULL)
-		return -1;
-
-	while (op->op_text) {
-		if (strcmp(s, op->op_text) == 0)
-			return op->op_type;
-		op++;
-	}
-	return -1;
-}
-
-static int filstat(char *nm, enum token mode)
-{
-	struct stat s;
-	mode_t i;
-
-	if (mode == FILSYM) {
-#ifdef S_IFLNK
-		if (lstat(nm, &s) == 0) {
-			i = S_IFLNK;
-			goto filetype;
-		}
-#endif
-		return 0;
-	}
-
-	if (stat(nm, &s) != 0)
-		return 0;
-
-	switch (mode) {
-	case FILRD:
-		return access(nm, R_OK) == 0;
-	case FILWR:
-		return access(nm, W_OK) == 0;
-	case FILEX:
-		return access(nm, X_OK) == 0;
-	case FILEXIST:
-		return access(nm, F_OK) == 0;
-	case FILREG:
-		i = S_IFREG;
-		goto filetype;
-	case FILDIR:
-		i = S_IFDIR;
-		goto filetype;
-	case FILCDEV:
-		i = S_IFCHR;
-		goto filetype;
-	case FILBDEV:
-		i = S_IFBLK;
-		goto filetype;
-	case FILFIFO:
-#ifdef S_IFIFO
-		i = S_IFIFO;
-		goto filetype;
-#else
-		return 0;
-#endif
-	case FILSOCK:
-#ifdef S_IFSOCK
-		i = S_IFSOCK;
-		goto filetype;
-#else
-		return 0;
-#endif
-	case FILSUID:
-		i = S_ISUID;
-		goto filebit;
-	case FILSGID:
-		i = S_ISGID;
-		goto filebit;
-	case FILSTCK:
-		i = S_ISVTX;
-		goto filebit;
-	case FILGZ:
-		return s.st_size > 0L;
-	case FILUID:
-		return s.st_uid == geteuid();
-	case FILGID:
-		return s.st_gid == getegid();
-	default:
-		return 1;
-	}
-
- filetype:
-	return ((s.st_mode & S_IFMT) == i);
-
- filebit:
-	return ((s.st_mode & i) != 0);
-}
-
-static enum token t_lex(char *s)
-{
-	struct t_op const *op = ops;
-
-	if (s == 0) {
-		t_wp_op = NULL;
-		return EOI;
-	}
-	while (op->op_text) {
-		if (strcmp(s, op->op_text) == 0) {
-			t_wp_op = op;
-			return op->op_num;
-		}
-		op++;
-	}
-	t_wp_op = NULL;
-	return OPERAND;
-}
-
-/* atoi with error detection */
-static int getn(const char *s)
-{
-	char *p;
-	long r;
-
-	errno = 0;
-	r = strtol(s, &p, 10);
-
-	if (errno != 0)
-		syntax(NULL, "out of range");
-
-	while (isspace(*p))
-		p++;
-
-	if (*p)
-		syntax(NULL, "bad number");
-
-	return (int)r;
-}
-
-static int newerf(const char *f1, const char *f2)
-{
-	struct stat b1, b2;
-
-	return (stat(f1, &b1) == 0 &&
-		stat(f2, &b2) == 0 && b1.st_mtime > b2.st_mtime);
-}
-
-static int olderf(const char *f1, const char *f2)
-{
-	struct stat b1, b2;
-
-	return (stat(f1, &b1) == 0 &&
-		stat(f2, &b2) == 0 && b1.st_mtime < b2.st_mtime);
-}
-
-static int equalf(const char *f1, const char *f2)
-{
-	struct stat b1, b2;
-
-	return (stat(f1, &b1) == 0 &&
-		stat(f2, &b2) == 0 &&
-		b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino);
-}

+ 0 - 3
faux/testc_module/Makefile.am

@@ -1,3 +0,0 @@
-libfaux_la_SOURCES += \
-	faux/testc_module/testc_module.c
-

+ 0 - 11
faux/testc_module/testc_module.c

@@ -1,11 +0,0 @@
-#include "faux/ini.h"
-
-const unsigned char testc_version_major = 1;
-const unsigned char testc_version_minor = 0;
-
-const char *testc_module[][2] = {
-	{"testc_faux_ini_good", "INI subsystem good"},
-	{"testc_faux_ini_bad", "INI bad"},
-	{"testc_faux_ini_signal", "Interrupted by signal"},
-	{NULL, NULL}
-	};

+ 0 - 9
testc/Makefile.am

@@ -1,9 +0,0 @@
-## Process this file with automake to produce Makefile.in
-bin_PROGRAMS += \
-	testc/testc
-
-testc_testc_SOURCES = \
-	testc/testc.c
-
-testc_testc_LDADD = \
-	libfaux.la

+ 0 - 361
testc/testc.c

@@ -1,361 +0,0 @@
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-#include <unistd.h>
-#include <dlfcn.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#if WITH_INTERNAL_GETOPT
-#include "libc/getopt.h"
-#else
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#endif
-#endif
-
-#if HAVE_LOCALE_H
-#include <locale.h>
-#endif
-#if HAVE_LANGINFO_CODESET
-#include <langinfo.h>
-#endif
-
-#include "faux/faux.h"
-#include "faux/str.h"
-#include "faux/list.h"
-
-#ifndef VERSION
-#define VERSION 1.0.0
-#endif
-#define QUOTE(t) #t
-#define version(v) printf("%s\n", v)
-
-// Version of testc API (not version of programm)
-#define TESTC_VERSION_MAJOR_DEFAULT 1
-#define TESTC_VERSION_MINOR_DEFAULT 0
-#define SYM_TESTC_VERSION_MAJOR "testc_version_major"
-#define SYM_TESTC_VERSION_MINOR "testc_version_minor"
-#define SYM_TESTC_MODULE "testc_module"
-
-
-// Command line options */
-struct opts_s {
-	int debug;
-	faux_list_t *so_list;
-};
-
-typedef struct opts_s opts_t;
-
-static opts_t *opts_parse(int argc, char *argv[]);
-static void opts_free(opts_t *opts);
-static void help(int status, const char *argv0);
-static int exec_test(int (*test_sym)(void));
-
-
-int main(int argc, char *argv[]) {
-
-	opts_t *opts = NULL;
-	faux_list_node_t *iter = NULL;
-	char *so = NULL;
-	// Return value will be negative on any error or failed test.
-	// It doesn't mean that any error will break the processing.
-	// The following var is error counter.
-	unsigned int total_errors = 0;
-	unsigned int total_modules = 0;
-	unsigned int total_tests = 0;
-
-#if HAVE_LOCALE_H
-	// Set current locale
-	setlocale(LC_ALL, "");
-#endif
-
-	// Parse command line options
-	opts = opts_parse(argc, argv);
-	if (!opts) {
-		fprintf(stderr, "Error: Can't parse command line options\n");
-		return -1;
-	}
-
-	iter = faux_list_head(opts->so_list);
-	while ((so = faux_list_each(&iter))) {
-		void *so_handle = NULL;
-		// Module symbols
-		unsigned char testc_version_major = TESTC_VERSION_MAJOR_DEFAULT;
-		unsigned char testc_version_minor = TESTC_VERSION_MINOR_DEFAULT;
-		unsigned char *testc_version = NULL;
-		const char *(*testc_module)[2] = NULL;
-		// Module counters
-		unsigned int module_tests = 0;
-		unsigned int module_errors = 0;
-
-		printf("--------------------------------------------------------------------------------\n");
-
-		if (access(so, R_OK) < 0) {
-			fprintf(stderr, "Error: Can't read module \"%s\"... Skipped\n", so);
-			total_errors++;
-			continue;
-		}
-
-		so_handle = dlopen(so, RTLD_LAZY | RTLD_LOCAL);
-		if (!so_handle) {
-			fprintf(stderr, "Error: Can't open module \"%s\"... Skipped\n", so);
-			total_errors++;
-			continue;
-		}
-
-		// Get testc API version from module
-		testc_version = dlsym(so_handle, SYM_TESTC_VERSION_MAJOR);
-		if (!testc_version) {
-			fprintf(stderr, "Warning: Can't get API version for module \"%s\"... Use defaults\n", so);
-		} else {
-			testc_version_major = *testc_version;
-			testc_version = dlsym(so_handle, SYM_TESTC_VERSION_MINOR);
-			if (!testc_version) {
-				fprintf(stderr, "Warning: Can't get API minor version for module \"%s\"... Use '0'\n", so);
-				testc_version_minor = 0;
-			} else {
-				testc_version_minor = *testc_version;
-			}
-		}
-		if ((testc_version_major > TESTC_VERSION_MAJOR_DEFAULT) ||
-			((testc_version_major == TESTC_VERSION_MAJOR_DEFAULT) &&
-			(testc_version_minor >TESTC_VERSION_MINOR_DEFAULT))) {
-			fprintf(stderr, "Error: Unsupported API v%u.%u for module \"%s\"... Skipped\n", 
-				testc_version_major, testc_version_minor, so);
-			continue;
-		}
-
-		testc_module = dlsym(so_handle, SYM_TESTC_MODULE);
-		if (!testc_module) {
-			fprintf(stderr, "Error: Can't get test list for module \"%s\"... Skipped\n", so);
-			total_errors++;
-			continue;
-		}
-
-		total_modules++;
-		printf("Processing module \"%s\" v%u.%u ...\n", so,
-			testc_version_major, testc_version_minor);
-
-		while ((*testc_module)[0]) {
-			const char *test_name = NULL;
-			const char *test_desc = NULL;
-			int (*test_sym)(void);
-			int wstatus = 0;
-			char *result_str = NULL;
-			char *attention_str = NULL;
-
-			test_name = (*testc_module)[0];
-			test_desc = (*testc_module)[1];
-			if (!test_desc)
-				test_desc = "";
-			testc_module++;
-			module_tests++;
-
-			test_sym = (int (*)(void))dlsym(so_handle, test_name);
-			if (!test_sym) {
-				fprintf(stderr, "Error: Can't find symbol \"%s\"... Skipped\n", test_name);
-				module_errors++;
-				continue;
-			}
-
-			wstatus = exec_test(test_sym);
-
-			if (WIFEXITED(wstatus)) {
-				if (WEXITSTATUS(wstatus) == 0) {
-					result_str = faux_str_dup("success");
-					attention_str = faux_str_dup("");
-				} else {
-					result_str = faux_str_sprintf("failed (%d)",
-						(int)((signed char)((unsigned char)WEXITSTATUS(wstatus))));
-					attention_str = faux_str_dup("(!) ");
-					module_errors++;
-				}
-			} else if (WIFSIGNALED(wstatus)) {
-				result_str = faux_str_sprintf("terminated (%d)",
-					WTERMSIG(wstatus));
-				attention_str = faux_str_dup("[!] ");
-				module_errors++;
-			} else {
-				result_str = faux_str_dup("unknown");
-				attention_str = faux_str_dup("[!] ");
-				module_errors++;
-			}
-
-			printf("%sTest #%03u %s() %s: %s\n", attention_str, module_tests, test_name, test_desc, result_str);
-			faux_str_free(result_str);
-			faux_str_free(attention_str);
-		}
-
-
-		dlclose(so_handle);
-		so_handle = NULL;
-
-		printf("Module tests: %u\n", module_tests);
-		printf("Module errors: %u\n", module_errors);
-
-		total_tests += module_tests;
-		total_errors += module_errors;
-
-	}
-
-	opts_free(opts);
-
-	// Total statistics
-	printf("================================================================================\n");
-	printf("Total modules: %u\n", total_modules);
-	printf("Total tests: %u\n", total_tests);
-	printf("Total errors: %u\n", total_errors);
-
-	if (total_errors > 0)
-		return -1;
-	return 0;
-}
-
-
-static int exec_test(int (*test_sym)(void)) {
-
-	pid_t pid = -1;
-	int wstatus = -1;
-
-	pid = fork();
-	assert(pid != -1);
-	if (pid == -1)
-		return -1;
-
-	// Child
-	if (pid == 0)
-		_exit(test_sym());
-
-	// Parent
-	while (waitpid(pid, &wstatus, 0) != pid);
-
-	return wstatus;
-}
-
-
-static void opts_free(opts_t *opts) {
-
-	assert(opts);
-	if (!opts)
-		return;
-
-	faux_list_free(opts->so_list);
-	faux_free(opts);
-}
-
-
-static opts_t *opts_new(void) {
-
-	opts_t *opts = NULL;
-
-	opts = faux_zmalloc(sizeof(*opts));
-	assert(opts);
-	if (!opts)
-		return NULL;
-
-	opts->debug = BOOL_FALSE;
-
-	// Members of list are static strings from argv so don't free() it
-	opts->so_list = faux_list_new(BOOL_FALSE, BOOL_TRUE,
-		(faux_list_cmp_fn)strcmp, NULL, NULL);
-	if (!opts->so_list) {
-		opts_free(opts);
-		return NULL;
-	}
-
-	return opts;
-}
-
-
-static opts_t *opts_parse(int argc, char *argv[]) {
-
-	opts_t *opts = NULL;
-
-	static const char *shortopts = "hvd";
-#ifdef HAVE_GETOPT_LONG
-	static const struct option longopts[] = {
-		{"help",	0, NULL, 'h'},
-		{"version",	0, NULL, 'v'},
-		{"debug",	0, NULL, 'd'},
-		{NULL,		0, NULL, 0}
-	};
-#endif
-
-	opts = opts_new();
-	if (!opts)
-		return NULL;
-
-	optind = 1;
-	while (1) {
-		int opt;
-#ifdef HAVE_GETOPT_LONG
-		opt = getopt_long(argc, argv, shortopts, longopts, NULL);
-#else
-		opt = getopt(argc, argv, shortopts);
-#endif
-		if (-1 == opt)
-			break;
-		switch (opt) {
-		case 'd':
-			opts->debug = BOOL_TRUE;
-			break;
-		case 'h':
-			help(0, argv[0]);
-			exit(0);
-			break;
-		case 'v':
-			version(VERSION);
-			exit(0);
-			break;
-		default:
-			help(-1, argv[0]);
-			exit(-1);
-			break;
-		}
-	}
-
-	if (optind < argc) {
-		int i = 0;
-		for (i = optind; i < argc; i++)
-			faux_list_add(opts->so_list, argv[i]);
-	} else {
-		help(-1, argv[0]);
-		exit(-1);
-	}
-
-	return opts;
-}
-
-
-static void help(int status, const char *argv0) {
-
-	const char *name = NULL;
-
-	if (!argv0)
-		return;
-
-	// Find the basename
-	name = strrchr(argv0, '/');
-	if (name)
-		name++;
-	else
-		name = argv0;
-
-	if (status != 0) {
-		fprintf(stderr, "Try `%s -h' for more information.\n",
-			name);
-	} else {
-		printf("Usage: %s [options] <so_object> [so_object] ...\n", name);
-		printf("Unit test helper for C code.\n");
-		printf("Options:\n");
-		printf("\t-v, --version\tPrint version.\n");
-		printf("\t-h, --help\tPrint this help.\n");
-		printf("\t-d, --debug\tDebug mode. Don't daemonize.\n");
-	}
-}