libfort
Classes | Macros | Typedefs | Enumerations | Functions
fort.h File Reference

Main header file describing libfort API. More...

#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
Include dependency graph for fort.h:
This graph shows which files directly or indirectly include this file:

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_tft_create_table (void)
 
void ft_destroy_table (ft_table_t *table)
 
ft_table_tft_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.
Note
Built-in border styles (FT_BASIC_STYLE, FT_BASIC2_STYLE ...) can be used as arguments for ft_set_border_style and ft_set_default_border_style, but their fields shouldn't be accessed directly because implementation doesn't guarantee that these objects are properly initialized.
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
 

Detailed Description

Main header file describing libfort API.

This file contains declarations of all libfort functions and macro definitions.

Macro Definition Documentation

#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.

Parameters
tablePointer to formatted table.
...Strings to write.
Returns
  • 0: Success; data were written
  • (<0): In case of error
#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).

Parameters
tablePointer to formatted table.
...Strings to write.
Returns
  • 0: Success; data were written
  • (<0): In case of error

Typedef Documentation

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.

Enumeration Type Documentation

Adding strategy.

Determines what happens with old content if current cell is not empty after adding data to it. Default strategy is FT_STRATEGY_REPLACE.

Enumerator
FT_STRATEGY_REPLACE 

Replace old content.

FT_STRATEGY_INSERT 

Insert new conten. Old content is shifted.

enum ft_color

Colors.

Enumerator
FT_COLOR_DEFAULT 

Default color

FT_COLOR_BLACK 

Black color

FT_COLOR_RED 

Red color

FT_COLOR_GREEN 

Green color

FT_COLOR_YELLOW 

Yellow color

FT_COLOR_BLUE 

Blue color

FT_COLOR_MAGENTA 

Magenta color

FT_COLOR_CYAN 

Cyan color

FT_COLOR_LIGHT_GRAY 

Light gray color

FT_COLOR_DARK_GRAY 

Dark gray color

FT_COLOR_LIGHT_RED 

Light red color

FT_COLOR_LIGHT_GREEN 

Light green color

FT_COLOR_LIGHT_YELLOW 

Light yellow color

FT_COLOR_LIGHT_BLUE 

Light blue color

FT_COLOR_LIGHT_MAGENTA 

Light magenta color

FT_COLOR_LIGHT_CYAN 

Light cyan color

FT_COLOR_LIGHT_WHYTE 

Light whyte color

Type of table row. Determines appearance of row.

Enumerator
FT_ROW_COMMON 

Common row

FT_ROW_HEADER 

Header row

Alignment of cell content.

Enumerator
FT_ALIGNED_LEFT 

Align left

FT_ALIGNED_CENTER 

Align center

FT_ALIGNED_RIGHT 

Align right

Text styles.

Enumerator
FT_TSTYLE_DEFAULT 

Default style

FT_TSTYLE_BOLD 

Bold

FT_TSTYLE_DIM 

Dim

FT_TSTYLE_ITALIC 

Italic

FT_TSTYLE_UNDERLINED 

Underlined

FT_TSTYLE_BLINK 

Blink

FT_TSTYLE_INVERTED 

Reverse (invert the foreground and background colors)

FT_TSTYLE_HIDDEN 

Hidden (useful for passwords)

Function Documentation

int ft_add_separator ( ft_table_t table)

Add separator after the current row.

Parameters
tableFormatted table.
Returns
  • 0: Success; separator was added.
  • (<0): In case of error
ft_table_t* ft_copy_table ( ft_table_t table)

Copy formatted table.

Parameters
tablePointer to formatted table previousley created with ft_create_table. If table is a null pointer, the function returns null.
Returns
The pointer to the new allocated ft_table_t, on success. NULL on error.
ft_table_t* ft_create_table ( void  )

Create formatted table.

Returns
The pointer to the new allocated ft_table_t, on success. NULL on error.
size_t ft_cur_col ( const ft_table_t table)

Get column number of the current cell.

Parameters
tablePointer to formatted table.
Returns
Column number of the current cell.
size_t ft_cur_row ( const ft_table_t table)

Get row number of the current cell.

Parameters
tablePointer to formatted table.
Returns
Row number of the current cell.
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.

Parameters
tablePointer 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).

Parameters
tablePointer to formatted table.
top_left_rowRow number of the top left cell in the range.
top_left_colColumn number of the top left cell in the range.
bottom_right_rowRow number of the bottom right cell in the range.
bottom_right_colColumn number of the bottom right cell in the range.
Returns
  • 0 - Operation was successfully implemented
  • (<0): In case of error

< Current row

< Current row

< Current column

< Current column

int ft_is_empty ( const ft_table_t table)

Check if table is empty.

Parameters
tablePointer to the table.
Returns
1 - table is empty 0 - some data has been inserted
int ft_ln ( ft_table_t table)

Move current position to the first cell of the next line(row).

Parameters
tablePointer to formatted table.
Returns
  • 0: Success; data were written
  • (<0): In case of error.
Note
This function can fail only in case FT_STRATEGY_INSERT adding strategy was set for the 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.

Note
In most cases it is more preferable to use MACRO ft_write instead of ft_nwrite, which is more safe (ft_write automatically counts the number of string arguments and at compile check that all passed arguments are strings).
Parameters
tablePointer to formatted table.
countNumber of strings to write.
cell_contentFirst string to write.
...Other strings to write.
Returns
  • 0: Success; data were written
  • (<0): In case of error
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).

Note
In most cases it is more preferable to use MACRO ft_write instead of ft_nwrite, which is more safe (ft_write automatically counts the number of string arguments and at compile check that all passed arguments are strings).
Parameters
tablePointer to formatted table.
countNumber of strings to write.
cell_contentFirst string to write.
...Other strings to write.
Returns
  • 0: Success; data were written
  • (<0): In case of error
int ft_printf ( ft_table_t table,
const char *  fmt,
  ... 
)

Write data formatted according to the format string to a variety of table cells.

Parameters
tablePointer to formatted table.
fmtPointer 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.
Returns
  • Number of printed cells
  • (<0): In case of error
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).

Parameters
tablePointer to formatted table.
fmtPointer 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.
Returns
  • Number of printed cells.
  • (<0): In case of error.
size_t ft_row_count ( const ft_table_t table)

Get number of rows in the table.

Parameters
tablePointer to formatted table.
Returns
Number of rows in the 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.

Parameters
tablePointer to formatted table.
colsNumber of elements in row_cells.
row_cellsArray of strings to write.
Returns
  • 0: Success; data were written
  • (<0): In case of error
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).

Parameters
tablePointer to formatted table.
colsNumber of elements in row_cells.
row_cellsArray of strings to write.
Returns
  • 0: Success; data were written
  • (<0): In case of error
int ft_set_border_style ( ft_table_t table,
const struct ft_border_style style 
)

Set border style for the table.

Parameters
tableA pointer to the ft_table_t structure.
stylePointer to border style.
Returns
  • 0: Success; table border style was changed.
  • (<0): In case of error
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.

Parameters
tableA pointer to the ft_table_t structure.
rowCell row.
colCell column.
propertyCell property identifier.
valueCell property value.
Returns
  • 0: Success; cell property was changed.
  • (<0): In case of error

< 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.

Parameters
tableA pointer to the ft_table_t structure.
rowCell row.
colCell column.
hor_spanColumn span.
Returns
  • 0: Success; cell span was changed.
  • (<0): In case of error

< 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 ...).

Parameters
tablePointer to formatted table.
rowNew row number for the current cell.
colNew 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.

Parameters
stylePointer to border style.
Returns
  • 0: Success; default border style was changed.
  • (<0): In case of error
int ft_set_default_cell_prop ( uint32_t  property,
int  value 
)

Set default cell property for all new formatted tables.

Parameters
propertyCell property identifier.
valueCell property value.
Returns
  • 0: Success; default cell property was changed.
  • (<0): In case of error
int int void ft_set_default_printf_field_separator ( char  separator)

Set field separator for ft_printf, ft_printf_ln (default separator is '|').

Parameters
separatorNew separator.
int ft_set_default_tbl_prop ( uint32_t  property,
int  value 
)

Set default table property.

Parameters
propertyTable property identifier.
valueTable property value.
Returns
  • 0: Success; default table property was changed.
  • (<0): In case of error
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.

Parameters
f_mallocPointer to a function for memory allocation that should be used instead of malloc.
f_freePointer to a function for memory deallocation that should be used instead of free.
Note
To return memory allocation/deallocation functions to their standard values set f_malloc and f_free to NULL.
int ft_set_tbl_prop ( ft_table_t table,
uint32_t  property,
int  value 
)

Set table property.

Parameters
tableA pointer to the ft_table_t structure.
propertyTable property identifier.
valueTable property value.
Returns
  • 0: Success; default table property was changed.
  • (<0): In case of error
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.

Parameters
u8strwidUser 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.

Parameters
error_codeError code returned by the library.
Returns
String describing the error.
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.

Parameters
tablePointer to formatted table.
rowsNumber of rows in the 2D array.
colsNumber of columns in the 2D array.
table_cells2D array of strings to write.
Returns
  • 0: Success; data were written
  • (<0): In case of error
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).

Parameters
tablePointer to formatted table.
rowsNumber of rows in the 2D array.
colsNumber of columns in the 2D array.
table_cells2D array of strings to write.
Returns
  • 0: Success; data were written
  • (<0): In case of error
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:

  • Calling ft_destroy_table;
  • Other invocations of ft_to_string.
Parameters
tableFormatted table.
Returns
  • The pointer to the string representation of formatted table, on success.
  • NULL on error.