Debian Codegraph @

texk/xdvipsk/glyphmap.c

raw
1 /* -------------------------------
2 * glyphmap.c
3 * external map file loading functions
4 */
5
6 #ifdef XDVIPSK
7 #include "xdvips.h" /* The copyright notice in that file is included too! */
8 #include "glyphmap.h"
9 /*
10 * The external declarations:
11 */
12 #include "protos_add.h"
13
14 void init_map_buf(char **p_map_buf, char **p_map_buf_ptr, size_t *p_map_buf_len)
15 {
16 assert(p_map_buf);
17 assert(p_map_buf_ptr);
18 assert(p_map_buf_len);
19
20 *p_map_buf_len = MAP_BUFSIZE;
21 *p_map_buf = malloc(*p_map_buf_len);
22 if (!*p_map_buf)
23 error("Out of memory");
24 *p_map_buf_ptr = *p_map_buf;
25 }
26
27 void append_map_buf(char **p_map_buf, char **p_map_buf_ptr, size_t *p_map_buf_len, const char *str)
28 {
29 size_t map_line_len = 0;
30 int cur_g2u_buf_offset = 0;
31
32 assert(p_map_buf);
33 assert(p_map_buf_ptr);
34 assert(p_map_buf_len);
35 assert(str);
36
37 map_line_len = strlen(str);
38 while (*p_map_buf_ptr + map_line_len >= *p_map_buf + *p_map_buf_len - 1)
39 {
40 cur_g2u_buf_offset = *p_map_buf_ptr - *p_map_buf;
41 *p_map_buf_len += MAP_BUFSIZE;
42 *p_map_buf = realloc(*p_map_buf, *p_map_buf_len);
43 if (!*p_map_buf)
44 error("Out of memory");
45 *p_map_buf_ptr = *p_map_buf + cur_g2u_buf_offset;
46 }
47 strcpy(*p_map_buf_ptr, str);
48 *p_map_buf_ptr += map_line_len;
49 }
50 #endif /* XDVIPSK */