summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid McMackins II <contact@mcmackins.org>2020-02-25 18:10:37 -0600
committerDavid McMackins II <contact@mcmackins.org>2020-02-25 18:10:37 -0600
commit7c9cf4a184595f589ff11bd0008dd4a8c54e1a25 (patch)
treecc8cf37ff4534428649b4b34813b3d7b4348011c
parent886ee4562ed98f97320b30a1adb4e5b48a2b42a5 (diff)
Use ANSI C
-rw-r--r--Makefile7
-rw-r--r--pfxtree-test.c12
-rw-r--r--pfxtree.c13
3 files changed, 17 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 443c3c3..2b0bcdd 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,7 @@
-CC=c99
-CFLAGS=-Wall -Wextra -Wunreachable-code -ftrapv -fPIC -g -D_POSIX_C_SOURCE=2
+CC ?= cc
+STND ?= -ansi -pedantic
+CFLAGS += $(STND) -O2 -Wall -Wextra -Wunreachable-code -ftrapv -fPIC \
+ -D_POSIX_C_SOURCE=2
PREFIX=/usr/local
LIBDIR=$(DESTDIR)$(PREFIX)/lib
PKGCONFIGDIR=$(LIBDIR)/pkgconfig
@@ -29,7 +31,6 @@ test: pfxtree-test
install: libpfxtree.so
install -m755 libpfxtree.so $(LIBDIR)/libpfxtree.so.$(VERSION)
install -m644 pfxtree.h $(HDIR)/pfxtree.h
- install -m644 pfxtree.pc $(PKGCONFIGDIR)/pfxtree.pc
ln -sf $(LIBDIR)/libpfxtree.so.$(VERSION) $(LIBDIR)/libpfxtree.so.$(MAJOR)
ln -sf $(LIBDIR)/libpfxtree.so.$(VERSION) $(LIBDIR)/libpfxtree.so
diff --git a/pfxtree-test.c b/pfxtree-test.c
index 8d9f25e..d176505 100644
--- a/pfxtree-test.c
+++ b/pfxtree-test.c
@@ -1,6 +1,6 @@
/*
* pfxtree-test - Delwink prefix tree library unit test
- * Copyright (C) 2017 Delwink, LLC
+ * Copyright (C) 2017, 2020 Delwink, LLC
*
* Redistributions, modified or unmodified, in whole or in part, must retain
* applicable copyright or other legal privilege notices, these conditions, and
@@ -59,10 +59,12 @@ main(void)
assert(NULL == pt_search(p, "hello"));
assert(pt_search(p, "hell") != NULL);
- void *dummy = malloc(0xDFDF);
- assert(dummy != NULL);
- assert(0 == pt_add_p(p, "hello", dummy));
- assert('p' == pt_data_type(pt_search(p, "hello")));
+ {
+ void *dummy = malloc(0xDFDF);
+ assert(dummy != NULL);
+ assert(0 == pt_add_p(p, "hello", dummy));
+ assert('p' == pt_data_type(pt_search(p, "hello")));
+ }
assert(PT_ENOWORD == pt_del(p, "asdf"));
diff --git a/pfxtree.c b/pfxtree.c
index 3e88e03..074bab8 100644
--- a/pfxtree.c
+++ b/pfxtree.c
@@ -1,6 +1,6 @@
/*
* libpfxtree - Delwink prefix tree library
- * Copyright (C) 2015, 2017 Delwink, LLC
+ * Copyright (C) 2015, 2017, 2020 Delwink, LLC
*
* Redistributions, modified or unmodified, in whole or in part, must retain
* applicable copyright or other legal privilege notices, these conditions, and
@@ -113,7 +113,7 @@ static int
add(PrefixTree *self, const char *word, union _pt_data data, int type)
{
int rc = 0;
- PrefixTree *node = self;
+ PrefixTree *node = self, *first_insertion = NULL;
size_t i, len = strlen(word);
for (i = 0; i <= len; ++i)
@@ -125,11 +125,9 @@ add(PrefixTree *self, const char *word, union _pt_data data, int type)
node = child;
}
- PrefixTree *first_insertion = NULL;
-
for (; i <= len; ++i)
{
- PrefixTree *new = pt_new();
+ PrefixTree *new = pt_new(), *end;
if (!new)
{
rc = PT_EALLOC;
@@ -139,7 +137,7 @@ add(PrefixTree *self, const char *word, union _pt_data data, int type)
new->ch = word[i];
new->parent = node;
- PrefixTree *end = get_last_child(node);
+ end = get_last_child(node);
if (!end)
node->children = new;
else
@@ -182,10 +180,11 @@ pt_add_p(PrefixTree *self, const char *word, void *data)
static size_t
num_children(PrefixTree *self)
{
+ size_t i;
+
if (!self->children)
return 0;
- size_t i;
self = self->children;
for (i = 1; self->next; ++i)
self = self->next;