-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
cilibrar
committed
Aug 21, 2004
1 parent
a34781c
commit 6b287bb
Showing
12 changed files
with
193 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.cvsignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.cvsignore | ||
NeuroServer.iss | ||
makeSetup.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
#define __STRINGTABLE_H | ||
|
||
#include <stdio.h> | ||
#include <neuro/neuro.h> | ||
|
||
struct StringTable; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|