summaryrefslogtreecommitdiff
path: root/src/constmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/constmap.c')
-rw-r--r--src/constmap.c72
1 files changed, 39 insertions, 33 deletions
diff --git a/src/constmap.c b/src/constmap.c
index ea153ea..decc42e 100644
--- a/src/constmap.c
+++ b/src/constmap.c
@@ -1,8 +1,9 @@
#include "constmap.h"
+
#include "alloc.h"
#include "case.h"
-static constmap_hash hash(char *s,int len)
+static constmap_hash hash(char *s, int len)
{
unsigned char ch;
constmap_hash h;
@@ -16,49 +17,48 @@ static constmap_hash hash(char *s,int len)
return h;
}
-char *constmap(struct constmap *cm,char *s,int len)
+char *constmap(struct constmap *cm, char *s, int len)
{
constmap_hash h;
int pos;
- h = hash(s,len);
+ h = hash(s, len);
pos = cm->first[h & cm->mask];
while (pos != -1) {
if (h == cm->hash[pos])
if (len == cm->inputlen[pos])
- if (!case_diffb(cm->input[pos],len,s))
- return cm->input[pos] + cm->inputlen[pos] + 1;
+ if (!case_diffb(cm->input[pos], len, s)) return cm->input[pos] + cm->inputlen[pos] + 1;
pos = cm->next[pos];
}
return 0;
}
-int constmap_init(struct constmap *cm,char *s,int len,int flagcolon)
+int constmap_init(struct constmap *cm, char *s, int len, int flagcolon)
{
int i;
int j;
int k;
int pos;
constmap_hash h;
-
+
cm->num = 0;
- for (j = 0; j < len; ++j) if (!s[j]) ++cm->num;
-
+ for (j = 0; j < len; ++j)
+ if (!s[j]) ++cm->num;
+
h = 64;
while (h && (h < cm->num)) h += h;
cm->mask = h - 1;
-
- cm->first = (int *) alloc(sizeof(int) * h);
+
+ cm->first = (int *)alloc(sizeof(int) * h);
if (cm->first) {
- cm->input = (char **) alloc(sizeof(char *) * cm->num);
+ cm->input = (char **)alloc(sizeof(char *) * cm->num);
if (cm->input) {
- cm->inputlen = (int *) alloc(sizeof(int) * cm->num);
+ cm->inputlen = (int *)alloc(sizeof(int) * cm->num);
if (cm->inputlen) {
- cm->hash = (constmap_hash *) alloc(sizeof(constmap_hash) * cm->num);
+ cm->hash = (constmap_hash *)alloc(sizeof(constmap_hash) * cm->num);
if (cm->hash) {
- cm->next = (int *) alloc(sizeof(int) * cm->num);
+ cm->next = (int *)alloc(sizeof(int) * cm->num);
if (cm->next) {
- for (h = 0; h <= cm->mask; ++h)
- cm->first[h] = -1;
+ for (h = 0; h <= cm->mask; ++h) cm->first[h] = -1;
pos = 0;
i = 0;
for (j = 0; j < len; ++j)
@@ -67,12 +67,15 @@ int constmap_init(struct constmap *cm,char *s,int len,int flagcolon)
if (flagcolon) {
for (k = i; k < j; ++k)
if (s[k] == ':') break;
- if (k >= j) { i = j + 1; continue; }
+ if (k >= j) {
+ i = j + 1;
+ continue;
+ }
k -= i;
}
cm->input[pos] = s + i;
cm->inputlen[pos] = k;
- h = hash(s + i,k);
+ h = hash(s + i, k);
cm->hash[pos] = h;
h &= cm->mask;
cm->next[pos] = cm->first[h];
@@ -93,7 +96,7 @@ int constmap_init(struct constmap *cm,char *s,int len,int flagcolon)
return 0;
}
-int constmap_init_char(struct constmap *cm,char *s,int len,int flagcolon,char flagchar)
+int constmap_init_char(struct constmap *cm, char *s, int len, int flagcolon, char flagchar)
{
int i;
int j;
@@ -106,24 +109,24 @@ int constmap_init_char(struct constmap *cm,char *s,int len,int flagcolon,char fl
}
cm->num = 0;
- for (j = 0; j < len; ++j) if (!s[j]) ++cm->num;
+ for (j = 0; j < len; ++j)
+ if (!s[j]) ++cm->num;
h = 64;
while (h && (h < cm->num)) h += h;
cm->mask = h - 1;
- cm->first = (int *) alloc(sizeof(int) * h);
+ cm->first = (int *)alloc(sizeof(int) * h);
if (cm->first) {
- cm->input = (char **) alloc(sizeof(char *) * cm->num);
+ cm->input = (char **)alloc(sizeof(char *) * cm->num);
if (cm->input) {
- cm->inputlen = (int *) alloc(sizeof(int) * cm->num);
+ cm->inputlen = (int *)alloc(sizeof(int) * cm->num);
if (cm->inputlen) {
- cm->hash = (constmap_hash *) alloc(sizeof(constmap_hash) * cm->num);
+ cm->hash = (constmap_hash *)alloc(sizeof(constmap_hash) * cm->num);
if (cm->hash) {
- cm->next = (int *) alloc(sizeof(int) * cm->num);
+ cm->next = (int *)alloc(sizeof(int) * cm->num);
if (cm->next) {
- for (h = 0; h <= cm->mask; ++h)
- cm->first[h] = -1;
+ for (h = 0; h <= cm->mask; ++h) cm->first[h] = -1;
pos = 0;
i = 0;
for (j = 0; j < len; ++j)
@@ -132,12 +135,15 @@ int constmap_init_char(struct constmap *cm,char *s,int len,int flagcolon,char fl
if (flagcolon) {
for (k = i; k < j; ++k)
if (s[k] == flagchar) break;
- if (k >= j) { i = j + 1; continue; }
+ if (k >= j) {
+ i = j + 1;
+ continue;
+ }
k -= i;
}
cm->input[pos] = s + i;
cm->inputlen[pos] = k;
- h = hash(s + i,k);
+ h = hash(s + i, k);
cm->hash[pos] = h;
h &= cm->mask;
cm->next[pos] = cm->first[h];
@@ -145,9 +151,9 @@ int constmap_init_char(struct constmap *cm,char *s,int len,int flagcolon,char fl
++pos;
i = j + 1;
}
- return 1;
- }
- alloc_free(cm->hash);
+ return 1;
+ }
+ alloc_free(cm->hash);
}
alloc_free(cm->inputlen);
}