-bitcount () {
- local c=$1
- echo $((
- c=((c>> 1)&0x55555555)+(c&0x55555555),
- c=((c>> 2)&0x33333333)+(c&0x33333333),
- c=((c>> 4)&0x0f0f0f0f)+(c&0x0f0f0f0f),
- c=((c>> 8)&0x00ff00ff)+(c&0x00ff00ff),
- c=((c>>16)&0x0000ffff)+(c&0x0000ffff)
- ))
+append() {
+ local var="$1"
+ local value="$2"
+ local sep="${3:- }"
+ eval "export ${var}=\"\${${var}:+\${${var}}${value:+$sep}}\$value\""
+}
+
+reset_cb() {
+ config_cb() {
+ return 0
+ }
+ option_cb() {
+ return 0
+ }
+}
+reset_cb
+
+config () {
+ local cfgtype="$1"
+ local name="$2"
+ _C=$(($_C + 1))
+ name="${name:-cfg${_C}}"
+ config_cb "$cfgtype" "$name"
+ export CONFIG_SECTION="$name"
+ export CONFIG_${CONFIG_SECTION}_TYPE="$cfgtype"
+}
+
+option () {
+ local varname="$1"; shift
+ export CONFIG_${CONFIG_SECTION}_${varname}="$*"
+ option_cb "$varname" "$*"
+}
+
+config_rename() {
+ local OLD="$1"
+ local NEW="$2"
+ local oldsetting
+ local newvar
+
+ [ -z "$OLD" -o -z "$NEW" ] && return
+ for oldsetting in `set | grep ^CONFIG_${OLD}_ | \
+ sed -e 's/\(.*\)=.*$/\1/'` ; do
+ newvar="CONFIG_${NEW}_${oldsetting##CONFIG_${OLD}_}"
+ eval "${newvar}=\${$oldsetting}"
+ unset "$oldsetting"
+ done
+ [ "$CONFIG_SECTION" = "$OLD" ] && CONFIG_SECTION="$NEW"