From 6b287bb8880091b37643201d2cebfadd8fdc9ef5 Mon Sep 17 00:00:00 2001 From: cilibrar Date: Sat, 21 Aug 2004 18:11:17 +0000 Subject: [PATCH] Made new library, libneuro.a, using libtool. Started with stringtable.[ch] Added first library header in $(includedir)/neuro/stringtable.h Most code will be moved into the library as it is refactored. Added .cvsignore files in several places. Added neurotest executable target in src. Now it is possible to install static library and headers using make install. --- .cvsignore | 11 ++++ configure.ac | 1 + doc/.cvsignore | 1 + doc/devguide.dox | 10 ++- scripts/.cvsignore | 3 + src/.cvsignore | 11 ++++ src/Makefile.am | 14 +++- src/config.h.in | 3 + src/neuro/neuro.h | 8 +++ src/{ => neuro}/stringtable.h | 1 + src/neurotest.c | 19 ++++++ src/stringtable.c | 116 +++++++++++++++++++++++++++++++++- 12 files changed, 193 insertions(+), 5 deletions(-) create mode 100644 .cvsignore create mode 100644 doc/.cvsignore create mode 100644 scripts/.cvsignore create mode 100644 src/.cvsignore create mode 100644 src/neuro/neuro.h rename src/{ => neuro}/stringtable.h (96%) create mode 100644 src/neurotest.c diff --git a/.cvsignore b/.cvsignore new file mode 100644 index 0000000..0aa21a7 --- /dev/null +++ b/.cvsignore @@ -0,0 +1,11 @@ +.cvsignore +Makefile +Makefile.in +aclocal.m4 +autom4te.cache +config.log +config.status +configure +libtool +o +stamp-h2.in diff --git a/configure.ac b/configure.ac index 78c555b..1d38527 100644 --- a/configure.ac +++ b/configure.ac @@ -5,6 +5,7 @@ AC_SUBST(TOPDIR) #AC_PROG_CC AC_PATH_PROGS([CC], [gcc-3.3 gcc-3.0 gcc]) AC_SUBST(CC) +AC_PROG_LIBTOOL() AM_CONFIG_HEADER(src/config.h) AM_INIT_AUTOMAKE(NeuroServer, 0.7.5) WINBUILDDIR="c:\build" diff --git a/doc/.cvsignore b/doc/.cvsignore new file mode 100644 index 0000000..009991f --- /dev/null +++ b/doc/.cvsignore @@ -0,0 +1 @@ +.cvsignore diff --git a/doc/devguide.dox b/doc/devguide.dox index 7415989..339052b 100644 --- a/doc/devguide.dox +++ b/doc/devguide.dox @@ -2,11 +2,11 @@ \page devguide NeuroServer Developer Guide \author Rudi Cilibrasi (cilibrar@ofb.net) -This program uses GNU autoconf/automake. +This program uses GNU autoconf/automake/libtool. To regenerate configuration scripts, do this: \code -aclocal ; autoconf ; automake -a +aclocal ; autoconf ; automake \endcode then configure with \code @@ -14,6 +14,12 @@ then configure with \endcode to regenerate the Makefile's. +If you get a persistent error, "ltmain.sh" missing, then you should +try running automake --add-missing +If this doesn't fix it then you must upgrade your libtool. +(Cygwin has a broken devel libtool, try using stable instead for this phase +to work around the bug) + When compiling, if you get 'attribute_used redefined' warnings, you may ignore them without consequence. If you want to eliminate them, you will need to install a newer (>=3) version of gcc; Debian uses the diff --git a/scripts/.cvsignore b/scripts/.cvsignore new file mode 100644 index 0000000..aedc056 --- /dev/null +++ b/scripts/.cvsignore @@ -0,0 +1,3 @@ +.cvsignore +NeuroServer.iss +makeSetup.sh diff --git a/src/.cvsignore b/src/.cvsignore new file mode 100644 index 0000000..4a04ad7 --- /dev/null +++ b/src/.cvsignore @@ -0,0 +1,11 @@ +Makefile +o +*.exe +stamp-h1 +stamp-h1.in +.cvsignore +.deps +.libs +Makefile.in +config.h +tmp diff --git a/src/Makefile.am b/src/Makefile.am index 25c2ff8..402feec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,10 +3,20 @@ AM_CFLAGS= -Wall -g AM_CPPFLAGS= -I. -bin_PROGRAMS = nsd modeegdriver readedf writeedf opencnvdriver writebdf +lib_LIBRARIES = libneuro.a + +libneuro_a_HEADERS = neuro/neuro.h neuro/stringtable.h +libneuro_adir = $(includedir)/neuro + +libneuro_a_SOURCES = stringtable.c + +bin_PROGRAMS = nsd modeegdriver readedf writeedf opencnvdriver writebdf neurotest + +neurotest_SOURCES = neurotest.c +neurotest_LDADD = libneuro.a nsd_SOURCES = nsd.c nsutil.c nsnet.c monitor.c monitor.h cmdhandler.c \ -openedf.c config.h cmdhandler.h edfmacros.h nsd.h nsnet.h nsutil.h openedf.h pctimer.h stringtable.c stringtable.h +openedf.c config.h cmdhandler.h edfmacros.h nsd.h nsnet.h nsutil.h openedf.h pctimer.h modeegdriver_SOURCES = modeegdriver.c nsser.c nsutil.c openedf.c \ nsnet.c monitor.c monitor.h \ diff --git a/src/config.h.in b/src/config.h.in index 3344051..9af01d9 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -1,5 +1,8 @@ /* src/config.h.in. Generated from configure.ac by autoheader. */ +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + /* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ #undef HAVE_DOPRNT diff --git a/src/neuro/neuro.h b/src/neuro/neuro.h new file mode 100644 index 0000000..0011e54 --- /dev/null +++ b/src/neuro/neuro.h @@ -0,0 +1,8 @@ +#ifndef __NEURO_H +#define __NEURO_H + +#define OK 0 + +#include + +#endif diff --git a/src/stringtable.h b/src/neuro/stringtable.h similarity index 96% rename from src/stringtable.h rename to src/neuro/stringtable.h index b702c9e..5037ef5 100644 --- a/src/stringtable.h +++ b/src/neuro/stringtable.h @@ -2,6 +2,7 @@ #define __STRINGTABLE_H #include +#include struct StringTable; diff --git a/src/neurotest.c b/src/neurotest.c new file mode 100644 index 0000000..7e36115 --- /dev/null +++ b/src/neurotest.c @@ -0,0 +1,19 @@ +#include +#include + +int main(int argc, char **argv) +{ + int val; + struct StringTable *st; + st = newStringTable(); + assert(st); + assert(putString(st, "cat", &val) == 0); + assert(findString(st, "cat") == &val); + assert(findString(st, "dog") == NULL); + assert(delString(st, "dog") == ERR_NOSTRING); + assert(delString(st, "cat") == 0); + assert(findString(st, "cat") == NULL); + freeStringTable(st); + return 0; +} + diff --git a/src/stringtable.c b/src/stringtable.c index 3fab58b..7f13928 100644 --- a/src/stringtable.c +++ b/src/stringtable.c @@ -1,2 +1,116 @@ -#include +#include +#include +#include +#include + +#define INITSIZE 10 + +struct StringTableNode { + char *key; + void *val; +}; + +struct StringTable { + int allocSize, usedSize; + int freeHoles; + struct StringTableNode *tab; +}; + +struct StringTable *newStringTable(void) +{ + struct StringTable *st; + st = calloc(sizeof(struct StringTable), 1); + st->allocSize = INITSIZE; + st->usedSize = 0; + st->freeHoles = 0; + st->tab = calloc(sizeof(struct StringTableNode), st->allocSize); + return st; +} + +static int findIndex(struct StringTable *st, const char *key) +{ + int i; + for (i = 0; i < st->usedSize; i += 1) { + if (st->tab[i].key == NULL) continue; + if (strcmp(st->tab[i].key, key) == 0) + return i; + } + return -1; +} + +static int getFreeHoleIndex(struct StringTable *st) +{ + int i; + assert(st->freeHoles > 0); + for (i = 0; i < st->usedSize; ++i) { + if (st->tab[i].key == NULL) { + st->freeHoles -= 1; + return i; + } + } + assert(0 && "StringTable free hole error."); + return -1; +} + +static int getFreeIndex(struct StringTable *st) +{ + if (st->freeHoles) + return getFreeHoleIndex(st); + if (st->usedSize < st->allocSize) { + st->usedSize += 1; + return st->usedSize - 1; + } + st->allocSize *= 2; + st->tab = realloc(st->tab, sizeof(struct StringTableNode)*st->allocSize); + return getFreeIndex(st); +} + +int putString(struct StringTable *st, const char *key, void *val) +{ + int ind = findIndex(st, key); + if (ind == -1) { + ind = getFreeIndex(st); + st->tab[ind].key = strdup(key); + } + st->tab[ind].val = val; + return 0; +} + +int delString(struct StringTable *st, const char *key) +{ + int ind = findIndex(st, key); + if (ind == -1) return ERR_NOSTRING; + free(st->tab[ind].key); + st->tab[ind].key = NULL; + st->freeHoles += 1; + return 0; +} + +void *findString(struct StringTable *st, const char *key) +{ + int ind = findIndex(st, key); + return (ind == -1) ? NULL : st->tab[ind].val; +} + +void allStrings(struct StringTable *st, StringTableIterator sti, void *udata) +{ + int i; + for (i = 0; i < st->usedSize; i += 1) { + if (st->tab[i].key != NULL) + sti(st, st->tab[i].key, st->tab[i].val, udata); + } +} + +void freeStringTable(struct StringTable *st) +{ + int i; + for (i = 0; i < st->usedSize; i += 1) { + if (st->tab[i].key != NULL) { + free(st->tab[i].key); + st->tab[i].key = NULL; + } + } + free(st->tab); + free(st); +}