From: <sg...@us...> - 2003-08-31 00:40:53
|
Update of /cvsroot/libfunutil/libfunutil/toc/sbin In directory sc8-pr-cvs1:/tmp/cvs-serv12328 Modified Files: toc_core.sh Log Message: removed a large amount of comment code. Made a lot of vars explicitely local. Index: toc_core.sh =================================================================== RCS file: /cvsroot/libfunutil/libfunutil/toc/sbin/toc_core.sh,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- toc_core.sh 30 Aug 2003 19:20:31 -0000 1.22 +++ toc_core.sh 31 Aug 2003 00:40:48 -0000 1.23 @@ -431,30 +431,28 @@ local showname="$testname" test "x${TOC_LOUD-0}" != "x0" -a "x$1" != "x" && showname="$showname $@" - toc_loudly -n "[$depth] " -# test "x${TOC_LOUD-0}" toc_boldecho -n "[$depth] ====" + toc_loudly -n "[$depth]" i=1; while test $i -le $depth; do - echo -n "${TOC_BOLD_}==${_TOC_BOLD_}" + echo -n "${TOC_BOLD_}===${_TOC_BOLD_}" i=$((i + 1)) done -# else - toc_boldecho -n " [$showname] " - test -n "$desc" && echo -n $desc -# echo -n "[$testname]====== " -# fi + toc_boldecho -n " [$showname] " + test -n "$desc" && echo -n $desc echo local err=0 toc_source_test $testname $@ err=$? - test ${TOC_FAIL_FAST-0} = 1 -a $err != 0 && toc_die $err "toc_run: TOC_FAIL_FAST is set, and test $testname returned an error." + if test ${TOC_FAIL_FAST-0} = 1 -a $err != 0; then + toc_die $err "toc_run: TOC_FAIL_FAST is set, and test $testname returned a non-zero error code." + fi TOC_RUN_DEPTH=$((TOC_RUN_DEPTH - 1)) return $err } function toc_run_failok { # runs toc_run and warns if there was an error. - # It does not exit - it returns 1 on error, however. + # It does not exit - it passed back the error code from the test. toc_debug toc_run_failok $@ local testname=$1 local depth=$((TOC_RUN_DEPTH + 1)) @@ -463,19 +461,16 @@ toc_loudly -n "[${depth}] " toc_boldecho -n "^^^^^^^^^^ " echo -n ${TOC_EMOTICON_WARNING} " " - toc_boldecho -n "$testname: $ret" + toc_boldecho -n "$testname" echo -n " " ${TOC_EMOTICON_WARNING} " " toc_boldecho "^^^^^^^^^^ " return $ret } - #&& echo ${TOC_EMOTICON_OKAY} - #toc_show_posttest_feedback return 0 } - # function toc_run_fail calls toc_run and fails if it returns !0 function toc_run_fail - { + { # calls toc_run and fails if it returns !0 toc_debug toc_run_fail $@ local testname=$1 local depth=$((TOC_RUN_DEPTH + 1)) @@ -484,7 +479,7 @@ toc_loudly -n "[${depth}] " toc_boldecho -n "^^^^^^^^^^ " echo -n ${TOC_EMOTICON_ERROR} " " - toc_boldecho -n "$testname: $ret" + toc_boldecho -n "$testname" echo -n " " ${TOC_EMOTICON_ERROR} " " toc_boldecho "^^^^^^^^^^ " exit $ret @@ -495,10 +490,8 @@ function toc_find_failok { # toc_find_failok works like toc_run, but searches for the passed-in app ($1) - # in ${2-${PATH}}, using the same conventions output/return conventions set by toc_run(). - # It returns 1 if it finds no file. - # It "returns" the found file in the ${TOC_FIND_RESULT}. - # This function generates output. + # in ${2-${PATH}. It returns 1 if it finds no file, else zero. + # It "returns" the found file in ${TOC_FIND_RESULT}. local bin=$1 path=${2-${PATH}} toc_quietly -n "? find $bin ..." @@ -522,45 +515,38 @@ function toc_source_test { # sources the given test script and returns it's error code. # it accepts a filename or X, where X resolves to is toc/tests/X.sh. - # - local test - test=$1 + local test=$1 shift - local tmpfile - tmpfile=.toc.${test##*/}.output - local sh - sh=${TOC_TESTSDIR}/$test.sh + local tmpfile=.toc.${test##*/}.output + local sh=${TOC_TESTSDIR}/$test.sh test -f $test && sh=$test test -f "$sh" || toc_die 1 "toc_source_test $test: $sh not found!" - local err - err=0 + local err=0 toc_debug "toc_source_test sourcing [$sh $@]" source $sh $@ err=$? return $err } - - } # end toc_run functions -{ # function toc_replace_file: helper to check if a file is changed, and replace it if it is - # usage: toc_replace_file target tmpfile - # tmpfile is deleted if target is the same as tmpfile, else it replaces target. - # The fact that it echos text is a side-effect of other parts of this code, - # so don't rely 100% on that "feature". i.e., it echos to fit in with common usage - # of this function, not because it's a logical part of the interface :/. - # - # It returns 0 if it replaces $1 with $2. It returns 1 if $1 does - # not need replacing ($1 and $2 are not different). - # - # - # It exits if it cannot mv or rm a file: that is considered a filesystem/rights-level - # problem which needs to be addressed immediately. - # - # +{ function toc_replace_file - { + { # toc_replace_file: helper to check if a file is changed, and replace it if it is + # usage: toc_replace_file target tmpfile + # tmpfile is deleted if target is the same as tmpfile, else it replaces target. + # The fact that it echos text is a side-effect of other parts of this code, + # so don't rely 100% on that "feature". i.e., it echos to fit in with common usage + # of this function, not because it's a logical part of the interface :/. + # + # It returns 0 if it replaces $1 with $2. It returns 1 if $1 does + # not need replacing ($1 and $2 are not different). + # + # + # It exits if it cannot mv or rm a file: that is considered a filesystem/rights-level + # problem which needs to be addressed immediately. + # + # local tgt=$1 local tmp=$2 #toc_boldecho toc_replace_file $tgt $tmp @@ -587,22 +573,26 @@ } } # end toc_replace_file -{ # toc_atfilter_file(): uses the @-parser to filter a template file. - # It returns !0 only if $TOC_ATSIGN_PARSER throws an error. +{ function toc_atfilter_file - { # $1 = file containing properties to @-filter. + { + # uses the @-parser to filter a template file. + # It returns !0 only if $TOC_ATSIGN_PARSER throws an error. + # $1 = file containing properties to @-filter. # $2 = input template (e.g. toc_shared.make.at) # $3 = output file (e.g. toc_shared.make). It only changed if # needed, so it is dependency-safe. - pfile=$1 - tmpl=$2 - ofile=$3 - local tmpfile=$ofile.toc_atfilter_file + local pfile=$1 + local tmpl=$2 + local ofile=$3 + test -f "$pfile" || toc_die $? "toc_atfilter_file: \$1: file not found: $pfile" + test -f "$tmpl" || toc_die $? "toc_atfilter_file: \$2: file not found: $tmpl" + local tmpfile=$ofile.tmp.toc_atfilter_file ${TOC_ATSIGN_PARSER} -f $pfile < $tmpl > $tmpfile || { - err=$? + local err=$? echo "toc_atfilter_file(): @-parsing failed: error $err " echo ${TOC_EMOTICON_ERROR} - return 1 + return $err } echo -n "$ofile ... " @@ -610,23 +600,19 @@ test -f $ofile && fstate="updated" toc_replace_file $ofile $tmpfile || fstate="up to date" echo "$fstate" - #echo " ${TOC_EMOTICON_OKAY}" return 0 } } # end toc_atfilter_file function toc_endconfigure -{ # ends the configuration process +{ # ends the configuration process, processing the files + # which need to be @-parsed toc_boldecho "==== Creating configuration-dependent files..." { toc_create_config_h -# | perl -ne '$|=1; print " $_";' -# nonportable: | sed -ue 's/^/ /' toc_create_make } -# | perl -ne '$|=1; print " $_";' -# | sed -ue 's/^/ /' - clean=$(ls .toc.* 2> /dev/null) + local clean="$(ls .toc.* 2> /dev/null)" test -n "$clean" && rm $clean } @@ -635,9 +621,9 @@ toc_debug "toc_parseargs: Handling command-line arguments: $@" # mostly stolen from the qt 3.1.0 configure script :) while [ "$#" -gt 0 ]; do - VAR= - VAL= - arg=$1 + local VAR= + local VAL= + local arg=$1 shift case $arg in --help|-?) @@ -733,10 +719,9 @@ esac toc_debug toc_parseargs: $arg "VAR=$VAR VAL=$VAL" test -n "$VAR" -a -n "$VAL" && { - export $VAR="$VAL" toc_debug "toc_parseargs: exporting [$VAR]=$VAL" - toc_add_make "$VAR=$VAL" - toc_add_config_h "$VAR=$VAL" + export $VAR="$VAL" + toc_add_config "$VAR=$VAL" } done return 0 @@ -747,27 +732,17 @@ { # usage: toc_makerelative /foo/bar/one/two /foo/bar # sets global var TOC_MAKERELATIVE to the "return value". # In the above example, it should = ./../.. - startat=${1-$PWD} - relto=${2-${TOC_TOPDIR}} + local startat=${1-$PWD} + local relto=${2-${TOC_TOPDIR}} test -n "$relto" || $relto=$PWD - -# export TOC_MAKERELATIVE=${startat##$relto} -# return 0 - test -f $startat && startat=$(dirname $startat) - dn=$startat/bogus - dn=${dn%*/*} - #echo "dn=$dn, relto=$relto" - rel="." -# rel="" + local dn=$startat/bogus + local dn=${dn%*/*} + local rel="." while test -n "$dn" -a "$dn" != "$relto" -a "$dn" != "/"; do rel="$rel/.." -# rel="../$rel" dn=${dn%*/*} - #echo "dn=$dn" done - #echo "rel=$rel" -# TOC_MAKERELATIVE=$rel TOC_MAKERELATIVE=${rel##./} } @@ -777,11 +752,6 @@ echo "Configuring build environment." toc_parseargs --prefix=${prefix} "$@" -# ^^^ --prefix=... will be overridden by any user-supplied value. -# note that any args with spaces in them are hosed at this point: -# --with-INCLUDES="-I. -I/some/path" -# will turn into: -# --with-INCLUDES=-I toc_loudly 'Loud mode enabled.' toc_quietly <<-EOF @@ -792,11 +762,8 @@ do not yet know if it is fatal. A warning might actually be an error: this is build tree dependent. - Note that not all config test failures are fatal, so do not be - alarmed if you see a warning/error below and the process keeps going. - It will stop if it fails a test which it /needs/ to pass. - Also, generally speaking, No News is Good News. - + Note that not all config test failures are fatal: it will stop if + it fails a test which it /needs/ to pass. EOF # source ${TOC_TOCDIR}/tests/toc_core_tests.sh || { |