From: Michael Göhler Date: Sun, 1 Feb 2015 20:16:05 +0000 (+0100) Subject: renamed text->text to text->value for better distinction X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=faaa6a40adb643fa62ab355b3ab617af1e454fed;p=smdp.git renamed text->text to text->value for better distinction --- diff --git a/include/cstring.h b/include/cstring.h index d74cd80..f9225be 100644 --- a/include/cstring.h +++ b/include/cstring.h @@ -42,7 +42,7 @@ #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); diff --git a/include/url.h b/include/url.h index e48e194..c2c386f 100644 --- a/include/url.h +++ b/include/url.h @@ -39,6 +39,6 @@ int url_get_amount(void); 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 ) diff --git a/src/cstring.c b/src/cstring.c index 1570786..c200572 100644 --- a/src/cstring.c +++ b/src/cstring.c @@ -28,7 +28,7 @@ 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; @@ -45,48 +45,48 @@ cstring_t *cstring_init() { 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); } diff --git a/src/parser.c b/src/parser.c index 4d48e33..59b6b52 100644 --- a/src/parser.c +++ b/src/parser.c @@ -109,7 +109,7 @@ deck_t *markdown_load(FILE *input) { 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 @@ -149,13 +149,13 @@ deck_t *markdown_load(FILE *input) { // 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; } @@ -300,7 +300,7 @@ int markdown_analyse(cstring_t *text, int prev) { 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; } @@ -309,12 +309,12 @@ int markdown_analyse(cstring_t *text, int prev) { 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) { @@ -387,15 +387,15 @@ int markdown_analyse(cstring_t *text, int prev) { } 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 @@ -403,26 +403,26 @@ int markdown_analyse(cstring_t *text, int prev) { 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; @@ -438,8 +438,8 @@ int markdown_analyse(cstring_t *text, int prev) { 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); } @@ -449,9 +449,9 @@ int markdown_analyse(cstring_t *text, int prev) { 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); } @@ -491,12 +491,12 @@ void markdown_debug(deck_t *deck, int debug) { 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; } } @@ -532,7 +532,7 @@ void markdown_debug(deck_t *deck, int debug) { 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 @@ -574,21 +574,21 @@ void adjust_line_length(line_t *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; diff --git a/src/url.c b/src/url.c index a7a5c0c..25c60c3 100644 --- a/src/url.c +++ b/src/url.c @@ -178,9 +178,9 @@ int url_count_inline(const wchar_t *line) { 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 == '\\') { diff --git a/src/viewer.c b/src/viewer.c index 8d97139..bf8af68 100644 --- a/src/viewer.c +++ b/src/viewer.c @@ -92,11 +92,11 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa 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; @@ -268,7 +268,7 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa // add text to header mvwaddwstr(stdscr, 0, (COLS - line->length + offset) / 2, - &line->text->text[offset]); + &line->text->value[offset]); } // setup footer @@ -278,7 +278,7 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa // add text to left footer mvwaddwstr(stdscr, LINES - 1, 3, - &line->text->text[offset]); + &line->text->value[offset]); } // add slide number to right footer @@ -458,7 +458,7 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa 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; } @@ -486,7 +486,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo "%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)) { @@ -505,7 +505,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo "%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)) { @@ -523,7 +523,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo "%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 @@ -537,7 +537,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo 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) && @@ -547,7 +547,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo // 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)); @@ -560,11 +560,11 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo // 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 @@ -586,18 +586,18 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo 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); } } }