Skip to content

Commit

Permalink
Made new library, libneuro.a, using libtool. Started with stringtable…
Browse files Browse the repository at this point in the history
….[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.
  • Loading branch information
cilibrar committed Aug 21, 2004
1 parent a34781c commit 6b287bb
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 5 deletions.
11 changes: 11 additions & 0 deletions .cvsignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.cvsignore
Makefile
Makefile.in
aclocal.m4
autom4te.cache
config.log
config.status
configure
libtool
o
stamp-h2.in
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions doc/.cvsignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cvsignore
10 changes: 8 additions & 2 deletions doc/devguide.dox
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@
\page devguide NeuroServer Developer Guide
\author Rudi Cilibrasi ([email protected])

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
./configure
\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
Expand Down
3 changes: 3 additions & 0 deletions scripts/.cvsignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.cvsignore
NeuroServer.iss
makeSetup.sh
11 changes: 11 additions & 0 deletions src/.cvsignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Makefile
o
*.exe
stamp-h1
stamp-h1.in
.cvsignore
.deps
.libs
Makefile.in
config.h
tmp
14 changes: 12 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* src/config.h.in. Generated from configure.ac by autoheader. */

/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H

/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
#undef HAVE_DOPRNT

Expand Down
8 changes: 8 additions & 0 deletions src/neuro/neuro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __NEURO_H
#define __NEURO_H

#define OK 0

#include <neuro/stringtable.h>

#endif
1 change: 1 addition & 0 deletions src/stringtable.h → src/neuro/stringtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __STRINGTABLE_H

#include <stdio.h>
#include <neuro/neuro.h>

struct StringTable;

Expand Down
19 changes: 19 additions & 0 deletions src/neurotest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <neuro/neuro.h>
#include <assert.h>

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;
}

116 changes: 115 additions & 1 deletion src/stringtable.c
Original file line number Diff line number Diff line change
@@ -1,2 +1,116 @@
#include <stringtable.h>
#include <neuro/stringtable.h>
#include <assert.h>
#include <malloc.h>
#include <string.h>

#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);
}

0 comments on commit 6b287bb

Please sign in to comment.