-
Notifications
You must be signed in to change notification settings - Fork 25
/
string.c
55 lines (47 loc) · 1.25 KB
/
string.c
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
52
53
54
55
#include <stdio.h>
#include <string.h>
#include "MEM.h"
#include "crowbar.h"
static char *st_string_literal_buffer = NULL;
static int st_string_literal_buffer_size = 0;
static int st_string_literal_buffer_alloc_size = 0;
void
crb_open_string_literal(void)
{
st_string_literal_buffer_size = 0;
}
void
crb_add_string_literal(int letter)
{
if (st_string_literal_buffer_size == st_string_literal_buffer_alloc_size) {
st_string_literal_buffer_alloc_size += STRING_ALLOC_SIZE;
st_string_literal_buffer = MEM_realloc(st_string_literal_buffer,
st_string_literal_buffer_alloc_size);
}
st_string_literal_buffer[st_string_literal_buffer_size] = letter;
st_string_literal_buffer_size++;
}
void
crb_reset_string_literal_buffer()
{
MEM_free(st_string_literal_buffer);
st_string_literal_buffer = NULL;
st_string_literal_buffer_size = 0;
st_string_literal_buffer_alloc_size = 0;
}
char *
crb_close_string_literal(void)
{
char *p = crb_malloc(st_string_literal_buffer_size + 1);
strcpy(p, st_string_literal_buffer, st_string_literal_buffer_size);
p[st_string_literal_buffer_size] = '\0';
return p;
}
char *
crb_create_identifier(char *str)
{
char *new_str;
new_str = crb_malloc(strlen(str) + 1);
strcpy(new_str, str);
return new_str;
}