mouse revision 238438
1238438Sdteske#!/bin/sh
2238438Sdteske#-
3238438Sdteske# Copyright (c) 2012 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 238438 2012-07-14 03:16:57Z dteske $
28238438Sdteske#
29238438Sdteske############################################################ INCLUDES
30238438Sdteske
31238438SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig"
32238438Sdteske. $BSDCFG_LIBE/include/common.subr || exit 1
33238438Sdteskef_include $BSDCFG_LIBE/include/dialog.subr
34238438Sdteskef_include $BSDCFG_LIBE/include/mustberoot.subr
35238438Sdteske
36238438SdteskeAPP_DIR="110.mouse"
37238438Sdteskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
38238438Sdteske
39238438Sdteskeipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
40238438Sdteske[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
41238438Sdteske
42238438Sdteske############################################################ FUNCTIONS
43238438Sdteske
44238438Sdteske# dialog_menu_main
45238438Sdteske#
46238438Sdteske# Display the dialog(1)-based application main menu.
47238438Sdteske#
48238438Sdteskedialog_menu_main()
49238438Sdteske{
50238438Sdteske	local menu_list size
51238438Sdteske	local hline=""
52238438Sdteske	local prompt="$msg_menu_text"
53238438Sdteske
54238438Sdteske	menu_list="
55238438Sdteske		'X $msg_exit'    '$msg_exit_this_menu'
56238438Sdteske		'2 $msg_enable'  '$msg_test_and_run_the_mouse_daemon'
57238438Sdteske		'3 $msg_type'    '$msg_select_mouse_protocol_type'
58238438Sdteske		'4 $msg_port'    '$msg_select_mouse_port'
59238438Sdteske		'5 $msg_flags'   '$msg_set_additional_flags'
60238438Sdteske		'6 $msg_disable' '$msg_disable_the_mouse_daemon'
61238438Sdteske	" # END-QUOTE
62238438Sdteske
63238438Sdteske	size=$( eval f_dialog_menu_size \
64238438Sdteske	        	\"\$DIALOG_TITLE\"     \
65238438Sdteske	        	\"\$DIALOG_BACKTITLE\" \
66238438Sdteske	                \"\$prompt\"           \
67238438Sdteske	        	\"\$hline\"            \
68238438Sdteske	        	$menu_list             )
69238438Sdteske
70238438Sdteske	eval $DIALOG \
71238438Sdteske		--clear --title \"\$DIALOG_TITLE\" \
72238438Sdteske		--backtitle \"\$DIALOG_BACKTITLE\" \
73238438Sdteske		--hline \"\$hline\"                \
74238438Sdteske		--ok-label \"\$msg_ok\"            \
75238438Sdteske		--cancel-label \"\$msg_cancel\"    \
76238438Sdteske		--menu \"\$prompt\" $size          \
77238438Sdteske		$menu_list                         \
78238438Sdteske		2> "$DIALOG_TMPDIR/dialog.menu.$$"
79238438Sdteske}
80238438Sdteske
81238438Sdteske############################################################ MAIN
82238438Sdteske
83238438Sdteske# Incorporate rc-file if it exists
84238438Sdteske[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
85238438Sdteske
86238438Sdteske#
87238438Sdteske# Process command-line arguments
88238438Sdteske#
89238438Sdteskewhile getopts hSX flag; do
90238438Sdteske	case "$flag" in
91238438Sdteske	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
92238438Sdteske	esac
93238438Sdteskedone
94238438Sdteskeshift $(( $OPTIND - 1 ))
95238438Sdteske
96238438Sdteske#
97238438Sdteske# Initialize
98238438Sdteske#
99238438Sdteskef_dialog_init
100238438Sdteskef_dialog_title "$msg_please_configure_your_mouse"
101238438Sdteskef_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
102238438Sdteskef_mustberoot_init
103238438Sdteske
104238438Sdteske#
105238438Sdteske# Launch application main menu
106238438Sdteske#
107238438Sdteskewhile :; do
108238438Sdteske	dialog_menu_main
109238438Sdteske	retval=$?
110238438Sdteske	mtag=$( f_dialog_menutag )
111238438Sdteske
112238438Sdteske	[ $retval -eq 0 ] || f_die
113238438Sdteske
114238438Sdteske	case "$mtag" in
115238438Sdteske	"X $msg_exit") break ;;
116238438Sdteske	"2 $msg_enable") # Test and run the mouse daemon
117238438Sdteske		$BSDCFG_LIBE/$APP_DIR/enable ${USE_XDIALOG:+-X} ;;
118238438Sdteske	"3 $msg_type") # Select mouse protocol type
119238438Sdteske		$BSDCFG_LIBE/$APP_DIR/type ${USE_XDIALOG:+-X} ;;
120238438Sdteske	"4 $msg_port") # Select mouse port
121238438Sdteske		$BSDCFG_LIBE/$APP_DIR/port ${USE_XDIALOG:+-X} ;;
122238438Sdteske	"5 $msg_flags") # Set additional flags
123238438Sdteske		$BSDCFG_LIBE/$APP_DIR/flags ${USE_XDIALOG:+-X} ;;
124238438Sdteske	"6 $msg_disable") # Disable the mouse daemon
125238438Sdteske		$BSDCFG_LIBE/$APP_DIR/disable ${USE_XDIALOG:+-X} ;;
126238438Sdteske	esac
127238438Sdteske
128238438Sdteskedone
129238438Sdteske
130238438Sdteskeexit $SUCCESS
131238438Sdteske
132238438Sdteske################################################################################
133238438Sdteske# END
134238438Sdteske################################################################################
135