From 7598274e15d3f0c5528623c5355667d414e5df27 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Tue, 24 Aug 2004 13:36:48 +0000 Subject: [PATCH] Clifford Wolf: Improved Config tool: now distinguish between automatic default values an user supplied config [2004081716030800560] (https://www.rocklinux.net/submaster) git-svn-id: http://www.rocklinux.org/svn/rock-linux/trunk@3945 c5f82cb5-29bc-0310-9cd0-bff59a50e3bc --- package/mnemoc/boehm-gc/subconfig-libs.in | 9 +- scripts/Config | 30 +++-- scripts/config.func | 137 +++++++++++++--------- 3 files changed, 108 insertions(+), 68 deletions(-) diff --git a/package/mnemoc/boehm-gc/subconfig-libs.in b/package/mnemoc/boehm-gc/subconfig-libs.in index 7366d18ea..3db418466 100644 --- a/package/mnemoc/boehm-gc/subconfig-libs.in +++ b/package/mnemoc/boehm-gc/subconfig-libs.in @@ -25,10 +25,9 @@ then comment '--- Boehm-Demers-Weiser conservative garbage collector' pkgout - while read x y; do - bool "Use it in Objective-C (gcc-$y)" ROCKCFG_PKG_BOEHMGC_OBJC${x#gcc} 0 - bool "Use it in Java (gcc-$y)" ROCKCFG_PKG_BOEHMGC_JAVA${x#gcc} 0 - #comment ' ' - done < <( grep '^X .* gcc.* ' config/$config/packages | grep -v cross | cut -d' ' -f 5,6 ) + while read x; do + bool "Use it in Objective-C (${x#gcc=})" ROCKCFG_PKG_BOEHMGC_OBJC${x#gcc=gcc} 0 + bool "Use it in Java (${x#gcc=})" ROCKCFG_PKG_BOEHMGC_JAVA${x#gcc=gcc} 0 + done < <( grep '^X .* gcc=' config/$config/packages | grep -v cross | cut -d' ' -f 5 ) fi diff --git a/scripts/Config b/scripts/Config index 8e4b80d2f..ce42d9844 100755 --- a/scripts/Config +++ b/scripts/Config @@ -93,7 +93,7 @@ if [ $do_config_cycle = 0 ] ; then fi echo "Creating configuration script." - cat << "EOT" > src/rockconfig.awk.$$ + cat << EOT > src/rockconfig.awk.$$ #!/usr/bin/awk -f FNR == 1 { @@ -108,13 +108,13 @@ END { print "### END of " FILENAME; } -$1 == "%include" { - $1 = "awk -f src/rockconfig.awk"; - system($0); +\$1 == "%include" { + \$1 = "awk -f src/rockconfig.awk"; + system(\$0); next; } -$1 == "#" { next; } +\$1 == "#" { next; } { print; } EOT mv src/rockconfig.awk.$$ src/rockconfig.awk @@ -173,7 +173,8 @@ menu_this=0 ; menu_current=0 ; menu_counter=0 menu_stack=x ; menu_back=-1 ; menu_backpos=-1 mkdir -p config/$config -touch config/$config/config config/$config/packages +touch config/$config/config +touch config/$config/packages configtitle="$(printf ' %-50s %6s active packages ]' \ "ROCK Linux $rockver Configuration - $config" \ @@ -181,11 +182,18 @@ configtitle="$(printf ' %-50s %6s active packages ]' \ bprof main stop . ./config/$config/config +if [ -f config/$config/config_usr ]; then + nousrconfig=0 + . ./config/$config/config_usr +else + nousrconfig=1 +fi bprof main start rm -f config.dialog config.data config.help touch config.dialog config.data config.help echo -e "#\n# ROCK Linux $rockver Config File\n#" > config/$config/config +echo -e "#\n# ROCK Linux $rockver User Config File\n#" > config/$config/config_usr spacer="" ; expert=0 ; tabspace="5" ; tabspace_list="" commentnr=0 ; editfilenr=0 @@ -209,6 +217,10 @@ rm -f config/$config/*.tmp cut -f1,2,4,5,8- -d' ' config/$config/packages | sed 's, [^ ]*$,,' | \ tr ' ' '\t' | expand -t2,15,35, > config/$config/packages.txt +for x in ${!ROCKCFGUSR_*}; do + eval "echo \"$x='\$$x'\"" +done >> config/$config/config_usr + configtitle="$(printf ' %-50s %6s active packages ]' \ "ROCK Linux $rockver Configuration - $config" \ "[ $(echo `grep '^X' config/$config/packages | wc -l`)" )" @@ -236,12 +248,12 @@ case "$returncode" in { echo -e "\n# Remember menu position:\ncurrent='$item'" echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'" echo -e "\n# Execute this config command:\n$command" - } >> config/$config/config + } >> config/$config/config_usr ;; menu-back) { echo -e "\n# New menu position:\ncurrent='$menu_backpos'" echo -e "\n# New sub-menu:\nmenu_current='$menu_back'" - } >> config/$config/config + } >> config/$config/config_usr ;; 1|255) rm -f config.data config.dialog config.out config.help @@ -257,7 +269,7 @@ case "$returncode" in item=$(echo $item | cut -f1 -d' ') # dialog(1) bug? { echo -e "\n# Remember menu position:\ncurrent='$item'" echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'" - } >> config/$config/config + } >> config/$config/config_usr get_help $item > config.dialog diff --git a/scripts/config.func b/scripts/config.func index 2e906d83f..57ab4909a 100644 --- a/scripts/config.func +++ b/scripts/config.func @@ -212,55 +212,73 @@ const() { # set_data() { bprof set_data start - local q="'" set_name="ROCKCFGSET_${1#ROCKCFG_}" + local q="'" + + set_name="ROCKCFGSET_${1#ROCKCFG_}" + usr_name="ROCKCFGUSR_${1#ROCKCFG_}" + eval "usr_data=\"\$$usr_name\"" + + menumode=0 + data="$2" - if eval "[ \"\$$set_name\" ]" ; then + if eval "[ \"\$$set_name\" ]"; then eval "data=\"\$$set_name\"" - eval "$1=\"\$data\"" - if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] - then menumode=2 ; else menumode=0 ; fi - - elif [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then - eval "data=\"\${$1:-$2}\"" - eval "$1=\"\$data\"" - menumode=1 - else - data="$2" ; eval "$1=\"\$data\"" - menumode=0 + fi + dfl_data="$data" + + if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ]; then + menumode=2 + if [ $nousrconfig -eq 1 ] && eval "[ -n \"\$$1\" -a \"\$$1\" != \"\$data\" ]"; then + eval "$usr_name=\"\$$1\"" + eval "usr_data=\"\$$1\"" + fi + if [ -n "$usr_data" ]; then + data="$usr_data" + obegin="<" oend=">" menumode=1 + else + unset $usr_name + fi fi + eval "$1=\"\$data\"" item="$1" + echo "export $1='${data//$q/$q\\$q$q}'" >> config/$config/config bprof set_data stop } choice() { bprof choice start + local obegin="(" oend=")" + local q="'" + + set_data "$1" "$2" - # reset to default if current value is not in list - # + # if data is not in list, leave usr_data unmodified + # but set the current value to the default + local fallback_hack=0 eval $( - eval "value=\$$1" ; name=$1 ; shift ; shift + shift; shift while [ "$#" != 0 ] ; do - [ "$value" = "$1" ] && name="" ; shift ; shift + [ "$data" = "$1" ] && exit + shift; shift done - [ "$name" ] && echo "unset $name" + echo "fallback_hack=1" ) - - set_data "$1" "$2" - - if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then - { echo -en "$item\tchoice_action '$1' '$data'" ; shift ; shift - for x ; do echo -n " '$x'" ; done ; echo ; } >> config.data + if [ "$fallback_hack" = 1 ]; then + obegin="?"; oend="?"; data="$dfl_data"; eval "$1=\"\$data\"" + echo "export $1='${data//$q/$q\\$q$q}'" >> config/$config/config fi if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then - if [ "$menumode" -eq 1 ] ; then xdata="($data)" - else xdata="=$data=" ; fi + { echo -en "$item\tchoice_action '$usr_name' '$usr_data'" ; shift ; shift + echo -n " '' 'Reset_this_switch_to_default_value'" + for x ; do echo -n " '$x'" ; done ; echo ; } >> config.data + + xdata="$obegin$data$oend" while [ "$1" -a "$1" != "$data" ] ; do shift ; shift ; done - printf "'$item' '$spacer%-${tabspace}s ${2//_/ }'\n" \ - "$xdata" >> config.dialog + printf "'$item' '$spacer%-${tabspace}s ${2//_/ }'\n" "$xdata" >> config.dialog fi bprof choice stop @@ -272,7 +290,7 @@ choice_action() { --radiolist 'Arrow keys navigate the menu. Press to activate menu items. Highlighted letters are hotkeys.' \ $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 ))" default=$2 ; item=$1 ; shift ; shift - while [ "$1" ] ; do + while [ "$#" -gt 1 ] ; do if [ "$1" = "$default" ] then command="$command '$1' '${2//_/ }' ON" else command="$command '$1' '${2//_/ }' OFF" ; fi @@ -292,19 +310,15 @@ choice_action() { text() { bprof text start - local q="'" + local q="'" obegin="(" oend=")" set_data "$2" "$3" - if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then - echo -e "$2\ttext_action '$1' '$2'" \ + if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then + echo -e "$2\ttext_action '$1' '$usr_name'" \ "'${data//$q/$q\\$q$q}'" >> config.data - fi - if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then - xdata="$( printf "%-${tabspace}s" \ - "$(echo $data | cut -c1-20)")" - if [ "$menumode" -eq 1 ] ; then xdata="($xdata)" - else xdata="=$xdata=" ; fi + xdata="${obegin}$( printf "%-${tabspace}s" \ + "$(echo $data | cut -c1-20)")${oend}" printf "'$2' '$spacer%s $1'\n" \ "${xdata//$q/$q\\$q$q}" >> config.dialog @@ -327,21 +341,14 @@ text_action() { bool() { bprof bool start - local x + local x obegin="[" oend="]" set_data "$2" "$3" - if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then - echo -e "$2\tbool_action '$1' '$2' '$data'" >> config.data - fi - if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then - if [ "$menumode" -eq 1 ] ; then - if [ $data -eq 0 ] ; then x='[ ]' ; else x='[*]' ; fi - else - if [ $data -eq 0 ] ; then x='= =' ; else x='=*=' ; fi - fi - printf "$2 '$spacer%-${tabspace}s ${1//_/ }'\n" \ - "$x" >> config.dialog + if [ $data -eq 0 ] ; then x="${obegin} ${oend}" ; else x="${obegin}*${oend}" ; fi + echo -e "$2\tbool_action '$usr_name' '$usr_data'" >> config.data + + printf "$2 '$spacer%-${tabspace}s ${1//_/ }'\n" "$x" >> config.dialog # If you do not know what mighty esden is doin here see comment() if [ "$4" != "" ] ; then @@ -352,8 +359,11 @@ bool() { } bool_action() { - if [ $3 -eq 0 ] ; then eval "$2=1" - else eval "$2=0" ; fi + case "$2" in + "") eval "$1=1" ;; + 1) eval "$1=0" ;; + *) eval "$1=" ;; + esac } editfile() { @@ -497,12 +507,31 @@ set_help() { get_help() { bprof get_help start + + cat << EOT + +This is the ROCK Linux $rockver Configuration Tool. + +Config option types: + [*] [ ] Unmodified bool value (set and unset) + <*> < > User-modified bool value (set and unset) + (foobar) Unmodified selection or text field + User-modified selection or text field + +Note that e.g. bool value are in fact tristate options: +user set, user unset and and the unmodified default value + +This is because one option might change the default value +of another option. You might need a while to get used to +the concept, but in the end it really makes sense. + +----- +EOT + # Create standard help output ... default_text=" There is no help on '$1' available. -This is the ROCK Linux $rockver Configuration Tool. - Please read the build Documentation (Documentation/BUILD) before building ROCK Linux.