From b1317c3e46b02db5cfc50dbbaefdc572907754b2 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Tue, 10 Aug 2021 18:21:01 +0200 Subject: [PATCH] [plain] one level of indentation less --- src/document/plain/renderer.c | 160 +++++++++++++++++----------------- 1 file changed, 79 insertions(+), 81 deletions(-) diff --git a/src/document/plain/renderer.c b/src/document/plain/renderer.c index d3fa98d11..493dbbc51 100644 --- a/src/document/plain/renderer.c +++ b/src/document/plain/renderer.c @@ -857,98 +857,96 @@ fixup_tables(struct plain_renderer *renderer) struct line *next_line = y < renderer->lineno - 1 ? &renderer->document->data[y + 1] : NULL; for (x = 0; x < line->length; x++) { + int dir; #ifdef CONFIG_UTF8 unicode_val_T ch = line->chars[x].data; + unicode_val_T prev_char, next_char, up_char, down_char; #else unsigned char ch = line->chars[x].data; + unsigned char prev_char, next_char, up_char, down_char; #endif - if (ch == '+' || ch == '-' || ch == '|') { - int dir; -#ifdef CONFIG_UTF8 - unicode_val_T prev_char = x > 0 ? line->chars[x - 1].data : ' '; - unicode_val_T next_char = x < line->length - 1 ? line->chars[x + 1].data : ' '; - unicode_val_T up_char = (prev_line && x < prev_line->length) ? prev_line->chars[x].data : ' '; - unicode_val_T down_char = (next_line && x < next_line->length) ? next_line->chars[x].data : ' '; -#else - unsigned char prev_char = x > 0 ? line->chars[x - 1].data : ' '; - unsigned char next_char = x < line->length - 1 ? line->chars[x + 1].data : ' '; - unsigned char up_char = (prev_line && x < prev_line->length) ? prev_line->chars[x].data : ' '; - unsigned char down_char = (next_line && x < next_line->length) ? next_line->chars[x].data : ' '; -#endif - switch (ch) { - case '+': - dir = 0; - if (up_char == '|' || up_char == BORDER_SVLINE) dir |= 1; - if (next_char == '-' || next_char == BORDER_SHLINE) dir |= 2; - if (down_char == '|' || down_char == BORDER_SVLINE) dir |= 4; - if (prev_char == '-' || prev_char == BORDER_SHLINE) dir |= 8; + if (ch != '+' && ch != '-' && ch != '|') { + continue; + } - switch (dir) { - case 15: - line->chars[x].data = BORDER_SCROSS; - line->chars[x].attr = SCREEN_ATTR_FRAME; - break; - case 13: - line->chars[x].data = BORDER_SLTEE; - line->chars[x].attr = SCREEN_ATTR_FRAME; - break; - case 7: - line->chars[x].data = BORDER_SRTEE; - line->chars[x].attr = SCREEN_ATTR_FRAME; - break; - case 6: - line->chars[x].data = BORDER_SULCORNER; - line->chars[x].attr = SCREEN_ATTR_FRAME; - break; - case 12: - line->chars[x].data = BORDER_SURCORNER; - line->chars[x].attr = SCREEN_ATTR_FRAME; - break; - case 3: - line->chars[x].data = BORDER_SDLCORNER; - line->chars[x].attr = SCREEN_ATTR_FRAME; - break; - case 9: - line->chars[x].data = BORDER_SDRCORNER; - line->chars[x].attr = SCREEN_ATTR_FRAME; - break; - case 11: - line->chars[x].data = BORDER_SUTEE; - line->chars[x].attr = SCREEN_ATTR_FRAME; - break; - case 14: - line->chars[x].data = BORDER_SDTEE; - line->chars[x].attr = SCREEN_ATTR_FRAME; - break; - default: - break; - } + prev_char = x > 0 ? line->chars[x - 1].data : ' '; + next_char = x < line->length - 1 ? line->chars[x + 1].data : ' '; + up_char = (prev_line && x < prev_line->length) ? prev_line->chars[x].data : ' '; + down_char = (next_line && x < next_line->length) ? next_line->chars[x].data : ' '; + + switch (ch) { + case '+': + dir = 0; + if (up_char == '|' || up_char == BORDER_SVLINE) dir |= 1; + if (next_char == '-' || next_char == BORDER_SHLINE) dir |= 2; + if (down_char == '|' || down_char == BORDER_SVLINE) dir |= 4; + if (prev_char == '-' || prev_char == BORDER_SHLINE) dir |= 8; + + switch (dir) { + case 15: + line->chars[x].data = BORDER_SCROSS; + line->chars[x].attr = SCREEN_ATTR_FRAME; break; - case '-': - if (prev_char == BORDER_SHLINE || prev_char == BORDER_SCROSS || prev_char == '+' || prev_char == '|' - || prev_char == BORDER_SULCORNER || prev_char == BORDER_SDLCORNER || prev_char == BORDER_SRTEE - || prev_char == BORDER_SUTEE || prev_char == BORDER_SDTEE) { - line->chars[x].data = BORDER_SHLINE; - line->chars[x].attr = SCREEN_ATTR_FRAME; - } + case 13: + line->chars[x].data = BORDER_SLTEE; + line->chars[x].attr = SCREEN_ATTR_FRAME; break; - case '|': - if (up_char == BORDER_SVLINE || up_char == '+' || up_char == '|' || up_char == BORDER_SULCORNER - || up_char == BORDER_SURCORNER || up_char == BORDER_SCROSS || up_char == BORDER_SRTEE || up_char == BORDER_SLTEE - || up_char == BORDER_SDTEE) { - if (next_char == '-') { - line->chars[x].data = BORDER_SRTEE; - } else if (prev_char == BORDER_SHLINE || prev_char == '-') { - line->chars[x].data = BORDER_SLTEE; - } else { - line->chars[x].data = BORDER_SVLINE; - } - line->chars[x].attr = SCREEN_ATTR_FRAME; - } + case 7: + line->chars[x].data = BORDER_SRTEE; + line->chars[x].attr = SCREEN_ATTR_FRAME; + break; + case 6: + line->chars[x].data = BORDER_SULCORNER; + line->chars[x].attr = SCREEN_ATTR_FRAME; + break; + case 12: + line->chars[x].data = BORDER_SURCORNER; + line->chars[x].attr = SCREEN_ATTR_FRAME; + break; + case 3: + line->chars[x].data = BORDER_SDLCORNER; + line->chars[x].attr = SCREEN_ATTR_FRAME; + break; + case 9: + line->chars[x].data = BORDER_SDRCORNER; + line->chars[x].attr = SCREEN_ATTR_FRAME; + break; + case 11: + line->chars[x].data = BORDER_SUTEE; + line->chars[x].attr = SCREEN_ATTR_FRAME; + break; + case 14: + line->chars[x].data = BORDER_SDTEE; + line->chars[x].attr = SCREEN_ATTR_FRAME; break; default: - continue; + break; } + break; + case '-': + if (prev_char == BORDER_SHLINE || prev_char == BORDER_SCROSS || prev_char == '+' || prev_char == '|' + || prev_char == BORDER_SULCORNER || prev_char == BORDER_SDLCORNER || prev_char == BORDER_SRTEE + || prev_char == BORDER_SUTEE || prev_char == BORDER_SDTEE) { + line->chars[x].data = BORDER_SHLINE; + line->chars[x].attr = SCREEN_ATTR_FRAME; + } + break; + case '|': + if (up_char == BORDER_SVLINE || up_char == '+' || up_char == '|' || up_char == BORDER_SULCORNER + || up_char == BORDER_SURCORNER || up_char == BORDER_SCROSS || up_char == BORDER_SRTEE || up_char == BORDER_SLTEE + || up_char == BORDER_SDTEE) { + if (next_char == '-') { + line->chars[x].data = BORDER_SRTEE; + } else if (prev_char == BORDER_SHLINE || prev_char == '-') { + line->chars[x].data = BORDER_SLTEE; + } else { + line->chars[x].data = BORDER_SVLINE; + } + line->chars[x].attr = SCREEN_ATTR_FRAME; + } + break; + default: + continue; } } }