1 | :- module(pltables_export_csv, [ | |
2 | csv_header/2, csv_footer/2, | |
3 | csv_table_header/2, csv_table_footer/2, | |
4 | csv_table_rows/2 | |
5 | ]). | |
6 | ||
7 | :- use_module(pltables_export_tools). | |
8 | :- use_module(pltables). | |
9 | ||
10 | :- use_module(probsrc(module_information)). | |
11 | ||
12 | :- module_info(group,pltables). | |
13 | :- module_info(description,'This module is used to export coverage tables to csv.'). | |
14 | ||
15 | % ---- | |
16 | % table headers | |
17 | % ---- | |
18 | csv_header(_S, _TableName). | |
19 | ||
20 | % ---- | |
21 | % table footers | |
22 | % ---- | |
23 | csv_footer(_S, _TableName). | |
24 | ||
25 | % ---- | |
26 | % table header / footer | |
27 | % ---- | |
28 | csv_table_header(S, TableName) :- | |
29 | write(S, '<table'), | |
30 | pltable(TableName, TableAttributes), | |
31 | pltable_header(TableName, Columns, _Attributes), | |
32 | ( | |
33 | member(description(XDU, _DescAttrs), TableAttributes) | |
34 | -> csv_escape(XDU,XD), | |
35 | format(S, ' description="~w"', [XD]) | |
36 | ; true | |
37 | ), | |
38 | write(S, '>\n'), | |
39 | write_csv_table_header(S, Columns). | |
40 | ||
41 | write_csv_table_header(S, Columns) :- | |
42 | write_csv_table_header2(S, Columns). | |
43 | ||
44 | write_csv_table_header2(S, [Column]) :- | |
45 | csv_escape(Column, EscapedColumn), | |
46 | format(S, '~w\n', [EscapedColumn]). | |
47 | write_csv_table_header2(S, [Column | Columns]) :- | |
48 | csv_escape(Column, EscapedColumn), | |
49 | format(S, '~w,', [EscapedColumn]), | |
50 | write_csv_table_header2(S, Columns). | |
51 | ||
52 | csv_table_footer(_S, _TableName). | |
53 | ||
54 | % ---- | |
55 | % table rows | |
56 | % ---- | |
57 | csv_table_rows(S, TableName) :- | |
58 | findall(Entries, pltable_row(TableName, Entries, _Attributes), ListOfEntries), | |
59 | write_csv_table_rows(S, ListOfEntries). | |
60 | ||
61 | write_csv_table_rows(_S, []). | |
62 | write_csv_table_rows(S, [Entries | MoreEntries]) :- | |
63 | write_csv_table_row(S, Entries), | |
64 | write_csv_table_rows(S, MoreEntries). | |
65 | ||
66 | write_csv_table_row(S, [Entry]) :- | |
67 | csv_escape(Entry, EscapedEntry), | |
68 | format(S, '~w\n', [EscapedEntry]). | |
69 | write_csv_table_row(S, [Entry | Entries]) :- | |
70 | csv_escape(Entry, EscapedEntry), | |
71 | format(S, '~w,', [EscapedEntry]), | |
72 | write_csv_table_row(S, Entries). | |
73 | ||
74 | % ---- | |
75 | % escaping characters ? | |
76 | % ---- | |
77 | csv_escape(ToEscape, ToEscape). | |
78 | ||
79 | %csv_escape(ToEscape, Escaped) :- | |
80 | % atom(ToEscape), !, | |
81 | % atom_codes(ToEscape, CodeList), | |
82 | % csv_escape2(CodeList, EscapedCodeList), | |
83 | % atom_codes(Escaped, EscapedCodeList). | |
84 | %csv_escape(ToEscape, ToEscape). | |
85 | ||
86 | %csv_escape2([],[]). | |
87 | %csv_escape2([95|T], [92,95|EscT]) :- | |
88 | % csv_escape2(T, EscT). | |
89 | %csv_escape2([35|T], [92,35|EscT]) :- | |
90 | % csv_escape2(T, EscT). | |
91 | %csv_escape2([36|T], [92,36|EscT]) :- | |
92 | % csv_escape2(T, EscT). | |
93 | %csv_escape2([37|T], [92,37|EscT]) :- | |
94 | % csv_escape2(T, EscT). | |
95 | %csv_escape2([H|T], [H|EscT]) :- | |
96 | % H \= 95, | |
97 | % csv_escape2(T, EscT). |