#define REALLOC_ADD 10
typedef struct _cstring_t {
- wchar_t *text;
+ wchar_t *value;
size_t size;
size_t alloc;
void (*expand)(struct _cstring_t *self, wchar_t x);
void url_purge(void);
void url_dump(void);
int url_count_inline(const wchar_t *line);
-int url_len_inline(const wchar_t *text);
+int url_len_inline(const wchar_t *value);
#endif // !defined( URL_H )
cstring_t *cstring_init() {
cstring_t *x = NULL;
if((x = malloc(sizeof(cstring_t))) != NULL) {
- x->text = NULL;
+ x->value = NULL;
x->size = x->alloc = 0;
x->expand = cstring_expand;
x->expand_arr = cstring_expand_arr;
void cstring_expand(cstring_t *self, wchar_t x) {
if((self->size + 2) * sizeof(wchar_t) > self->alloc) {
self->alloc += (REALLOC_ADD * sizeof(wchar_t));
- if((self->text = realloc(self->text, self->alloc)) == NULL) {
+ if((self->value = realloc(self->value, self->alloc)) == NULL) {
fprintf(stderr, "%s\n", "cstring_expand() failed to reallocate memory.");
exit(EXIT_FAILURE);
}
}
- self->text[self->size] = x;
- self->text[self->size+1] = L'\0';
- self->size = wcslen(self->text);
+ self->value[self->size] = x;
+ self->value[self->size+1] = L'\0';
+ self->size = wcslen(self->value);
}
void cstring_expand_arr(cstring_t *self, wchar_t *x) {
if((self->size + wcslen(x) + 1) * sizeof(wchar_t) > self->alloc) {
self->alloc = ((self->size + wcslen(x) + 1) * sizeof(wchar_t));
- if((self->text = realloc(self->text, self->alloc)) == NULL) {
+ if((self->value = realloc(self->value, self->alloc)) == NULL) {
fprintf(stderr, "%s\n", "cstring_expand_arr() failed to reallocate memory.");
exit(EXIT_FAILURE);
}
}
- self->text = wcscat(self->text, x);
- self->size = wcslen(self->text);
- self->text[self->size+1] = L'\0';
+ self->value = wcscat(self->value, x);
+ self->size = wcslen(self->value);
+ self->value[self->size+1] = L'\0';
}
void cstring_strip(cstring_t *self, int pos, int len) {
if(pos + len >= self->size) {
if(pos <= self->size) {
- self->text[pos] = L'\0';
+ self->value[pos] = L'\0';
self->size = pos;
}
return;
}
- wmemmove(&self->text[pos], &self->text[pos+len], self->size - pos - len+1);
+ wmemmove(&self->value[pos], &self->value[pos+len], self->size - pos - len+1);
self->size -= len;
}
void cstring_reset(cstring_t *self) {
- free(self->text);
- self->text = NULL;
+ free(self->value);
+ self->value = NULL;
self->size = self->alloc = 0;
}
void cstring_delete(cstring_t *self) {
- free(self->text);
+ free(self->value);
free(self);
}
line->offset = next_nonblank(text, 0);
// adjust line length dynamicaly - excluding markup
- if(line->text->text)
+ if(line->text->value)
adjust_line_length(line);
// new text
// detect header
line = deck->slide->line;
- if(line && line->text->size > 0 && line->text->text[0] == L'%') {
+ if(line && line->text->size > 0 && line->text->value[0] == L'%') {
// assign header to deck
deck->header = line;
// find first non-header line
- while(line && line->text->size > 0 && line->text->text[0] == L'%') {
+ while(line && line->text->size > 0 && line->text->value[0] == L'%') {
hc++;
line = line->next;
}
const int unordered_list_offset = unordered_list_level_offset[unordered_list_level];
// return IS_EMPTY on null pointers
- if(!text || !text->text) {
+ if(!text || !text->value) {
SET_BIT(bits, IS_EMPTY);
return bits;
}
offset = next_nonblank(text, 0);
// strip trailing spaces
- for(eol = text->size; eol > offset && iswspace(text->text[eol - 1]); eol--);
+ for(eol = text->size; eol > offset && iswspace(text->value[eol - 1]); eol--);
// IS_UNORDERED_LIST_#
if(text->size >= offset + 2 &&
- (text->text[offset] == L'*' || text->text[offset] == L'-') &&
- iswspace(text->text[offset + 1])) {
+ (text->value[offset] == L'*' || text->value[offset] == L'-') &&
+ iswspace(text->value[offset + 1])) {
// if different from last lines offset
if(offset != unordered_list_offset) {
} else {
// IS_QUOTE
- if(text->text[offset] == L'>') {
+ if(text->value[offset] == L'>') {
SET_BIT(bits, IS_QUOTE);
}
// IS_CENTER
if(text->size >= offset + 3 &&
- text->text[offset] == L'-' &&
- text->text[offset + 1] == L'>' &&
- iswspace(text->text[offset + 2])) {
+ text->value[offset] == L'-' &&
+ text->value[offset + 1] == L'>' &&
+ iswspace(text->value[offset + 2])) {
SET_BIT(bits, IS_CENTER);
// remove start tag
eol -= 3;
if(text->size >= offset + 3 &&
- text->text[eol - 1] == L'-' &&
- text->text[eol - 2] == L'<' &&
- iswspace(text->text[eol - 3])) {
+ text->value[eol - 1] == L'-' &&
+ text->value[eol - 2] == L'<' &&
+ iswspace(text->value[eol - 3])) {
// remove end tags
(text->strip)(text, eol - 3, 3);
// adjust end of line
- for(eol = text->size; eol > offset && iswspace(text->text[eol - 1]); eol--);
+ for(eol = text->size; eol > offset && iswspace(text->value[eol - 1]); eol--);
}
}
for(i = offset; i < eol; i++) {
- if(iswspace(text->text[i])) {
+ if(iswspace(text->value[i])) {
spaces++;
} else {
- switch(text->text[i]) {
+ switch(text->value[i]) {
case L'=': equals++; break;
case L'#': hashes++; break;
case L'*': stars++; break;
hashes + stars + minus + spaces + other == 0) {
SET_BIT(bits, IS_H1);
}
- if(text->text[offset] == L'#' &&
- iswspace(text->text[offset+1])) {
+ if(text->value[offset] == L'#' &&
+ iswspace(text->value[offset+1])) {
SET_BIT(bits, IS_H1);
SET_BIT(bits, IS_H1_ATX);
}
equals + hashes + stars + spaces + other == 0) {
SET_BIT(bits, IS_H2);
}
- if(text->text[offset] == L'#' &&
- text->text[offset+1] == L'#' &&
- iswspace(text->text[offset+2])) {
+ if(text->value[offset] == L'#' &&
+ text->value[offset+1] == L'#' &&
+ iswspace(text->value[offset+2])) {
SET_BIT(bits, IS_H2);
SET_BIT(bits, IS_H2_ATX);
}
header = deck->header;
while(header &&
header->length > 0 &&
- header->text->text[0] == L'%') {
+ header->text->value[0] == L'%') {
// skip descriptor word (e.g. %title:)
offset = next_blank(header->text, 0) + 1;
- fwprintf(stderr, L"header: %S\n", &header->text->text[offset]);
+ fwprintf(stderr, L"header: %S\n", &header->text->value[offset]);
header = header->next;
}
}
void adjust_line_length(line_t *line) {
int l = 0;
const static wchar_t *special = L"\\*_`"; // list of interpreted chars
- const wchar_t *c = &line->text->text[line->offset];
+ const wchar_t *c = &line->text->value[line->offset];
cstack_t *stack = cstack_init();
// for each char in line
}
int next_nonblank(cstring_t *text, int i) {
- while ((i < text->size) && iswspace((text->text)[i]))
+ while ((i < text->size) && iswspace((text->value)[i]))
i++;
return i;
}
int prev_blank(cstring_t *text, int i) {
- while ((i > 0) && !iswspace((text->text)[i]))
+ while ((i > 0) && !iswspace((text->value)[i]))
i--;
return i;
}
int next_blank(cstring_t *text, int i) {
- while ((i < text->size) && !iswspace((text->text)[i]))
+ while ((i < text->size) && !iswspace((text->value)[i]))
i++;
return i;
return count;
}
-int url_len_inline(const wchar_t *text) {
+int url_len_inline(const wchar_t *value) {
int count = 0;
- const wchar_t *i = text;
+ const wchar_t *i = value;
for (; *i; i++) {
if (*i == '\\') {
while(line && line->text) {
- if (line->text->text)
- lc += url_count_inline(line->text->text);
+ if (line->text->value)
+ lc += url_count_inline(line->text->value);
- if (line->text->text)
- line->length -= url_len_inline(line->text->text);
+ if (line->text->value)
+ line->length -= url_len_inline(line->text->value);
if(line->length > COLS) {
i = line->length;
// add text to header
mvwaddwstr(stdscr,
0, (COLS - line->length + offset) / 2,
- &line->text->text[offset]);
+ &line->text->value[offset]);
}
// setup footer
// add text to left footer
mvwaddwstr(stdscr,
LINES - 1, 3,
- &line->text->text[offset]);
+ &line->text->value[offset]);
}
// add slide number to right footer
void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors) {
- if(!line->text->text) {
+ if(!line->text->value) {
return;
}
"%s", prompt);
if(!CHECK_BIT(line->bits, IS_CODE))
- inline_display(window, &line->text->text[offset], colors);
+ inline_display(window, &line->text->value[offset], colors);
// IS_UNORDERED_LIST_2
} else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_2)) {
"%s", prompt);
if(!CHECK_BIT(line->bits, IS_CODE))
- inline_display(window, &line->text->text[offset], colors);
+ inline_display(window, &line->text->value[offset], colors);
// IS_UNORDERED_LIST_1
} else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)) {
"%s", prompt);
if(!CHECK_BIT(line->bits, IS_CODE))
- inline_display(window, &line->text->text[offset], colors);
+ inline_display(window, &line->text->value[offset], colors);
}
// IS_CODE
wattron(window, COLOR_PAIR(CP_BLACK));
// print whole lines
- waddwstr(window, &line->text->text[offset]);
+ waddwstr(window, &line->text->value[offset]);
}
if(!CHECK_BIT(line->bits, IS_UNORDERED_LIST_1) &&
// IS_QUOTE
if(CHECK_BIT(line->bits, IS_QUOTE)) {
- while(line->text->text[offset] == '>') {
+ while(line->text->value[offset] == '>') {
// print a reverse color block
if(colors) {
wattron(window, COLOR_PAIR(CP_BLACK));
// find next quote or break
offset++;
- if(line->text->text[offset] == ' ')
+ if(line->text->value[offset] == ' ')
offset = next_word(line->text, offset);
}
- inline_display(window, &line->text->text[offset], colors);
+ inline_display(window, &line->text->value[offset], colors);
} else {
// IS_CENTER
wattron(window, A_UNDERLINE);
// skip hashes
- while(line->text->text[offset] == '#')
+ while(line->text->value[offset] == '#')
offset = next_word(line->text, offset);
// print whole lines
- waddwstr(window, &line->text->text[offset]);
+ waddwstr(window, &line->text->value[offset]);
wattroff(window, A_UNDERLINE);
// no line-wide markdown
} else {
- inline_display(window, &line->text->text[offset], colors);
+ inline_display(window, &line->text->value[offset], colors);
}
}
}