Blame utf8trans/strings_buffer.h

Packit e4b6da
/*
Packit e4b6da
 * strings_buffer.h
Packit e4b6da
 *
Packit e4b6da
 * This module implements a packed storage area for
Packit e4b6da
 * null-terminated constant strings.  It is efficient for 
Packit e4b6da
 * making tables of many strings of small length.
Packit e4b6da
 * In utf8trans, we use this for the strings
Packit e4b6da
 * in the Unicode translation table.
Packit e4b6da
 * 
Packit e4b6da
 * Initially, we allocate a large buffer.  As more
Packit e4b6da
 * and more strings are stored, they fill up
Packit e4b6da
 * the buffer, and when the buffer is (nearly) full,
Packit e4b6da
 * new buffers are allocated automatically to store
Packit e4b6da
 * new strings.
Packit e4b6da
 */
Packit e4b6da
Packit e4b6da
#ifndef STRINGS_BUFFER_H
Packit e4b6da
#define STRINGS_BUFFER_H
Packit e4b6da
Packit e4b6da
#include <stdlib.h>
Packit e4b6da
Packit e4b6da
struct strings_section
Packit e4b6da
{
Packit e4b6da
    size_t cur_size;
Packit e4b6da
    size_t size;
Packit e4b6da
    char *cur;
Packit e4b6da
    char *start;
Packit e4b6da
    struct strings_section *next;
Packit e4b6da
};
Packit e4b6da
Packit e4b6da
typedef struct strings_section *strings_buffer_t;
Packit e4b6da
Packit e4b6da
/*
Packit e4b6da
 * Makes a strings buffer.  size is the initial
Packit e4b6da
 * buffer size in bytes.
Packit e4b6da
 */
Packit e4b6da
strings_buffer_t strings_buffer_new(size_t size);
Packit e4b6da
Packit e4b6da
/*
Packit e4b6da
 * Deallocates a strings buffer.  The strings
Packit e4b6da
 * stored inside are all destroyed at once.
Packit e4b6da
 */
Packit e4b6da
void strings_buffer_delete(strings_buffer_t ss);
Packit e4b6da
Packit e4b6da
/*
Packit e4b6da
 * Copies the null-terminated string s into the strings 
Packit e4b6da
 * buffer, and returns its address inside the buffer.
Packit e4b6da
 */
Packit e4b6da
char *strings_buffer_add(strings_buffer_t *ss, const char *s);
Packit e4b6da
Packit e4b6da
#endif  /* !defined(STRINGS_BUFFER_H) */