refatoring: move init of tty lines drawing onto separate function

Refactoring: transform integer variables into list of integers.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2009-09-04 16:31:38 +03:00 committed by Ilia Maslakov
parent 465d4d2cc5
commit c1c8671370
4 changed files with 73 additions and 92 deletions

View File

@ -551,6 +551,49 @@ setup__move_panels_config_into_separate_file(const char*profile)
}
static int
setup_srt_to_char (char* str)
{
int res = -1;
if (!str)
return (int) ' ';
res = g_utf8_get_char_validated (str, -1);
if ( res < 0 ) {
return (int) *str;
} else {
return res;
}
}
static inline int
setup_load_lines_frm(const char *name)
{
int ret;
char *frm_val = NULL;
frm_val = mc_config_get_string(mc_main_config, "Lines", name, " ");
ret = setup_srt_to_char (frm_val);
g_free (frm_val);
return ret;
}
static void
setup_load_lines_tty(void)
{
mc_tty_ugly_frm[MC_TTY_FRM_horiz] = setup_load_lines_frm("horiz");
mc_tty_ugly_frm[MC_TTY_FRM_vert] = setup_load_lines_frm("vert");
mc_tty_ugly_frm[MC_TTY_FRM_lefttop] = setup_load_lines_frm("lefttop");
mc_tty_ugly_frm[MC_TTY_FRM_righttop] = setup_load_lines_frm("righttop");
mc_tty_ugly_frm[MC_TTY_FRM_leftbottom] = setup_load_lines_frm("leftbottom");
mc_tty_ugly_frm[MC_TTY_FRM_rightbottom] = setup_load_lines_frm("rightbottom");
mc_tty_ugly_frm[MC_TTY_FRM_thinvert] = setup_load_lines_frm("thinvert");
mc_tty_ugly_frm[MC_TTY_FRM_thinhoriz] = setup_load_lines_frm("thinhoriz");
mc_tty_ugly_frm[MC_TTY_FRM_rightmiddle] = setup_load_lines_frm("rightmiddle");
mc_tty_ugly_frm[MC_TTY_FRM_leftmiddle] = setup_load_lines_frm("leftmiddle");
}
char *
setup_init (void)
{
@ -582,29 +625,12 @@ setup_init (void)
return profile;
}
int
setup_srt_to_char (char* str)
{
int res = -1;
if (!str)
return (int) ' ';
res = g_utf8_get_char_validated (str, -1);
if ( res < 0 ) {
return (int) *str;
} else {
return res;
}
}
void
load_setup (void)
{
char *profile;
int i;
char *buffer;
char *frm_val = NULL;
profile = setup_init ();
@ -699,48 +725,8 @@ load_setup (void)
utf8_display = str_isutf8 (get_codepage_id( display_codepage ));
#endif /* HAVE_CHARSET */
if (!mc_args__ugly_line_drawing) {
frm_val = mc_config_get_string(mc_main_config, "Frames", "horiz", " ");
ugly_frm_horiz = setup_srt_to_char (frm_val);
g_free (frm_val);
frm_val = mc_config_get_string(mc_main_config, "Frames", "vert", " ");
ugly_frm_vert = setup_srt_to_char (frm_val);
g_free (frm_val);
frm_val = mc_config_get_string(mc_main_config, "Frames", "lefttop", " ");
ugly_frm_lefttop = setup_srt_to_char (frm_val);
g_free (frm_val);
frm_val = mc_config_get_string(mc_main_config, "Frames", "righttop", " ");
ugly_frm_righttop = setup_srt_to_char (frm_val);
g_free (frm_val);
frm_val = mc_config_get_string(mc_main_config, "Frames", "leftbottom", " ");
ugly_frm_leftbottom = setup_srt_to_char (frm_val);
g_free (frm_val);
frm_val = mc_config_get_string(mc_main_config, "Frames", "rightbottom", " ");
ugly_frm_rightbottom = setup_srt_to_char (frm_val);
g_free (frm_val);
frm_val = mc_config_get_string(mc_main_config, "Frames", "thinvert", " ");
ugly_frm_thinvert = setup_srt_to_char (frm_val);
g_free (frm_val);
frm_val = mc_config_get_string(mc_main_config, "Frames", "thinhoriz", "-");
ugly_frm_thinhoriz = setup_srt_to_char (frm_val);
g_free (frm_val);
frm_val = mc_config_get_string(mc_main_config, "Frames", "rightmiddle", " ");
ugly_frm_rightmiddle = setup_srt_to_char (frm_val);
g_free (frm_val);
frm_val = mc_config_get_string(mc_main_config, "Frames", "leftmiddle", " ");
ugly_frm_leftmiddle = setup_srt_to_char (frm_val);
g_free (frm_val);
}
if (!mc_args__ugly_line_drawing)
setup_load_lines_tty();
}
#if defined(USE_VFS) && defined (USE_NETCODE)

View File

@ -388,7 +388,7 @@ void
tty_draw_hline (int y, int x, int ch, int len)
{
if (ch == ACS_HLINE && (ugly_line_drawing || slow_tty)) {
ch = ugly_frm_thinhoriz;
ch = mc_tty_ugly_frm[MC_TTY_FRM_thinhoriz];
}
if ((y < 0) || (x < 0)) {
@ -475,11 +475,11 @@ void
tty_print_alt_char (int c)
{
if (c == ACS_RTEE && (ugly_line_drawing || slow_tty)) {
c = ugly_frm_rightmiddle;
c = mc_tty_ugly_frm[MC_TTY_FRM_rightmiddle];
}
if (c == ACS_LTEE && (ugly_line_drawing || slow_tty)) {
c = ugly_frm_leftmiddle;
c = mc_tty_ugly_frm[MC_TTY_FRM_leftmiddle];
}
if (ugly_line_drawing || slow_tty) {
tty_print_char (c);

View File

@ -49,16 +49,7 @@ gboolean slow_tty = FALSE;
/* If true use +, -, | for line drawing */
gboolean ugly_line_drawing = FALSE;
int ugly_frm_thinvert = '|';
int ugly_frm_thinhoriz = '-';
int ugly_frm_vert = '|';
int ugly_frm_horiz = '-';
int ugly_frm_lefttop = '+';
int ugly_frm_righttop = '+';
int ugly_frm_leftbottom = '+';
int ugly_frm_rightbottom = '+';
int ugly_frm_leftmiddle = '+';
int ugly_frm_rightmiddle = '+';
int mc_tty_ugly_frm[] = { '|', '-', '|', '-', '+', '+', '+', '+', '+', '+'};
/*** file scope macro definitions **************************************/
@ -133,7 +124,7 @@ void
tty_print_one_hline (void)
{
if (ugly_line_drawing || slow_tty)
tty_print_char (ugly_frm_thinhoriz);
tty_print_char (mc_tty_ugly_frm[MC_TTY_FRM_thinhoriz]);
else
tty_print_alt_char (ACS_HLINE);
}
@ -142,7 +133,7 @@ void
tty_print_one_vline (void)
{
if (ugly_line_drawing || slow_tty)
tty_print_char (ugly_frm_thinvert);
tty_print_char (mc_tty_ugly_frm[MC_TTY_FRM_thinvert]);
else
tty_print_alt_char (ACS_VLINE);
}
@ -150,16 +141,16 @@ tty_print_one_vline (void)
void
tty_draw_box_slow (int y, int x, int ys, int xs)
{
tty_draw_vline (y, x, ugly_frm_vert, ys);
tty_draw_vline (y, x + xs - 1, ugly_frm_vert, ys);
tty_draw_hline (y, x, ugly_frm_horiz, xs);
tty_draw_hline (y + ys - 1, x, ugly_frm_horiz, xs);
tty_draw_vline (y, x, mc_tty_ugly_frm[MC_TTY_FRM_vert], ys);
tty_draw_vline (y, x + xs - 1, mc_tty_ugly_frm[MC_TTY_FRM_vert], ys);
tty_draw_hline (y, x, mc_tty_ugly_frm[MC_TTY_FRM_horiz], xs);
tty_draw_hline (y + ys - 1, x, mc_tty_ugly_frm[MC_TTY_FRM_horiz], xs);
tty_gotoyx (y, x);
tty_print_char (ugly_frm_lefttop);
tty_print_char (mc_tty_ugly_frm[MC_TTY_FRM_lefttop]);
tty_gotoyx (y + ys - 1, x);
tty_print_char (ugly_frm_leftbottom);
tty_print_char (mc_tty_ugly_frm[MC_TTY_FRM_leftbottom]);
tty_gotoyx (y, x + xs - 1);
tty_print_char (ugly_frm_righttop);
tty_print_char (mc_tty_ugly_frm[MC_TTY_FRM_righttop]);
tty_gotoyx (y + ys - 1, x + xs - 1);
tty_print_char (ugly_frm_rightbottom);
tty_print_char (mc_tty_ugly_frm[MC_TTY_FRM_rightbottom]);
}

View File

@ -77,16 +77,20 @@ extern void tty_draw_box (int y, int x, int rows, int cols);
extern void tty_draw_box_slow (int y, int x, int ys, int xs);
extern void tty_fill_region (int y, int x, int rows, int cols, unsigned char ch);
extern int ugly_frm_thinvert;
extern int ugly_frm_thinhoriz;
extern int ugly_frm_vert;
extern int ugly_frm_horiz;
extern int ugly_frm_lefttop;
extern int ugly_frm_righttop;
extern int ugly_frm_leftbottom;
extern int ugly_frm_rightbottom;
extern int ugly_frm_leftmiddle;
extern int ugly_frm_rightmiddle;
extern int mc_tty_ugly_frm[];
typedef enum{
MC_TTY_FRM_thinvert,
MC_TTY_FRM_thinhoriz,
MC_TTY_FRM_vert,
MC_TTY_FRM_horiz,
MC_TTY_FRM_lefttop,
MC_TTY_FRM_righttop,
MC_TTY_FRM_leftbottom,
MC_TTY_FRM_rightbottom,
MC_TTY_FRM_leftmiddle,
MC_TTY_FRM_rightmiddle
} mc_tty_frm_t;
extern char *tty_tgetstr (const char *name);