1 #ifndef R_UTIL_TABLE_H
2 #define R_UTIL_TABLE_H
3 
4 #include <r_util.h>
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 typedef struct {
11 	const char *name;
12 	RListComparator cmp;
13 } RTableColumnType;
14 
15 typedef struct {
16 	char *name;
17 	RTableColumnType *type;
18 	int align; // left, right, center (TODO: unused)
19 	int width; // computed
20 	int maxWidth;
21 	bool forceUppercase;
22 	int total;
23 } RTableColumn;
24 
25 typedef struct {
26 	char *name;
27 	RInterval pitv;
28 	RInterval vitv;
29 	int perm;
30 	char *extra;
31 } RListInfo;
32 
33 enum {
34 	R_TABLE_ALIGN_LEFT,
35 	R_TABLE_ALIGN_RIGHT,
36 	R_TABLE_ALIGN_CENTER
37 };
38 
39 typedef struct {
40 	// TODO: use RVector
41 	RList *items;
42 } RTableRow;
43 
44 typedef struct {
45 	char *name;
46 	RList *rows;
47 	RList *cols;
48 	int totalCols;
49 	bool showHeader;
50 	bool showFancy;
51 	bool showSQL;
52 	bool showJSON;
53 	bool showCSV;
54 	bool showR2;
55 	bool showSum;
56 	bool adjustedCols;
57 	void *cons;
58 } RTable;
59 
60 typedef void (*RTableSelector)(RTableRow *acc, RTableRow *new_row, int nth);
61 
62 R_API void r_table_row_free(void *_row);
63 R_API void r_table_column_free(void *_col);
64 R_API RTableColumn *r_table_column_clone(RTableColumn *col);
65 R_API RTableColumnType *r_table_type(const char *name);
66 R_API RTable *r_table_new(const char *name);
67 R_API RTable *r_table_clone(const RTable *t);
68 R_API void r_table_free(RTable *t);
69 R_API int r_table_column_nth(RTable *t, const char *name);
70 R_API void r_table_add_column(RTable *t, RTableColumnType *type, const char *name, int maxWidth);
71 R_API void r_table_set_columnsf(RTable *t, const char *fmt, ...);
72 R_API RTableRow *r_table_row_new(RList *items);
73 R_API void r_table_add_row(RTable *t, const char *name, ...);
74 R_API void r_table_add_rowf(RTable *t, const char *fmt, ...);
75 R_API void r_table_add_row_list(RTable *t, RList *items);
76 R_API char *r_table_tofancystring(RTable *t);
77 R_API char *r_table_tosimplestring(RTable *t);
78 R_API char *r_table_tostring(RTable *t);
79 R_API char *r_table_tosql(RTable *t);
80 R_API char *r_table_tocsv(RTable *t);
81 R_API char *r_table_tor2cmds(RTable *t);
82 R_API char *r_table_tojson(RTable *t);
83 R_API const char *r_table_help(void);
84 R_API void r_table_filter(RTable *t, int nth, int op, const char *un);
85 R_API void r_table_sort(RTable *t, int nth, bool inc);
86 R_API void r_table_uniq(RTable *t);
87 R_API void r_table_group(RTable *t, int nth, RTableSelector fcn);
88 R_API bool r_table_query(RTable *t, const char *q);
89 R_API void r_table_hide_header(RTable *t);
90 R_API bool r_table_align(RTable *t, int nth, int align);
91 R_API void r_table_visual_list(RTable *table, RList* list, ut64 seek, ut64 len, int width, bool va);
92 R_API RTable *r_table_push(RTable *t);
93 R_API RTable *r_table_pop(RTable *t);
94 R_API void r_table_fromjson(RTable *t, const char *csv);
95 R_API void r_table_fromcsv(RTable *t, const char *csv);
96 R_API char *r_table_tohtml(RTable *t);
97 R_API void r_table_transpose(RTable *t);
98 R_API void r_table_format(RTable *t, int nth, RTableColumnType *type);
99 R_API ut64 r_table_reduce(RTable *t, int nth);
100 R_API void r_table_columns(RTable *t, RList *cols); // const char *name, ...);
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 #endif
107