mouse revision 251244
1238438Sdteske#!/bin/sh
2238438Sdteske#-
3249746Sdteske# Copyright (c) 2012-2013 Devin Teske
4238438Sdteske# All Rights Reserved.
5238438Sdteske#
6238438Sdteske# Redistribution and use in source and binary forms, with or without
7238438Sdteske# modification, are permitted provided that the following conditions
8238438Sdteske# are met:
9238438Sdteske# 1. Redistributions of source code must retain the above copyright
10238438Sdteske#    notice, this list of conditions and the following disclaimer.
11238438Sdteske# 2. Redistributions in binary form must reproduce the above copyright
12238438Sdteske#    notice, this list of conditions and the following disclaimer in the
13238438Sdteske#    documentation and/or other materials provided with the distribution.
14238438Sdteske#
15238438Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16238438Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
17238438Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18238438Sdteske# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19238438Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20238438Sdteske# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21238438Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22238438Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23238438Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24238438Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25238438Sdteske# SUCH DAMAGE.
26238438Sdteske#
27238438Sdteske# $FreeBSD: head/usr.sbin/bsdconfig/mouse/mouse 251244 2013-06-02 09:02:12Z dteske $
28238438Sdteske#
29238438Sdteske############################################################ INCLUDES
30238438Sdteske
31240684SdteskeBSDCFG_SHARE="/usr/share/bsdconfig"
32240684Sdteske. $BSDCFG_SHARE/common.subr || exit 1
33244675Sdteskef_dprintf "%s: loading includes..." "$0"
34240684Sdteskef_include $BSDCFG_SHARE/dialog.subr
35240684Sdteskef_include $BSDCFG_SHARE/mustberoot.subr
36238438Sdteske
37240684SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="110.mouse"
38238438Sdteskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
39238438Sdteske
40243112Sdteskeipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
41238438Sdteske[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
42238438Sdteske
43238438Sdteske############################################################ FUNCTIONS
44238438Sdteske
45238438Sdteske# dialog_menu_main
46238438Sdteske#
47238438Sdteske# Display the dialog(1)-based application main menu.
48238438Sdteske#
49238438Sdteskedialog_menu_main()
50238438Sdteske{
51251190Sdteske	local menu_list
52238438Sdteske	local hline=""
53238438Sdteske	local prompt="$msg_menu_text"
54251244Sdteske	local defaultitem= # Calculated below
55238438Sdteske
56238438Sdteske	menu_list="
57238438Sdteske		'X $msg_exit'    '$msg_exit_this_menu'
58238438Sdteske		'2 $msg_enable'  '$msg_test_and_run_the_mouse_daemon'
59238438Sdteske		'3 $msg_type'    '$msg_select_mouse_protocol_type'
60238438Sdteske		'4 $msg_port'    '$msg_select_mouse_port'
61238438Sdteske		'5 $msg_flags'   '$msg_set_additional_flags'
62238438Sdteske		'6 $msg_disable' '$msg_disable_the_mouse_daemon'
63238438Sdteske	" # END-QUOTE
64238438Sdteske
65251190Sdteske	local height width rows
66251190Sdteske	eval f_dialog_menu_size height width rows \
67251190Sdteske	                        \"\$DIALOG_TITLE\"     \
68251190Sdteske	                        \"\$DIALOG_BACKTITLE\" \
69251190Sdteske	                        \"\$prompt\"           \
70251190Sdteske	                        \"\$hline\"            \
71251190Sdteske	                        $menu_list
72238438Sdteske
73251244Sdteske	# Obtain default-item from previously stored selection
74251244Sdteske	f_dialog_default_fetch defaultitem
75251244Sdteske
76251236Sdteske	local menu_choice
77251236Sdteske	menu_choice=$( eval $DIALOG \
78251244Sdteske		--title \"\$DIALOG_TITLE\"         \
79251244Sdteske		--backtitle \"\$DIALOG_BACKTITLE\" \
80251244Sdteske		--hline \"\$hline\"                \
81251244Sdteske		--ok-label \"\$msg_ok\"            \
82251244Sdteske		--cancel-label \"\$msg_cancel\"    \
83251244Sdteske		--default-item \"\$defaultitem\"   \
84251244Sdteske		--menu \"\$prompt\"                \
85251244Sdteske		$height $width $rows               \
86251244Sdteske		$menu_list                         \
87240768Sdteske		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
88240768Sdteske	)
89240768Sdteske	local retval=$?
90251236Sdteske	f_dialog_data_sanitize menu_choice
91251236Sdteske	f_dialog_menutag_store "$menu_choice"
92251244Sdteske	f_dialog_default_store "$menu_choice"
93240768Sdteske	return $retval
94238438Sdteske}
95238438Sdteske
96238438Sdteske############################################################ MAIN
97238438Sdteske
98238438Sdteske# Incorporate rc-file if it exists
99238438Sdteske[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
100238438Sdteske
101238438Sdteske#
102238438Sdteske# Process command-line arguments
103238438Sdteske#
104250633Sdteskewhile getopts h$GETOPTS_STDARGS flag; do
105238438Sdteske	case "$flag" in
106238438Sdteske	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
107238438Sdteske	esac
108238438Sdteskedone
109238438Sdteskeshift $(( $OPTIND - 1 ))
110238438Sdteske
111238438Sdteske#
112238438Sdteske# Initialize
113238438Sdteske#
114238438Sdteskef_dialog_title "$msg_please_configure_your_mouse"
115238438Sdteskef_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
116238438Sdteskef_mustberoot_init
117238438Sdteske
118238438Sdteske#
119238438Sdteske# Launch application main menu
120238438Sdteske#
121238438Sdteskewhile :; do
122251236Sdteske	dialog_menu_main || f_die
123251236Sdteske	f_dialog_menutag_fetch mtag
124238438Sdteske
125238438Sdteske	case "$mtag" in
126238438Sdteske	"X $msg_exit") break ;;
127238438Sdteske	"2 $msg_enable") # Test and run the mouse daemon
128238438Sdteske		$BSDCFG_LIBE/$APP_DIR/enable ${USE_XDIALOG:+-X} ;;
129238438Sdteske	"3 $msg_type") # Select mouse protocol type
130238438Sdteske		$BSDCFG_LIBE/$APP_DIR/type ${USE_XDIALOG:+-X} ;;
131238438Sdteske	"4 $msg_port") # Select mouse port
132238438Sdteske		$BSDCFG_LIBE/$APP_DIR/port ${USE_XDIALOG:+-X} ;;
133238438Sdteske	"5 $msg_flags") # Set additional flags
134238438Sdteske		$BSDCFG_LIBE/$APP_DIR/flags ${USE_XDIALOG:+-X} ;;
135238438Sdteske	"6 $msg_disable") # Disable the mouse daemon
136238438Sdteske		$BSDCFG_LIBE/$APP_DIR/disable ${USE_XDIALOG:+-X} ;;
137238438Sdteske	esac
138238438Sdteske
139238438Sdteskedone
140238438Sdteske
141238438Sdteskeexit $SUCCESS
142238438Sdteske
143238438Sdteske################################################################################
144238438Sdteske# END
145238438Sdteske################################################################################
146