1 | #! /mnt/amd/users/urmel/insider/schmidt/bin/bash |
---|
2 | # $Id: runfex,v 1.1 1997-10-10 13:07:25 schmidt Exp $ |
---|
3 | |
---|
4 | #{{{ docu |
---|
5 | # |
---|
6 | # runfxc - run factory example collection. |
---|
7 | # |
---|
8 | #}}} |
---|
9 | |
---|
10 | set -o nounset |
---|
11 | set -o noglob |
---|
12 | |
---|
13 | #{{{ global constants |
---|
14 | #{{{ docu |
---|
15 | # |
---|
16 | # - global constants. |
---|
17 | # |
---|
18 | # ExecName: used to prefix error messages. Used by warn(). |
---|
19 | # XXColWidth: default width for data columns. Used by main() and |
---|
20 | # example(). |
---|
21 | # PreCharWidth: width of one preformatted character in pixels. |
---|
22 | # Used by printData(). |
---|
23 | # EvalAlg: algorithm to read run/collection data from. Used by |
---|
24 | # main(). |
---|
25 | # |
---|
26 | #}}} |
---|
27 | readonly ExecName="$0" |
---|
28 | |
---|
29 | typeset -ir TBColWidth=300 |
---|
30 | typeset -ir XOColWidth=400 |
---|
31 | typeset -ir ROColWidth=400 |
---|
32 | |
---|
33 | typeset -ir PreCharWidth=6 |
---|
34 | |
---|
35 | readonly EvalAlg="feval" |
---|
36 | #}}} |
---|
37 | |
---|
38 | #{{{ global variables |
---|
39 | #{{{ docu |
---|
40 | # |
---|
41 | # - global variables. |
---|
42 | # |
---|
43 | # runName: name of current run. Used by main() and example(). |
---|
44 | # collectionName, collectionNote: name of current collection, |
---|
45 | # comment on it. Used by main() and createTable(). |
---|
46 | # runOptions, collectionOptions, runEnvironment, |
---|
47 | # collectionEnvironment: options and environment for the |
---|
48 | # examples. Used by runAlgorithm(). |
---|
49 | # collectionROOptions: options to print run overview. Use by |
---|
50 | # main(). |
---|
51 | # runXXOptions, collectionXXOptions: options to print XX tables. |
---|
52 | # Used by example(). |
---|
53 | # debugMode: do not execute anything, just print what we would |
---|
54 | # have executed. Used by main(), example(), and |
---|
55 | # runAlgorithm(). |
---|
56 | # |
---|
57 | # The run* variables, debugMode, and collectionName are set in |
---|
58 | # the main program, the rest of the collection* variables in |
---|
59 | # collection(). |
---|
60 | # |
---|
61 | #}}} |
---|
62 | runName="" |
---|
63 | runOptions="" |
---|
64 | runEnvironment="" |
---|
65 | runTBOptions="" |
---|
66 | runXOOptions="" |
---|
67 | |
---|
68 | collectionName="" |
---|
69 | collectionNote="" |
---|
70 | collectionOptions="" |
---|
71 | collectionEnvironment="" |
---|
72 | collectionTBOptions="" |
---|
73 | collectionXOOptions="" |
---|
74 | collectionROOptions="" |
---|
75 | |
---|
76 | debugMode="" |
---|
77 | #}}} |
---|
78 | |
---|
79 | # |
---|
80 | # - functions. |
---|
81 | # |
---|
82 | |
---|
83 | #{{{ warn() |
---|
84 | #{{{ docu |
---|
85 | # |
---|
86 | # warn() - print arguments to stderr prefixed $ExecName. |
---|
87 | # |
---|
88 | # Global variables used: |
---|
89 | # ExecName |
---|
90 | # |
---|
91 | #}}} |
---|
92 | warn() |
---|
93 | { |
---|
94 | echo "$ExecName:" "${@-}" >&2 |
---|
95 | } |
---|
96 | #}}} |
---|
97 | |
---|
98 | #{{{ pc() |
---|
99 | #{{{ docu |
---|
100 | # |
---|
101 | # pc() - print html table cell. |
---|
102 | # |
---|
103 | # $1: cell contents |
---|
104 | # $2: cell format information |
---|
105 | # |
---|
106 | # Global variables used: none |
---|
107 | # |
---|
108 | #}}} |
---|
109 | pc() |
---|
110 | { |
---|
111 | echo "<th ${2-}><font size=+1>$1</font></th>" |
---|
112 | } |
---|
113 | #}}} |
---|
114 | |
---|
115 | #{{{ pct() |
---|
116 | #{{{ docu |
---|
117 | # |
---|
118 | # pc() - print html table cell in type writer style. |
---|
119 | # |
---|
120 | # $1: cell contents |
---|
121 | # $2: cell format information |
---|
122 | # |
---|
123 | # Global variables used: none |
---|
124 | # |
---|
125 | #}}} |
---|
126 | pct() |
---|
127 | { |
---|
128 | echo "<th valign=center ${2-}><tt><font size=+2>$1</font></tt></th>" |
---|
129 | } |
---|
130 | #}}} |
---|
131 | |
---|
132 | #{{{ runAlgorithm() |
---|
133 | #{{{ docu |
---|
134 | # |
---|
135 | # runAlgorithm() - run algorithm with the correct options. |
---|
136 | # |
---|
137 | # $1: algorithm to run |
---|
138 | # $2: output options |
---|
139 | # rest: arguments to algorithm |
---|
140 | # |
---|
141 | # Global variables used: |
---|
142 | # runOptions, runEnvironment, |
---|
143 | # collectionOptions, collectionEnvironment, |
---|
144 | # exampleOptions, exampleEnvironment, |
---|
145 | # debugMode |
---|
146 | # |
---|
147 | #}}} |
---|
148 | runAlgorithm() |
---|
149 | { |
---|
150 | typeset \ |
---|
151 | algorithmName="$1" \ |
---|
152 | outputOptions="$2" \ |
---|
153 | algorithmOptions="$collectionOptions${exampleOptions-}$runOptions" \ |
---|
154 | algorithmEnvironment="$collectionEnvironment${exampleEnvironment-}$runEnvironment" |
---|
155 | shift 2 |
---|
156 | |
---|
157 | # reset factory environemnt to exclude external influences |
---|
158 | FTEST_ENV="" |
---|
159 | FTEST_CIRCLE="" |
---|
160 | FTEST_ALARM="" |
---|
161 | |
---|
162 | if [ -n "$debugMode" ]; then |
---|
163 | echo "calling $algorithmName" $algorithmOptions "$outputOptions" "$algorithmEnvironment" "$@" |
---|
164 | else |
---|
165 | "$algorithmName" $algorithmOptions "$outputOptions" "$algorithmEnvironment" "$@" |
---|
166 | fi |
---|
167 | } |
---|
168 | #}}} |
---|
169 | |
---|
170 | #{{{ printData() |
---|
171 | #{{{ docu |
---|
172 | # |
---|
173 | # printData() - print example/run table. |
---|
174 | # |
---|
175 | # $1: options how to print data |
---|
176 | # $2: default width to print data |
---|
177 | # $3: initial cell |
---|
178 | # $4: blockheight offset |
---|
179 | # |
---|
180 | # Global variables used: |
---|
181 | # alg* algorithm information, |
---|
182 | # PreCharWidth |
---|
183 | # |
---|
184 | #}}} |
---|
185 | printData() |
---|
186 | { |
---|
187 | typeset \ |
---|
188 | options="$1" \ |
---|
189 | colWidth |
---|
190 | |
---|
191 | colWidth="${options//[a-z]/}" |
---|
192 | colWidth="${colWidth:-$2}" |
---|
193 | options="${options//[0-9]/}" |
---|
194 | |
---|
195 | typeset -i \ |
---|
196 | colCharWidth=$colWidth/PreCharWidth+1 \ |
---|
197 | blockHeight=$4 \ |
---|
198 | i=0 n=0 |
---|
199 | |
---|
200 | # get correct block height |
---|
201 | blockHeight=blockHeight+${#options} |
---|
202 | case "$options" in |
---|
203 | *r*) blockHeight=blockHeight+${#algResultTags[@]}-1 ;; |
---|
204 | esac |
---|
205 | case "$options" in |
---|
206 | *d*) blockHeight=blockHeight+${#algDataTags[@]}-1 ;; |
---|
207 | esac |
---|
208 | |
---|
209 | #{{{ print first line |
---|
210 | # for efficiency, we repeat this case statement to print the first line |
---|
211 | if [ -n "$options" ]; then |
---|
212 | case "$options" in |
---|
213 | *p*) echo "<tr align=left valign=top>$( pc "$3" "rowspan=$blockHeight" )<!bol>$( pc Char )$( pct "$algChar" "width=$colWidth" )<!eol></tr>" |
---|
214 | options="${options//p/}" ;; |
---|
215 | *s*) echo "<tr align=left valign=top>$( pc "$3" "rowspan=$blockHeight" )<!bol>$( pc Switches )$( pct "$algSwitch" "width=$colWidth" )<!eol></tr>" |
---|
216 | options="${options//s/}" ;; |
---|
217 | *v*) echo "<tr align=left valign=top>$( pc "$3" "rowspan=$blockHeight" )<!bol>$( pc Variables )$( pct "$algVars" "width=$colWidth" )<!eol></tr>" |
---|
218 | options="${options//v/}" ;; |
---|
219 | *n*) echo "<tr align=left valign=top>$( pc "$3" "rowspan=$blockHeight" )<!bol>$( pc Circles )$( pct "$algCircle" "width=$colWidth" )<!eol></tr>" |
---|
220 | options="${options//n/}" ;; |
---|
221 | *g*) echo "<tr align=left valign=top>$( pc "$3" "rowspan=$blockHeight" )<!bol>$( pc Seed )$( pct "$algSeed" "width=$colWidth" )<!eol></tr>" |
---|
222 | options="${options//g/}" ;; |
---|
223 | *f*) echo "<tr align=left valign=top>$( pc "$3" "rowspan=$blockHeight" )<!bol>$( pc Version )$( pct "$algVers" "width=$colWidth" )<!eol></tr>" |
---|
224 | options="${options//f/}" ;; |
---|
225 | *t*) echo "<tr align=left valign=top>$( pc "$3" "rowspan=$blockHeight" )<!bol>$( pc Time )$( pct "$algTime" "width=$colWidth" )<!eol></tr>" |
---|
226 | options="${options//t/}" ;; |
---|
227 | *c*) echo "<tr align=left valign=top>$( pc "$3" "rowspan=$blockHeight" )<!bol>$( pc Check )$( pct "$algCheck" "width=$colWidth" )<!eol></tr>" |
---|
228 | options="${options//c/}" ;; |
---|
229 | *d*|*r*) |
---|
230 | warn "first line in a table must not start with data or result information" |
---|
231 | options="" ;; |
---|
232 | *) warn "unknown output type specifier '$options' in table specification" |
---|
233 | options="" ;; |
---|
234 | esac |
---|
235 | fi |
---|
236 | #}}} |
---|
237 | |
---|
238 | #{{{ print other lines |
---|
239 | while [ -n "$options" ]; do |
---|
240 | case "$options" in |
---|
241 | *p*) echo "<tr align=left valign=top><!bol>$( pc Char )$( pct "$algChar" )<!eol></tr>" |
---|
242 | options="${options//p/}" ;; |
---|
243 | *s*) echo "<tr align=left valign=top><!bol>$( pc Switches )$( pct "$algSwitch" )<!eol></tr>" |
---|
244 | options="${options//s/}" ;; |
---|
245 | *v*) echo "<tr align=left valign=top><!bol>$( pc Variables )$( pct "$algVars" )<!eol></tr>" |
---|
246 | options="${options//v/}" ;; |
---|
247 | *n*) echo "<tr align=left valign=top><!bol>$( pc Circles )$( pct "$algCircle" )<!eol></tr>" |
---|
248 | options="${options//n/}" ;; |
---|
249 | *g*) echo "<tr align=left valign=top><!bol>$( pc Seed )$( pct "$algSeed" )<!eol></tr>" |
---|
250 | options="${options//g/}" ;; |
---|
251 | *f*) echo "<tr align=left valign=top><!bol>$( pc Version )$( pct "$algVers" )<!eol></tr>" |
---|
252 | options="${options//f/}" ;; |
---|
253 | *t*) echo "<tr align=left valign=top><!bol>$( pc Time )$( pct "$algTime" )<!eol></tr>" |
---|
254 | options="${options//t/}" ;; |
---|
255 | *c*) echo "<tr align=left valign=top><!bol>$( pc Check )$( pct "$algCheck" )<!eol></tr>" |
---|
256 | options="${options//c/}" ;; |
---|
257 | *d*) |
---|
258 | n=${#algDataTags[@]} |
---|
259 | i=0 |
---|
260 | while [ $i -lt $n ]; do |
---|
261 | cat << EOT |
---|
262 | <tr align=left valign=top> |
---|
263 | <!bol> |
---|
264 | $( pc "${algDataTags[i]}" )<th><pre> |
---|
265 | EOT |
---|
266 | echo "${algData[i]}" | fold -s -w$colCharWidth |
---|
267 | cat << EOT |
---|
268 | </pre></th> |
---|
269 | <!eol> |
---|
270 | </tr> |
---|
271 | EOT |
---|
272 | i=i+1 |
---|
273 | done |
---|
274 | options="${options//d/}" ;; |
---|
275 | *r*) |
---|
276 | n=${#algResultTags[@]} |
---|
277 | i=0 |
---|
278 | while [ $i -lt $n ]; do |
---|
279 | cat << EOT |
---|
280 | <tr align=left valign=top> |
---|
281 | <!bol> |
---|
282 | $( pc "${algResultTags[i]}" )<th><pre> |
---|
283 | EOT |
---|
284 | echo "${algResult[i]}" | fold -s -w$colCharWidth |
---|
285 | cat << EOT |
---|
286 | </pre></th> |
---|
287 | <!eol> |
---|
288 | </tr> |
---|
289 | EOT |
---|
290 | i=i+1 |
---|
291 | done |
---|
292 | options="${options//r/}" ;; |
---|
293 | *) warn "unknown output type specifier '$options' in table specification" |
---|
294 | options="" ;; |
---|
295 | esac |
---|
296 | done |
---|
297 | #}}} |
---|
298 | } |
---|
299 | #}}} |
---|
300 | |
---|
301 | #{{{ collection() |
---|
302 | #{{{ docu |
---|
303 | # |
---|
304 | # collection() - set up collection data. |
---|
305 | # |
---|
306 | # All we do is setting the collection* variables (except |
---|
307 | # collectionName) from commandline. |
---|
308 | # We do not set collectionNote and collectionXXOptions if they |
---|
309 | # are already set but reset collectionOptions and |
---|
310 | # collectionEnvironment on each run to allow for multiple calls |
---|
311 | # to collection() in one example collection file (though this is |
---|
312 | # bad style). |
---|
313 | # |
---|
314 | # Global variables used: none |
---|
315 | # |
---|
316 | #}}} |
---|
317 | collection() |
---|
318 | { |
---|
319 | collectionOptions="" |
---|
320 | collectionEnvironment="" |
---|
321 | |
---|
322 | #{{{ read options and environment |
---|
323 | # read options |
---|
324 | typeset opt |
---|
325 | while getopts "n:a:c:t:x:r:" opt; do |
---|
326 | case "$opt" in |
---|
327 | n) collectionNote="${collectionNote:-$OPTARG}" ;; |
---|
328 | a) collectionOptions="$collectionOptions -a$OPTARG" ;; |
---|
329 | c) collectionOptions="$collectionOptions -c$OPTARG" ;; |
---|
330 | t) collectionTBOptions="${collectionTBOptions:-$OPTARG}" ;; |
---|
331 | x) collectionXOOptions="${collectionXOOptions:-$OPTARG}" ;; |
---|
332 | r) collectionROOptions="${collectionROOptions:-$OPTARG}" ;; |
---|
333 | ?) warn "bad collection option"; exit 1 ;; |
---|
334 | esac |
---|
335 | done |
---|
336 | # shift options and reset OPTIND |
---|
337 | typeset -i optind |
---|
338 | optind=OPTIND-1 |
---|
339 | shift $optind |
---|
340 | OPTIND=1 |
---|
341 | |
---|
342 | # read environment |
---|
343 | while [ "${1-}" != "${1+${1#/}}" ]; do |
---|
344 | collectionEnvironment="$collectionEnvironment $1" |
---|
345 | shift |
---|
346 | done |
---|
347 | #}}} |
---|
348 | } |
---|
349 | #}}} |
---|
350 | |
---|
351 | #{{{ createTable() |
---|
352 | #{{{ docu |
---|
353 | # |
---|
354 | # createTable() - create html file from output data. |
---|
355 | # |
---|
356 | # $1: runName |
---|
357 | # |
---|
358 | # Global variables used: |
---|
359 | # collectionName, collectionNote |
---|
360 | # |
---|
361 | #}}} |
---|
362 | createTable() |
---|
363 | { |
---|
364 | typeset runName="$1" |
---|
365 | |
---|
366 | # write header |
---|
367 | cat << EOT |
---|
368 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> |
---|
369 | <html> |
---|
370 | <head> |
---|
371 | <title>Results from running $collectionName</title> |
---|
372 | <meta name="Author" content="Jens Schmidt"> |
---|
373 | </head> |
---|
374 | <! this corresponds to burlywood1> |
---|
375 | <body bgcolor="#fcce8e"> |
---|
376 | EOT |
---|
377 | |
---|
378 | |
---|
379 | # example table |
---|
380 | cat << EOT |
---|
381 | <h2>Examples and Runs</h2> |
---|
382 | <table border=1 cellpadding=5 cellspacing=1> |
---|
383 | <tr align=left valign=top>$( pc "Coll. Name" )$( pct "$collectionName" colspan=2 )</tr> |
---|
384 | <tr align=left valign=top>$( pc "Coll. Note" )$( pct "${collectionNote:-(no note)}" colspan=2 )</tr> |
---|
385 | <tr align=left valign=top><!bol>$( pc "" )$( pc "<a name=\"TB$runName\" href=\"#RO$runName\">$runName</a>" "colspan=2")<!eol></tr> |
---|
386 | EOT |
---|
387 | cat "$runName.tb.tbl" |
---|
388 | |
---|
389 | cat << EOT |
---|
390 | </table> |
---|
391 | EOT |
---|
392 | |
---|
393 | # example overview |
---|
394 | cat << EOT |
---|
395 | <h2>Overview over Examples</h2> |
---|
396 | <table border=1 cellpadding=5 cellspacing=1> |
---|
397 | <tr align=left valign=top>$( pc "Coll. Name" )$( pct "$collectionName" colspan=2 )</tr> |
---|
398 | <tr align=left valign=top>$( pc "Coll. Note" )$( pct "${collectionNote:-(no note)}" colspan=2 )</tr> |
---|
399 | <tr align=left valign=top>$( pc "Examples" )$( pc "Data" colspan=2 )</tr> |
---|
400 | EOT |
---|
401 | cat "$runName.xo.tbl" |
---|
402 | |
---|
403 | cat << EOT |
---|
404 | </table> |
---|
405 | EOT |
---|
406 | |
---|
407 | |
---|
408 | # run overview |
---|
409 | cat << EOT |
---|
410 | <h2>Overview over Runs</h2> |
---|
411 | <table border=1 cellpadding=5 cellspacing=1> |
---|
412 | <tr align=left valign=top>$( pc "Coll. Name" )$( pct "$collectionName" colspan=2 )</tr> |
---|
413 | <tr align=left valign=top>$( pc "Coll. Note" )$( pct "${collectionNote:-(no note)}" colspan=2 )</tr> |
---|
414 | <tr align=left valign=top>$( pc "Runs" )$( pc "Data" colspan=2 )</tr> |
---|
415 | EOT |
---|
416 | cat "$runName.ro.tbl" |
---|
417 | |
---|
418 | cat << EOT |
---|
419 | </table> |
---|
420 | EOT |
---|
421 | |
---|
422 | |
---|
423 | # write footer |
---|
424 | cat << EOT |
---|
425 | </body> |
---|
426 | </html> |
---|
427 | EOT |
---|
428 | } |
---|
429 | #}}} |
---|
430 | |
---|
431 | #{{{ defineSkip() |
---|
432 | #{{{ docu |
---|
433 | # |
---|
434 | # defineSkip() - define function skipExample(). |
---|
435 | # |
---|
436 | #}}} |
---|
437 | defineSkip() |
---|
438 | { |
---|
439 | typeset regExp="" |
---|
440 | typeset notRegExp="" |
---|
441 | typeset rawArg arg |
---|
442 | |
---|
443 | for rawArg; do |
---|
444 | # check for leading ^ |
---|
445 | arg="${rawArg#^}" |
---|
446 | if [ "$rawArg" = "$arg" ]; then |
---|
447 | regExp="$regExp|$arg" |
---|
448 | else |
---|
449 | notRegExp="$notRegExp|$arg" |
---|
450 | fi |
---|
451 | shift |
---|
452 | done |
---|
453 | regExp="${regExp#|}" |
---|
454 | notRegExp="${notRegExp#|}" |
---|
455 | |
---|
456 | if [ -z "$regExp" -a -z "$notRegExp" ]; then |
---|
457 | eval " |
---|
458 | skipExample() |
---|
459 | { |
---|
460 | return 1 |
---|
461 | } |
---|
462 | " |
---|
463 | elif [ -n "$regExp" -a -z "$notRegExp" ]; then |
---|
464 | eval " |
---|
465 | skipExample() |
---|
466 | { |
---|
467 | case \"\$1\" in |
---|
468 | $regExp) return 1 ;; |
---|
469 | *) return 0 ;; |
---|
470 | esac |
---|
471 | } |
---|
472 | " |
---|
473 | elif [ -z "$regExp" -a -n "$notRegExp" ]; then |
---|
474 | eval " |
---|
475 | skipExample() |
---|
476 | { |
---|
477 | case \"\$1\" in |
---|
478 | $notRegExp) return 0 ;; |
---|
479 | *) return 1 ;; |
---|
480 | esac |
---|
481 | } |
---|
482 | " |
---|
483 | else |
---|
484 | eval " |
---|
485 | skipExample() |
---|
486 | { |
---|
487 | case \"\$1\" in |
---|
488 | $notRegExp) return 0 ;; |
---|
489 | $regExp) return 1 ;; |
---|
490 | *) return 0 ;; |
---|
491 | esac |
---|
492 | } |
---|
493 | " |
---|
494 | fi |
---|
495 | } |
---|
496 | #}}} |
---|
497 | |
---|
498 | #{{{ example() |
---|
499 | #{{{ docu |
---|
500 | # |
---|
501 | # example() - run an example. |
---|
502 | # |
---|
503 | # Global variables used: |
---|
504 | # runName, debugMode, |
---|
505 | # runTBOptions, runXOOptions, |
---|
506 | # collectionTBOptions, collectionXOOptions, |
---|
507 | # TBColWidth, XOColWidth |
---|
508 | # |
---|
509 | #}}} |
---|
510 | example() |
---|
511 | { |
---|
512 | typeset exampleName="" \ |
---|
513 | exampleNote="" \ |
---|
514 | exampleOptions="" \ |
---|
515 | exampleEnvironment="" \ |
---|
516 | exampleTBOptions="" \ |
---|
517 | exampleXOOptions="" |
---|
518 | |
---|
519 | typeset algorithm="" \ |
---|
520 | algorithmTBOptions="" \ |
---|
521 | algorithmXOOptions="" |
---|
522 | |
---|
523 | #{{{ read example name and skip it if necessary |
---|
524 | if [ "$#" = "0" ]; then |
---|
525 | warn "no example name specified" |
---|
526 | exit 1 |
---|
527 | fi |
---|
528 | exampleName="$1" |
---|
529 | shift |
---|
530 | |
---|
531 | if skipExample "$exampleName"; then |
---|
532 | if [ -n "$debugMode" ]; then |
---|
533 | echo "skipping $exampleName" |
---|
534 | else |
---|
535 | warn "skipping $exampleName" |
---|
536 | fi |
---|
537 | return |
---|
538 | else |
---|
539 | warn "running $exampleName" |
---|
540 | fi |
---|
541 | #}}} |
---|
542 | |
---|
543 | #{{{ read options and environment |
---|
544 | # read options |
---|
545 | typeset opt |
---|
546 | while getopts "n:a:c:t:x:" opt; do |
---|
547 | case "$opt" in |
---|
548 | n) exampleNote="$OPTARG" ;; |
---|
549 | a) exampleOptions="$exampleOptions -a$OPTARG" ;; |
---|
550 | c) exampleOptions="$exampleOptions -c$OPTARG" ;; |
---|
551 | t) exampleTBOptions="$OPTARG" ;; |
---|
552 | x) exampleXOOptions="$OPTARG" ;; |
---|
553 | ?) warn "bad example option"; exit 1 ;; |
---|
554 | esac |
---|
555 | done |
---|
556 | # shift options and reset OPTIND |
---|
557 | typeset -i optind |
---|
558 | optind=OPTIND-1 |
---|
559 | shift $optind |
---|
560 | OPTIND=1 |
---|
561 | |
---|
562 | # read environment |
---|
563 | while [ "${1-}" != "${1+${1#/}}" ]; do |
---|
564 | exampleEnvironment="$exampleEnvironment $1" |
---|
565 | shift |
---|
566 | done |
---|
567 | #}}} |
---|
568 | |
---|
569 | #{{{ read rest of arguments |
---|
570 | if [ "$#" = "0" ]; then |
---|
571 | warn "no example specified" |
---|
572 | exit 1 |
---|
573 | fi |
---|
574 | algorithm="$1" |
---|
575 | shift |
---|
576 | #}}} |
---|
577 | |
---|
578 | # check for debug mode |
---|
579 | if [ -n "$debugMode" ]; then |
---|
580 | runAlgorithm "$algorithm" -oas "$@" |
---|
581 | return |
---|
582 | fi |
---|
583 | |
---|
584 | # collect output options |
---|
585 | algorithmTBOptions="${runTBOptions:-${exampleTBOptions:-$collectionTBOptions}}" |
---|
586 | algorithmXOOptions="${runXOOptions:-${exampleXOOptions:-$collectionXOOptions}}" |
---|
587 | |
---|
588 | #{{{ read and print data |
---|
589 | typeset algChar \ |
---|
590 | algSwitch \ |
---|
591 | algVars \ |
---|
592 | algCircle \ |
---|
593 | algSeed \ |
---|
594 | algVers \ |
---|
595 | algTime \ |
---|
596 | algCheck |
---|
597 | |
---|
598 | typeset -a algData \ |
---|
599 | algResult \ |
---|
600 | algDataTags \ |
---|
601 | algResultTags |
---|
602 | |
---|
603 | typeset -i i=0 j=0 |
---|
604 | |
---|
605 | # read data |
---|
606 | runAlgorithm "$algorithm" -oas "$@" \ |
---|
607 | | { |
---|
608 | read algChar |
---|
609 | read algSwitch |
---|
610 | read algVars |
---|
611 | read algCircle |
---|
612 | read algSeed |
---|
613 | read algVers |
---|
614 | read algTime |
---|
615 | read algCheck |
---|
616 | |
---|
617 | # preprocess output and store result in the arrays |
---|
618 | while read line; do |
---|
619 | case "$line" in |
---|
620 | @@!*) |
---|
621 | # read data lines |
---|
622 | algDataTags[i]="${line#@@!}" |
---|
623 | read line |
---|
624 | algData[i]="$line" |
---|
625 | while read line && test "$line" != "@@"; do |
---|
626 | algData[i]="${algData[i]} |
---|
627 | $line" |
---|
628 | done |
---|
629 | i=i+1 ;; |
---|
630 | @!*) |
---|
631 | # read one data line |
---|
632 | algDataTags[i]="${line#@!}" |
---|
633 | algDataTags[i]="${algDataTags[i]%%:*}" |
---|
634 | algData[i]="${line#*: }" |
---|
635 | i=i+1 ;; |
---|
636 | @@*) |
---|
637 | # read result lines |
---|
638 | algResultTags[j]="${line#@@}" |
---|
639 | read line |
---|
640 | algResult[j]="$line" |
---|
641 | while read line && test "$line" != "@@"; do |
---|
642 | algResult[j]="${algResult[j]} |
---|
643 | $line" |
---|
644 | done |
---|
645 | j=j+1 ;; |
---|
646 | @*) |
---|
647 | # read one result line |
---|
648 | algResultTags[j]="${line#@}" |
---|
649 | algResultTags[j]="${algResultTags[j]%%:*}" |
---|
650 | algResult[j]="${line#*: }" |
---|
651 | j=j+1 ;; |
---|
652 | esac |
---|
653 | done |
---|
654 | |
---|
655 | #{{{ print table |
---|
656 | # print header |
---|
657 | cat << EOT >> "$runName.tb.tbl" |
---|
658 | <!TBBlock $exampleName> |
---|
659 | EOT |
---|
660 | |
---|
661 | # print table |
---|
662 | printData "$algorithmTBOptions" "$TBColWidth" \ |
---|
663 | "<a name=\"TB$exampleName\" href=\"#XO$exampleName\">$exampleName</a>" 0 >> "$runName.tb.tbl" |
---|
664 | |
---|
665 | # print trailer |
---|
666 | cat << EOT >> "$runName.tb.tbl" |
---|
667 | <!/TBBlock $exampleName> |
---|
668 | EOT |
---|
669 | #}}} |
---|
670 | |
---|
671 | #{{{ print example overview |
---|
672 | # print header |
---|
673 | cat << EOT >> "$runName.xo.tbl" |
---|
674 | <!XOBlockX $exampleName> |
---|
675 | <tr align=left valign=top>$( pc "<a name=\"XO$exampleName\" href=\"#TB$exampleName\">$exampleName</a>" )$( pc "Ex. Note" )$( pct "${exampleNote:-(no note)}" )</tr> |
---|
676 | <!XOBlockR $runName> |
---|
677 | EOT |
---|
678 | |
---|
679 | # print data |
---|
680 | printData "$algorithmXOOptions" "$XOColWidth" \ |
---|
681 | "<a href=\"#RO$runName\">$runName</a>" 0 >> "$runName.xo.tbl" |
---|
682 | |
---|
683 | # print trailer |
---|
684 | cat << EOT >> "$runName.xo.tbl" |
---|
685 | <!/XOBlockR $runName> |
---|
686 | <!/XOBlockX $exampleName> |
---|
687 | EOT |
---|
688 | #}}} |
---|
689 | } |
---|
690 | #}}} |
---|
691 | } |
---|
692 | #}}} |
---|
693 | |
---|
694 | #{{{ main program |
---|
695 | #{{{ docu |
---|
696 | # |
---|
697 | # - main program. |
---|
698 | # |
---|
699 | # runROOptions: options for RO table. Read from commandline. |
---|
700 | # runNote: comment on run. Read from commandline. |
---|
701 | # rawCollectionName: collection name with full path |
---|
702 | # |
---|
703 | # Global variables used: |
---|
704 | # runName, collectionName, |
---|
705 | # collectionROOptions, |
---|
706 | # debugMode, |
---|
707 | # ROColWidth, EvalAlg |
---|
708 | # |
---|
709 | #}}} |
---|
710 | typeset runROOptions="" |
---|
711 | typeset runNote="" |
---|
712 | typeset rawCollectionName="" |
---|
713 | |
---|
714 | #{{{ read options and environment |
---|
715 | # read options |
---|
716 | typeset opt |
---|
717 | while getopts "n:a:c:t:x:r:d" opt; do |
---|
718 | case "$opt" in |
---|
719 | n) runNote="$OPTARG" ;; |
---|
720 | a) runOptions="$runOptions -a$OPTARG" ;; |
---|
721 | c) runOptions="$runOptions -c$OPTARG" ;; |
---|
722 | t) runTBOptions="$OPTARG" ;; |
---|
723 | x) runXOOptions="$OPTARG" ;; |
---|
724 | r) runROOptions="$OPTARG" ;; |
---|
725 | d) debugMode="1" ;; |
---|
726 | ?) warn "bad run option"; exit 1 ;; |
---|
727 | esac |
---|
728 | done |
---|
729 | # shift options and reset OPTIND |
---|
730 | typeset -i optind |
---|
731 | optind=OPTIND-1 |
---|
732 | shift $optind |
---|
733 | OPTIND=1 |
---|
734 | |
---|
735 | # read environment |
---|
736 | while [ "${1-}" != "${1+${1#/}}" ]; do |
---|
737 | runEnvironment="$runEnvironment $1" |
---|
738 | shift |
---|
739 | done |
---|
740 | #}}} |
---|
741 | |
---|
742 | #{{{ read rest of arguments |
---|
743 | # process rest of arguments |
---|
744 | if [ "$#" = "0" ]; then |
---|
745 | warn "no collection name specified" |
---|
746 | exit 1 |
---|
747 | fi |
---|
748 | rawCollectionName="${1%.fex}" |
---|
749 | collectionName="${rawCollectionName##*/}" |
---|
750 | shift |
---|
751 | |
---|
752 | if [ "$#" = "0" ]; then |
---|
753 | warn "no run name specified" |
---|
754 | exit 1 |
---|
755 | fi |
---|
756 | runName="${1%.html}" |
---|
757 | shift |
---|
758 | |
---|
759 | defineSkip "$@" |
---|
760 | #}}} |
---|
761 | |
---|
762 | # before going on, check for existence of collection |
---|
763 | if [ ! -f "$rawCollectionName.fex" ]; then |
---|
764 | warn "collection $rawCollectionName.fex not found" |
---|
765 | exit 1 |
---|
766 | fi |
---|
767 | |
---|
768 | # remove existing table files |
---|
769 | if [ -z "$debugMode" ]; then |
---|
770 | rm -f "$runName.tb.tbl" |
---|
771 | rm -f "$runName.xo.tbl" |
---|
772 | rm -f "$runName.ro.tbl" |
---|
773 | rm -f "$runName.html" |
---|
774 | fi |
---|
775 | |
---|
776 | # execute collection |
---|
777 | . "$rawCollectionName.fex" |
---|
778 | |
---|
779 | if [ -z "$debugMode" ]; then |
---|
780 | #{{{ read and print data |
---|
781 | typeset algChar |
---|
782 | typeset algSwitch |
---|
783 | typeset algVars |
---|
784 | typeset algCircle |
---|
785 | typeset algSeed |
---|
786 | typeset algVers |
---|
787 | |
---|
788 | # read data |
---|
789 | runAlgorithm "$EvalAlg" -oes \ |
---|
790 | | { |
---|
791 | read algChar |
---|
792 | read algSwitch |
---|
793 | read algVars |
---|
794 | read algCircle |
---|
795 | read algSeed |
---|
796 | read algVers |
---|
797 | |
---|
798 | # create empty file |
---|
799 | cp /dev/null "$runName.ro.tbl" |
---|
800 | |
---|
801 | # print header |
---|
802 | cat << EOT >> "$runName.ro.tbl" |
---|
803 | <!ROBlock $runName> |
---|
804 | EOT |
---|
805 | |
---|
806 | # print data |
---|
807 | typeset options="${runROOptions:-$collectionROOptions}" |
---|
808 | # remove some options |
---|
809 | options="${options//tcrd/}" |
---|
810 | |
---|
811 | printData "$options" "$ROColWidth" \ |
---|
812 | "<a name=\"RO$runName\" href=\"#TB$runName\">$runName</a>" 4 >> "$runName.ro.tbl" |
---|
813 | |
---|
814 | # print trailer |
---|
815 | cat << EOT >> "$runName.ro.tbl" |
---|
816 | <tr align=left valign=top><!bol>$( pc Note )$( pct "${runNote:-(no note)}" )<!eol></tr> |
---|
817 | <tr align=left valign=top><!bol>$( pc Date )$( pct "$( date )" )<!eol></tr> |
---|
818 | <tr align=left valign=top><!bol>$( pc User )$( pct "${USER:-unknown}" )<!eol></tr> |
---|
819 | <tr align=left valign=top><!bol>$( pc Computer )$( pct "$( uname -a )" )<!eol></tr> |
---|
820 | <!/ROBlock $runName> |
---|
821 | EOT |
---|
822 | } |
---|
823 | #}}} |
---|
824 | |
---|
825 | createTable "$runName" > "$runName.html" |
---|
826 | fi |
---|
827 | #}}} |
---|