rcedit.subr (0bfd163f522701b486e066fa2e56624c02f5081a) rcedit.subr (d4ae33f0721c1b170fe37d97e395228ffcfb3f80)
1if [ ! "$_STARTUP_RCEDIT_SUBR" ]; then _STARTUP_RCEDIT_SUBR=1
2#
3# Copyright (c) 2012 Devin Teske
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:

--- 18 unchanged lines hidden (view full) ---

27# $FreeBSD$
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." startup/rcedit.subr
34f_include $BSDCFG_SHARE/dialog.subr
1if [ ! "$_STARTUP_RCEDIT_SUBR" ]; then _STARTUP_RCEDIT_SUBR=1
2#
3# Copyright (c) 2012 Devin Teske
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:

--- 18 unchanged lines hidden (view full) ---

27# $FreeBSD$
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." startup/rcedit.subr
34f_include $BSDCFG_SHARE/dialog.subr
35f_include $BSDCFG_SHARE/strings.subr
35f_include $BSDCFG_SHARE/sysrc.subr
36
37BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
38f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
39
40############################################################ FUNCTIONS
41
42# f_dialog_rcedit $var [[--] $init ...]

--- 6 unchanged lines hidden (view full) ---

49# to be displayed, overriding the default behavior to display the currently
50# configured value as the initial text.
51#
52# If instead the second argument is "--", then the third argument (NULL or
53# otherwise) will be treated as the initial text.
54#
55f_dialog_rcedit()
56{
36f_include $BSDCFG_SHARE/sysrc.subr
37
38BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
39f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
40
41############################################################ FUNCTIONS
42
43# f_dialog_rcedit $var [[--] $init ...]

--- 6 unchanged lines hidden (view full) ---

50# to be displayed, overriding the default behavior to display the currently
51# configured value as the initial text.
52#
53# If instead the second argument is "--", then the third argument (NULL or
54# otherwise) will be treated as the initial text.
55#
56f_dialog_rcedit()
57{
58 local funcname=f_dialog_rcedit
57 local msg var="$1" _input
58
59 local msg var="$1" _input
60
59 msg=$( printf "$msg_please_enter_a_new_value" \
60 "$var" "$( f_sysrc_get_default "$var" )" )
61 f_sprintf msg "$msg_please_enter_a_new_value" \
62 "$var" "$( f_sysrc_get_default "$var" )"
61
62 shift 1 # var
63 if [ "$1" ]; then
64 [ "$1" = "--" ] && shift 1 # --
65 _input="$1"
66 else
67 _input=$( f_sysrc_get "$var" )
68 fi
69
70 # Return if user has either pressed ESC or chosen Cancel/No
71 f_dialog_input _input "$msg" "$_input" \
72 "$hline_alnum_punc_tab_enter" || return $?
73
74 # Return if the value has not changed from current
75 local cur_val="$( f_sysrc_get "$var" )"
76 [ "$_input" = "$cur_val" ] && return $DIALOG_OK
77
78 f_dprintf "%s: [%s]->[%s]" "$var" "$cur_val" "$_input"
79
63
64 shift 1 # var
65 if [ "$1" ]; then
66 [ "$1" = "--" ] && shift 1 # --
67 _input="$1"
68 else
69 _input=$( f_sysrc_get "$var" )
70 fi
71
72 # Return if user has either pressed ESC or chosen Cancel/No
73 f_dialog_input _input "$msg" "$_input" \
74 "$hline_alnum_punc_tab_enter" || return $?
75
76 # Return if the value has not changed from current
77 local cur_val="$( f_sysrc_get "$var" )"
78 [ "$_input" = "$cur_val" ] && return $DIALOG_OK
79
80 f_dprintf "%s: [%s]->[%s]" "$var" "$cur_val" "$_input"
81
80 err=$( f_sysrc_set "$var" "$_input" 2>&1 ) || f_dialog_msgbox "$err"
82 f_eval_catch $funcname f_sysrc_set \
83 'f_sysrc_set "%s" "%s"' "$var" "$_input"
81}
82
83############################################################ MAIN
84
85f_dprintf "%s: Successfully loaded." startup/rcedit.subr
86
87fi # ! $_STARTUP_RCEDIT_SUBR
84}
85
86############################################################ MAIN
87
88f_dprintf "%s: Successfully loaded." startup/rcedit.subr
89
90fi # ! $_STARTUP_RCEDIT_SUBR