- Timestamp:
- Mar 31, 1998, 12:49:08 PM (26 years ago)
- Branches:
- (u'spielwiese', 'd1b01e9d51ade4b46b745d3bada5c5f3696be3a8')
- Children:
- 825bc1a562f338a4dfdcf877e7e973a13c91f9b9
- Parents:
- 847ebddd2a19445d1f5f58aa9aae2175e2ba965c
- Location:
- factory/fex
- Files:
-
- 3 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/fex/runfex
r847ebdd r751138 1 #! / home/schmidt/bin/bash2 # $Id: runfex,v 1. 6 1998-03-11 16:11:28 schmidt Exp $1 #! /bin/bash 2 # $Id: runfex,v 1.7 1998-03-31 10:49:08 schmidt Exp $ 3 3 4 4 #{{{ docu … … 11 11 set -o noglob 12 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 # EvalAlg: algorithm to read run/collection data from. Used by 22 # main(). 13 trap signalHandlerInterrupt SIGINT 14 trap signalHandlerQuit SIGQUIT 15 16 # 17 # - functions. 18 # 19 20 #{{{ signalHandlerInterrupt (), signalHandlerQuit () 21 #{{{ docu 22 # 23 # signalHandler*() - catch signals. 24 # 25 #}}} 26 signalHandlerInterrupt() 27 { 28 warn "received signal SIGINT" 29 exit 30 } 31 32 signalHandlerQuit() 33 { 34 warn "received signal SIGQUIT" 35 exit 36 } 37 #}}} 38 39 #{{{ warn () 40 #{{{ docu 41 # 42 # warn() - print arguments to stderr prefixed by ExecName. 43 # 44 # ExecName (global constant): name of the shell script 45 # being executed 23 46 # 24 47 #}}} 25 48 readonly ExecName="$0" 26 49 27 typeset -ir TBColWidth=8028 typeset -ir ROColWidth=8029 30 readonly EvalAlg="feval"31 #}}}32 33 #{{{ global variables34 #{{{ docu35 #36 # - global variables.37 #38 # runOptions, collectionOptions, runEnvironment,39 # collectionEnvironment: options and environment for the40 # examples. Used by runAlgorithm().41 # runConfiguration: which configurations' executables to use.42 # Used by runAlgorithm().43 # collectionROOptions: options to print run overview. Use by44 # main().45 # runTBOptions, collectionTBOptions: options to print XX tables.46 # Used by example().47 # debugMode: do not execute anything, just print what we would48 # have executed. Used by main(), example(), and49 # runAlgorithm().50 #51 # The run* variables and debugMode are set in the main program,52 # the rest of the collection* variables in collection().53 #54 #}}}55 runOptions=""56 runEnvironment=""57 runTBOptions=""58 runConfiguration="opt"59 60 collectionOptions=""61 collectionEnvironment=""62 collectionTBOptions=""63 collectionROOptions=""64 65 debugMode=""66 #}}}67 68 #69 # - functions.70 #71 72 #{{{ warn ()73 #{{{ docu74 #75 # warn() - print arguments to stderr prefixed $ExecName.76 #77 # Global variables used:78 # ExecName79 #80 #}}}81 50 warn() 82 51 { … … 85 54 #}}} 86 55 87 #{{{ runAlgorithm () 88 #{{{ docu 89 # 90 # runAlgorithm() - run algorithm with the correct options. 91 # 92 # $1: algorithm to run 93 # $2: output options 94 # rest: arguments to algorithm 95 # 96 # Global variables used: 97 # runOptions, runEnvironment, runConfiguration, 98 # collectionOptions, collectionEnvironment, 99 # exampleOptions, exampleEnvironment, 100 # debugMode 101 # 102 #}}} 103 runAlgorithm() 104 { 105 typeset \ 106 algorithmName="$1" \ 107 outputOptions="$2" \ 108 algorithmOptions="$collectionOptions${exampleOptions-}$runOptions" \ 109 algorithmEnvironment="$collectionEnvironment${exampleEnvironment-}$runEnvironment" 110 shift 2 111 112 # reset factory environemnt to exclude external influences 113 FTEST_ENV="" 114 FTEST_CIRCLE="" 115 FTEST_ALARM="" 116 117 if [ -n "$debugMode" ]; then 118 echo "calling $algorithmName.$runConfiguration" $algorithmOptions "$outputOptions" "$algorithmEnvironment" "$@" 119 else 120 "$algorithmName.$runConfiguration" $algorithmOptions "$outputOptions" "$algorithmEnvironment" "$@" 121 fi 122 } 123 #}}} 124 125 #{{{ printData () 126 #{{{ docu 127 # 128 # printData() - print example/run table. 129 # 130 # $1: options how to print data 131 # $2: default width to print data 132 # $3: name of example/collection 133 # $4: note on example/collection 134 # 135 # Global variables used: 136 # alg* algorithm information, 137 # 138 #}}} 139 printData() 140 { 141 typeset \ 142 options="$1" \ 143 name="$3" \ 144 note="$4" \ 145 colWidth 146 147 colWidth="${options//[a-z]/}" 148 colWidth="${colWidth:-$2}" 149 options="${options//[0-9]/}" 150 151 typeset -i i=0 n=0 152 153 while [ -n "$options" ]; do 154 case "$options" in 155 (*h*) 156 # do some pretty printing 157 if [ ${#name} -lt 7 ]; then 158 echo "$name: $note." 159 elif [ ${#name} -lt 15 ]; then 160 echo "$name: $note." 161 else 162 echo "$name: $note." 163 fi 164 options="${options//h/}" ;; 165 (*p*) echo "$algChar" 166 options="${options//p/}" ;; 167 (*s*) echo "$algSwitch" 168 options="${options//s/}" ;; 169 (*v*) echo "$algVars" 170 options="${options//v/}" ;; 171 (*n*) echo "$algCircle" 172 options="${options//n/}" ;; 173 (*g*) echo "$algSeed" 174 options="${options//g/}" ;; 175 (*f*) echo "$algVers" 176 options="${options//f/}" ;; 177 (*t*) echo "$algTime" 178 options="${options//t/}" ;; 179 (*c*) echo "$algCheck" 180 options="${options//c/}" ;; 181 (*r*) 182 n=${#algResult[@]} 183 i=0 184 while [ $i -lt $n ]; do 185 echo "${algResult[i]}" | fold -s -w$colWidth 186 i=i+1 187 done 188 options="${options//r/}" ;; 189 (*) warn "unknown output type specifier '$options' in table specification" 190 options="" ;; 191 esac 192 done 193 } 194 #}}} 195 196 #{{{ collection () 197 #{{{ docu 198 # 199 # collection() - set up collection data. 200 # 201 # All we do is setting the collection* variables (except 202 # collectionName) from commandline. 203 # We do not set collectionNote and collectionXXOptions if they 204 # are already set but reset collectionOptions and 205 # collectionEnvironment on each run to allow for multiple calls 206 # to collection() in one example collection file (though this is 207 # bad style). 208 # 209 # Global variables used: none 210 # 211 #}}} 212 collection() 213 { 214 collectionOptions="" 215 collectionEnvironment="" 216 217 # read collection name 218 if [ "$#" = "0" ]; then 219 warn "no collection name specified" 220 exit 1 221 fi 222 collectionName="$1" 223 shift 224 225 #{{{ read options and environment 226 # read options 227 typeset opt 228 while getopts "n:a:c:t:r:" opt; do 229 case "$opt" in 230 (n) collectionNote="${collectionNote:-$OPTARG}" ;; 231 (a) collectionOptions="$collectionOptions -a$OPTARG" ;; 232 (c) collectionOptions="$collectionOptions -c$OPTARG" ;; 233 (t) collectionTBOptions="${collectionTBOptions:-$OPTARG}" ;; 234 (r) collectionROOptions="${collectionROOptions:-$OPTARG}" ;; 235 (?) warn "bad collection option"; exit 1 ;; 236 esac 237 done 238 # shift options and reset OPTIND 239 typeset -i optind 240 optind=OPTIND-1 241 shift $optind 242 OPTIND=1 243 244 # read environment 245 while [ "${1-}" != "${1+${1#/}}" ]; do 246 collectionEnvironment="$collectionEnvironment $1" 247 shift 248 done 249 #}}} 56 #{{{ usage () 57 usage() 58 { 59 echo " 60 Usage: runfex [<options>] [<factoryOpts>] [<factoryEnvSpec>] <fexFile> [<examplePatterns>] 61 62 Runs all examples in <fexFile> matching <examplePattern>. 63 <examplePatterns> should be regular shell patterns, which may be 64 preceded by a \`^' to exclude all examples matching <examplePattern>. 65 66 When run in foreground, SIGQUIT immediately interrupts \`runfex', 67 while SIGINT only interrupts the example currently being 68 calculated. In background, SIGTERM interrupts \`runfex' after the 69 current example has been finished. 70 71 <options>: -d: debug mode. In debug mode, examples are 72 echoed to stdout instead of being executed. 73 -C <runConfiguration>: specifies which object/executable 74 configuration to use. Defaults to \`opt'. 75 -t: do not run checks 76 77 Besides from regular shell commands, the commands \`collection' 78 and \`example' may be used in a Factory example file. 79 \`collection' specifies options and environment common to a 80 collection of examples, \`example' defines an example. 81 82 collection <collectionName> [<collectionOptions>] [<factoryOpts>] [<factoryEnvSpec>] 83 example <exampleName> [<exampleOptions>] [<factoryOpts>] [<factoryEnvSpec>] <example> 84 85 <collectionOptions>/<exampleOptions>: 86 -n <note>: specifies comment on the collection/example 87 88 <factoryOpts>: 89 -a <time>: sets alarm option 90 -c <times>: sets times option 91 -O <options>: specifies optional arguments 92 -o <outputOptions>: specifies which results to print 93 94 <outputOptions>: 95 <number>: column width x: do not print anything 96 h: header p: characteristic 97 s: switches v: variables 98 n: number fo runs g: random generator seed 99 f: Factories version t: time 100 c: check r: result" \ 101 >& 2 250 102 } 251 103 #}}} … … 255 107 # 256 108 # defineSkip() - define function skipExample(). 109 # 110 # rest: the patterns 111 # 112 # One function at least that does not use neither global 113 # variables nor constants. 257 114 # 258 115 #}}} … … 318 175 #}}} 319 176 177 #{{{ runAlgorithm () 178 #{{{ docu 179 # 180 # runAlgorithm() - run algorithm with the correct options. 181 # 182 # To a pity, there is a lot of global variables necessary to 183 # determine the "correct options". The run* variables are set 184 # in main program, the collection* variables in collection() 185 # and the example* variables in example(). 186 # All of these variables are exclusively used here. 187 # 188 # $1: debugMode 189 # $2: algorithm to run 190 # rest: its arguments 191 # 192 # runConfiguration (global variable): which configurations' 193 # executables to use 194 # run* (global variables): options, optional arguments, and 195 # environment specified at run level 196 # collection* (global variables): options, optional arguments, 197 # and environment specified at collection level 198 # example* (global variables): options, optional arguments, 199 # and environment specified at example level 200 # 201 #}}} 202 runConfiguration="opt" 203 204 runOptions="" 205 runOptArguments="" 206 runEnvironment="" 207 208 collectionOptions="" 209 collectionOptArguments="" 210 collectionEnvironment="" 211 212 exampleOptions="" 213 exampleOptArguments="" 214 exampleEnvironment="" 215 216 runAlgorithm() 217 { 218 typeset debugMode="$1" \ 219 name="$2" 220 shift 2 221 222 # now its time to paste the options together 223 $debugMode "$name.$runConfiguration" \ 224 $collectionOptions $exampleOptions $runOptions -oa -- \ 225 $collectionEnvironment $exampleEnvironment $runEnvironment \ 226 ${runOptArguments:-${exampleOptArguments:-${collectionOptArguments}}} \ 227 "$@" 228 } 229 #}}} 230 231 #{{{ printData () 232 #{{{ docu 233 # 234 # printData() - print example data. 235 # 236 # Yet another bunch of global variables. The *OutputOptions are 237 # set by the main program, collection(), and example(), resp., 238 # and determine which information to print. All the variables 239 # are used exclusively here. 240 # 241 # $1: name 242 # $2: note 243 # 244 # defColWidth (global constant): default width to print results 245 # *OutputOptions (global variables): which information to print 246 # 247 #}}} 248 typeset -ir defColWidth=80 249 250 runOutputOptions="" 251 collectionOutputOptions="" 252 exampleOutputOptions="" 253 254 printData() 255 { 256 typeset -i colWidth 257 258 typeset name="$1" \ 259 note="$2" \ 260 options="${runOutputOptions:-${exampleOutputOptions:-${collectionOutputOptions}}}" \ 261 line="" 262 263 # get column width (we use line as a dummy here) 264 line="$( echo "$options" | sed s/[^0-9]//g )" 265 colWidth=${line:-$defColWidth} 266 267 case "$options" in 268 (*x*) return ;; 269 esac 270 271 case "$options" in 272 (*h*) 273 # do some pretty printing 274 if [ ${#name} -lt 7 ]; then 275 echo "$name: $note." 276 elif [ ${#name} -lt 15 ]; then 277 echo "$name: $note." 278 else 279 echo "$name: $note." 280 fi ;; 281 esac 282 if read line; then case "$options" in 283 (*p*) echo "$line" ;; 284 esac; fi 285 if read line; then case "$options" in 286 (*s*) echo "$line" ;; 287 esac; fi 288 if read line; then case "$options" in 289 (*v*) echo "$line" ;; 290 esac; fi 291 if read line; then case "$options" in 292 (*n*) echo "$line" ;; 293 esac; fi 294 if read line; then case "$options" in 295 (*g*) echo "$line" ;; 296 esac; fi 297 if read line; then case "$options" in 298 (*f*) echo "$line" ;; 299 esac; fi 300 if read line; then case "$options" in 301 (*t*) echo "$line" ;; 302 esac; fi 303 if read line; then case "$options" in 304 (*c*) echo "$line" ;; 305 esac; fi 306 307 # format the result 308 case "$options" in 309 (*r*) 310 if [ $colWidth = 0 ]; then 311 cat -u 312 else 313 fold -s -w "$colWidth" 314 fi ;; 315 esac 316 } 317 #}}} 318 320 319 #{{{ example () 321 320 #{{{ docu … … 323 322 # example() - run an example. 324 323 # 325 # Global variables used: 326 # debugMode, 327 # runTBOptions, 328 # collectionTBOptions, 329 # TBColWidth 330 # 331 #}}} 324 # Sets the example* variables from the commandline. Runs the 325 # example in dependency on debugMode and on the result of 326 # skipExample(). Collects data from the example in the alg* 327 # variables for printData(). 328 # 329 # debugMode (global variable): set by main program. Whether to 330 # run examples or to print them. 331 # 332 #}}} 333 debugMode="" 334 332 335 example() 333 336 { 334 typeset exampleName="" \335 exampleNote="" \336 exampleOptions=""\337 exampleEnvironment="" \338 exampleTBOptions=""339 340 typeset algorithm=""\341 algorithmTBOptions=""342 343 # {{{ read example name and skip itif necessary337 typeset name="" \ 338 note="" \ 339 \ 340 options="" \ 341 optArguments="" \ 342 environment="" \ 343 \ 344 outputOptions="" 345 346 # read example name and skip if necessary 344 347 if [ "$#" = "0" ]; then 345 348 warn "no example name specified" 346 349 exit 1 347 350 fi 348 exampleName="$1"351 name="$1" 349 352 shift 350 353 351 if skipExample "$ exampleName"; then354 if skipExample "$name"; then 352 355 if [ -n "$debugMode" ]; then 353 echo "skipping $ exampleName"356 echo "skipping $name" 354 357 fi 355 358 return 356 359 else 357 warn "running $ exampleName"360 warn "running $name" 358 361 fi 359 #}}}360 362 361 #{{{ read options and environment362 363 # read options 363 364 typeset opt 364 while getopts "n:a:c: t:x:" opt; do365 while getopts "n:a:c:O:o:" opt; do 365 366 case "$opt" in 366 (n) exampleNote="$OPTARG" ;; 367 (a) exampleOptions="$exampleOptions -a$OPTARG" ;; 368 (c) exampleOptions="$exampleOptions -c$OPTARG" ;; 369 (t) exampleTBOptions="$OPTARG" ;; 367 (n) note="$OPTARG" ;; 368 (a) options="$options -a$OPTARG" ;; 369 (c) options="$options -c$OPTARG" ;; 370 (O) optArguments="$optArguments $OPTARG" ;; 371 (o) outputOptions="$OPTARG" ;; 370 372 (?) warn "bad example option"; exit 1 ;; 371 373 esac … … 379 381 # read environment 380 382 while [ "${1-}" != "${1+${1#/}}" ]; do 381 e xampleEnvironment="$exampleEnvironment $1"383 environment="$environment $1" 382 384 shift 383 385 done 384 #}}} 385 386 #{{{ read rest of arguments 386 387 # set global variables 388 exampleOptions="$options" 389 exampleOptArguments="$optArguments" 390 exampleEnvironment="$environment" 391 exampleOutputOptions="$outputOptions" 392 393 # run algorithm and print data 394 if [ -n "$debugMode" ]; then 395 runAlgorithm "echo" "$@" 396 else 397 runAlgorithm "" "$@" | printData "$name" "$note" 398 fi 399 } 400 #}}} 401 402 #{{{ collection () 403 #{{{ docu 404 # 405 # collection() - set up collection data. 406 # 407 # Sets the collection* variables from commandline. 408 # 409 #}}} 410 collection() 411 { 412 typeset options="" \ 413 optArguments="" \ 414 environment="" \ 415 \ 416 outputOptions="" \ 417 418 # read collection name (and ignore it) 387 419 if [ "$#" = "0" ]; then 388 warn "no example specified"420 warn "no collection name specified" 389 421 exit 1 390 422 fi 391 algorithm="$1"392 423 shift 393 #}}} 394 395 # check for debug mode 396 if [ -n "$debugMode" ]; then 397 runAlgorithm "$algorithm" -oa "$@" 398 return 399 fi 400 401 # collect output options 402 algorithmTBOptions="${runTBOptions:-${exampleTBOptions:-$collectionTBOptions}}" 403 404 #{{{ read and print data 405 typeset algChar \ 406 algSwitch \ 407 algVars \ 408 algCircle \ 409 algSeed \ 410 algVers \ 411 algTime \ 412 algCheck 413 414 typeset -a algResult 415 416 typeset -i j=0 417 418 # read data 419 runAlgorithm "$algorithm" -oa "$@" \ 420 | { 421 read algChar 422 read algSwitch 423 read algVars 424 read algCircle 425 read algSeed 426 read algVers 427 read algTime 428 read algCheck 429 430 # preprocess output and store result in the arrays 431 while read line; do 432 algResult[j]="$line" 433 j=j+1 434 done 435 436 # print table 437 printData "$algorithmTBOptions" "$TBColWidth" "$exampleName" "$exampleNote" 438 } 439 #}}} 424 425 # read options 426 typeset opt 427 while getopts "n:a:c:O:o:" opt; do 428 case "$opt" in 429 (n) : ;; 430 (a) options="$options -a$OPTARG" ;; 431 (c) options="$options -c$OPTARG" ;; 432 (O) optArguments="$optArguments $OPTARG" ;; 433 (o) outputOptions="$OPTARG" ;; 434 (?) warn "bad collection option"; exit 1 ;; 435 esac 436 done 437 # shift options and reset OPTIND 438 typeset -i optind 439 optind=OPTIND-1 440 shift $optind 441 OPTIND=1 442 443 # read environment 444 while [ "${1-}" != "${1+${1#/}}" ]; do 445 environment="$environment $1" 446 shift 447 done 448 449 # set global variables 450 collectionOptions="$options" 451 collectionOptArguments="$optArguments" 452 collectionEnvironment="$environment" 453 collectionOutputOptions="$outputOptions" 440 454 } 441 455 #}}} … … 446 460 # - main program. 447 461 # 448 # runROOptions: options for RO table. Read from commandline. 449 # rawCollectionName: collection name with full path 450 # 451 # Global variables used: 452 # collectionROOptions, 453 # debugMode, 454 # ROColWidth, EvalAlg 455 # 456 #}}} 457 typeset runROOptions="" 458 typeset rawCollectionName="" 459 460 #{{{ read options and environment 462 # Sets the run* variables for runAlgorithm() and printData() 463 # from commandline. Sets debugMode for example(). Reads the 464 # collection. 465 # 466 #}}} 467 typeset configuration="opt" \ 468 \ 469 options="" \ 470 optArguments="" \ 471 environment="" \ 472 \ 473 outputOptions="" \ 474 \ 475 fexFile="" 476 461 477 # read options 462 478 typeset opt 463 while getopts " a:c:C:t:r:d" opt; do479 while getopts "dC:ta:c:O:o:" opt; do 464 480 case "$opt" in 465 (a) runOptions="$runOptions -a$OPTARG" ;;466 (c) runOptions="$runOptions -c$OPTARG" ;;467 (C) runConfiguration="$OPTARG" ;;468 (t) runTBOptions="$OPTARG" ;;469 (r) runROOptions="$OPTARG" ;;470 481 (d) debugMode="1" ;; 471 (?) warn "bad run option"; exit 1 ;; 482 (C) configuration="$OPTARG" ;; 483 (t) options="$options -t" ;; 484 (a) options="$options -a$OPTARG" ;; 485 (c) options="$options -c$OPTARG" ;; 486 (O) optArguments="$optArguments $OPTARG" ;; 487 (o) outputOptions="$OPTARG" ;; 488 (?) warn "bad run option"; usage; exit 1 ;; 472 489 esac 473 490 done … … 480 497 # read environment 481 498 while [ "${1-}" != "${1+${1#/}}" ]; do 482 runEnvironment="$runEnvironment $1"499 environment="$environment $1" 483 500 shift 484 501 done 485 #}}}486 502 487 503 # process rest of arguments 488 504 if [ "$#" = "0" ]; then 489 warn "no collection name specified" 505 warn "no fexFile specified" 506 usage 490 507 exit 1 491 508 fi 492 rawCollectionName="${1%.fex}"509 fexFile="${1%.fex}" 493 510 shift 494 511 … … 496 513 497 514 # before going on, check for existence of collection 498 if [ ! -f "$ rawCollectionName.fex" ]; then499 warn "collection $ rawCollectionName.fex not found"515 if [ ! -f "$fexFile.fex" ]; then 516 warn "collection $fexFile.fex not found" 500 517 exit 1 501 518 fi 502 519 503 # execute collection 504 . "$rawCollectionName.fex" 505 506 if [ -z "$debugMode" ]; then 507 typeset algChar 508 typeset algSwitch 509 typeset algVars 510 typeset algCircle 511 typeset algSeed 512 typeset algVers 513 514 # read data 515 runAlgorithm "$EvalAlg" -oe \ 516 | { 517 read algChar 518 read algSwitch 519 read algVars 520 read algCircle 521 read algSeed 522 read algVers 523 524 # print data 525 typeset options="${runROOptions:-$collectionROOptions}" 526 # remove some options 527 options="${options//tcrd/}" 528 529 printData "$options" "$ROColWidth" "$collectionName" "$collectionNote" 530 } 531 fi 532 #}}} 520 # reset factory environemnt to exclude external influences 521 FTEST_ENV="" 522 FTEST_CIRCLE="" 523 FTEST_ALARM="" 524 525 # set global variables and execute collection 526 runConfiguration="$configuration" 527 runOptions="$options" 528 runOptArguments="$optArguments" 529 runEnvironment="$environment" 530 runOutputOptions="$outputOptions" 531 532 . "$fexFile.fex" 533 #}}}
Note: See TracChangeset
for help on using the changeset viewer.