From owner-freebsd-ports@FreeBSD.ORG Sun Dec 7 18:35:04 2008 Return-Path: Delivered-To: ports@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1ED7E1065673 for ; Sun, 7 Dec 2008 18:35:04 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from mail.allbsd.org (unknown [IPv6:2001:2f0:104:e001::32]) by mx1.freebsd.org (Postfix) with ESMTP id 952CB8FC1F for ; Sun, 7 Dec 2008 18:35:03 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from delta.allbsd.org (p2191-ipbf1403funabasi.chiba.ocn.ne.jp [118.7.161.191]) (authenticated bits=128) by mail.allbsd.org (8.14.2/8.14.2) with ESMTP id mB7IYoAu016083 for ; Mon, 8 Dec 2008 03:35:02 +0900 (JST) (envelope-from hrs@FreeBSD.org) Received: from localhost (alph.allbsd.org [192.168.0.10]) (authenticated bits=0) by delta.allbsd.org (8.13.4/8.13.4) with ESMTP id mB7IYOkg074027 for ; Mon, 8 Dec 2008 03:34:26 +0900 (JST) (envelope-from hrs@FreeBSD.org) Date: Mon, 08 Dec 2008 03:18:44 +0900 (JST) Message-Id: <20081208.031844.45215576.hrs@allbsd.org> To: ports@FreeBSD.org From: Hiroki Sato X-PGPkey-fingerprint: BDB3 443F A5DD B3D0 A530 FFD7 4F2C D3D8 2793 CF2D X-Mailer: Mew version 6.1 on Emacs 22.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Multipart/Signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="--Security_Multipart0(Mon_Dec__8_03_18_44_2008_307)--" Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV version 0.93.3, clamav-milter version 0.93.3 on gatekeeper.allbsd.org X-Virus-Status: Clean X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0 (mail.allbsd.org [133.31.130.32]); Mon, 08 Dec 2008 03:35:02 +0900 (JST) Cc: Subject: RFC: $OPTIONS in line-oriented terminal X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Dec 2008 18:35:04 -0000 ----Security_Multipart0(Mon_Dec__8_03_18_44_2008_307)-- Content-Type: Multipart/Mixed; boundary="--Next_Part(Mon_Dec__8_03_18_44_2008_581)--" Content-Transfer-Encoding: 7bit ----Next_Part(Mon_Dec__8_03_18_44_2008_581)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello, I would like your comments about the attached patch. This is for making $OPTIONS work on line-oriented terminals. To see the difference, you can try the following after applying the patch: % cd /usr/ports/print/ghostscript8 && env TERM=foo make config The current implementation of $OPTIONS uses dialog(1) for listing the options, but dialog(1) requires a screen-oriented terminal. Although today's most of terminals used are virtual ones with the capability, there are still a few situations that line-oriented operation is useful; operations over low-speed serial console, for example. Also, another problem of the current implementation is that it silently skips the selection menu if the $TERM is invalid and prevents the selection itself. -- | Hiroki SATO ----Next_Part(Mon_Dec__8_03_18_44_2008_581)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ports_dialog.diff" Index: Mk/bsd.commands.mk =================================================================== RCS file: /home/ncvs/ports/Mk/bsd.commands.mk,v retrieving revision 1.3 diff -d -u -I\$FreeBSD:.*\$ -I\$NetBSD:.*\$ -I\$OpenBSD:.*\$ -I\$DragonFly:.*\$ -I\$Id:.*\$ -I\$Translation:.*\$ -I\$hrs:.*\$ -r1.3 bsd.commands.mk --- Mk/bsd.commands.mk 14 Apr 2008 16:46:41 -0000 1.3 +++ Mk/bsd.commands.mk 7 Dec 2008 18:13:35 -0000 @@ -33,7 +33,7 @@ CPIO?= /usr/bin/cpio CUT?= /usr/bin/cut DC?= /usr/bin/dc -DIALOG?= /usr/bin/dialog +DIALOG?= ${PORTSDIR}/Tools/scripts/dialog.sh DIFF?= /usr/bin/diff DIRNAME?= /usr/bin/dirname EGREP?= /usr/bin/egrep Index: Tools/scripts/dialog.sh =================================================================== RCS file: Tools/scripts/dialog.sh diff -N Tools/scripts/dialog.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Tools/scripts/dialog.sh 7 Dec 2008 18:17:00 -0000 @@ -0,0 +1,222 @@ +#!/bin/sh +# +# $FreeBSD$ +# +# Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hiroki Sato , +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +DIALOG_CMD=/usr/bin/dialog + +if ${DIALOG_CMD} --clear 2> /dev/null; then + exec ${DIALOG_CMD} "$@" +fi + +shjot() +{ + _sj_num=$1 + _sj_begin=$2 + + case ${_sj_num}:${_sj_begin} in + [0-9]*:[0-9]*) + _sj_i=${_sj_begin} + _sj_num=$(( ${_sj_num} + ${_sj_begin} )) + ;; + *) + _sj_i=1 + ;; + esac + + while [ ${_sj_i} -le ${_sj_num} ]; do + echo ${_sj_i} + _sj_i=$(( ${_sj_i} + 1 )) + done +} + +print_sep() +{ + echo "---- $*" +} + +calc_b_e() +{ + _cbe_begin=$((${IPAGE} * ${CPAGE} + 1)) + case ${CPAGE} in + ${NPAGE}) _cbe_ritems=$(((${NITEMS} - ${IPAGE} * ${CPAGE}) % ${IPAGE})) ;; + *) _cbe_ritems=${IPAGE} ;; + esac + _cbe_end=$((${_cbe_begin} + ${_cbe_ritems} - 1)) + + echo ${_cbe_begin} ${_cbe_end} ${_cbe_ritems} +} + +print_knobs() +{ + set -- `calc_b_e` + _pk_begin=$1 + _pk_end=$2 + _pk_ritems=$3 + + for _i in `shjot $(( ${_pk_ritems} - 1 )) ${_pk_begin}`; do + printf "%3d) [%3s] %s\n" ${_i} "`eval echo \\$PSW_${_i}`" "`eval echo \\$PITEM_${_i}`" + done +} + +print_prompt() +{ + print_sep + + set -- `calc_b_e` + _begin=$1 + _end=$2 + _ritems=$3 + + case "${_begin}:${_ritems}:${CPAGE}" in + 1:1:*) echo -n "${_begin},le,ld,?,q) " ;; + 1:*:${NPAGE}) echo -n "${_begin}-${_end},le,ld,?,q) " ;; + *:1:*) echo -n "${_begin},p,le,ld,?,q) "; + VALIDC="p" ;; + *:*:${NPAGE}) echo -n "${_begin}-${_end},p,le,ld,?,q) "; + VALIDC="p" ;; + 1:*:*) echo -n "${_begin}-${_end}(max:${NITEMS}),n,le,ld,?,q) "; + VALIDC="n" ;; + *) echo -n "${_begin}-${_end}(max:${NITEMS}),p,n,le,ld,?,q) "; + VALIDC="pn" ;; + esac +} + +print_vars() +{ + for _i in `shjot ${NITEMS}`; do + case $1:`eval echo \\$PSW_${_i}` in + enables:on) echo "WITH_`eval echo \\$PTAG_\${_i}`=true" ;; + disables:off) echo "WITHOUT_`eval echo \\$PTAG_\${_i}`=true" ;; + knobs:on) echo -n " \"`eval echo \\$PTAG_\${_i}`\"" ;; + esac + done +} + +flipflop() +{ + _tmp=`eval echo \\$PSW_$1` + + case "${_tmp}" in + on) echo "off" ;; + off) echo "on" ;; + *) echo "${_tmp}" ;; + esac +} + +check_input() +{ + read _in + + case "${_in}:${VALIDC}" in + [123456789]:*|[123456789][0123456789]:*|[123456789][0123456789][0123456789]:*) + STATE=MENU + echo "PSW_${_in}=`flipflop ${_in}`; STATE=${STATE}" + ;; + q:*|Q:*) + echo "STATE=DONE" + ;; + n:*n*|N:*n*) + STATE=MENU + echo "PAGE=$((${CPAGE}+1)); STATE=${STATE}" + ;; + p:*p*|P:*p*) + STATE=MENU + echo "PAGE=$((${CPAGE}-1)); STATE=${STATE}" + ;; + ld:*) + STATE=NOMENU + echo "print_vars disables; STATE=${STATE}" + ;; + le:*) + STATE=NOMENU + echo "print_vars enables; STATE=${STATE}" + ;; + \?:*) + STATE=NOMENU + MSG=' p: previous\n n: next\n le: list enables\n ld: list disables\n ?: help\n q: quit\n' + echo "print_sep Usage; printf \"${MSG}\"; STATE=${STATE}" + ;; + *) + STATE=NOMENU + echo "echo \"invalid command: ${_in}\"; STATE=${STATE}" + ;; + esac +} + +DONE=0 +CPAGE=0 # current page +NITEMS=0 # total number of items +NPAGE=0 # total number of pages +IPAGE=10 # items per page + +while [ $# != 0 ]; do + case $1 in + --checklist) + shift; TITLE=$1 + shift; WIDTH=$1 + shift; HEIGHT=$1 + shift; LHEIGHT=$1 + shift; + + NITEMS=$(($# / 3)) + NPAGE=$(($# / 3 / ${IPAGE})) + + for i in `shjot ${NITEMS}`; do + eval "PTAG_${i}=\"$1\"" + eval "PITEM_${i}=\"$2\"" + eval "PSW_${i}=\"$3\"" + shift 3 + done + + break + ;; + *) + shift + ;; + esac +done + +STATE=MENU; + +while :; do + case ${STATE} in + MENU) + print_sep "${TITLE}" + print_knobs "${NITEMS}" "${CPAGE}" "${IPAGE}" + ;; + NOMENU) + # do nothing + ;; + DONE) + break; + ;; + esac + print_prompt + eval `check_input "${NITEMS}" "${CPAGE}" "${IPAGE}"` +done + +print_vars knobs >&2 ----Next_Part(Mon_Dec__8_03_18_44_2008_581)---- ----Security_Multipart0(Mon_Dec__8_03_18_44_2008_307)-- Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEABECAAYFAkk8E4QACgkQTyzT2CeTzy1yFwCeJfCEvzzcEBVBsV+am7iJcvSh VSsAoKpQ5CWrPOl7jaSA55eBwRjrcVnU =aPLI -----END PGP SIGNATURE----- ----Security_Multipart0(Mon_Dec__8_03_18_44_2008_307)----