5 static constmap_hash
hash(s
,len
)
14 if (ch
<= 'Z' - 'A') ch
+= 'a' - 'A';
15 h
= ((h
<< 5) + h
) ^ ch
;
21 /* Returns index of string in constmap. 1 = first string, 2 = second ... */
22 /* 0 not found. Use for commands */
23 int constmap_index(cm
,s
,len
)
31 pos
= cm
->first
[h
& cm
->mask
];
33 if (h
== cm
->hash
[pos
])
34 if (len
== cm
->inputlen
[pos
])
35 if (!case_diffb(cm
->input
[pos
],len
,s
))
42 /* returns pointer to sz of string with index "idx". 1 = first, 2 = second...*/
43 char *constmap_get(cm
,idx
)
48 if (idx
<= 0 || idx
> cm
->num
)
51 return cm
->input
[idx
-1];
54 char *constmap(cm
,s
,len
)
62 pos
= cm
->first
[h
& cm
->mask
];
64 if (h
== cm
->hash
[pos
])
65 if (len
== cm
->inputlen
[pos
])
66 if (!case_diffb(cm
->input
[pos
],len
,s
))
67 return cm
->input
[pos
] + cm
->inputlen
[pos
] + 1;
73 int constmap_init(cm
,s
,len
,flagcolon
)
74 /* if flagcolon is true, we process only the stuff before the colon on */
75 /* each line. Otherwise, it's the entire line. Still, the entire line */
89 for (j
= 0;j
< len
;++j
) if (!s
[j
]) ++cm
->num
;
92 while (h
&& (h
< cm
->num
)) h
+= h
;
95 cm
->first
= (int *) alloc(sizeof(int) * h
);
97 cm
->input
= (char **) alloc(sizeof(char *) * cm
->num
);
99 cm
->inputlen
= (int *) alloc(sizeof(int) * cm
->num
);
101 cm
->hash
= (constmap_hash
*) alloc(sizeof(constmap_hash
) * cm
->num
);
103 cm
->next
= (int *) alloc(sizeof(int) * cm
->num
);
105 for (h
= 0;h
<= cm
->mask
;++h
)
109 for (j
= 0;j
< len
;++j
)
113 for (k
= i
;k
< j
;++k
)
116 if (k
>= j
) { i
= j
+ 1; continue; }
119 cm
->input
[pos
] = s
+ i
;
120 cm
->inputlen
[pos
] = k
;
124 cm
->next
[pos
] = cm
->first
[h
];
131 alloc_free(cm
->hash
);
133 alloc_free(cm
->inputlen
);
135 alloc_free(cm
->input
);
137 alloc_free(cm
->first
);
142 void constmap_free(cm
)
145 alloc_free(cm
->next
);
146 alloc_free(cm
->hash
);
147 alloc_free(cm
->inputlen
);
148 alloc_free(cm
->input
);
149 alloc_free(cm
->first
);