~sircmpwn/scdoc

e2794c96be81352d2af6c6648b7ee208d298b7fb — Drew DeVault 7 months ago c95b3ef
Replace str_t with struct str
3 files changed, 15 insertions(+), 17 deletions(-)

M include/str.h
M src/main.c
M src/string.c
M include/str.h => include/str.h +4 -6
@@ 7,11 7,9 @@ struct str {
	size_t len, size;
};

typedef struct str str_t;

str_t *str_create();
void str_free(str_t *str);
void str_reset(str_t *str);
int str_append_ch(str_t *str, uint32_t ch);
struct str *str_create();
void str_free(struct str *str);
void str_reset(struct str *str);
int str_append_ch(struct str *str, uint32_t ch);

#endif

M src/main.c => src/main.c +6 -6
@@ 17,7 17,7 @@ char *strstr(const char *haystack, const char *needle);
char *strerror(int errnum);

static int parse_section(struct parser *p) {
	str_t *section = str_create();
	struct str *section = str_create();
	uint32_t ch;
	while ((ch = parser_getch(p)) != UTF8_INVALID) {
		if (ch < 0x80 && isdigit(ch)) {


@@ 43,8 43,8 @@ static int parse_section(struct parser *p) {
	return -1;
}

static str_t *parse_extra(struct parser *p) {
	str_t *extra = str_create();
static struct str *parse_extra(struct parser *p) {
	struct str *extra = str_create();
	int ret = str_append_ch(extra, '"');
	assert(ret != -1);
	uint32_t ch;


@@ 66,9 66,9 @@ static str_t *parse_extra(struct parser *p) {
}

static void parse_preamble(struct parser *p) {
	str_t *name = str_create();
	struct str *name = str_create();
	int ex = 0;
	str_t *extras[2] = { NULL };
	struct str *extras[2] = { NULL };
	int section = -1;
	uint32_t ch;
	time_t date_time;


@@ 446,7 446,7 @@ struct table_row {

struct table_cell {
	enum table_align align;
	str_t *contents;
	struct str *contents;
	struct table_cell *next;
};


M src/string.c => src/string.c +5 -5
@@ 3,7 3,7 @@
#include "str.h"
#include "unicode.h"

static int ensure_capacity(str_t *str, size_t len) {
static int ensure_capacity(struct str *str, size_t len) {
	if (len + 1 >= str->size) {
		char *new = realloc(str->str, str->size * 2);
		if (!new) {


@@ 15,8 15,8 @@ static int ensure_capacity(str_t *str, size_t len) {
	return 1;
}

str_t *str_create() {
	str_t *str = calloc(sizeof(str_t), 1);
struct str *str_create() {
	struct str *str = calloc(sizeof(struct str), 1);
	str->str = malloc(16);
	str->size = 16;
	str->len = 0;


@@ 24,13 24,13 @@ str_t *str_create() {
	return str;
}

void str_free(str_t *str) {
void str_free(struct str *str) {
	if (!str) return;
	free(str->str);
	free(str);
}

int str_append_ch(str_t *str, uint32_t ch) {
int str_append_ch(struct str *str, uint32_t ch) {
	int size = utf8_chsize(ch);
	if (size <= 0) {
		return -1;