File: strings_buffer.h

package info (click to toggle)
docbook2x 0.8.8-15
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 4,720 kB
  • ctags: 389
  • sloc: xml: 16,229; sh: 3,674; perl: 3,461; ansic: 639; makefile: 409; sed: 11
file content (51 lines) | stat: -rw-r--r-- 1,252 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * strings_buffer.h
 *
 * This module implements a packed storage area for
 * null-terminated constant strings.  It is efficient for 
 * making tables of many strings of small length.
 * In utf8trans, we use this for the strings
 * in the Unicode translation table.
 * 
 * Initially, we allocate a large buffer.  As more
 * and more strings are stored, they fill up
 * the buffer, and when the buffer is (nearly) full,
 * new buffers are allocated automatically to store
 * new strings.
 */

#ifndef STRINGS_BUFFER_H
#define STRINGS_BUFFER_H

#include <stdlib.h>

struct strings_section
{
    size_t cur_size;
    size_t size;
    char *cur;
    char *start;
    struct strings_section *next;
};

typedef struct strings_section *strings_buffer_t;

/*
 * Makes a strings buffer.  size is the initial
 * buffer size in bytes.
 */
strings_buffer_t strings_buffer_new(size_t size);

/*
 * Deallocates a strings buffer.  The strings
 * stored inside are all destroyed at once.
 */
void strings_buffer_delete(strings_buffer_t ss);

/*
 * Copies the null-terminated string s into the strings 
 * buffer, and returns its address inside the buffer.
 */
char *strings_buffer_add(strings_buffer_t *ss, const char *s);

#endif  /* !defined(STRINGS_BUFFER_H) */