forked from github/server
Some old files that weren't in use. Goodbye.
This commit is contained in:
parent
2e547d6ae8
commit
10e64c59e1
14 changed files with 0 additions and 818 deletions
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
#include <util/console.c>
|
#include <util/console.c>
|
||||||
#include <util/attrib.c>
|
#include <util/attrib.c>
|
||||||
#include <util/argstack.c>
|
|
||||||
#include <util/base36.c>
|
#include <util/base36.c>
|
||||||
#include <util/crmessage.c>
|
#include <util/crmessage.c>
|
||||||
#include <util/cvector.c>
|
#include <util/cvector.c>
|
||||||
|
|
|
@ -86,11 +86,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#define PTRIES 0 /* it turns out they are slow :-( */
|
|
||||||
#if PTRIES
|
|
||||||
#include <util/patricia.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct settings global = {
|
struct settings global = {
|
||||||
"Eressea", /* gamename */
|
"Eressea", /* gamename */
|
||||||
};
|
};
|
||||||
|
|
|
@ -87,7 +87,6 @@
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="util\argstack.h" />
|
|
||||||
<ClInclude Include="util\attrib.h" />
|
<ClInclude Include="util\attrib.h" />
|
||||||
<ClInclude Include="util\base36.h" />
|
<ClInclude Include="util\base36.h" />
|
||||||
<ClInclude Include="util\bsdstring.h" />
|
<ClInclude Include="util\bsdstring.h" />
|
||||||
|
@ -109,7 +108,6 @@
|
||||||
<ClInclude Include="util\nrmessage_struct.h" />
|
<ClInclude Include="util\nrmessage_struct.h" />
|
||||||
<ClInclude Include="util\os.h" />
|
<ClInclude Include="util\os.h" />
|
||||||
<ClInclude Include="util\parser.h" />
|
<ClInclude Include="util\parser.h" />
|
||||||
<ClInclude Include="util\patricia.h" />
|
|
||||||
<ClInclude Include="util\quicklist.h" />
|
<ClInclude Include="util\quicklist.h" />
|
||||||
<ClInclude Include="util\rand.h" />
|
<ClInclude Include="util\rand.h" />
|
||||||
<ClInclude Include="util\resolve.h" />
|
<ClInclude Include="util\resolve.h" />
|
||||||
|
@ -123,7 +121,6 @@
|
||||||
<ClInclude Include="util\xml.h" />
|
<ClInclude Include="util\xml.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="util\argstack.c" />
|
|
||||||
<ClCompile Include="util\attrib.c" />
|
<ClCompile Include="util\attrib.c" />
|
||||||
<ClCompile Include="util\base36.c" />
|
<ClCompile Include="util\base36.c" />
|
||||||
<ClCompile Include="util\base36_test.c" />
|
<ClCompile Include="util\base36_test.c" />
|
||||||
|
@ -145,7 +142,6 @@
|
||||||
<ClCompile Include="util\nrmessage.c" />
|
<ClCompile Include="util\nrmessage.c" />
|
||||||
<ClCompile Include="util\os.c" />
|
<ClCompile Include="util\os.c" />
|
||||||
<ClCompile Include="util\parser.c" />
|
<ClCompile Include="util\parser.c" />
|
||||||
<ClCompile Include="util\patricia.c" />
|
|
||||||
<ClCompile Include="util\quicklist.c" />
|
<ClCompile Include="util\quicklist.c" />
|
||||||
<ClCompile Include="util\quicklist_test.c" />
|
<ClCompile Include="util\quicklist_test.c" />
|
||||||
<ClCompile Include="util\rand.c" />
|
<ClCompile Include="util\rand.c" />
|
||||||
|
|
|
@ -11,9 +11,6 @@
|
||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="util\argstack.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="util\attrib.h">
|
<ClInclude Include="util\attrib.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -74,9 +71,6 @@
|
||||||
<ClInclude Include="util\parser.h">
|
<ClInclude Include="util\parser.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="util\patricia.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="util\rand.h">
|
<ClInclude Include="util\rand.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -115,9 +109,6 @@
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="util\argstack.c">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="util\attrib.c">
|
<ClCompile Include="util\attrib.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -178,9 +169,6 @@
|
||||||
<ClCompile Include="util\parser.c">
|
<ClCompile Include="util\parser.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="util\patricia.c">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="util\rand.c">
|
<ClCompile Include="util\rand.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
#include "argstack.h"
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#define ARGSTKSIZE 16
|
|
||||||
typedef struct arguments {
|
|
||||||
int n;
|
|
||||||
struct value {
|
|
||||||
int type;
|
|
||||||
union {
|
|
||||||
double number;
|
|
||||||
const char * str;
|
|
||||||
void * data;
|
|
||||||
} value;
|
|
||||||
} stack[ARGSTKSIZE];
|
|
||||||
} arguments;
|
|
||||||
|
|
||||||
void arg_init(struct arguments * arg) {
|
|
||||||
arg->n = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void arg_done(struct arguments * arg) {
|
|
||||||
arg = arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void arg_pushuserdata(struct arguments * arg, int type, void * data) {
|
|
||||||
assert(arg->n<ARGSTKSIZE);
|
|
||||||
arg->stack[arg->n].type = type;
|
|
||||||
arg->stack[arg->n].value.data = data;
|
|
||||||
++arg->n;
|
|
||||||
}
|
|
||||||
|
|
||||||
void arg_pushstring(struct arguments * arg, const char * str) {
|
|
||||||
assert(arg->n<ARGSTKSIZE);
|
|
||||||
arg->stack[arg->n].type = ARG_TSTRING;
|
|
||||||
arg->stack[arg->n].value.str = str;
|
|
||||||
++arg->n;
|
|
||||||
}
|
|
||||||
|
|
||||||
void arg_pushnumber(struct arguments * arg, double number) {
|
|
||||||
assert(arg->n<ARGSTKSIZE);
|
|
||||||
arg->stack[arg->n].type = ARG_TSTRING;
|
|
||||||
arg->stack[arg->n].value.number = number;
|
|
||||||
++arg->n;
|
|
||||||
}
|
|
||||||
|
|
||||||
int arg_size(struct arguments * arg) {
|
|
||||||
return arg->n;
|
|
||||||
}
|
|
||||||
|
|
||||||
void * arg_touserdata(struct arguments * arg, int idx, int type) {
|
|
||||||
assert(arg->n>idx && idx>=0);
|
|
||||||
assert(arg->stack[arg->n].type==type);
|
|
||||||
return arg->stack[arg->n].value.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
double arg_tonumber(struct arguments * arg, int idx) {
|
|
||||||
assert(arg->n>idx && idx>=0);
|
|
||||||
assert(arg->stack[arg->n].type==ARG_TNUMBER);
|
|
||||||
return arg->stack[arg->n].value.number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char * arg_tostring(struct arguments * arg, int idx) {
|
|
||||||
assert(arg->n>idx && idx>=0);
|
|
||||||
assert(arg->stack[arg->n].type==ARG_TSTRING);
|
|
||||||
return arg->stack[arg->n].value.str;
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
#ifndef UTIL_ARG_H
|
|
||||||
#define UTIL_ARG_H
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct arguments;
|
|
||||||
|
|
||||||
#define ARG_TNUMBER -1
|
|
||||||
#define ARG_TSTRING -2
|
|
||||||
|
|
||||||
void arg_init(struct arguments * arg);
|
|
||||||
void arg_done(struct arguments * arg);
|
|
||||||
|
|
||||||
void arg_push(struct arguments * arg, int type, void * data);
|
|
||||||
void arg_pushstring(struct arguments * arg, const char * str);
|
|
||||||
void arg_pushnumber(struct arguments * arg, double number);
|
|
||||||
|
|
||||||
int arg_size(struct arguments * arg);
|
|
||||||
void * arg_touserdata(struct arguments * arg, int idx, int type);
|
|
||||||
double arg_tonumber(struct arguments * arg, int idx);
|
|
||||||
const char * arg_tostring(struct arguments * arg, int idx);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
|
@ -1,236 +0,0 @@
|
||||||
#include <platform.h>
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "patricia.h"
|
|
||||||
|
|
||||||
#define MAXKEYLEN 128
|
|
||||||
|
|
||||||
/* TODO: custom memory management to optimize cache layout, or use arrays. */
|
|
||||||
|
|
||||||
/* NOTE: The structure saves an extra 0 delimiter for the key. Technically
|
|
||||||
* this wouldn't be necessary (because we know its' length from data[0]),
|
|
||||||
* but it makes it possible for trie_getkey to return a key without making
|
|
||||||
* a copy or have a cumbersome (const char**, size_t*) interface.
|
|
||||||
* +-----------+-------------+------+------------+
|
|
||||||
* data: | keylen(1) | key(keylen) | 0(1) | data(size) |
|
|
||||||
* +-----------+-------------+------+------------+
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct trie_node {
|
|
||||||
struct trie_node *l, *r;
|
|
||||||
char * data;
|
|
||||||
unsigned int bitpos;
|
|
||||||
};
|
|
||||||
|
|
||||||
#if 1
|
|
||||||
#define get_bit(c, s, p) (unsigned int)((((p)>>3)>(unsigned int)(s))?0:((c)[(p)>>3]>>((p)&7)&1))
|
|
||||||
#else
|
|
||||||
unsigned int get_bit(const char * c, size_t s, unsigned int p)
|
|
||||||
{
|
|
||||||
if ((p>>3)>=(unsigned int)s) return 0;
|
|
||||||
return ((c)[p>>3]>>(p&7)&1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#define node_bit(n, p) get_bit((n)->data+1, (n)->data[0], (p))
|
|
||||||
|
|
||||||
trie_node * trie_insert(trie_node **root_p, const char * key, const void * data, size_t size)
|
|
||||||
{
|
|
||||||
trie_node * new_node;
|
|
||||||
size_t keylen = strlen(key);
|
|
||||||
trie_node ** insert_p = root_p, *node = *insert_p;
|
|
||||||
unsigned int p, bit=0;
|
|
||||||
|
|
||||||
assert(keylen<MAXKEYLEN);
|
|
||||||
|
|
||||||
for (p=0;p!=keylen*8+1;++p) {
|
|
||||||
bit = get_bit(key, keylen, p);
|
|
||||||
|
|
||||||
/* NULL-pointers lead to someplace we haven't got a prefix yet. */
|
|
||||||
if (node==NULL) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if we have the full prefix that the current node represents, move on */
|
|
||||||
if (p==node->bitpos) {
|
|
||||||
insert_p = bit?&node->r:&node->l;
|
|
||||||
node = *insert_p;
|
|
||||||
if (node==NULL) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if we are looking at a back-node, we need to add our node before it. */
|
|
||||||
if (p>=node->bitpos) {
|
|
||||||
/* find the point p where both differ. */
|
|
||||||
if (keylen==(unsigned int)node->data[0] && strncmp(key, node->data+1, keylen)==0) {
|
|
||||||
/* we are trying to insert the same key again */
|
|
||||||
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
do {
|
|
||||||
++p;
|
|
||||||
bit = get_bit(key, keylen, p);
|
|
||||||
} while (node_bit(node, p)==bit);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if instead we differ before reaching the end of the current prefix, we must split.
|
|
||||||
* we insert our node before the current one and re-attach it. */
|
|
||||||
if (node_bit(node, p)!=bit) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
new_node = (trie_node *)malloc(sizeof(trie_node));
|
|
||||||
new_node->bitpos = p;
|
|
||||||
new_node->data = malloc(keylen+2+size);
|
|
||||||
new_node->data[0] = (char)keylen;
|
|
||||||
memcpy(new_node->data+1, key, keylen+1);
|
|
||||||
if (data!=NULL && size>0) {
|
|
||||||
/* if data is NULL then the user only wanted some space that they're going to write to later */
|
|
||||||
/* if size is 0 then the user is using the trie as a set, not a map */
|
|
||||||
memcpy(new_node->data+2+keylen, data, size);
|
|
||||||
}
|
|
||||||
if (bit) {
|
|
||||||
new_node->l = node;
|
|
||||||
new_node->r = new_node; /* loop the 1-bit to ourselves, search will end */
|
|
||||||
} else {
|
|
||||||
new_node->l = new_node; /* loop the 0-bit to ourselves, search will end */
|
|
||||||
new_node->r = node;
|
|
||||||
}
|
|
||||||
*insert_p = new_node;
|
|
||||||
return new_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
void trie_remove(trie_node **root_p, trie_node *pos)
|
|
||||||
{
|
|
||||||
if (pos!=NULL) {
|
|
||||||
const char * key = trie_getkey(pos);
|
|
||||||
size_t keylen = pos->data[0];
|
|
||||||
trie_node ** node_p = root_p;
|
|
||||||
trie_node * node = *root_p;
|
|
||||||
|
|
||||||
while (node) {
|
|
||||||
int bit;
|
|
||||||
trie_node ** next_p;
|
|
||||||
trie_node * next;
|
|
||||||
|
|
||||||
if (node == pos) {
|
|
||||||
if (node->l==node) {
|
|
||||||
*node_p = node->r;
|
|
||||||
break;
|
|
||||||
} else if (node->r==node) {
|
|
||||||
*node_p = node->l;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bit = get_bit(key, keylen, node->bitpos);
|
|
||||||
next_p = bit?&node->r:&node->l;
|
|
||||||
next = *next_p;
|
|
||||||
if (next == pos && next->bitpos<=node->bitpos) {
|
|
||||||
/* the element that has a back-pointer to pos gets swapped with pos */
|
|
||||||
char * data = pos->data;
|
|
||||||
pos->data = node->data;
|
|
||||||
node->data = data;
|
|
||||||
|
|
||||||
/* finally, find the back-pointer to node and set it to pos */
|
|
||||||
next_p = bit?&node->l:&node->r; /* NB: this is the OTHER child of node */
|
|
||||||
next = *next_p;
|
|
||||||
key = trie_getkey(node);
|
|
||||||
keylen = (unsigned int)node->data[0];
|
|
||||||
while (next) {
|
|
||||||
int new_bit;
|
|
||||||
if (next==node) {
|
|
||||||
*next_p = pos;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
new_bit = get_bit(key, keylen, next->bitpos);
|
|
||||||
next_p = new_bit?&next->r:&next->l;
|
|
||||||
next = *next_p;
|
|
||||||
}
|
|
||||||
*node_p = bit?node->l:node->r;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
node = *next_p;
|
|
||||||
node_p = next_p;
|
|
||||||
}
|
|
||||||
free(node->data);
|
|
||||||
free(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void trie_debug(trie_node * root)
|
|
||||||
{
|
|
||||||
const char * l = root->l?trie_getkey(root->l):"?";
|
|
||||||
const char * r = root->r?trie_getkey(root->r):"?";
|
|
||||||
printf("%s %d | %s | %s\n", trie_getkey(root), root->bitpos, l, r);
|
|
||||||
if (root->l && root->l->bitpos > root->bitpos) trie_debug(root->l);
|
|
||||||
if (root->r && root->r->bitpos > root->bitpos) trie_debug(root->r);
|
|
||||||
}
|
|
||||||
|
|
||||||
trie_node * trie_find(trie_node *root, const char *key)
|
|
||||||
{
|
|
||||||
trie_node * node = root;
|
|
||||||
size_t keylen = strlen(key);
|
|
||||||
|
|
||||||
while (node) {
|
|
||||||
int bit = get_bit(key, keylen, node->bitpos);
|
|
||||||
trie_node * next = bit?node->r:node->l;
|
|
||||||
|
|
||||||
if (next!=NULL) {
|
|
||||||
if (node->bitpos>=next->bitpos) {
|
|
||||||
if (keylen==(unsigned int)next->data[0] && strncmp(key, next->data+1, keylen)==0) {
|
|
||||||
return next;
|
|
||||||
}
|
|
||||||
next = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
node = next;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
trie_node * trie_find_prefix(trie_node *root, const char *key)
|
|
||||||
{
|
|
||||||
trie_node * node = root;
|
|
||||||
size_t keylen = strlen(key);
|
|
||||||
|
|
||||||
while (node) {
|
|
||||||
int bit = get_bit(key, keylen, node->bitpos);
|
|
||||||
trie_node * next = bit?node->r:node->l;
|
|
||||||
|
|
||||||
if (next!=NULL) {
|
|
||||||
if (node->bitpos>=next->bitpos) {
|
|
||||||
if (keylen<=(unsigned int)next->data[0] && strncmp(key, next->data+1, keylen)==0) {
|
|
||||||
return next;
|
|
||||||
}
|
|
||||||
next = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
node = next;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void * trie_getdata(trie_node * node)
|
|
||||||
{
|
|
||||||
return node->data+2+node->data[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
const char * trie_getkey(trie_node * node)
|
|
||||||
{
|
|
||||||
return node->data+1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void trie_free(trie_node * root)
|
|
||||||
{
|
|
||||||
if (root) {
|
|
||||||
if (root->l && root->l->bitpos>root->bitpos) trie_free(root->l);
|
|
||||||
if (root->r && root->r->bitpos>root->bitpos) trie_free(root->r);
|
|
||||||
free(root);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
#ifndef H_PATRICIA
|
|
||||||
#define H_PATRICIA
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct trie_node trie_node;
|
|
||||||
|
|
||||||
trie_node * trie_insert(trie_node **root, const char *key, const void *data, size_t size);
|
|
||||||
trie_node * trie_find(trie_node *root, const char *key);
|
|
||||||
void * trie_getdata(trie_node *node);
|
|
||||||
const char * trie_getkey(trie_node *node);
|
|
||||||
void trie_free(trie_node * root);
|
|
||||||
void trie_remove(trie_node **root_p, trie_node *pos);
|
|
||||||
void trie_debug(trie_node * root);
|
|
||||||
trie_node * trie_find_prefix(trie_node *root, const char *key);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
146
src/util/vmap.c
146
src/util/vmap.c
|
@ -1,146 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
|
||||||
Katja Zedel <katze@felidae.kn-bremen.de
|
|
||||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma warning (disable: 4711)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <config.h>
|
|
||||||
#include "vmap.h"
|
|
||||||
|
|
||||||
size_t
|
|
||||||
vmap_lowerbound(const vmap * vm, const int key)
|
|
||||||
/* returns the index of the entry which has the greatest key that is less or
|
|
||||||
* equal to 'key' */
|
|
||||||
{
|
|
||||||
vmapentry *first = vm->data, *middle;
|
|
||||||
unsigned int half, len = vm->size;
|
|
||||||
while (len > 0) {
|
|
||||||
half = len / 2;
|
|
||||||
middle = first;
|
|
||||||
middle += half;
|
|
||||||
if (middle->key < key) {
|
|
||||||
first = middle + 1;
|
|
||||||
len = len - half - 1;
|
|
||||||
} else
|
|
||||||
len = half;
|
|
||||||
}
|
|
||||||
return first - vm->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
vmap_init(vmap * map)
|
|
||||||
{
|
|
||||||
map->size = 0; /* !! */
|
|
||||||
map->maxsize = 4;
|
|
||||||
map->data = calloc(4, sizeof(vmapentry));
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
|
||||||
vmap_upperbound(const vmap * vm, const int key)
|
|
||||||
/* returns the index of the entry which has the smallest key that is greater
|
|
||||||
* or equal to 'key' */
|
|
||||||
{
|
|
||||||
unsigned int half, len = vm->size;
|
|
||||||
vmapentry *first = vm->data, *middle;
|
|
||||||
while (len > 0) {
|
|
||||||
half = len / 2;
|
|
||||||
middle = first;
|
|
||||||
middle += half;
|
|
||||||
if (key < middle->key)
|
|
||||||
len = half;
|
|
||||||
else {
|
|
||||||
first = middle + 1;
|
|
||||||
len = len - half - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return first - vm->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
|
||||||
vmap_get(vmap * vm, const int key)
|
|
||||||
{
|
|
||||||
size_t insert = vmap_lowerbound(vm, key);
|
|
||||||
vmapentry *at;
|
|
||||||
|
|
||||||
/* make sure it's a unique key: */
|
|
||||||
if (insert != vm->size && vm->data[insert].key == key)
|
|
||||||
return insert;
|
|
||||||
/* insert at this position: */
|
|
||||||
if (vm->size == vm->maxsize) {
|
|
||||||
/* need more space */
|
|
||||||
vm->maxsize *= 2;
|
|
||||||
vm->data = realloc(vm->data, vm->maxsize * sizeof(vmapentry));
|
|
||||||
}
|
|
||||||
at = vm->data + insert;
|
|
||||||
memmove(at + 1, at, (vm->size - insert) * sizeof(vmapentry)); /* !1.3! */
|
|
||||||
at->key = key;
|
|
||||||
at->value = 0;
|
|
||||||
++vm->size;
|
|
||||||
return insert;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
|
||||||
vmap_insert(vmap * vm, const int key, void *data)
|
|
||||||
/* inserts an object into the vmap, identifies it with the 'key' which must be
|
|
||||||
* unique, and returns the vmapentry it created. */
|
|
||||||
{
|
|
||||||
size_t insert = vmap_lowerbound(vm, key);
|
|
||||||
vmapentry *at;
|
|
||||||
|
|
||||||
/* make sure it's a unique key: */
|
|
||||||
assert(insert == vm->size || vm->data[insert].key != key);
|
|
||||||
/* insert at this position: */
|
|
||||||
if (vm->size == vm->maxsize) {
|
|
||||||
/* need more space */
|
|
||||||
vm->maxsize = vm->maxsize ? (vm->maxsize * 2) : 4;
|
|
||||||
vm->data = realloc(vm->data, vm->maxsize * sizeof(vmapentry));
|
|
||||||
}
|
|
||||||
at = vm->data + insert;
|
|
||||||
memmove(at + 1, at, (vm->size - insert) * sizeof(vmapentry));
|
|
||||||
at->key = key;
|
|
||||||
at->value = data;
|
|
||||||
++vm->size;
|
|
||||||
return insert;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
|
||||||
vmap_find(const vmap * vm, const int key)
|
|
||||||
/* returns the index of the vmapentry that's identified by the key or size (a
|
|
||||||
* past-the-end value) if it is not found. */
|
|
||||||
{
|
|
||||||
vmapentry *first = vm->data, *middle;
|
|
||||||
unsigned int half, len = vm->size;
|
|
||||||
while (len > 0) {
|
|
||||||
half = len / 2;
|
|
||||||
middle = first;
|
|
||||||
middle += half;
|
|
||||||
if (middle->key < key) {
|
|
||||||
first = middle + 1;
|
|
||||||
len = len - half - 1;
|
|
||||||
} else
|
|
||||||
len = half;
|
|
||||||
}
|
|
||||||
if (first != vm->data + vm->size && first->key == key)
|
|
||||||
return first - vm->data;
|
|
||||||
else
|
|
||||||
return vm->size;
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
|
||||||
Katja Zedel <katze@felidae.kn-bremen.de
|
|
||||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef VMAP_H
|
|
||||||
#define VMAP_H
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct vmapentry vmapentry;
|
|
||||||
struct vmapentry {
|
|
||||||
int key;
|
|
||||||
void *value;
|
|
||||||
};
|
|
||||||
typedef struct vmap vmap;
|
|
||||||
struct vmap {
|
|
||||||
vmapentry *data;
|
|
||||||
unsigned int size;
|
|
||||||
unsigned int maxsize;
|
|
||||||
};
|
|
||||||
|
|
||||||
size_t vmap_lowerbound(const vmap * vm, const int key);
|
|
||||||
size_t vmap_upperbound(const vmap * vm, const int key);
|
|
||||||
size_t vmap_insert(vmap * vm, const int key, void *data);
|
|
||||||
size_t vmap_find(const vmap * vm, const int key);
|
|
||||||
size_t vmap_get(vmap * vm, const int key);
|
|
||||||
void vmap_init(vmap * vm);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
104
src/util/vset.c
104
src/util/vset.c
|
@ -1,104 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
|
||||||
Katja Zedel <katze@felidae.kn-bremen.de
|
|
||||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "vset.h"
|
|
||||||
|
|
||||||
void
|
|
||||||
vset_init(vset * s)
|
|
||||||
{
|
|
||||||
s->data = 0;
|
|
||||||
s->size = 0;
|
|
||||||
s->maxsize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
vset_destroy(vset * s)
|
|
||||||
{
|
|
||||||
if (s->data)
|
|
||||||
free(s->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
vset_erase(vset * s, void *item)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
for (i = 0; i != s->size; ++i)
|
|
||||||
if (s->data[i] == item) {
|
|
||||||
s->size--;
|
|
||||||
s->data[i] = s->data[s->size];
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
|
||||||
vset_add(vset * s, void *item)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (!s->data) {
|
|
||||||
s->size = 0;
|
|
||||||
s->maxsize = 4;
|
|
||||||
s->data = calloc(4, sizeof(void *));
|
|
||||||
}
|
|
||||||
for (i = 0; i != s->size; ++i)
|
|
||||||
if (s->data[i] == item)
|
|
||||||
return i;
|
|
||||||
if (s->size == s->maxsize) {
|
|
||||||
s->maxsize *= 2;
|
|
||||||
s->data = realloc(s->data, s->maxsize * sizeof(void *));
|
|
||||||
}
|
|
||||||
s->data[s->size] = item;
|
|
||||||
++s->size;
|
|
||||||
return s->size - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
vset_pop(vset *s)
|
|
||||||
{
|
|
||||||
if(s->size == 0) return NULL;
|
|
||||||
s->size--;
|
|
||||||
return s->data[s->size+1];
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
vset_count(vset *s, void *item)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
int c = 0;
|
|
||||||
|
|
||||||
for(i = 0; i != s->size; ++i) {
|
|
||||||
if(s->data[i] == item) c++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
vset_concat(vset *to, vset *from)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
for(i=0; i != from->size; ++i) {
|
|
||||||
vset_add(to, from->data[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
|
||||||
Katja Zedel <katze@felidae.kn-bremen.de
|
|
||||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef VOIDPTR_SETS
|
|
||||||
#define VOIDPTR_SETS
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
typedef struct vset vset;
|
|
||||||
struct vset {
|
|
||||||
void **data;
|
|
||||||
size_t size;
|
|
||||||
size_t maxsize;
|
|
||||||
};
|
|
||||||
extern void vset_init(vset * s);
|
|
||||||
extern void vset_destroy(vset * s);
|
|
||||||
extern size_t vset_add(vset * s, void *);
|
|
||||||
extern int vset_erase(vset * s, void *);
|
|
||||||
extern int vset_count(vset *s, void * i);
|
|
||||||
extern void *vset_pop(vset *s);
|
|
||||||
extern void vset_concat(vset *to, vset *from);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
|
@ -1,56 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
|
||||||
Katja Zedel <katze@felidae.kn-bremen.de
|
|
||||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include <config.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "windir.h"
|
|
||||||
|
|
||||||
DIR *
|
|
||||||
opendir(const char *name)
|
|
||||||
{
|
|
||||||
static DIR direct; /* STATIC_RESULT: used for return, not across calls */
|
|
||||||
|
|
||||||
direct.first = 1;
|
|
||||||
_searchenv(name, "ERESSEA_PATH", direct.name);
|
|
||||||
if (*direct.name != '\0')
|
|
||||||
return &direct;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct dirent *
|
|
||||||
readdir(DIR * thedir)
|
|
||||||
{
|
|
||||||
static struct _finddata_t ft; /* STATIC_RESULT: used for return, not across calls */
|
|
||||||
static struct dirent de; /* STATIC_RESULT: used for return, not across calls */
|
|
||||||
char where[_MAX_PATH];
|
|
||||||
|
|
||||||
strcat(strcpy(where, thedir->name), "/*");
|
|
||||||
if (thedir->first) {
|
|
||||||
thedir->first = 0;
|
|
||||||
de.hnd = _findfirst(where, &ft);
|
|
||||||
} else {
|
|
||||||
if (_findnext(de.hnd, &ft) != 0)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
_splitpath(ft.name, de.d_drive, de.d_dir, de.d_name, de.d_ext);
|
|
||||||
return &de;
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,50 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
|
||||||
Katja Zedel <katze@felidae.kn-bremen.de
|
|
||||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef WINDIR_H
|
|
||||||
#define WINDIR_H
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <io.h>
|
|
||||||
typedef struct DIR {
|
|
||||||
char name[_MAX_PATH];
|
|
||||||
int first;
|
|
||||||
} DIR;
|
|
||||||
|
|
||||||
typedef struct dirent {
|
|
||||||
char d_path[_MAX_PATH];
|
|
||||||
char d_name[_MAX_FNAME];
|
|
||||||
char d_drive[_MAX_DRIVE];
|
|
||||||
char d_dir[_MAX_DIR];
|
|
||||||
char d_ext[_MAX_EXT];
|
|
||||||
intptr_t hnd;
|
|
||||||
} dirent;
|
|
||||||
|
|
||||||
DIR *opendir(const char *name);
|
|
||||||
struct dirent *readdir(DIR * thedir);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
Loading…
Reference in a new issue