1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 if args
.length
< 3 then
18 print
"Usage ./csv_gen record_length record_nb out_filepath [--unicode]"
22 var record_length
= args
[0].to_i
23 var record_nb
= args
[1].to_i
27 if args
.length
== 4 then
28 if not args
[3] == "--unicode" then
29 print
"Usage ./csv_gen record_length record_nb [--unicode]"
35 var ocsv
= new CsvDocument
38 var sep
= ocsv
.separator
.to_s
40 var del
= ocsv
.delimiter
.to_s
42 for i
in [0 .. record_length
[ do ocsv
.header
.add
"Col{i}"
44 var c
= if unicode
then "รก" else "a"
45 for i
in [0 .. record_nb
[ do
46 var line
= new Array[String].with_capacity
(record_length
)
47 for j
in [0 .. record_length
[ do
48 var add_sep
= 100.rand
> 70
49 var add_del
= 100.rand
> 70
50 var add_eol
= 100.rand
> 70
53 if add_sep
then s
= sep
+ s
54 if add_del
then s
+= del
55 if add_eol
then s
+= eol
61 ocsv
.write_to_file
(outpath
)