-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
doc.tcl
307 lines (229 loc) · 8.4 KB
/
doc.tcl
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# Tulip Indicators
# https://tulipindicators.org/
# Copyright (c) 2010-2017 Tulip Charts LLC
# Lewis Van Winkle (LV@tulipcharts.org)
#
# This file is part of Tulip Indicators.
#
# Tulip Indicators is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# Tulip Indicators is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Tulip Indicators. If not, see <http://www.gnu.org/licenses/>.
puts "Generating documentation"
set h [open "indicators.h" r]
set header [read $h]
set header [split $header \n]
close $h
#Returns the C prototype for a given indicator
proc get_prototype {full_name} {
global header
set i [lsearch -exact $header "/* $full_name */"]
if {$i == -1} {
puts "Couldn't find prototype for: $full_name"
exit 1
}
set l $i
while {[lindex $header $l] ne ""} {
incr l
}
return [join [lrange $header $i $l-1] \n]
}
rename open open_old
proc open {n m} {
puts "Writing $n"
set k [open_old $n $m]
fconfigure $k -translation {auto lf}
return $k
}
file mkdir docs
set per 5
set indicators [exec sample --list]
set indicators [split $indicators "\n"]
#Make simple text list of indicators
set list {overlay {} indicator {} math {} simple {}}
foreach i $indicators {
array set ind $i
dict set list $ind(type) "[dict get $list $ind(type)] [format %-20s $ind(name)]$ind(full_name)\n"
}
set md [open [file join docs list.txt] w]
puts $md "[llength $indicators] total indicators\n"
puts $md "Overlay\n[dict get $list overlay]"
puts $md "Indicator\n[dict get $list indicator]"
puts $md "Math\n[dict get $list math]"
puts $md "Simple\n[dict get $list simple]"
close $md
#Make index of options and such for php
set php_array {}
foreach i $indicators {
array set ind $i
set members {}
foreach m {type name full_name} {
lappend members "\"$m\" => \"$ind($m)\""
}
foreach m {inputs options outputs} {
if {[llength $ind($m)] == 0} {
lappend members "\"$m\" => array()"
} else {
lappend members "\"$m\" => array(\"[join $ind($m) {", "}]\")"
}
}
lappend php_array "\"$ind(name)\" => array([join $members ", "])"
}
set o [open [file join docs index.php] w]
puts $o {<?php}
puts $o {}
puts $o {#GENERATED BY doc.tcl}
puts $o {#DO NOT MODIFY DIRECTLY}
puts $o {}
puts $o {$ti_indicators = array(}
puts $o [join $php_array ",\n"]
puts $o {);}
puts $o {}
puts $o {$ti_prototype = array();}
puts $o {$ti_example = array();}
puts $o {$ti_lua_example = array();}
puts $o {$ti_table = array();}
puts $o {}
set untest [open [file join tests untest.txt] w]
puts $untest "# These tests are generated by sample.c and doc.tcl"
puts $untest "# They can be ran with smoke.c"
puts $untest "# Failing a test here doesn't necessarily indicate a fault"
puts $untest "# but it means that output has changed from a previous version\n\n"
foreach i $indicators {
array set ind $i
puts "$ind(name) $ind(options) "
set options {}
switch $ind(name) {
kst {
lappend options 4 6 8 10 5 5 5 8
}
default {
foreach opt $ind(options) {
switch $opt {
period {lappend options 5}
"%k period" {lappend options 5}
"%k slowing period" {lappend options 3}
"%d period" {lappend options 3}
"acceleration factor step" {lappend options .2}
"acceleration factor maximum" {lappend options 2}
"alpha" {lappend options .2}
"beta" {lappend options .9}
"fast limit" {lappend options .5}
"long period" {lappend options 5}
"lookback period" {lappend options 5}
"medium period" {lappend options 3}
"multiple" {lappend options 2}
"offset" {lappend options .85}
"q period" {lappend options 3}
"r period" {lappend options 3}
"s period" {lappend options 3}
"sigma" {lappend options 6}
"signal period" {lappend options 9}
"slow limit" {lappend options .05}
"short period" {lappend options 2}
"smooth period" {lappend options 5}
"stddev" {lappend options 2}
default {
puts "\n\nERROR: Unhandled option $opt"
exit
}
}
}
}
}
puts -nonewline $o "\$ti_prototype\['$ind(name)'\] = \""
puts -nonewline $o [get_prototype $ind(full_name)]
puts $o "\";\n"
set oline {}
foreach opt $ind(options) oval $options {
lappend oline "$opt = $oval"
}
set oline [join $oline ", "]
set cmd [list sample $ind(name) {*}$options]
set table [exec {*}$cmd]
puts -nonewline $o "\$ti_table\['$ind(name)'\] = \""
puts $o $oline
puts -nonewline $o $table
puts $o "\";\n"
#Need to transpose the table to create test data
set table [regsub -all {[ ]+} $table " "]
puts $untest "\n[join [list $ind(name) {*}$options]]"
set table [split $table "\n"]
set cols [lindex $table 0]
set rest [lrange $table 1 end]
foreach col $cols {
if {$col eq "date"} continue
set cnum [lsearch -exact $cols $col]
set bars {}
foreach l $rest {
set v [lindex [split $l " "] $cnum]
if {$v ne {}} {lappend bars $v}
}
puts $untest "{[join $bars ,]}"
}
#C example code
puts -nonewline $o "\$ti_example\['$ind(name)'\] = \""
puts $o "/* Example usage of $ind(full_name) */"
if {$ind(inputs) == "real"} {
puts $o "/* Assuming that 'input' is a pre-loaded array of size 'in_size'. */"
set inputs input
} elseif {$ind(inputs) == "real real"} {
puts $o "/* Assuming that 'input1' and 'input2' are pre-loaded arrays of size 'in_size'. */"
set inputs "input1 input2"
} else {
if {[llength $ind(inputs)] == 2} {
set ins "'[lindex $ind(inputs) 0]' and '[lindex $ind(inputs) end]'"
} else {
set ins "[join '[lrange $ind(inputs) 0 end-1] "', '"]', and '[lindex $ind(inputs) end]'"
}
set inputs $ind(inputs)
puts $o "/* Assuming that $ins are pre-loaded arrays of size 'in_size'. */"
}
if {$options == {}} {
set oc "No options"
} else {
set oc [join $ind(options) ", "]
}
set outc [join $ind(outputs) ", "]
puts $o "TI_REAL *inputs\[\] = {[join $inputs {, }]};"
puts $o "TI_REAL options\[\] = {[join $options {, }]}; /* $oc */";
puts $o "TI_REAL *outputs\[[llength $ind(outputs)]\]; /* $outc */";
puts $o "\n/* Determine how large the output size is for our options. */"
puts $o "const int out_size = in_size - ti_$ind(name)_start(options);"
if {[llength $ind(outputs)] > 1} {
puts $o "\n/* Allocate memory for each output. */"
} else {
puts $o "\n/* Allocate memory for output. */"
}
for {set i 0} {$i < [llength $ind(outputs)]} {incr i} {
puts -nonewline $o "outputs\[$i\] = malloc(sizeof(TI_REAL) * out_size);"
puts $o " assert(outputs\[$i\] != 0); /* [lindex $ind(outputs) $i] */"
}
puts $o "\n/* Run the actual calculation. */"
puts $o "const int ret = ti_$ind(name)(in_size, inputs, options, outputs);"
puts $o "assert(ret == TI_OKAY);"
puts $o "\";\n"
#Lua example code
puts -nonewline $o "\$ti_lua_example\['$ind(name)'\] = \""
puts $o "-- Example usage of $ind(full_name)"
puts $o "[join $ind(outputs) {, }] = ti.$ind(name)([join [list {*}$inputs {*}$options] {, }])"
puts $o "\";\n"
}
puts $o {?>}
close $o
foreach i $indicators {
array set ind $i
set name $ind(name)
set fname $ind(full_name)
if {![file exists [file join www pages $name.md]]} {
puts "WARNING: no documentation for $name ($fname)"
}
}