[R] Refactoring of setting style
This commit is contained in:
145
src/fort.c
145
src/fort.c
@@ -665,120 +665,69 @@ int ft_add_separator(FTABLE *table)
|
||||
|
||||
/* ******************************************************************************* */
|
||||
|
||||
struct ft_border_style ft_basic_style =
|
||||
{
|
||||
{
|
||||
'-', /* top_border_ch */
|
||||
'\0', /* separator_ch */
|
||||
'-', /* bottom_border_ch */
|
||||
'|', /* side_border_ch */
|
||||
'+', /* out_intersect_ch */
|
||||
'\0', /* in_intersect_ch */
|
||||
},
|
||||
{
|
||||
'-', /* top_border_ch */
|
||||
'-', /* separator_ch */
|
||||
'-', /* bottom_border_ch */
|
||||
'|', /* side_border_ch */
|
||||
'+', /* out_intersect_ch */
|
||||
'+', /* in_intersect_ch */
|
||||
}
|
||||
};
|
||||
|
||||
//struct ft_border_style ft_simple_style =
|
||||
//{
|
||||
// {
|
||||
// ' ', /* top_border_ch */
|
||||
// '\0', /* separator_ch */
|
||||
// ' ', /* bottom_border_ch */
|
||||
// ' ', /* side_border_ch */
|
||||
// ' ', /* out_intersect_ch */
|
||||
// '\0', /* in_intersect_ch */
|
||||
// },
|
||||
// {
|
||||
// ' ', /* top_border_ch */
|
||||
// '-', /* separator_ch */
|
||||
// ' ', /* bottom_border_ch */
|
||||
// ' ', /* side_border_ch */
|
||||
// ' ', /* out_intersect_ch */
|
||||
// ' ', /* in_intersect_ch */
|
||||
// }
|
||||
//};
|
||||
|
||||
//struct ft_border_style ft_dot_style =
|
||||
//{
|
||||
// {
|
||||
// '.', /* top_border_ch */
|
||||
// '\0', /* separator_ch */
|
||||
// '.', /* bottom_border_ch */
|
||||
// ':', /* side_border_ch */
|
||||
// '.', /* out_intersect_ch */
|
||||
// '\0', /* in_intersect_ch */
|
||||
// },
|
||||
// {
|
||||
// '.', /* top_border_ch */
|
||||
// '.', /* separator_ch */
|
||||
// '.', /* bottom_border_ch */
|
||||
// ':', /* side_border_ch */
|
||||
// '.', /* out_intersect_ch */
|
||||
// '.', /* in_intersect_ch */
|
||||
// }
|
||||
//};
|
||||
|
||||
struct ft_border_style * FT_BASIC_STYLE = &ft_basic_style;
|
||||
//struct ft_border_style * FT_SIMPLE_STYLE = &ft_simple_style;
|
||||
//struct ft_border_style * FT_DOT_STYLE = &ft_dot_style;
|
||||
struct ft_border_style * FT_BASIC_STYLE = (struct ft_border_style *)&FORT_BASIC_STYLE;
|
||||
struct ft_border_style * FT_SIMPLE_STYLE = (struct ft_border_style *)&FORT_SIMPLE_STYLE;
|
||||
struct ft_border_style * FT_DOT_STYLE = (struct ft_border_style *)&FORT_DOT_STYLE;
|
||||
|
||||
|
||||
|
||||
static void set_border_options_for_options(fort_table_options_t *options, struct ft_border_style *style)
|
||||
{
|
||||
struct ft_border_chars *border_chs = &(style->border_chs);
|
||||
struct ft_border_chars *header_border_chs = &(style->header_border_chs);
|
||||
if ((struct fort_border_style *)style == &FORT_BASIC_STYLE
|
||||
|| (struct fort_border_style *)style == &FORT_SIMPLE_STYLE
|
||||
|| (struct fort_border_style *)style == &FORT_DOT_STYLE)
|
||||
{
|
||||
memcpy(&(options->border_style), (struct fort_border_style *)style, sizeof(struct fort_border_style));
|
||||
return;
|
||||
}
|
||||
|
||||
#define BOR_CHARS options->border_chars
|
||||
#define H_BOR_CHARS options->header_border_chars
|
||||
struct ft_border_chars *border_chs = &(style->border_chs);
|
||||
struct ft_border_chars *header_border_chs = &(style->header_border_chs);
|
||||
|
||||
/*
|
||||
BOR_CHARS[TL_bip] = BOR_CHARS[TT_bip] = BOR_CHARS[TV_bip] = BOR_CHARS[TR_bip] = border_chs->top_border_ch;
|
||||
BOR_CHARS[LH_bip] = BOR_CHARS[IH_bip] = BOR_CHARS[II_bip] = BOR_CHARS[RH_bip] = border_chs->separator_ch;
|
||||
BOR_CHARS[BL_bip] = BOR_CHARS[BB_bip] = BOR_CHARS[BV_bip] = BOR_CHARS[BR_bip] = border_chs->bottom_border_ch;
|
||||
BOR_CHARS[LL_bip] = BOR_CHARS[IV_bip] = BOR_CHARS[RR_bip] = border_chs->side_border_ch;
|
||||
#define BOR_CHARS options->border_style.border_chars
|
||||
#define H_BOR_CHARS options->border_style.header_border_chars
|
||||
|
||||
H_BOR_CHARS[TL_bip] = H_BOR_CHARS[TT_bip] = H_BOR_CHARS[TV_bip] = H_BOR_CHARS[TR_bip] = header_border_chs->top_border_ch;
|
||||
H_BOR_CHARS[LH_bip] = H_BOR_CHARS[IH_bip] = H_BOR_CHARS[II_bip] = H_BOR_CHARS[RH_bip] = header_border_chs->separator_ch;
|
||||
H_BOR_CHARS[BL_bip] = H_BOR_CHARS[BB_bip] = H_BOR_CHARS[BV_bip] = H_BOR_CHARS[BR_bip] = header_border_chs->bottom_border_ch;
|
||||
H_BOR_CHARS[LL_bip] = H_BOR_CHARS[IV_bip] = H_BOR_CHARS[RR_bip] = header_border_chs->side_border_ch;
|
||||
*/
|
||||
/*
|
||||
BOR_CHARS[TL_bip] = BOR_CHARS[TT_bip] = BOR_CHARS[TV_bip] = BOR_CHARS[TR_bip] = border_chs->top_border_ch;
|
||||
BOR_CHARS[LH_bip] = BOR_CHARS[IH_bip] = BOR_CHARS[II_bip] = BOR_CHARS[RH_bip] = border_chs->separator_ch;
|
||||
BOR_CHARS[BL_bip] = BOR_CHARS[BB_bip] = BOR_CHARS[BV_bip] = BOR_CHARS[BR_bip] = border_chs->bottom_border_ch;
|
||||
BOR_CHARS[LL_bip] = BOR_CHARS[IV_bip] = BOR_CHARS[RR_bip] = border_chs->side_border_ch;
|
||||
|
||||
BOR_CHARS[TT_bip] = border_chs->top_border_ch;
|
||||
BOR_CHARS[IH_bip] = border_chs->separator_ch;
|
||||
BOR_CHARS[BB_bip] = border_chs->bottom_border_ch;
|
||||
BOR_CHARS[LL_bip] = BOR_CHARS[IV_bip] = BOR_CHARS[RR_bip] = border_chs->side_border_ch;
|
||||
H_BOR_CHARS[TL_bip] = H_BOR_CHARS[TT_bip] = H_BOR_CHARS[TV_bip] = H_BOR_CHARS[TR_bip] = header_border_chs->top_border_ch;
|
||||
H_BOR_CHARS[LH_bip] = H_BOR_CHARS[IH_bip] = H_BOR_CHARS[II_bip] = H_BOR_CHARS[RH_bip] = header_border_chs->separator_ch;
|
||||
H_BOR_CHARS[BL_bip] = H_BOR_CHARS[BB_bip] = H_BOR_CHARS[BV_bip] = H_BOR_CHARS[BR_bip] = header_border_chs->bottom_border_ch;
|
||||
H_BOR_CHARS[LL_bip] = H_BOR_CHARS[IV_bip] = H_BOR_CHARS[RR_bip] = header_border_chs->side_border_ch;
|
||||
*/
|
||||
|
||||
BOR_CHARS[TL_bip] = BOR_CHARS[TV_bip] = BOR_CHARS[TR_bip] = border_chs->out_intersect_ch;
|
||||
BOR_CHARS[LH_bip] = BOR_CHARS[RH_bip] = border_chs->out_intersect_ch;
|
||||
BOR_CHARS[BL_bip] = BOR_CHARS[BV_bip] = BOR_CHARS[BR_bip] = border_chs->out_intersect_ch;
|
||||
BOR_CHARS[II_bip] = border_chs->in_intersect_ch;
|
||||
BOR_CHARS[TT_bip] = border_chs->top_border_ch;
|
||||
BOR_CHARS[IH_bip] = border_chs->separator_ch;
|
||||
BOR_CHARS[BB_bip] = border_chs->bottom_border_ch;
|
||||
BOR_CHARS[LL_bip] = BOR_CHARS[IV_bip] = BOR_CHARS[RR_bip] = border_chs->side_border_ch;
|
||||
|
||||
if (border_chs->separator_ch == '\0' && border_chs->in_intersect_ch == '\0') {
|
||||
BOR_CHARS[LH_bip] = BOR_CHARS[RH_bip] = '\0';
|
||||
}
|
||||
BOR_CHARS[TL_bip] = BOR_CHARS[TV_bip] = BOR_CHARS[TR_bip] = border_chs->out_intersect_ch;
|
||||
BOR_CHARS[LH_bip] = BOR_CHARS[RH_bip] = border_chs->out_intersect_ch;
|
||||
BOR_CHARS[BL_bip] = BOR_CHARS[BV_bip] = BOR_CHARS[BR_bip] = border_chs->out_intersect_ch;
|
||||
BOR_CHARS[II_bip] = border_chs->in_intersect_ch;
|
||||
|
||||
if (border_chs->separator_ch == '\0' && border_chs->in_intersect_ch == '\0') {
|
||||
BOR_CHARS[LH_bip] = BOR_CHARS[RH_bip] = '\0';
|
||||
}
|
||||
|
||||
|
||||
H_BOR_CHARS[TT_bip] = header_border_chs->top_border_ch;
|
||||
H_BOR_CHARS[IH_bip] = header_border_chs->separator_ch;
|
||||
H_BOR_CHARS[BB_bip] = header_border_chs->bottom_border_ch;
|
||||
H_BOR_CHARS[LL_bip] = H_BOR_CHARS[IV_bip] = H_BOR_CHARS[RR_bip] = header_border_chs->side_border_ch;
|
||||
H_BOR_CHARS[TT_bip] = header_border_chs->top_border_ch;
|
||||
H_BOR_CHARS[IH_bip] = header_border_chs->separator_ch;
|
||||
H_BOR_CHARS[BB_bip] = header_border_chs->bottom_border_ch;
|
||||
H_BOR_CHARS[LL_bip] = H_BOR_CHARS[IV_bip] = H_BOR_CHARS[RR_bip] = header_border_chs->side_border_ch;
|
||||
|
||||
H_BOR_CHARS[TL_bip] = H_BOR_CHARS[TV_bip] = H_BOR_CHARS[TR_bip] = header_border_chs->out_intersect_ch;
|
||||
H_BOR_CHARS[LH_bip] = H_BOR_CHARS[RH_bip] = header_border_chs->out_intersect_ch;
|
||||
H_BOR_CHARS[BL_bip] = H_BOR_CHARS[BV_bip] = H_BOR_CHARS[BR_bip] = header_border_chs->out_intersect_ch;
|
||||
H_BOR_CHARS[II_bip] = header_border_chs->in_intersect_ch;
|
||||
H_BOR_CHARS[TL_bip] = H_BOR_CHARS[TV_bip] = H_BOR_CHARS[TR_bip] = header_border_chs->out_intersect_ch;
|
||||
H_BOR_CHARS[LH_bip] = H_BOR_CHARS[RH_bip] = header_border_chs->out_intersect_ch;
|
||||
H_BOR_CHARS[BL_bip] = H_BOR_CHARS[BV_bip] = H_BOR_CHARS[BR_bip] = header_border_chs->out_intersect_ch;
|
||||
H_BOR_CHARS[II_bip] = header_border_chs->in_intersect_ch;
|
||||
|
||||
if (header_border_chs->separator_ch == '\0' && header_border_chs->in_intersect_ch == '\0') {
|
||||
H_BOR_CHARS[LH_bip] = H_BOR_CHARS[RH_bip] = '\0';
|
||||
}
|
||||
if (header_border_chs->separator_ch == '\0' && header_border_chs->in_intersect_ch == '\0') {
|
||||
H_BOR_CHARS[LH_bip] = H_BOR_CHARS[RH_bip] = '\0';
|
||||
}
|
||||
|
||||
#undef BOR_CHARS
|
||||
#undef H_BOR_CHARS
|
||||
|
@@ -207,31 +207,78 @@ fort_status_t set_default_cell_option(uint32_t option, int value)
|
||||
* ***************************************************************************/
|
||||
|
||||
|
||||
#define BASIC_STYLE { \
|
||||
/* border_chars */ \
|
||||
{ \
|
||||
'+', '-', '+', '+', \
|
||||
'|', '|', '|', \
|
||||
'\0', '\0', '\0', '\0', \
|
||||
'+', '-', '+', '+' \
|
||||
}, \
|
||||
/* header_border_chars */ \
|
||||
{ \
|
||||
'+', '-', '+', '+', \
|
||||
'|', '|', '|', \
|
||||
'+', '-', '+', '+', \
|
||||
'+', '-', '+', '+' \
|
||||
}, \
|
||||
/* separator_chars */ \
|
||||
{ \
|
||||
'+', '=', '+', '+', \
|
||||
}, \
|
||||
}
|
||||
|
||||
#define SIMPLE_STYLE { \
|
||||
/* border_chars */ \
|
||||
{ \
|
||||
' ', ' ', ' ', ' ', \
|
||||
' ', ' ', ' ', \
|
||||
'\0', '\0', '\0', '\0', \
|
||||
' ', ' ', ' ', ' ' \
|
||||
}, \
|
||||
/* header_border_chars */ \
|
||||
{ \
|
||||
' ', ' ', ' ', ' ', \
|
||||
' ', ' ', ' ', \
|
||||
' ', '-', ' ', ' ', \
|
||||
' ', ' ', ' ', ' ' \
|
||||
}, \
|
||||
/* separator_chars */ \
|
||||
{ \
|
||||
' ', '=', ' ', ' ', \
|
||||
}, \
|
||||
}
|
||||
|
||||
#define DOT_STYLE { \
|
||||
/* border_chars */ \
|
||||
{ \
|
||||
'.', '.', '.', '.', \
|
||||
':', ':', ':', \
|
||||
'\0', '\0', '\0', '\0', \
|
||||
':', '.', ':', ':' \
|
||||
}, \
|
||||
/* header_border_chars */ \
|
||||
{ \
|
||||
'.', '.', '.', '.', \
|
||||
':', ':', ':', \
|
||||
':', '.', ':', ':', \
|
||||
':', '.', ':', ':' \
|
||||
}, \
|
||||
/* separator_chars */ \
|
||||
{ \
|
||||
'+', '=', '+', '+', \
|
||||
}, \
|
||||
}
|
||||
|
||||
struct fort_border_style FORT_BASIC_STYLE = BASIC_STYLE;
|
||||
struct fort_border_style FORT_SIMPLE_STYLE = SIMPLE_STYLE;
|
||||
struct fort_border_style FORT_DOT_STYLE = DOT_STYLE;
|
||||
|
||||
|
||||
|
||||
fort_table_options_t g_table_options = {
|
||||
/* border_chars */
|
||||
{
|
||||
'+', '-', '+', '+',
|
||||
'|', '|', '|',
|
||||
'\0', '\0', '\0', '\0',
|
||||
'+', '-', '+', '+'
|
||||
},
|
||||
|
||||
/* header_border_chars */
|
||||
{
|
||||
'+', '-', '+', '+',
|
||||
'|', '|', '|',
|
||||
'+', '-', '+', '+',
|
||||
'+', '-', '+', '+'
|
||||
},
|
||||
|
||||
/* separator_chars */
|
||||
{
|
||||
'+', '=', '+', '+',
|
||||
},
|
||||
|
||||
/* border_style */
|
||||
BASIC_STYLE,
|
||||
NULL, /* cell_options */
|
||||
};
|
||||
|
||||
|
@@ -145,17 +145,17 @@ struct fort_border_style
|
||||
char header_border_chars[BorderItemPosSize];
|
||||
char separator_chars[SepratorItemPosSize];
|
||||
};
|
||||
extern struct fort_border_style FORT_BASIC_STYLE;
|
||||
extern struct fort_border_style FORT_SIMPLE_STYLE;
|
||||
extern struct fort_border_style FORT_DOT_STYLE;
|
||||
|
||||
|
||||
struct fort_table_options
|
||||
{
|
||||
char border_chars[BorderItemPosSize];
|
||||
char header_border_chars[BorderItemPosSize];
|
||||
char separator_chars[SepratorItemPosSize];
|
||||
|
||||
struct fort_border_style border_style;
|
||||
fort_cell_opt_container_t * cell_options;
|
||||
};
|
||||
typedef struct fort_table_options fort_table_options_t;
|
||||
/*typedef fort_table_options_t context_t;*/
|
||||
extern fort_table_options_t g_table_options;
|
||||
|
||||
|
||||
|
32
src/row.c
32
src/row.c
@@ -156,16 +156,16 @@ int print_row_separator(char *buffer, size_t buffer_sz,
|
||||
|
||||
typedef const char (*border_chars_point_t)[BorderItemPosSize];
|
||||
const char (*border_chars)[BorderItemPosSize] = NULL;
|
||||
border_chars = (border_chars_point_t)&context->table_options->border_chars;
|
||||
border_chars = (border_chars_point_t)&context->table_options->border_style.border_chars;
|
||||
if (upper_row_type == Header || lower_row_type == Header) {
|
||||
border_chars = (border_chars_point_t)&context->table_options->header_border_chars;
|
||||
border_chars = (border_chars_point_t)&context->table_options->border_style.header_border_chars;
|
||||
}
|
||||
|
||||
if (sep && sep->enabled) {
|
||||
L = &(context->table_options->separator_chars[LH_sip]);
|
||||
I = &(context->table_options->separator_chars[IH_sip]);
|
||||
IV = &(context->table_options->separator_chars[II_sip]);
|
||||
R = &(context->table_options->separator_chars[RH_sip]);
|
||||
L = &(context->table_options->border_style.separator_chars[LH_sip]);
|
||||
I = &(context->table_options->border_style.separator_chars[IH_sip]);
|
||||
IV = &(context->table_options->border_style.separator_chars[II_sip]);
|
||||
R = &(context->table_options->border_style.separator_chars[RH_sip]);
|
||||
} else {
|
||||
switch (separatorPos) {
|
||||
case TopSeparator:
|
||||
@@ -262,17 +262,17 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz,
|
||||
|
||||
typedef const char (*border_chars_point_t)[BorderItemPosSize];
|
||||
const char (*border_chars)[BorderItemPosSize] = NULL;
|
||||
border_chars = (border_chars_point_t)&context->table_options->border_chars;
|
||||
border_chars = (border_chars_point_t)&context->table_options->border_style.border_chars;
|
||||
if (upper_row_type == Header || lower_row_type == Header) {
|
||||
border_chars = (border_chars_point_t)&context->table_options->header_border_chars;
|
||||
border_chars = (border_chars_point_t)&context->table_options->border_style.header_border_chars;
|
||||
}
|
||||
|
||||
|
||||
if (sep && sep->enabled) {
|
||||
L = &(context->table_options->separator_chars[LH_sip]);
|
||||
I = &(context->table_options->separator_chars[IH_sip]);
|
||||
IV = &(context->table_options->separator_chars[II_sip]);
|
||||
R = &(context->table_options->separator_chars[RH_sip]);
|
||||
L = &(context->table_options->border_style.separator_chars[LH_sip]);
|
||||
I = &(context->table_options->border_style.separator_chars[IH_sip]);
|
||||
IV = &(context->table_options->border_style.separator_chars[II_sip]);
|
||||
R = &(context->table_options->border_style.separator_chars[RH_sip]);
|
||||
} else {
|
||||
switch (separatorPos) {
|
||||
case TopSeparator:
|
||||
@@ -475,8 +475,8 @@ int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col
|
||||
typedef const char (*border_chars_point_t)[BorderItemPosSize];
|
||||
enum RowType row_type = get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_OPT_ROW_TYPE);
|
||||
const char (*bord_chars)[BorderItemPosSize] = (row_type == Header)
|
||||
? (border_chars_point_t) (&context->table_options->header_border_chars)
|
||||
: (border_chars_point_t) (&context->table_options->border_chars);
|
||||
? (border_chars_point_t) (&context->table_options->border_style.header_border_chars)
|
||||
: (border_chars_point_t) (&context->table_options->border_style.border_chars);
|
||||
const char *L = &(*bord_chars)[LL_bip];
|
||||
const char *IV = &(*bord_chars)[IV_bip];
|
||||
const char *R = &(*bord_chars)[RR_bip];
|
||||
@@ -534,8 +534,8 @@ int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t
|
||||
typedef const char (*border_chars_point_t)[BorderItemPosSize];
|
||||
enum RowType row_type = get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_OPT_ROW_TYPE);
|
||||
const char (*bord_chars)[BorderItemPosSize] = (row_type)
|
||||
? (border_chars_point_t) (&context->table_options->header_border_chars)
|
||||
: (border_chars_point_t) (&context->table_options->border_chars);
|
||||
? (border_chars_point_t) (&context->table_options->border_style.header_border_chars)
|
||||
: (border_chars_point_t) (&context->table_options->border_style.border_chars);
|
||||
const char *L = &(*bord_chars)[LL_bip];
|
||||
const char *IV = &(*bord_chars)[IV_bip];
|
||||
const char *R = &(*bord_chars)[RR_bip];
|
||||
|
Reference in New Issue
Block a user