/* * Add text to text box */ static void l_add_text(struct tbox *tb, const char *str) { char *line, *line_end, *str_cpy; str_cpy = line_end = ht_strdup(str); for (line = str_cpy; line_end != NULL; line = line_end + 1) { line_end = strchr(line, '\n'); if (line_end) *line_end = 0; tbox_line_add(tb, line); } ht_free(str_cpy); }
int ht_set(void *base, va_ht_hash_t va_ht, const char *key, const char *value, lmc_error_t *e) { ht_hash_t *ht = base + va_ht; ht_hash_entry_t *hr = ht_lookup(base, va_ht, key); unsigned v; if (hr->va_key == 0) { va_ht_hash_entry_t va = lmc_valloc(base, sizeof(ht_hash_entry_t)); hr = va ? base + va : 0; if (hr == NULL || (hr->va_key = ht_strdup(base, key)) == 0) { lmc_handle_error_with_err_string("ht_set", "memory pool full", e); return 0; } v = ht_hash_key(key); hr->va_next = ht->va_buckets[v]; ht->va_buckets[v] = va; } else { lmc_free(base, hr->va_value); } if ((hr->va_value = ht_strdup(base, value)) == 0) { lmc_handle_error_with_err_string("ht_set", "memory pool full", e); return 0; } return 1; }