54#define LINE_BUFFER_SIZE 512
67 unsigned int z = 0x811c9dc5;
68 const char *start = datum;
105 while ((key < value) &&
106 ((*key ==
' ') || (*key ==
'\t'))) {
111 if ((*key == 0) || (*key ==
'#')) {
116 for (colon = key; colon < value; colon++) {
121 if (colon == value) {
129 res =
hash_add(hash, (
char *)key, (
char *)value);
132 "Unable to add %s:%s to hash table", ln, value);
145 unsigned int slen = 0;
151 if (s[slen] ==
'\n') {
160 if (slen >
sizeof s) {
161 NSLOG(netsurf, INFO,
"Overlength line\n");
190 strm.zalloc = Z_NULL;
192 strm.opaque = Z_NULL;
194 strm.next_in = (uint8_t *)data;
195 strm.avail_in = size;
197 ret = inflateInit2(&strm, 32 + MAX_WBITS);
199 NSLOG(netsurf, INFO,
"inflateInit returned %d", ret);
204 strm.next_out = s + used;
205 strm.avail_out =
sizeof(s) - used;
207 ret = inflate(&strm, Z_NO_FLUSH);
208 if ((ret != Z_OK) && (ret != Z_STREAM_END)) {
212 used =
sizeof(s) - strm.avail_out;
215 for (nl = &s[0]; nl < &s[used]; nl++) {
220 if (nl == &s[used]) {
233 memmove(&s[0], nl + 1, used - ((nl + 1) - &s[0]) );
234 used -= ((nl +1) - &s[0]);
236 if (used ==
sizeof(s)) {
238 NSLOG(netsurf, INFO,
"Overlength line");
241 }
while (ret != Z_STREAM_END);
245 if (ret != Z_STREAM_END) {
246 NSLOG(netsurf, INFO,
"inflate returned %d", ret);
260 NSLOG(netsurf, INFO,
"Not enough memory for hash table.");
267 if (r->
chain == NULL) {
269 "Not enough memory for %d hash table chains.", chains);
286 for (i = 0; i < ht->
nchains; i++) {
287 if (ht->
chain[i] != NULL) {
306 unsigned int h, c, v;
309 if (ht == NULL || key == NULL || value == NULL)
314 NSLOG(netsurf, INFO,
"Not enough memory for hash entry.");
325 "Not enough memory for string duplication.");
345 if (ht == NULL || key == NULL)
374 fp = gzopen(
path,
"r");
377 "Unable to open file \"%.100s\": %s",
path,
383 while (gzgets(fp, s,
sizeof s)) {
384 int slen = strlen(s);
402 if ((data[0]==0x1f) && (data[1] == 0x8b)) {
nserror
Enumeration of error codes.
@ NSERROR_NOT_FOUND
Requested item not found.
@ NSERROR_BAD_PARAMETER
Bad Parameter.
@ NSERROR_INVALID
Invalid data.
@ NSERROR_NOMEM
Memory exhaustion.
struct hash_table * hash_create(unsigned int chains)
Create a new hash table.
nserror hash_add(struct hash_table *ht, const char *key, const char *value)
Adds a key/value pair to a hash table.
static unsigned int hash_string_fnv(const char *datum, unsigned int *len)
Hash a string, returning a 32bit value.
nserror hash_add_inline(struct hash_table *ht, const uint8_t *data, size_t size)
Add key/value pairs to a hash table with data from a memory buffer.
nserror hash_add_file(struct hash_table *ht, const char *path)
Add key/value pairs to a hash table with data from a file.
static nserror hash_add_inline_plain(struct hash_table *ht, const uint8_t *data, size_t size)
adds key/value pairs to a hash from a memory area
static nserror hash_add_inline_gzip(struct hash_table *ht, const uint8_t *data, size_t size)
adds key/value pairs to a hash from a compressed memory area
static nserror process_line(struct hash_table *hash, uint8_t *ln, int lnlen)
process a line of input.
void hash_destroy(struct hash_table *ht)
Destroys a hash table.
const char * hash_get(struct hash_table *ht, const char *key)
Looks up a the value associated with with a key from a specific hash table.
#define LINE_BUFFER_SIZE
maximum length of line for file or inline add
Interface to Write-Once hash table for string to string mapping.
#define NSLOG(catname, level, logmsg, args...)
Interface to utility string handling.
struct hash_entry * next
next entry
char * pairing
block containing 'key\0value\0'
unsigned int key_length
length of key
struct hash_entry ** chain
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.