From 74f141ad00fe4aa4791ccbb56397f02b72a80bb5 Mon Sep 17 00:00:00 2001 From: David Griffith Date: Fri, 20 Sep 2019 18:31:57 -0700 Subject: [PATCH] Convert ux_text.c to K&R style. --- src/curses/ux_text.c | 326 +++++++++++++++++++++---------------------- 1 file changed, 160 insertions(+), 166 deletions(-) diff --git a/src/curses/ux_text.c b/src/curses/ux_text.c index f0fb425..c1e02e8 100644 --- a/src/curses/ux_text.c +++ b/src/curses/ux_text.c @@ -16,10 +16,9 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * Or visit http://www.fsf.org/ + * Or visit http://www.fsf.org/ */ - #define __UNIX_PORT_FILE #include @@ -45,12 +44,12 @@ bool color_enabled = FALSE; /* int current_color = 0; */ static char latin1_to_ascii[] = - " ! c L >o> 1/41/23/4? " - "A A A A Ae A AE C E E E E I I I I " - "Th N O O O O Oe * O U U U Ue Y Th ss " - "a a a a ae a ae c e e e e i i i i " - "th n o o o o oe : o u u u ue y th y "; + " ! c L >o> 1/41/23/4? " + "A A A A Ae A AE C E E E E I I I I " + "Th N O O O O Oe * O U U U Ue Y Th ss " + "a a a a ae a ae c e e e e i i i i " + "th n o o o o oe : o u u u ue y th y "; /* @@ -63,18 +62,20 @@ static char latin1_to_ascii[] = * GRAPHICS_FONT * FIXED_WIDTH_FONT * - * The font size should be stored in "height" and "width". If - * the given font is unavailable then these values must _not_ - * be changed. + * The font size should be stored in "height" and "width". + * If the given font is unavailable then these values must + * _not_ be changed. * */ int os_font_data (int font, int *height, int *width) { - if (font == TEXT_FONT) { - *height = 1; *width = 1; return 1; /* Truth in advertising */ - } - return 0; -}/* os_font_data */ + if (font == TEXT_FONT) { + *height = 1; + *width = 1; + return 1; /* Truth in advertising */ + } + return 0; +} /* os_font_data */ #ifdef COLOR_SUPPORT @@ -86,18 +87,18 @@ int os_font_data (int font, int *height, int *width) */ static int unix_convert(int color) { - switch(color) { - case BLACK_COLOUR: return COLOR_BLACK; - case RED_COLOUR: return COLOR_RED; - case GREEN_COLOUR: return COLOR_GREEN; - case YELLOW_COLOUR: return COLOR_YELLOW; - case BLUE_COLOUR: return COLOR_BLUE; - case MAGENTA_COLOUR: return COLOR_MAGENTA; - case CYAN_COLOUR: return COLOR_CYAN; - case WHITE_COLOUR: return COLOR_WHITE; - } - return 0; -} + switch(color) { + case BLACK_COLOUR: return COLOR_BLACK; + case RED_COLOUR: return COLOR_RED; + case GREEN_COLOUR: return COLOR_GREEN; + case YELLOW_COLOUR: return COLOR_YELLOW; + case BLUE_COLOUR: return COLOR_BLUE; + case MAGENTA_COLOUR: return COLOR_MAGENTA; + case CYAN_COLOUR: return COLOR_CYAN; + case WHITE_COLOUR: return COLOR_WHITE; + } + return 0; +} /* unix_convert */ #endif @@ -132,32 +133,32 @@ static int unix_convert(int color) */ void os_set_colour (int new_foreground, int new_background) { - if (new_foreground == 1) new_foreground = h_default_foreground; - if (new_background == 1) new_background = h_default_background; - if (u_setup.color_enabled) { + if (new_foreground == 1) new_foreground = h_default_foreground; + if (new_background == 1) new_background = h_default_background; + if (u_setup.color_enabled) { #ifdef COLOR_SUPPORT - static int colorspace[10][10]; - static int n_colors = 0; - - if (!colorspace[new_foreground][new_background]) { - init_pair(++n_colors, unix_convert(new_foreground), - unix_convert(new_background)); - colorspace[new_foreground][new_background] = n_colors; - } - u_setup.current_color = COLOR_PAIR(colorspace[new_foreground][new_background]); + static int colorspace[10][10]; + static int n_colors = 0; + + if (!colorspace[new_foreground][new_background]) { + init_pair(++n_colors, unix_convert(new_foreground), + unix_convert(new_background)); + colorspace[new_foreground][new_background] = n_colors; + } + u_setup.current_color = COLOR_PAIR(colorspace[new_foreground][new_background]); #endif - } else - u_setup.current_color = (((new_foreground == h_default_background) + } else + u_setup.current_color = (((new_foreground == h_default_background) && (new_background == h_default_foreground)) ? A_REVERSE : 0); - os_set_text_style(u_setup.current_text_style); -}/* os_set_colour */ + os_set_text_style(u_setup.current_text_style); +} /* os_set_colour */ /* * os_set_text_style * - * Set the current text style. Following flags can be set: + * Set the current text style. Following flags can be set: * * REVERSE_STYLE * BOLDFACE_STYLE @@ -167,27 +168,27 @@ void os_set_colour (int new_foreground, int new_background) */ void os_set_text_style (int new_style) { - int temp = 0; + int temp = 0; - u_setup.current_text_style = new_style; - if (new_style & REVERSE_STYLE) temp |= A_REVERSE; - if (new_style & BOLDFACE_STYLE) temp |= A_BOLD; - if (new_style & EMPHASIS_STYLE) temp |= A_UNDERLINE; - attrset(temp ^ u_setup.current_color); -}/* os_set_text_style */ + u_setup.current_text_style = new_style; + if (new_style & REVERSE_STYLE) temp |= A_REVERSE; + if (new_style & BOLDFACE_STYLE) temp |= A_BOLD; + if (new_style & EMPHASIS_STYLE) temp |= A_UNDERLINE; + attrset(temp ^ u_setup.current_color); +} /* os_set_text_style */ /* * os_set_font * - * Set the font for text output. The interpreter takes care not to + * Set the font for text output. The interpreter takes care not to * choose fonts which aren't supported by the interface. * */ void os_set_font (int UNUSED(new_font)) { - /* Not implemented */ -}/* os_set_font */ + /* Not implemented */ +} /* os_set_font */ /* @@ -203,51 +204,49 @@ void os_set_font (int UNUSED(new_font)) */ void os_display_char (zchar c) { - if (c >= ZC_LATIN1_MIN) { - if (u_setup.plain_ascii) { - - char *ptr = latin1_to_ascii + 3 * (c - ZC_LATIN1_MIN); - char c1 = *ptr++; - char c2 = *ptr++; - char c3 = *ptr++; - - addch(c1); - - if (c2 != ' ') - addch(c2); - if (c3 != ' ') - addch(c3); + if (c >= ZC_LATIN1_MIN) { + if (u_setup.plain_ascii) { + char *ptr = latin1_to_ascii + 3 * (c - ZC_LATIN1_MIN); + char c1 = *ptr++; + char c2 = *ptr++; + char c3 = *ptr++; + addch(c1); + + if (c2 != ' ') + addch(c2); + if (c3 != ' ') + addch(c3); #ifndef USE_UTF8 - } else - addch(c); + } else + addch(c); #else - } else { - if(c > 0x7ff) { - addch(0xe0 | ((c >> 12) & 0xf)); - addch(0x80 | ((c >> 6) & 0x3f)); - addch(0x80 | (c & 0x3f)); - } else { - addch(0xc0 | ((c >> 6) & 0x1f)); - addch(0x80 | (c & 0x3f)); - } - } + } else { + if(c > 0x7ff) { + addch(0xe0 | ((c >> 12) & 0xf)); + addch(0x80 | ((c >> 6) & 0x3f)); + addch(0x80 | (c & 0x3f)); + } else { + addch(0xc0 | ((c >> 6) & 0x1f)); + addch(0x80 | (c & 0x3f)); + } + } #endif /* USE_UTF8 */ - return; - } - if (c >= ZC_ASCII_MIN && c <= ZC_ASCII_MAX) { - addch(c); - return; - } - if (c == ZC_INDENT) { - addch(' '); addch(' '); addch(' '); - return; - } - if (c == ZC_GAP) { - addch(' '); addch(' '); - return; - } -}/* os_display_char */ + return; + } + if (c >= ZC_ASCII_MIN && c <= ZC_ASCII_MAX) { + addch(c); + return; + } + if (c == ZC_INDENT) { + addch(' '); addch(' '); addch(' '); + return; + } + if (c == ZC_GAP) { + addch(' '); addch(' '); + return; + } +} /* os_display_char */ /* @@ -258,24 +257,20 @@ void os_display_char (zchar c) */ void os_display_string (const zchar *s) { - zchar c; - - while ((c = *s++) != 0) { - - if (c == ZC_NEW_FONT || c == ZC_NEW_STYLE) { - - int arg = (unsigned char) *s++; - - if (c == ZC_NEW_FONT) - os_set_font (arg); - if (c == ZC_NEW_STYLE) - os_set_text_style (arg); - - } else - os_display_char (c); - } + zchar c; + + while ((c = *s++) != 0) { + if (c == ZC_NEW_FONT || c == ZC_NEW_STYLE) { + int arg = (unsigned char) *s++; + if (c == ZC_NEW_FONT) + os_set_font (arg); + if (c == ZC_NEW_STYLE) + os_set_text_style (arg); + } else + os_display_char (c); + } +} /* os_display_string */ -}/* os_display_string */ /* * os_check_unicode @@ -286,37 +281,37 @@ void os_display_string (const zchar *s) */ int os_check_unicode(int font, zchar c) { -/* Assume full input and output. */ - return 3; + /* Assume full input and output. */ + return 3; } + /* * os_char_width * * Return the width of the character in screen units. * */ -int os_char_width (zchar c) +int os_char_width(zchar c) { - if (c >= ZC_LATIN1_MIN && u_setup.plain_ascii) { - - int width = 0; - const char *ptr = latin1_to_ascii + 3 * (c - ZC_LATIN1_MIN); - char c2, c3; - - ptr++; - c2 = *ptr++; - c3 = *ptr++; - - width++; - if (c2 != ' ') - width++; - if (c3 != ' ') - width++; - return width; - } - return 1; -}/* os_char_width*/ + if (c >= ZC_LATIN1_MIN && u_setup.plain_ascii) { + int width = 0; + const char *ptr = latin1_to_ascii + 3 * (c - ZC_LATIN1_MIN); + char c2, c3; + + ptr++; + c2 = *ptr++; + c3 = *ptr++; + + width++; + if (c2 != ' ') + width++; + if (c3 != ' ') + width++; + return width; + } + return 1; +} /* os_char_width*/ /* @@ -329,21 +324,20 @@ int os_char_width (zchar c) * NEW_FONT - next character is a new font * */ -int os_string_width (const zchar *s) +int os_string_width(const zchar *s) { - int width = 0; - zchar c; - - while ((c = *s++) != 0) { - - if (c == ZC_NEW_STYLE || c == ZC_NEW_FONT) { - s++; - /* No effect */ - } else - width += os_char_width(c); - } - return width; -}/* os_string_width */ + int width = 0; + zchar c; + + while ((c = *s++) != 0) { + if (c == ZC_NEW_STYLE || c == ZC_NEW_FONT) { + s++; + /* No effect */ + } else + width += os_char_width(c); + } + return width; +} /* os_string_width */ /* @@ -352,11 +346,11 @@ int os_string_width (const zchar *s) * Place the text cursor at the given coordinates. Top left is (1,1). * */ -void os_set_cursor (int y, int x) +void os_set_cursor(int y, int x) { - /* Curses thinks the top left is (0,0) */ - move(--y, --x); -}/* os_set_cursor */ + /* Curses thinks the top left is (0,0) */ + move(--y, --x); +} /* os_set_cursor */ /* @@ -366,20 +360,20 @@ void os_set_cursor (int y, int x) * prompt from the screen. * */ -void os_more_prompt (void) +void os_more_prompt(void) { - int saved_style, saved_x, saved_y; + int saved_style, saved_x, saved_y; - /* Save some useful information */ - saved_style = u_setup.current_text_style; - getyx(stdscr, saved_y, saved_x); + /* Save some useful information */ + saved_style = u_setup.current_text_style; + getyx(stdscr, saved_y, saved_x); - os_set_text_style(0); - addstr("[MORE]"); - os_read_key(0, TRUE); + os_set_text_style(0); + addstr("[MORE]"); + os_read_key(0, TRUE); - move(saved_y, saved_x); - addstr(" "); - move(saved_y, saved_x); - os_set_text_style(saved_style); -}/* os_more_prompt */ + move(saved_y, saved_x); + addstr(" "); + move(saved_y, saved_x); + os_set_text_style(saved_style); +} /* os_more_prompt */ -- 2.34.1