libfort
|
Main header file describing libfort API. More...
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
Go to the source code of this file.
Classes | |
struct | ft_border_chars |
struct | ft_border_style |
Macros | |
#define | LIBFORT_MAJOR_VERSION 0 |
#define | LIBFORT_MINOR_VERSION 4 |
#define | LIBFORT_REVISION 2 |
#define | LIBFORT_VERSION_STR "0.4.2" |
#define | FT_HAVE_WCHAR |
#define | FT_HAVE_UTF8 |
#define | FT_SUCCESS 0 |
#define | FT_MEMORY_ERROR -1 |
#define | FT_EINVAL -2 |
#define | FT_INTERN_ERROR -3 |
#define | FT_GEN_ERROR -4 |
#define | FT_IS_SUCCESS(arg) ((arg) >= 0) |
#define | FT_IS_ERROR(arg) ((arg) < 0) |
#define | FT_PRINTF_ATTRIBUTE_FORMAT(string_index, first_to_check) __attribute__ ((format (printf, string_index, first_to_check))) |
#define | ft_write(table, ...) (0 ? FT_CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)) |
#define | ft_write_ln(table, ...) (0 ? FT_CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite_ln(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)) |
#define | FT_MAX_ROW_INDEX (UINT_MAX - 2) |
#define | FT_MAX_COL_INDEX (UINT_MAX - 2) |
#define | ft_wwrite(table, ...) (0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) : ft_nwwrite(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)) |
#define | ft_wwrite_ln(table, ...) (0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) : ft_nwwrite_ln(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)) |
#define | ft_u8write(table, ...) (ft_u8nwrite(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)) |
#define | ft_u8write_ln(table, ...) (ft_u8nwrite_ln(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)) |
Special macros to define cell position (row and column). | |
#define | FT_ANY_COLUMN (UINT_MAX) |
#define | FT_CUR_COLUMN (UINT_MAX - 1) |
#define | FT_ANY_ROW (UINT_MAX) |
#define | FT_CUR_ROW (UINT_MAX - 1) |
Cell properties identifiers. | |
#define | FT_CPROP_MIN_WIDTH (0x01U << 0) |
#define | FT_CPROP_TEXT_ALIGN (0x01U << 1) |
#define | FT_CPROP_TOP_PADDING (0x01U << 2) |
#define | FT_CPROP_BOTTOM_PADDING (0x01U << 3) |
#define | FT_CPROP_LEFT_PADDING (0x01U << 4) |
#define | FT_CPROP_RIGHT_PADDING (0x01U << 5) |
#define | FT_CPROP_EMPTY_STR_HEIGHT (0x01U << 6) |
#define | FT_CPROP_ROW_TYPE (0x01U << 7) |
#define | FT_CPROP_CONT_FG_COLOR (0x01U << 8) |
#define | FT_CPROP_CELL_BG_COLOR (0x01U << 9) |
#define | FT_CPROP_CONT_BG_COLOR (0x01U << 10) |
#define | FT_CPROP_CELL_TEXT_STYLE (0x01U << 11) |
#define | FT_CPROP_CONT_TEXT_STYLE (0x01U << 12) |
Table properties identifiers. | |
#define | FT_TPROP_LEFT_MARGIN (0x01U << 0) |
#define | FT_TPROP_TOP_MARGIN (0x01U << 1) |
#define | FT_TPROP_RIGHT_MARGIN (0x01U << 2) |
#define | FT_TPROP_BOTTOM_MARGIN (0x01U << 3) |
#define | FT_TPROP_ADDING_STRATEGY (0x01U << 4) |
Typedefs | |
typedef struct ft_table | ft_table_t |
Enumerations | |
enum | ft_color { FT_COLOR_DEFAULT = 0, FT_COLOR_BLACK = 1, FT_COLOR_RED = 2, FT_COLOR_GREEN = 3, FT_COLOR_YELLOW = 4, FT_COLOR_BLUE = 5, FT_COLOR_MAGENTA = 6, FT_COLOR_CYAN = 7, FT_COLOR_LIGHT_GRAY = 8, FT_COLOR_DARK_GRAY = 9, FT_COLOR_LIGHT_RED = 10, FT_COLOR_LIGHT_GREEN = 11, FT_COLOR_LIGHT_YELLOW = 12, FT_COLOR_LIGHT_BLUE = 13, FT_COLOR_LIGHT_MAGENTA = 15, FT_COLOR_LIGHT_CYAN = 16, FT_COLOR_LIGHT_WHYTE = 17 } |
enum | ft_text_style { FT_TSTYLE_DEFAULT = (1U << 0), FT_TSTYLE_BOLD = (1U << 1), FT_TSTYLE_DIM = (1U << 2), FT_TSTYLE_ITALIC = (1U << 3), FT_TSTYLE_UNDERLINED = (1U << 4), FT_TSTYLE_BLINK = (1U << 5), FT_TSTYLE_INVERTED = (1U << 6), FT_TSTYLE_HIDDEN = (1U << 7) } |
enum | ft_text_alignment { FT_ALIGNED_LEFT = 0, FT_ALIGNED_CENTER, FT_ALIGNED_RIGHT } |
enum | ft_row_type { FT_ROW_COMMON = 0, FT_ROW_HEADER } |
enum | ft_adding_strategy { FT_STRATEGY_REPLACE = 0, FT_STRATEGY_INSERT } |
Functions | |
ft_table_t * | ft_create_table (void) |
void | ft_destroy_table (ft_table_t *table) |
ft_table_t * | ft_copy_table (ft_table_t *table) |
int | ft_ln (ft_table_t *table) |
size_t | ft_cur_row (const ft_table_t *table) |
size_t | ft_cur_col (const ft_table_t *table) |
void | ft_set_cur_cell (ft_table_t *table, size_t row, size_t col) |
int | ft_is_empty (const ft_table_t *table) |
size_t | ft_row_count (const ft_table_t *table) |
int | ft_erase_range (ft_table_t *table, size_t top_left_row, size_t top_left_col, size_t bottom_right_row, size_t bottom_right_col) |
int | ft_printf (ft_table_t *table, const char *fmt,...) __attribute__((format(printf |
int int | ft_printf_ln (ft_table_t *table, const char *fmt,...) __attribute__((format(printf |
int int void | ft_set_default_printf_field_separator (char separator) |
int | ft_nwrite (ft_table_t *table, size_t count, const char *cell_content,...) |
int | ft_nwrite_ln (ft_table_t *table, size_t count, const char *cell_content,...) |
int | ft_row_write (ft_table_t *table, size_t cols, const char *row_cells[]) |
int | ft_row_write_ln (ft_table_t *table, size_t cols, const char *row_cells[]) |
int | ft_table_write (ft_table_t *table, size_t rows, size_t cols, const char *table_cells[]) |
int | ft_table_write_ln (ft_table_t *table, size_t rows, size_t cols, const char *table_cells[]) |
int | ft_add_separator (ft_table_t *table) |
const char * | ft_to_string (const ft_table_t *table) |
int | ft_set_default_border_style (const struct ft_border_style *style) |
int | ft_set_border_style (ft_table_t *table, const struct ft_border_style *style) |
int | ft_set_default_cell_prop (uint32_t property, int value) |
int | ft_set_cell_prop (ft_table_t *table, size_t row, size_t col, uint32_t property, int value) |
int | ft_set_default_tbl_prop (uint32_t property, int value) |
int | ft_set_tbl_prop (ft_table_t *table, uint32_t property, int value) |
int | ft_set_cell_span (ft_table_t *table, size_t row, size_t col, size_t hor_span) |
void | ft_set_memory_funcs (void *(*f_malloc)(size_t size), void(*f_free)(void *ptr)) |
const char * | ft_strerror (int error_code) |
int | ft_wprintf (ft_table_t *table, const wchar_t *fmt,...) |
int | ft_wprintf_ln (ft_table_t *table, const wchar_t *fmt,...) |
int | ft_nwwrite (ft_table_t *table, size_t n, const wchar_t *cell_content,...) |
int | ft_nwwrite_ln (ft_table_t *table, size_t n, const wchar_t *cell_content,...) |
int | ft_row_wwrite (ft_table_t *table, size_t cols, const wchar_t *row_cells[]) |
int | ft_row_wwrite_ln (ft_table_t *table, size_t cols, const wchar_t *row_cells[]) |
int | ft_table_wwrite (ft_table_t *table, size_t rows, size_t cols, const wchar_t *table_cells[]) |
int | ft_table_wwrite_ln (ft_table_t *table, size_t rows, size_t cols, const wchar_t *table_cells[]) |
const wchar_t * | ft_to_wstring (const ft_table_t *table) |
int | ft_u8nwrite (ft_table_t *table, size_t n, const void *cell_content,...) |
int | ft_u8nwrite_ln (ft_table_t *table, size_t n, const void *cell_content,...) |
int | ft_u8printf (ft_table_t *table, const char *fmt,...) __attribute__((format(printf |
int int | ft_u8printf_ln (ft_table_t *table, const char *fmt,...) __attribute__((format(printf |
int int const void * | ft_to_u8string (const ft_table_t *table) |
void | ft_set_u8strwid_func (int(*u8strwid)(const void *beg, const void *end, size_t *width)) |
Variables | |
Built-in table border styles. | |
| |
const struct ft_border_style *const | FT_BASIC_STYLE |
const struct ft_border_style *const | FT_BASIC2_STYLE |
const struct ft_border_style *const | FT_SIMPLE_STYLE |
const struct ft_border_style *const | FT_PLAIN_STYLE |
const struct ft_border_style *const | FT_DOT_STYLE |
const struct ft_border_style *const | FT_EMPTY_STYLE |
const struct ft_border_style *const | FT_EMPTY2_STYLE |
const struct ft_border_style *const | FT_SOLID_STYLE |
const struct ft_border_style *const | FT_SOLID_ROUND_STYLE |
const struct ft_border_style *const | FT_NICE_STYLE |
const struct ft_border_style *const | FT_DOUBLE_STYLE |
const struct ft_border_style *const | FT_DOUBLE2_STYLE |
const struct ft_border_style *const | FT_BOLD_STYLE |
const struct ft_border_style *const | FT_BOLD2_STYLE |
const struct ft_border_style *const | FT_FRAME_STYLE |
Main header file describing libfort API.
This file contains declarations of all libfort functions and macro definitions.
#define FT_ANY_COLUMN (UINT_MAX) |
Any column (can be used to refer to all cells in a row)
#define FT_ANY_ROW (UINT_MAX) |
Any row (can be used to refer to all cells in a column)
#define FT_CPROP_BOTTOM_PADDING (0x01U << 3) |
Bottom padding for cell content
#define FT_CPROP_CELL_BG_COLOR (0x01U << 9) |
Cell background color
#define FT_CPROP_CELL_TEXT_STYLE (0x01U << 11) |
Cell text style
#define FT_CPROP_CONT_BG_COLOR (0x01U << 10) |
Cell content background color
#define FT_CPROP_CONT_FG_COLOR (0x01U << 8) |
Cell content foreground text color
#define FT_CPROP_CONT_TEXT_STYLE (0x01U << 12) |
Cell content text style
#define FT_CPROP_EMPTY_STR_HEIGHT (0x01U << 6) |
Height of empty cell
#define FT_CPROP_LEFT_PADDING (0x01U << 4) |
Left padding for cell content
#define FT_CPROP_MIN_WIDTH (0x01U << 0) |
Minimum width
#define FT_CPROP_RIGHT_PADDING (0x01U << 5) |
Right padding for cell content
#define FT_CPROP_ROW_TYPE (0x01U << 7) |
Row type
#define FT_CPROP_TEXT_ALIGN (0x01U << 1) |
Text alignment
#define FT_CPROP_TOP_PADDING (0x01U << 2) |
Top padding for cell content
#define FT_CUR_COLUMN (UINT_MAX - 1) |
Current column
#define FT_CUR_ROW (UINT_MAX - 1) |
Current row
#define FT_EINVAL -2 |
Invalid argument.
#define FT_GEN_ERROR -4 |
General error.
Different errors that do not belong to the group of errors mentioned above.
#define FT_HAVE_WCHAR |
libfort configuration macros (to disable wchar_t/UTF-8 support this macros should be defined)#define FT_CONGIG_DISABLE_WCHAR #define FT_CONGIG_DISABLE_UTF8
#define FT_INTERN_ERROR -3 |
Libfort internal logic error.
Usually such errors mean that something is wrong in libfort internal logic and in most of cases cause of these errors is a library bug.
#define FT_MEMORY_ERROR -1 |
Memory allocation failed.
#define FT_SUCCESS 0 |
Operation successfully ended.
#define ft_write | ( | table, | |
... | |||
) | (0 ? FT_CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)) |
Write strings to the table.
Write specified strings to the same number of consecutive cells in the current row.
table | Pointer to formatted table. |
... | Strings to write. |
#define ft_write_ln | ( | table, | |
... | |||
) | (0 ? FT_CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite_ln(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)) |
Write strings to the table and go to the next line.
Write specified strings to the same number of consecutive cells in the current row and move current position to the first cell of the next line(row).
table | Pointer to formatted table. |
... | Strings to write. |
typedef struct ft_table ft_table_t |
The main structure of libfort containing information about formatted table.
ft_table_t objects should be created by a call to ft_create_table and destroyed with ft_destroy_table.
enum ft_adding_strategy |
enum ft_color |
Colors.
enum ft_row_type |
enum ft_text_alignment |
enum ft_text_style |
int ft_add_separator | ( | ft_table_t * | table | ) |
Add separator after the current row.
table | Formatted table. |
ft_table_t* ft_copy_table | ( | ft_table_t * | table | ) |
Copy formatted table.
table | Pointer to formatted table previousley created with ft_create_table. If table is a null pointer, the function returns null. |
ft_table_t* ft_create_table | ( | void | ) |
Create formatted table.
size_t ft_cur_col | ( | const ft_table_t * | table | ) |
Get column number of the current cell.
table | Pointer to formatted table. |
size_t ft_cur_row | ( | const ft_table_t * | table | ) |
Get row number of the current cell.
table | Pointer to formatted table. |
void ft_destroy_table | ( | ft_table_t * | table | ) |
Destroy formatted table.
Destroy formatted table and free all resources allocated during table creation and work with it.
table | Pointer to formatted table previousley created with ft_create_table. If table is a null pointer, the function does nothing. |
int ft_erase_range | ( | ft_table_t * | table, |
size_t | top_left_row, | ||
size_t | top_left_col, | ||
size_t | bottom_right_row, | ||
size_t | bottom_right_col | ||
) |
Erase range of cells.
Range of cells is determined by 2 points (top-left and bottom-right) (both ends are included).
table | Pointer to formatted table. |
top_left_row | Row number of the top left cell in the range. |
top_left_col | Column number of the top left cell in the range. |
bottom_right_row | Row number of the bottom right cell in the range. |
bottom_right_col | Column number of the bottom right cell in the range. |
< Current row
< Current row
< Current column
< Current column
int ft_is_empty | ( | const ft_table_t * | table | ) |
Check if table is empty.
table | Pointer to the table. |
int ft_ln | ( | ft_table_t * | table | ) |
Move current position to the first cell of the next line(row).
table | Pointer to formatted table. |
int ft_nwrite | ( | ft_table_t * | table, |
size_t | count, | ||
const char * | cell_content, | ||
... | |||
) |
Write specified number of strings to the table.
Write specified number of strings to the same number of consecutive cells in the current row.
table | Pointer to formatted table. |
count | Number of strings to write. |
cell_content | First string to write. |
... | Other strings to write. |
int ft_nwrite_ln | ( | ft_table_t * | table, |
size_t | count, | ||
const char * | cell_content, | ||
... | |||
) |
Write specified number of strings to the table and go to the next line.
Write specified number of strings to the same number of consecutive cells in the current row and move current position to the first cell of the next line(row).
table | Pointer to formatted table. |
count | Number of strings to write. |
cell_content | First string to write. |
... | Other strings to write. |
int ft_printf | ( | ft_table_t * | table, |
const char * | fmt, | ||
... | |||
) |
Write data formatted according to the format string to a variety of table cells.
table | Pointer to formatted table. |
fmt | Pointer to a null-terminated multibyte string specifying how to interpret the data. The format string consists of ordinary characters (except % and |), which are copied unchanged into the output stream, and conversion specifications. Conversion specifications are the same as for standard printf function. Character '|' (which can be changed with ft_set_default_printf_field_separator) in the format string is treated as a cell separator. |
... | Arguments specifying data to print. Similarly to standard printf-like functions if any argument after default conversions is not the type expected by the corresponding conversion specifier, or if there are fewer arguments than required by format, the behavior is undefined. If there are more arguments than required by format, the extraneous arguments are evaluated and ignored. |
int int ft_printf_ln | ( | ft_table_t * | table, |
const char * | fmt, | ||
... | |||
) |
Write data formatted according to the format string to a variety of table cells and move current position to the first cell of the next line(row).
table | Pointer to formatted table. |
fmt | Pointer to a null-terminated multibyte string specifying how to interpret the data. The format string consists of ordinary characters (except % and |), which are copied unchanged into the output stream, and conversion specifications. Conversion specifications are the same as for standard printf function. Character '|' (which can be changed with ft_set_default_printf_field_separator) in the format string is treated as a cell separator. |
... | Arguments specifying data to print. Similarly to standard printf-like functions if any argument after default conversions is not the type expected by the corresponding conversion specifier, or if there are fewer arguments than required by format, the behavior is undefined. If there are more arguments than required by format, the extraneous arguments are evaluated and ignored. |
size_t ft_row_count | ( | const ft_table_t * | table | ) |
Get number of rows in the table.
table | Pointer to formatted table. |
int ft_row_write | ( | ft_table_t * | table, |
size_t | cols, | ||
const char * | row_cells[] | ||
) |
Write strings from the array to the table.
Write specified number of strings from the array to the same number of consecutive cells in the current row.
table | Pointer to formatted table. |
cols | Number of elements in row_cells. |
row_cells | Array of strings to write. |
int ft_row_write_ln | ( | ft_table_t * | table, |
size_t | cols, | ||
const char * | row_cells[] | ||
) |
Write strings from the array to the table and go to the next line.
Write specified number of strings from the array to the same number of consecutive cells in the current row and move current position to the first cell of the next line(row).
table | Pointer to formatted table. |
cols | Number of elements in row_cells. |
row_cells | Array of strings to write. |
int ft_set_border_style | ( | ft_table_t * | table, |
const struct ft_border_style * | style | ||
) |
Set border style for the table.
table | A pointer to the ft_table_t structure. |
style | Pointer to border style. |
int ft_set_cell_prop | ( | ft_table_t * | table, |
size_t | row, | ||
size_t | col, | ||
uint32_t | property, | ||
int | value | ||
) |
Set property for the specified cell of the table.
table | A pointer to the ft_table_t structure. |
row | Cell row. |
col | Cell column. |
property | Cell property identifier. |
value | Cell property value. |
< Current row
< Current column
int ft_set_cell_span | ( | ft_table_t * | table, |
size_t | row, | ||
size_t | col, | ||
size_t | hor_span | ||
) |
Set column span for the specified cell of the table.
table | A pointer to the ft_table_t structure. |
row | Cell row. |
col | Cell column. |
hor_span | Column span. |
< Current row
< Current column
void ft_set_cur_cell | ( | ft_table_t * | table, |
size_t | row, | ||
size_t | col | ||
) |
Set current cell position.
Current cell - cell that will be edited with all modifiing functions (ft_printf, ft_write ...).
table | Pointer to formatted table. |
row | New row number for the current cell. |
col | New row number for the current cell. |
int ft_set_default_border_style | ( | const struct ft_border_style * | style | ) |
Set default border style for all new formatted tables.
style | Pointer to border style. |
int ft_set_default_cell_prop | ( | uint32_t | property, |
int | value | ||
) |
Set default cell property for all new formatted tables.
property | Cell property identifier. |
value | Cell property value. |
int int void ft_set_default_printf_field_separator | ( | char | separator | ) |
Set field separator for ft_printf, ft_printf_ln (default separator is '|').
separator | New separator. |
int ft_set_default_tbl_prop | ( | uint32_t | property, |
int | value | ||
) |
Set default table property.
property | Table property identifier. |
value | Table property value. |
void ft_set_memory_funcs | ( | void *(*)(size_t size) | f_malloc, |
void(*)(void *ptr) | f_free | ||
) |
Set functions for memory allocation and deallocation to be used instead of standard ones.
f_malloc | Pointer to a function for memory allocation that should be used instead of malloc. |
f_free | Pointer to a function for memory deallocation that should be used instead of free. |
int ft_set_tbl_prop | ( | ft_table_t * | table, |
uint32_t | property, | ||
int | value | ||
) |
Set table property.
table | A pointer to the ft_table_t structure. |
property | Table property identifier. |
value | Table property value. |
void ft_set_u8strwid_func | ( | int(*)(const void *beg, const void *end, size_t *width) | u8strwid | ) |
Set custom function to compute visible width of UTF-8 string.
libfort internally has a very simple logic to compute visible width of UTF-8 strings. It considers that each codepoint will occupy one position on the terminal in case of monowidth font (some east asians wide and fullwidth characters (see http://www.unicode.org/reports/tr11/tr11-33.html) will occupy 2 positions). This logic is very simple and covers wide range of cases. But obviously there a lot of cases when it is not sufficient. In such cases user should use some external libraries and provide an appropriate function to libfort.
u8strwid | User provided function to evaluate width of UTF-8 string ( beg - start of UTF-8 string, end - end of UTF-8 string (not included), width - pointer to the result). If function succeed it should return 0, otherwise some non- zero value. If function returns nonzero value libfort fallbacks to default internal algorithm. |
const char* ft_strerror | ( | int | error_code | ) |
Return string describing the error_code
.
error_code | Error code returned by the library. |
int ft_table_write | ( | ft_table_t * | table, |
size_t | rows, | ||
size_t | cols, | ||
const char * | table_cells[] | ||
) |
Write strings from the 2D array to the table.
Write specified number of strings from the 2D array to the formatted table.
table | Pointer to formatted table. |
rows | Number of rows in the 2D array. |
cols | Number of columns in the 2D array. |
table_cells | 2D array of strings to write. |
int ft_table_write_ln | ( | ft_table_t * | table, |
size_t | rows, | ||
size_t | cols, | ||
const char * | table_cells[] | ||
) |
Write strings from the 2D array to the table and go to the next line.
Write specified number of strings from the 2D array to the formatted table and move current position to the first cell of the next line(row).
table | Pointer to formatted table. |
rows | Number of rows in the 2D array. |
cols | Number of columns in the 2D array. |
table_cells | 2D array of strings to write. |
const char* ft_to_string | ( | const ft_table_t * | table | ) |
Convert table to string representation.
ft_table_t has ownership of the returned pointer. So there is no need to free it. To take ownership user should explicitly copy the returned string with strdup or similar functions.
Returned pointer may be later invalidated by:
table | Formatted table. |