2018-01-01 09:26:34 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "fort.h"
|
2018-03-05 19:08:14 +01:00
|
|
|
#include <wchar.h>
|
|
|
|
#include <locale.h>
|
2018-01-01 09:26:34 +01:00
|
|
|
|
2018-03-14 19:30:27 +01:00
|
|
|
static FTABLE *create_basic_table()
|
|
|
|
{
|
|
|
|
FTABLE *table = ft_create_table();
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, CenterAligned);
|
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, LeftAligned);
|
2018-03-14 19:30:27 +01:00
|
|
|
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
2018-03-14 19:30:27 +01:00
|
|
|
FT_NWRITE_LN(table, "Rank", "Title", "Year", "Rating");
|
|
|
|
|
|
|
|
FT_NWRITE_LN(table, "1", "The Shawshank Redemption", "1994", "9.5");
|
|
|
|
FT_NWRITE_LN(table, "2", "12 Angry Men", "1957", "8.8");
|
|
|
|
FT_NWRITE_LN(table, "3", "It's a Wonderful Life", "1946", "8.6");
|
|
|
|
ft_add_separator(table);
|
|
|
|
FT_NWRITE_LN(table, "4", "2001: A Space Odyssey", "1968", "8.5");
|
|
|
|
FT_NWRITE_LN(table, "5", "Blade Runner", "1982", "8.1");
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2018-03-31 16:54:01 +02:00
|
|
|
int main(void)
|
2018-01-01 09:26:34 +01:00
|
|
|
{
|
2018-03-31 12:33:37 +02:00
|
|
|
int result = 0;
|
2018-03-29 21:18:49 +02:00
|
|
|
|
2018-03-05 19:08:14 +01:00
|
|
|
FTABLE *table = NULL;
|
|
|
|
|
|
|
|
table = ft_create_table();
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, CenterAligned);
|
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, LeftAligned);
|
2018-02-27 18:41:57 +01:00
|
|
|
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
2018-03-05 19:18:26 +01:00
|
|
|
ft_printf_ln(table, "%d|%s|%5.2f km/s", 1, "Mercury", 47.362);
|
|
|
|
|
2018-01-22 19:31:03 +01:00
|
|
|
ft_printf_ln(table, "%d|%s|%5.2f km/s", 1, "Mercury", 47.362);
|
|
|
|
ft_printf_ln(table, "%d|%s|%5.2f km/s", 2, "Venus", 35.02);
|
|
|
|
ft_printf_ln(table, "%d|%s|%5.2f km/s", 3, "Earth", 29.78);
|
2018-01-01 09:26:34 +01:00
|
|
|
|
2018-01-21 18:02:43 +01:00
|
|
|
printf("Table:\n");
|
|
|
|
printf("%s\n", ft_to_string(table));
|
|
|
|
ft_destroy_table(table);
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/
|
2018-01-21 09:19:18 +01:00
|
|
|
|
2018-01-21 18:02:43 +01:00
|
|
|
table = ft_create_table();
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, CenterAligned);
|
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, LeftAligned);
|
2018-01-20 19:27:24 +01:00
|
|
|
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
2018-03-05 19:18:26 +01:00
|
|
|
ft_printf_ln(table, "Rank|Title|Year|Rating");
|
|
|
|
|
2018-01-21 18:02:43 +01:00
|
|
|
FT_NWRITE_LN(table, "1", "The Shawshank Redemption", "1994", "9.5");
|
|
|
|
FT_NWRITE_LN(table, "2", "12 Angry Men", "1957", "8.8");
|
|
|
|
FT_NWRITE_LN(table, "3", "2001: A Space Odyssey", "1968", "8.5");
|
|
|
|
FT_NWRITE_LN(table, "4", "Blade Runner", "1982", "8.1");
|
2018-01-20 19:27:24 +01:00
|
|
|
|
|
|
|
|
2018-01-21 18:02:43 +01:00
|
|
|
printf("Table:\n");
|
|
|
|
printf("%s\n", ft_to_string(table));
|
|
|
|
ft_destroy_table(table);
|
2018-01-20 19:27:24 +01:00
|
|
|
|
2018-01-21 18:02:43 +01:00
|
|
|
/*-------------------------------------------------------------*/
|
2018-01-20 19:27:24 +01:00
|
|
|
|
2018-01-21 18:02:43 +01:00
|
|
|
table = ft_create_table();
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, LeftAligned);
|
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, CenterAligned);
|
2018-01-21 18:02:43 +01:00
|
|
|
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
2018-03-05 19:18:26 +01:00
|
|
|
ft_printf_ln(table, "Commodity|Farm price|Avg. spread");
|
|
|
|
|
2018-01-21 18:02:43 +01:00
|
|
|
const char *row1[] = {"Potatoes", "$1.60", "200.94%"};
|
|
|
|
const char *row2[] = {"Carrots", "$0.32 ", "190.63%"};
|
|
|
|
ft_row_write_ln(table, 3, row1);
|
|
|
|
ft_row_write_ln(table, 3, row2);
|
|
|
|
|
|
|
|
printf("Table:\n");
|
|
|
|
printf("%s\n", ft_to_string(table));
|
|
|
|
ft_destroy_table(table);
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/
|
2018-03-17 19:53:38 +01:00
|
|
|
#if !defined(__cplusplus) && !defined(FT_MICROSOFT_COMPILER)
|
2018-01-21 18:02:43 +01:00
|
|
|
table = ft_create_table();
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, LeftAligned);
|
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, CenterAligned);
|
2018-01-21 18:02:43 +01:00
|
|
|
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
2018-03-05 19:18:26 +01:00
|
|
|
ft_printf_ln(table, "No.|Name|Avg. Mark");
|
2018-01-21 18:02:43 +01:00
|
|
|
const char *ctab[2][3] = {
|
|
|
|
{"1", "Joe Public", "3.14"},
|
|
|
|
{"2", "John Doe", "4.50"}
|
|
|
|
};
|
|
|
|
ft_s_table_write_ln(table, 2, 3, ctab);
|
|
|
|
|
|
|
|
printf("Table:\n");
|
|
|
|
printf("%s\n", ft_to_string(table));
|
|
|
|
ft_destroy_table(table);
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/
|
2018-01-20 19:27:24 +01:00
|
|
|
|
2018-03-12 20:28:55 +01:00
|
|
|
|
|
|
|
|
2018-01-21 18:02:43 +01:00
|
|
|
table = ft_create_table();
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, CenterAligned);
|
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, LeftAligned);
|
2018-01-20 19:27:24 +01:00
|
|
|
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
2018-03-05 19:18:26 +01:00
|
|
|
ft_printf_ln(table, "No.|Name|Avg. Mark");
|
2018-01-20 19:27:24 +01:00
|
|
|
const char **tab[2] = {
|
2018-01-21 18:02:43 +01:00
|
|
|
row1,
|
|
|
|
row2
|
2018-01-20 19:27:24 +01:00
|
|
|
};
|
2018-01-21 18:02:43 +01:00
|
|
|
ft_table_write_ln(table, 2, 3, tab);
|
2018-01-20 19:27:24 +01:00
|
|
|
|
2018-01-21 18:02:43 +01:00
|
|
|
printf("Table:\n");
|
|
|
|
printf("%s\n", ft_to_string(table));
|
|
|
|
ft_destroy_table(table);
|
2018-03-17 19:53:38 +01:00
|
|
|
#endif
|
2018-03-05 19:08:14 +01:00
|
|
|
|
2018-03-12 20:28:55 +01:00
|
|
|
/*---------------- Different styles --------------------*/
|
|
|
|
|
2018-03-14 20:18:59 +01:00
|
|
|
ft_set_default_border_style(FT_BASIC_STYLE);
|
2018-03-14 19:30:27 +01:00
|
|
|
table = create_basic_table();
|
|
|
|
printf("Table:\n%s\n", ft_to_string(table));
|
2018-03-12 20:28:55 +01:00
|
|
|
ft_destroy_table(table);
|
|
|
|
|
2018-03-14 20:18:59 +01:00
|
|
|
ft_set_default_border_style(FT_SIMPLE_STYLE);
|
2018-03-14 19:30:27 +01:00
|
|
|
table = create_basic_table();
|
|
|
|
printf("Table:\n%s\n", ft_to_string(table));
|
2018-03-12 21:02:59 +01:00
|
|
|
ft_destroy_table(table);
|
2018-03-12 20:28:55 +01:00
|
|
|
|
2018-03-14 20:18:59 +01:00
|
|
|
ft_set_default_border_style(FT_PLAIN_STYLE);
|
2018-03-14 19:30:27 +01:00
|
|
|
table = create_basic_table();
|
|
|
|
printf("Table:\n%s\n", ft_to_string(table));
|
|
|
|
ft_destroy_table(table);
|
2018-03-12 20:28:55 +01:00
|
|
|
|
2018-03-14 20:18:59 +01:00
|
|
|
ft_set_default_border_style(FT_DOT_STYLE);
|
2018-03-14 19:30:27 +01:00
|
|
|
table = create_basic_table();
|
|
|
|
printf("Table:\n%s\n", ft_to_string(table));
|
|
|
|
ft_destroy_table(table);
|
2018-03-12 20:28:55 +01:00
|
|
|
|
2018-03-14 20:18:59 +01:00
|
|
|
ft_set_default_border_style(FT_EMPTY_STYLE);
|
2018-03-14 19:30:27 +01:00
|
|
|
table = create_basic_table();
|
|
|
|
printf("Table:\n%s\n", ft_to_string(table));
|
2018-03-12 21:02:59 +01:00
|
|
|
ft_destroy_table(table);
|
2018-03-12 20:28:55 +01:00
|
|
|
|
2018-03-24 16:09:32 +01:00
|
|
|
/*-------------------------------------------------------------*/
|
2018-03-31 17:13:30 +02:00
|
|
|
#if defined(FT_HAVE_WCHAR) && !defined(FT_MICROSOFT_COMPILER)
|
2018-03-24 16:09:32 +01:00
|
|
|
setlocale(LC_CTYPE, "");
|
|
|
|
|
|
|
|
table = ft_create_table();
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, CenterAligned);
|
|
|
|
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, LeftAligned);
|
2018-03-24 16:09:32 +01:00
|
|
|
|
2018-03-25 10:11:08 +02:00
|
|
|
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
2018-03-24 16:09:32 +01:00
|
|
|
FT_NWWRITE_LN(table, L"Ранг", L"Название", L"Год", L"Рейтинг");
|
|
|
|
|
|
|
|
FT_NWWRITE_LN(table, L"1", L"Побег из Шоушенка", L"1994", L"9.5");
|
|
|
|
FT_NWWRITE_LN(table, L"2", L"12 разгневанных мужчин", L"1957", L"8.8");
|
|
|
|
FT_NWWRITE_LN(table, L"3", L"Космическая одиссея 2001 года", L"1968", L"8.5");
|
|
|
|
FT_NWWRITE_LN(table, L"4", L"Бегущий по лезвию", L"1982", L"8.1");
|
|
|
|
|
|
|
|
/* Ранг | Название | Год | Рейтинг */
|
2018-03-25 13:19:35 +02:00
|
|
|
/*FT_NWWRITE_LN(table, L"\x420\x430\x43d\x433", L"\x41d\x430\x437\x432\x430\x43d\x438\x435", L"\x413\x43e\x434", L"\x420\x435\x439\x442\x438\x43d\x433"); */
|
2018-03-24 16:09:32 +01:00
|
|
|
|
|
|
|
/*FT_NWWRITE_LN(table, L"1", L"\x41f\x43e\x431\x435\x433 \x438\x437 \x428\x43e\x443\x448\x435\x43d\x43a\x430", L"1994", L"9.5");*/ /* Побег из Шоушенка */
|
|
|
|
/*FT_NWWRITE_LN(table, L"2", L"12 \x440\x430\x437\x433\x43d\x435\x432\x430\x43d\x43d\x44b\x445 \x43c\x443\x436\x447\x438\x43d", L"1957", L"8.8");*/ /* 12 разгневанных мужчин */
|
|
|
|
/*FT_NWWRITE_LN(table, L"3", L"\x41a\x43e\x441\x43c\x438\x447\x435\x441\x43a\x430\x44f \x43e\x434\x438\x441\x441\x435\x44f 2001 \x433\x43e\x434\x430", L"1968", L"8.5");*/ /* Космическая одиссея 2001 года */
|
|
|
|
/*FT_NWWRITE_LN(table, L"4", L"\x411\x435\x433\x443\x449\x438\x439 \x43f\x43e \x43b\x435\x437\x432\x438\x44e", L"1982", L"8.1");*/ /* Бегущий по лезвию */
|
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
const wchar_t* table_wstr = ft_to_wstring(table);
|
|
|
|
if (table_wstr) {
|
|
|
|
fwprintf(stderr, L"Table:\n%ls\n ", table_wstr);
|
|
|
|
} else {
|
|
|
|
fwprintf(stderr, L"Table conversion failed !!!\n ");
|
|
|
|
result += 1;
|
|
|
|
}
|
2018-03-24 16:09:32 +01:00
|
|
|
|
|
|
|
ft_destroy_table(table);
|
|
|
|
#endif
|
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
return result;
|
2018-01-01 09:26:34 +01:00
|
|
|
}
|