Date: Tue, 18 Jun 2013 23:18:32 +0000 (UTC) From: Devin Teske <dteske@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r251975 - head/usr.sbin/bsdconfig/startup Message-ID: <201306182318.r5INIWP5056729@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dteske Date: Tue Jun 18 23:18:32 2013 New Revision: 251975 URL: http://svnweb.freebsd.org/changeset/base/251975 Log: Perform some code consolidation and replace nested case-statements with more logical if-else statements for each menu selection. Modified: head/usr.sbin/bsdconfig/startup/misc Modified: head/usr.sbin/bsdconfig/startup/misc ============================================================================== --- head/usr.sbin/bsdconfig/startup/misc Tue Jun 18 23:14:45 2013 (r251974) +++ head/usr.sbin/bsdconfig/startup/misc Tue Jun 18 23:18:32 2013 (r251975) @@ -346,86 +346,90 @@ while :; do case "$mtag" in "X $msg_exit") break ;; + ?" [X] "*) toggled=1 ;; + *) toggled= ;; + esac + + case "$mtag" in + # Simple On/Off toggle bits ?" ["?"] $msg_apm") - case "$mtag" in - ?" [X] "*) err=$( f_sysrc_set apm_enable NO 2>&1 ) ;; - ?" [ ] "*) err=$( f_sysrc_set apm_enable YES 2>&1 ) ;; - esac - [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; - ?" ["?"] $msg_startup_dirs") - dialog_input_value \ - "$msg_startup_dirs_desc" \ - "$( f_sysrc_get local_startup )" - if [ $? -eq $SUCCESS ]; then - err=$( f_sysrc_set local_startup "$value" ) || - f_dialog_msgbox "$err\n" + if [ "$toggled" ]; then + err=$( f_sysrc_set apm_enable NO 2>&1 ) + else + err=$( f_sysrc_set apm_enable YES 2>&1 ) fi ;; ?" ["?"] $msg_named") - case "$mtag" in - ?" [X] "*) err=$( f_sysrc_set named_enable NO 2>&1 ) ;; - ?" [ ] "*) err=$( f_sysrc_set named_enable YES 2>&1 ) ;; - esac - [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; - ?" ["?"] $msg_named_flags") - dialog_input_value \ - "$msg_named_flags_desc" \ - "$( f_sysrc_get named_flags )" - if [ $? -eq $SUCCESS ]; then - err=$( f_sysrc_set named_flags "$value" ) || - f_dialog_msgbox "$err\n" + if [ "$toggled" ]; then + err=$( f_sysrc_set named_enable NO 2>&1 ) + else + err=$( f_sysrc_set named_enable YES 2>&1 ) + fi + ;; + ?" ["?"] $msg_accounting") + if [ "$toggled" ]; then + err=$( f_sysrc_set accounting_enable NO 2>&1 ) + else + err=$( f_sysrc_set accounting_enable YES 2>&1 ) fi ;; + ?" ["?"] $msg_lpd") + if [ "$toggled" ]; then + err=$( f_sysrc_set lpd_enable NO 2>&1 ) + else + err=$( f_sysrc_set lpd_enable YES 2>&1 ) + fi + ;; + ?" ["?"] $msg_sco") + if [ "$toggled" ]; then + err=$( f_sysrc_set ibcs2_enable NO 2>&1 ) + else + err=$( f_sysrc_set ibcs2_enable YES 2>&1 ) + fi + ;; + ?" ["?"] $msg_svr4") + if [ "$toggled" ]; then + err=$( f_sysrc_set svr4_enable NO 2>&1 ) + else + err=$( f_sysrc_set svr4_enable YES 2>&1 ) + fi + ;; + # Multi-variable On/Off toggle bits ?" ["?"] $msg_nis_client") - case "$mtag" in - ?" [X] "*) err=$( f_sysrc_set nis_client_enable NO 2>&1 ) ;; - ?" [ ] "*) + if [ "$toggled" ]; then + err=$( f_sysrc_set nis_client_enable NO 2>&1 ) + else err=$( f_sysrc_set nis_client_enable YES 2>&1 ) \ - && err=$( f_sysrc_set rpcbind_enable YES 2>&1 ) ;; - esac - [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; - ?" ["?"] $msg_nis_domainname") - dialog_input_value \ - "$msg_nis_domainname_desc" \ - "$( f_sysrc_get nisdomainname )" - if [ $? -eq $SUCCESS ]; then - err=$( f_sysrc_set nisdomainname "$value" ) || - f_dialog_msgbox "$err\n" + && err=$( f_sysrc_set rpcbind_enable YES 2>&1 ) fi ;; ?" ["?"] $msg_nis_server") - case "$mtag" in - ?" [X] "*) err=$( f_sysrc_set nis_server_enable NO 2>&1 ) ;; - ?" [ ] "*) + if [ "$toggled" ]; then + err=$( f_sysrc_set nis_server_enable NO 2>&1 ) + else err=$( f_sysrc_set nis_server_enable YES 2>&1 ) \ - && err=$( f_sysrc_set rpcbind_enable YES 2>&1 ) ;; - esac - [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; - ?" ["?"] $msg_accounting") - case "$mtag" in - ?" [X] "*) err=$( f_sysrc_set accounting_enable NO 2>&1 ) ;; - ?" [ ] "*) err=$( f_sysrc_set accounting_enable YES 2>&1 ) ;; - esac - [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; - ?" ["?"] $msg_lpd") - case "$mtag" in - ?" [X] "*) err=$( f_sysrc_set lpd_enable NO 2>&1 ) ;; - ?" [ ] "*) err=$( f_sysrc_set lpd_enable YES 2>&1 ) ;; - esac - [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; - ?" ["?"] $msg_sco") - case "$mtag" in - ?" [X] "*) err=$( f_sysrc_set ibcs2_enable NO 2>&1 ) ;; - ?" [ ] "*) err=$( f_sysrc_set ibcs2_enable YES 2>&1 ) ;; - esac - [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; - ?" ["?"] $msg_svr4") - case "$mtag" in - ?" [X] "*) err=$( f_sysrc_set svr4_enable NO 2>&1 ) ;; - ?" [ ] "*) err=$( f_sysrc_set svr4_enable YES 2>&1 ) ;; - esac - [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; + && err=$( f_sysrc_set rpcbind_enable YES 2>&1 ) + fi + ;; + # Checkboxes for non-boolean options + ?" ["?"] $msg_nis_domainname") + dialog_input_value "$msg_nis_domainname_desc" \ + "$( f_sysrc_get nisdomainname )" || continue + err=$( f_sysrc_set nisdomainname "$value" 2>&1 ) + ;; + ?" ["?"] $msg_startup_dirs") + dialog_input_value "$msg_startup_dirs_desc" \ + "$( f_sysrc_get local_startup )" || continue + err=$( f_sysrc_set local_startup "$value" 2>&1 ) + ;; + ?" ["?"] $msg_named_flags") + dialog_input_value "$msg_named_flags_desc" \ + "$( f_sysrc_get named_flags )" || continue + err=$( f_sysrc_set named_flags "$value" 2>&1 ) + ;; esac + + [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" done exit $SUCCESS
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306182318.r5INIWP5056729>