这份代码
起源于一个项目中,需要在命令行显示一些运行参数。由于是嵌入式系统,项目使用的是C语言。在github没有找到C写的Table,就想自己写一个类似功能的代码:
方便在CLI中,对表格类数据进行打印输出。
方便对二维任意数据类型进行管理。
这里共享出来,需要的人可以拿去试试。
static const char* csvString =
"\"name\",\"ch1\",\"ch2\",\"ch3\",\"ch4\",\"ch5\"\n"
"\"enable\",\"false\",\"false\",\"false\",\"false\",\"false\"\n"
"\"fre\",\"20000\",\"20000\",\"20000\",\"20000\",\"20000\"\n"
"\"point\",\"8192\",\"8192\",\"8192\",\"8192\",\"8192\"\n"
"\"cutoff\",\"15001\",\"15002\",\"15003\",\"15004\",\"15005\"";
int test_cli_static_table_print(void){
printf("\n")
printf("=====================test_cli_static_table_csv_create=======================\n")
StaticTableObject* sTable = cli_static_table_csv_str_create(csvString)
unit_test_assert_not_null(sTable)
printf("default type:\n")
cli_static_table_printtype_set(sTable, PRINT_TYPE_DEFAULT, NULL)
cli_static_table_print(sTable)
printf("type2:\n")
cli_static_table_printtype_set(sTable, PRINT_TYPE_2, NULL)
cli_static_table_print(sTable)
printf("type3:\n")
cli_static_table_printtype_set(sTable, PRINT_TYPE_3, NULL)
cli_static_table_print(sTable)
printf("custom type:\n")
cli_static_table_printtype_set(sTable, PRINT_TYPE_CUSTOM, printChar)
unit_test_assert_int_equal(cli_static_table_printtype_get(sTable), PRINT_TYPE_CUSTOM)
cli_static_table_print(sTable)
cli_static_table_delete(sTable)
return 0
}
原作者:yushigengyu