54#define LINE_BUFFER_SIZE 512
67 unsigned int z = 0x811c9dc5;
68 const char *start = datum;
104 while ((key < value) &&
105 ((*key ==
' ') || (*key ==
'\t'))) {
110 if ((*key == 0) || (*key ==
'#')) {
115 for (colon = key; colon < value; colon++) {
120 if (colon == value) {
128 if (
hash_add(hash, (
char *)key, (
char *)value) ==
false) {
130 "Unable to add %s:%s to hash table", ln, value);
144 unsigned int slen = 0;
150 if (s[slen] ==
'\n') {
159 if (slen >
sizeof s) {
160 NSLOG(netsurf, INFO,
"Overlength line\n");
189 strm.zalloc = Z_NULL;
191 strm.opaque = Z_NULL;
193 strm.next_in = (uint8_t *)data;
194 strm.avail_in = size;
196 ret = inflateInit2(&strm, 32 + MAX_WBITS);
198 NSLOG(netsurf, INFO,
"inflateInit returned %d", ret);
203 strm.next_out = s + used;
204 strm.avail_out =
sizeof(s) - used;
206 ret = inflate(&strm, Z_NO_FLUSH);
207 if ((ret != Z_OK) && (ret != Z_STREAM_END)) {
211 used =
sizeof(s) - strm.avail_out;
214 for (nl = &s[0]; nl < &s[used]; nl++) {
219 if (nl == &s[used]) {
232 memmove(&s[0], nl + 1, used - ((nl + 1) - &s[0]) );
233 used -= ((nl +1) - &s[0]);
235 if (used ==
sizeof(s)) {
237 NSLOG(netsurf, INFO,
"Overlength line");
240 }
while (ret != Z_STREAM_END);
244 if (ret != Z_STREAM_END) {
245 NSLOG(netsurf, INFO,
"inflate returned %d", ret);
259 NSLOG(netsurf, INFO,
"Not enough memory for hash table.");
266 if (r->
chain == NULL) {
268 "Not enough memory for %d hash table chains.", chains);
285 for (i = 0; i < ht->
nchains; i++) {
286 if (ht->
chain[i] != NULL) {
305 unsigned int h, c, v;
308 if (ht == NULL || key == NULL || value == NULL)
313 NSLOG(netsurf, INFO,
"Not enough memory for hash entry.");
324 "Not enough memory for string duplication.");
344 if (ht == NULL || key == NULL)
373 fp = gzopen(
path,
"r");
376 "Unable to open file \"%.100s\": %s",
path,
382 while (gzgets(fp, s,
sizeof s)) {
383 int slen = strlen(s);
401 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.
struct hash_table * hash_create(unsigned int chains)
Create a new hash table.
static unsigned int hash_string_fnv(const char *datum, unsigned int *len)
Hash a string, returning a 32bit value.
bool hash_add(struct hash_table *ht, const char *key, const char *value)
Adds a key/value pair to a hash table.
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.