Commit 4fb1d6c69cbc395d39e857318b2708f45b16e4c3

Authored by David René
1 parent be0f81ed

add files with replace by for maintain compatibility with older programs

anubis_dev/library/install_released_files.bat
... ... @@ -58,6 +58,10 @@ copy .\tools\saturate.anubis C:\Anubis_dev\anubis_distrib\lib
58 58 copy .\tools\streams.anubis C:\Anubis_dev\anubis_distrib\library\tools\streams.anubis
59 59 copy .\tools\tables.anubis C:\Anubis_dev\anubis_distrib\library\tools\tables.anubis
60 60 copy .\tools\tools.anubis C:\Anubis_dev\anubis_distrib\library\tools\tools.anubis
  61 +copy .\tools\sdbms.anubis C:\Anubis_dev\anubis_distrib\library\tools\sdbms.anubis
  62 +copy .\tools\maml.anubis C:\Anubis_dev\anubis_distrib\library\tools\maml.anubis
  63 +copy .\tools\latex.anubis C:\Anubis_dev\anubis_distrib\library\tools\latex.anubis
  64 +copy .\tools\read_table.anubis C:\Anubis_dev\anubis_distrib\library\tools\read_table.anubis
61 65  
62 66 copy .\web\web_arg_encode.anubis C:\Anubis_dev\anubis_distrib\library\web\web_arg_encode.anubis
63 67 copy .\web\common.anubis C:\Anubis_dev\anubis_distrib\library\web\common.anubis
... ...
anubis_dev/library/tools/latex.anubis 0 → 100644
  1 +
  2 +
  3 +replaced by doc_tools/latex.anubis (since version 1.6)
... ...
anubis_dev/library/tools/maml.anubis 0 → 100644
  1 +replaced by doc_tools/maml.anubis (since version 1.6)
... ...
anubis_dev/library/tools/read_table.anubis
1   -
2   -
3   - The Anubis Project.
4 1  
5   - Reading tables.
6   -
7   - Copyright (c) Alain Proute' 2003.
8   - All rights reserved.
9 2  
10   -
11   - This file defines a tool for reading tables. A 'table' is a file containing 'lines'
12   - separated by a special character (or a combination of special characters), most often
13   - '\n' (ASCII 10) or '\r' (ASCII 13). Each line is separated into 'cells'. A special
14   - character is used for separating the cells within a line, most often '\t' (ASCII 9),
15   - ';' or '&'. Of course, this implies that these special characters are not used for the
16   - content of the cells themselves.
17   -
18   - Below is an example of a table whose line separator is '\n' (hence invisible in the
19   - example), and cell separator is '&':
20   -
21   - cell_1_1&cell_1_2&cell_1_3
22   - cell_2_1&cell_2_2
23   -
24   - This table has two lines. Notice that the lines need not have the same number of
25   - cells. Also, no line separator is following the string "cell_2_2" (the last byte in the
26   - file is '2'), otherwise the table would have 3 lines (with the last line empty).
27   -
28   - The content of a cell is considered as a character string. The contents of selected
29   - cells must eventually be transformed into integers or floating point numbers (or
30   - anything else), but this transformation is not handled here. The function defined here
31   - returns (maybe) a datum of type:
32   -
33   - List(List(String))
34   -
35   - which is to be interpreted as a list of lines, each line being a list of cells, each
36   - cell being a character strings.
37   -
38   - The function requires that you declare the possible separators. Each line separator is
39   - declared as a list of 'Int8'. For example, if the lines of the table to be read are
40   - separated by carriage return '\r' and line feed '\n' (in this order), the line
41   - separator is represented by '[13,10]', or by '['\r','\n']'.
42   -
43   - On the contrary, we assume that only one character is used as cell separator. Hence, a
44   - cell separator is represented by a single Int8. Below are realistic examples:
45   -
46   - ';' '&' '\t' 9
47   -
48   - The function below can handle several line separators and several cell separators
49   - simultaneously, so that the same call to the function can handle tables whose
50   - separators are different, or even handle tables with mixed separators (not usual). The
51   - function can also ignore some charaters (typically the space (ASCII 32)).
52   -
53   -public define Maybe(List(List(String)))
54   - read_table
55   - (
56   - String filename,
57   - NonEmptyList(NonEmptyList(Int8)) line_separators,
58   - NonEmptyList(Int8) cell_separators
59   - ).
60   -
61   - For example, the next call can read several sorts of tables:
62   -
63   - read_table(filename,
64   - [[10],[13],[13,10]],
65   - [';','\t'])
66   -
67   - It reads tables whose lines are separated either by '\n', '\r' or '\r' followed by
68   - '\n', and whose cells are separated either by ';' or by a tabulator.
69   -
70   - The result is 'failure' when the file cannot be opened. Otherwise, a table is always
71   - read (which may be empty, or wrong if you do not choose the right separators).
72   -
73   -
74   -
75   -
76   - --- That's all for the public part. ---------------------------------------------------
77   -
78   -
79   -
80   -
81   -
82   - Transforming a non empty list into a list.
83   -
84   -define List($T)
85   - to_list
86   - (
87   - NonEmptyList($T) l
88   - ) =
89   - if l is [first . others] then [first . others].
90   -
91   -
92   -
93   -
94   -
95   -
96   -
97   - Checking if a list of Int8 'candidate' is a prefix in a line separator.
98   -
99   -
100   -define Bool
101   - begins_line_separator
102   - (
103   - List(Int8) candidate,
104   - List(Int8) line_sep
105   - ) =
106   - if candidate is
107   - {
108   - [ ] then true,
109   - [ch . ct] then
110   - if line_sep is
111   - {
112   - [ ] then false,
113   - [sh . st] then
114   - if ch = sh
115   - then begins_line_separator(ct,st)
116   - else false
117   - }
118   - }.
119   -
120   -
121   -
122   - Here is the test.
123   -
124   -define Bool
125   - begins_line_separator
126   - (
127   - List(Int8) candidate,
128   - List(List(Int8)) line_seps
129   - ) =
130   - if line_seps is
131   - {
132   - [ ] then false,
133   - [s . others] then
134   - if begins_line_separator(candidate,s)
135   - then true
136   - else begins_line_separator(candidate,others)
137   - }.
138   -
139   -
140   -
141   -
142   - We have two cross recursive functions 'read_table' and 'read_more_lines'.
143   -
144   -define List(List(String))
145   - read_table
146   - (
147   - RAddr(Int8) file,
148   - List(List(Int8)) line_seps,
149   - List(Int8) line_sep_firsts,
150   - List(Int8) cell_seps,
151   - List(List(String)) so_far,
152   - List(String) current_line,
153   - List(Int8) current_cell
154   - ).
155   -
156   -
157   -
158   - Reading more lines from a table. We have already read several lines (at least one) and
159   - we have read a character 'c' (or several) which is (are) the first in a line separator.
160   - We read a new character 'd'. If a line separator begins by 'c' 'd' we continue until
161   - the characters read do not form a line separator. Of course we must handle end of
162   - file. If end of file is read, the last line of the table is empty. Otherwise, we
163   - return to 'read_table', with the correct 'current_line' and 'current_cell'.
164   -
165   -define List(List(String))
166   - read_more_lines
167   - (
168   - RAddr(Int8) file,
169   - List(List(Int8)) line_seps,
170   - List(Int8) line_sep_firsts,
171   - List(Int8) cell_seps,
172   - List(List(String)) so_far, // lines read so far
173   - List(Int8) firsts_in_sep // first characters of line separator (just read)
174   - ) =
175   - if *file is
176   - {
177   - failure then reverse([[] . so_far]), // last line empty
178   - success(d) then with firsts = (List(Int8))[d . firsts_in_sep],
179   - if begins_line_separator(firsts,line_seps)
180   - then read_more_lines(file,line_seps,line_sep_firsts,cell_seps,so_far,firsts)
181   - else read_table(file,line_seps,line_sep_firsts,cell_seps,so_far,[],[d])
182   - }.
183   -
184   -
185   -
186   - Reading a table from an already opened file.
187   -
188   -define List(List(String))
189   - read_table
190   - (
191   - RAddr(Int8) file,
192   - List(List(Int8)) line_seps,
193   - List(Int8) line_sep_firsts, // first characters in line separators
194   - List(Int8) cell_seps,
195   - List(List(String)) so_far, // lines read so far
196   - List(String) current_line, // cells read so far in the current line
197   - List(Int8) current_cell // characters read so far in the current cell
198   - ) =
199   - if *file is
200   - {
201   - failure then
202   - reverse([reverse([implode(reverse(current_cell)) . current_line]) . so_far]),
203   -
204   - success(c) then
205   - if member(line_sep_firsts,c)
206   - then read_more_lines(file,line_seps,line_sep_firsts,cell_seps,
207   - [reverse([implode(reverse(current_cell)) . current_line]) . so_far],[c])
208   - else if member(cell_seps,c)
209   - then read_table(file,line_seps,line_sep_firsts,cell_seps,so_far,
210   - [implode(reverse(current_cell)) . current_line],[])
211   - else read_table(file,line_seps,line_sep_firsts,cell_seps,so_far,current_line,
212   - [c . current_cell])
213   - }.
214   -
215   -
216   -
217   -
218   -
219   - Now, here is our tool.
220   -
221   -public define Maybe(List(List(String)))
222   - read_table
223   - (
224   - String filename,
225   - NonEmptyList(NonEmptyList(Int8)) line_separators,
226   - NonEmptyList(Int8) cell_separators
227   - ) =
228   - if (Maybe(RAddr(Int8)))file(filename,read) is
229   - {
230   - failure then failure,
231   - success(file) then with line_seps = to_list(line_separators),
232   - success(read_table(file,
233   - map(reverse,map(to_list,line_seps)),
234   - map((NonEmptyList(Int8) l) |-> if l is [h.t] then h, line_seps),
235   - to_list(cell_separators),
236   - [],[],[]))
237   - }.
238   -
239   -
240   -
241   -
242   -
243   -
244   - Try it !
245   -
246   -
247   -
248   -define One
249   - table_print
250   - (
251   - List(String) l
252   - ) =
253   - if l is
254   - {
255   - [ ] then print("\n"),
256   - [h . t] then print(h);
257   - (if t is [] then unique else print(" | "));
258   - table_print(t)
259   - }.
260   -
261   -define One
262   - table_print
263   - (
264   - List(List(String)) t
265   - ) =
266   - if t is
267   - {
268   - [ ] then unique,
269   - [h . t] then table_print(h); table_print(t)
270   - }.
271   -
272   -define One
273   - table_print
274   - (
275   - Maybe(List(List(String))) t
276   - ) =
277   - if t is
278   - {
279   - failure then print("File not found.\n"),
280   - success(l) then table_print(l)
281   - }.
282   -
283   -global define One
284   - read_table
285   - (
286   - List(String) args
287   - ) =
288   - if args is
289   - {
290   - [ ] then print("Usage: read_table <filename>\n"),
291   - [h . t] then
292   - table_print(read_table(h,
293   - [[10],[13],[13,10]],
294   - [';','\t','&']))
295   - }.
296   -
297   -
298   -
299 3 \ No newline at end of file
  4 +replaced by data_base/import_csv.anubis (since version 1.6)
... ...