1252995Sdteske#!/bin/sh
2252995Sdteske#-
3252995Sdteske# Copyright (c) 2012-2013 Devin Teske
4252995Sdteske# All rights reserved.
5252995Sdteske#
6252995Sdteske# Redistribution and use in source and binary forms, with or without
7252995Sdteske# modification, are permitted provided that the following conditions
8252995Sdteske# are met:
9252995Sdteske# 1. Redistributions of source code must retain the above copyright
10252995Sdteske#    notice, this list of conditions and the following disclaimer.
11252995Sdteske# 2. Redistributions in binary form must reproduce the above copyright
12252995Sdteske#    notice, this list of conditions and the following disclaimer in the
13252995Sdteske#    documentation and/or other materials provided with the distribution.
14252995Sdteske#
15252995Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16252995Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17252995Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18252995Sdteske# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19252995Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20252995Sdteske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21252995Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22252995Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23252995Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24252995Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25252995Sdteske# SUCH DAMAGE.
26252995Sdteske#
27252995Sdteske# $FreeBSD$
28252995Sdteske#
29252995Sdteske############################################################ INCLUDES
30252995Sdteske
31252995SdteskeBSDCFG_SHARE="/usr/share/bsdconfig"
32252995Sdteske. $BSDCFG_SHARE/common.subr || exit 1
33252995Sdteskef_dprintf "%s: loading includes..." "$0"
34252995Sdteskef_include $BSDCFG_SHARE/dialog.subr
35252995Sdteskef_include $BSDCFG_SHARE/mustberoot.subr
36252995Sdteskef_include $BSDCFG_SHARE/sysrc.subr
37252995Sdteske
38252995SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="110.mouse"
39252995Sdteskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
40252995Sdteske
41263791Sdteskef_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm &&
42263791Sdteske	pgm="${ipgm:-$pgm}"
43252995Sdteske
44252995Sdteske############################################################ FUNCTIONS
45252995Sdteske
46252995Sdteske# dialog_menu_main
47252995Sdteske#
48252995Sdteske# Display the dialog(1)-based application main menu.
49252995Sdteske#
50252995Sdteskedialog_menu_main()
51252995Sdteske{
52252995Sdteske	local prompt="$msg_port_menu_text"
53252995Sdteske	local menu_list="
54252995Sdteske		'1 $msg_ps2'      '$msg_ps2_desc'
55252995Sdteske		'2 $msg_com1'     '$msg_com1_desc'
56252995Sdteske		'3 $msg_com2'     '$msg_com2_desc'
57252995Sdteske		'4 $msg_com3'     '$msg_com3_desc'
58252995Sdteske		'5 $msg_com4'     '$msg_com4_desc'
59252995Sdteske		'6 $msg_busmouse' '$msg_busmouse_desc'
60252995Sdteske	" # END-QUOTE
61252995Sdteske	local defaultitem= # Calculated below
62252995Sdteske	local hline=
63252995Sdteske
64252995Sdteske	local height width rows
65252995Sdteske	eval f_dialog_menu_size height width rows \
66252995Sdteske	                        \"\$DIALOG_TITLE\"     \
67252995Sdteske	                        \"\$DIALOG_BACKTITLE\" \
68252995Sdteske	                        \"\$prompt\"           \
69252995Sdteske	                        \"\$hline\"            \
70252995Sdteske	                        $menu_list
71252995Sdteske
72252995Sdteske	case "$( f_sysrc_get moused_port )" in
73252995Sdteske	/dev/psm0)  defaultitem="1 $msg_ps2"      ;;
74252995Sdteske	/dev/cuau0) defaultitem="2 $msg_com1"     ;;
75252995Sdteske	/dev/cuau1) defaultitem="3 $msg_com2"     ;;
76252995Sdteske	/dev/cuau2) defaultitem="4 $msg_com3"     ;;
77252995Sdteske	/dev/cuau3) defaultitem="5 $msg_com4"     ;;
78252995Sdteske	/dev/mse0)  defaultitem="6 $msg_busmouse" ;;
79252995Sdteske	esac
80252995Sdteske
81252995Sdteske	local menu_choice
82252995Sdteske	menu_choice=$( eval $DIALOG \
83252995Sdteske		--title \"\$DIALOG_TITLE\"         \
84252995Sdteske		--backtitle \"\$DIALOG_BACKTITLE\" \
85252995Sdteske		--hline \"\$hline\"                \
86252995Sdteske		--ok-label \"\$msg_ok\"            \
87252995Sdteske		--cancel-label \"\$msg_cancel\"    \
88252995Sdteske		--default-item \"\$defaultitem\"   \
89252995Sdteske		--menu \"\$prompt\"                \
90252995Sdteske		$height $width $rows               \
91252995Sdteske		$menu_list                         \
92252995Sdteske		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
93252995Sdteske	)
94252995Sdteske	local retval=$?
95252995Sdteske	f_dialog_menutag_store -s "$menu_choice"
96252995Sdteske	return $retval
97252995Sdteske}
98252995Sdteske
99252995Sdteske############################################################ MAIN
100252995Sdteske
101252995Sdteske# Incorporate rc-file if it exists
102252995Sdteske[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
103252995Sdteske
104252995Sdteske#
105252995Sdteske# Process command-line arguments
106252995Sdteske#
107252995Sdteskewhile getopts h$GETOPTS_STDARGS flag; do
108252995Sdteske	case "$flag" in
109252995Sdteske	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
110252995Sdteske	esac
111252995Sdteskedone
112252995Sdteskeshift $(( $OPTIND - 1 ))
113252995Sdteske
114252995Sdteske#
115252995Sdteske# Initialize
116252995Sdteske#
117252995Sdteskef_dialog_title "$msg_select_your_mouse_port_from_the_following_menu"
118252995Sdteskef_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
119252995Sdteskef_mustberoot_init
120252995Sdteske
121252995Sdteske#
122252995Sdteske# Launch application main menu
123252995Sdteske#
124252995Sdteskedialog_menu_main || f_die
125252995Sdteskef_dialog_menutag_fetch mtag
126252995Sdteske
127252995Sdteskemoused_port_to_set=
128252995Sdteskecase "$mtag" in
129252995Sdteske"1 $msg_ps2") # PS/2 style mouse (/dev/psm0)
130252995Sdteske	moused_port_to_set="/dev/psm0" ;;
131252995Sdteske"2 $msg_com1") # Serial mouse on COM1 (/dev/cuau0)
132252995Sdteske	moused_port_to_set="/dev/cuau0" ;;
133252995Sdteske"3 $msg_com2") # Serial mouse on COM2 (/dev/cuau1)
134252995Sdteske	moused_port_to_set="/dev/cuau1" ;;
135252995Sdteske"4 $msg_com3") # Serial mouse on COM3 (/dev/cuau2)
136252995Sdteske	moused_port_to_set="/dev/cuau2" ;;
137252995Sdteske"5 $msg_com4") # Serial mouse on COM4 (/dev/cuau3)
138252995Sdteske	moused_port_to_set="/dev/cuau3" ;;
139252995Sdteske"6 $msg_busmouse") # Logitech, ATI or MS bus mouse (/dev/mse0)
140252995Sdteske	moused_port_to_set="/dev/mse0" ;;
141252995Sdteskeesac
142252995Sdteske
143252995Sdteskeif [ "$moused_port_to_set" ]; then
144263791Sdteske	f_eval_catch "$0" f_sysrc_set \
145263791Sdteske		'f_sysrc_set moused_port "%s"' "$moused_port_to_set" || f_die
146252995Sdteskeelse
147252995Sdteske	f_die 1 "$msg_unknown_mouse_port_selection"
148252995Sdteskefi
149252995Sdteske
150252995Sdteskeexit $SUCCESS
151252995Sdteske
152252995Sdteske################################################################################
153252995Sdteske# END
154252995Sdteske################################################################################
155