-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcsv-handler-test.c
More file actions
118 lines (94 loc) · 3.65 KB
/
csv-handler-test.c
File metadata and controls
118 lines (94 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <stdlib.h>
#include <stdio.h>
#include "csv-handler.h"
// REMINDER: Need to pass stdin for this to work!
void testfunc(char **line);
int main()
{
char *outputLine = NULL;
char *borderLine = NULL;
char *borderPadd = NULL;
csv_handler_set_width(17);
// Normal test.
// Print header, with border.
//csv_handler_set_has_headers(0); // Need to do this, if do it, before read_next_line.
//csv_handler_set_delim('|');
csv_handler_read_next_line(); // Not bothering checking RCs right now.
csv_handler_set_headers_from_line(); // Needed for setting fields.
// Always do above two things *first*.
//csv_handler_set_selected_fields("B,D");
csv_handler_output_line_padding(&borderPadd);
csv_handler_border_line(&borderLine);
printf("%s", borderPadd);
printf("%s\n", borderLine);
csv_handler_output_line(&outputLine);
printf("%s", borderPadd);
printf("%s\n", outputLine);
printf("%s", borderPadd);
printf("%s\n", borderLine);
//csv_handler_restrict_by_lines("2-3,5");
//// This specific restriction can technically be done before getting the
//// headers, but since other restrictions can't, putting this here for
//// consistency.
//csv_handler_restrict_by_ranges("3", "10-17,23");
//csv_handler_restrict_by_equals("3", "7,15");
while (csv_handler_read_next_line() == CSV_HANDLER__OK) {
csv_handler_output_line_number(&outputLine);
printf("%s", outputLine);
csv_handler_output_line(&outputLine);
printf("%s\n", outputLine);
}
printf("%s", borderPadd);
printf("%s\n", borderLine);
// Transposed test.
////csv_handler_set_has_headers(0);
//csv_handler_read_next_line();
//csv_handler_set_headers_from_line();
//csv_handler_set_selected_fields("HeadA,HeadC,Range");
//csv_handler_restrict_by_lines("1-4");
////csv_handler_restrict_by_ranges("Range", "5,7-9");
//csv_handler_initialize_transpose();
//csv_handler_transposed_number_line(&outputLine);
//printf("%s\n", outputLine);
//csv_handler_transposed_border_line(&borderLine);
//printf("%s\n", borderLine);
//while (csv_handler_transposed_line(&outputLine) == CSV_HANDLER__OK) {
// printf("%s\n", outputLine);
//}
//printf("%s\n", borderLine);
// Vertical test.
//csv_handler_set_has_headers(0);
//csv_handler_vertical_border_line(&borderLine);
//csv_handler_read_next_line();
//csv_handler_set_headers_from_line(); // Needed for vertical output.
//csv_handler_set_selected_fields("B,C");
//csv_handler_restrict_by_lines("1-2,4");
//while (csv_handler_read_next_line() == CSV_HANDLER__OK) {
// printf("%s\n", borderLine);
// csv_handler_output_vertical_entry(&outputLine);
// printf("%s\n", outputLine);
//}
//printf("%s\n", borderLine);
// Print headers test.
//csv_handler_read_next_line();
//csv_handler_set_headers_from_line();
//while (csv_handler_output_headers(&outputLine) == CSV_HANDLER__OK) {
// printf("%s\n", outputLine);
//}
// Print raw lines.
//csv_handler_set_delim('|');
//csv_handler_read_next_line(); // Not bothering checking RCs right now.
//csv_handler_set_headers_from_line(); // Needed for setting fields.
//csv_handler_set_selected_fields("B,D");
//csv_handler_restrict_by_lines("2-4");
//csv_handler_raw_line(&outputLine);
//printf("%s\n", outputLine);
//while (csv_handler_read_next_line() == CSV_HANDLER__OK) {
// csv_handler_raw_line(&outputLine);
// printf("%s\n", outputLine);
//}
free(outputLine);
free(borderLine);
free(borderPadd);
csv_handler_close();
}