wok diff sane-backends/stuff/tazpanel/sane.cgi @ rev 21768

sane-backends/sane.cgi: do not limit parameters
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jun 30 11:35:08 2019 +0200 (2019-06-30)
parents 9a1f50677074
children 5b7852dbf3f4
line diff
     1.1 --- a/sane-backends/stuff/tazpanel/sane.cgi	Thu Jun 27 22:27:24 2019 +0200
     1.2 +++ b/sane-backends/stuff/tazpanel/sane.cgi	Sun Jun 30 11:35:08 2019 +0200
     1.3 @@ -44,8 +44,18 @@
     1.4  		CMD="$CMD -$i $j"
     1.5  		ARGS="$ARGS $j"
     1.6  	done
     1.7 -	for i in mode source contrast brightness ; do
     1.8 -		[ "$(xPOST $i)" ] && CMD="$CMD --$i '$(xPOST $i)'"
     1.9 +	for i in $(POST) ; do
    1.10 +		case $i in
    1.11 +		preview|format|resolution|res_min|res_max|l_min|l_max);;
    1.12 +		geometry_l|t_min|t_max|geometry_t|x_min|x_max|geometry_x);;
    1.13 +		y_min|y_max|geometry_y|tmpreview|device|params);;
    1.14 +		*)  v="$(xPOST $i)"; i="--${i//_/-}"
    1.15 +		    case "$v" in
    1.16 +			'')	;;
    1.17 +			yes|no) CMD="$CMD $i=$v" ;;
    1.18 +			*)	CMD="$CMD $i '$v'" ;;
    1.19 +		    esac
    1.20 +		esac
    1.21  	done
    1.22  	resolution=${1:-0}
    1.23  	if [ $resolution -eq 0 ]; then
    1.24 @@ -72,12 +82,12 @@
    1.25  ')"
    1.26  		suf="png"; [ "$1" ] && suf="pnm"
    1.27  		cat <<EOT
    1.28 -if convert -crop $c $mode $f /tmp/sane$$.$suf 2> /dev/null ; then
    1.29 +if convert -crop $c $mode $f /tmp/sane$$.$suf ; then
    1.30  	cat /tmp/sane$$.$suf
    1.31  	rm -f /tmp/sane$$.$suf
    1.32  else
    1.33  	cat $f
    1.34 -fi
    1.35 +fi 2> /dev/null
    1.36  EOT
    1.37  		;;
    1.38  	*)	echo -n "scanimage -d '$(echo $device | sed 's/,.*//')' --resolution '$(inrange $resolution $(xPOST res_min) $(xPOST res_max))dpi'$CMD"
    1.39 @@ -165,6 +175,7 @@
    1.40  	eval "$(getgeometry)" > $tmp.pnm 2> $tmp.err
    1.41  	if [ -s "$tmp.pnm" ]; then
    1.42  		convert $tmp.pnm $tmpreview > /dev/null 2>&1 ||
    1.43 +		pnm2png < $tmp.pnm > $tmpreview ||
    1.44  		cp $tmp.pnm $tmpreview
    1.45  	else
    1.46  		error="$(sed 's|$|<br />|' $tmp.err)"
    1.47 @@ -180,6 +191,18 @@
    1.48  [ -n "$error" ] && msg warn "$error"
    1.49  [ -n "$info" ] && msg tip "$info"
    1.50  if [ -z "$device" ]; then
    1.51 +	suggested=""
    1.52 +	while read exe pkg msg; do
    1.53 +		[ "$(which $exe 2> /dev/null)" ] && continue
    1.54 +		suggested="$suggested
    1.55 +<li><a href=\"/user/pkgs.cgi?info=$pkg\">$pkg</a>&nbsp;$msg</li>"
    1.56 +	done <<EOT
    1.57 +convert		imagemagick	$(_ "to preview images and support more image formats (recommended)")
    1.58 +gocr		gocr		$(_ "a basic optical character recognition")
    1.59 +tesseract	tesseract-ocr	$(_ "a better optical character recognition")
    1.60 +EOT
    1.61 +	[ "$suggested" ] &&
    1.62 +	msg tip "$(_ "You may need to install:") <ol>$suggested</ol>"
    1.63  	all="$(scanimage -f '%d,%v %m|'|\
    1.64  		cat - sane-fake.log fake-sane/sane-fake.log |sed 's/|/\n/g')"
    1.65  	case "$(echo "$all" | wc -l)" in
    1.66 @@ -190,20 +213,23 @@
    1.67  			xhtml_footer
    1.68  			exit 0
    1.69  		fi
    1.70 +		if [ "$suggested" ]; then
    1.71 +			cat <<EOT
    1.72 +<section>
    1.73 +	<header>
    1.74 +		<form name="scanner" method="post">
    1.75 +			<input type="hidden" name="device" value="$all">
    1.76 +			Scanner ${all#*,}
    1.77 +			<button data-icon="start">Continue</button>
    1.78 +		</form>
    1.79 +	</header>
    1.80 +</section>
    1.81 +EOT
    1.82 +			xhtml_footer
    1.83 +		exit 0
    1.84 +		fi
    1.85  		device="${all%|}" ;;
    1.86  	*)
    1.87 -		suggested=""
    1.88 -		while read exe pkg msg; do
    1.89 -			[ "$(which $exe 2> /dev/null)" ] && continue
    1.90 -			suggested="$suggested
    1.91 -<li><a href=\"/user/pkgs.cgi?info=$pkg\">$pkg</a>&nbsp;$msg</li>"
    1.92 -		done <<EOT
    1.93 -convert		imagemagick	$(_ "to preview images and support more image formats")
    1.94 -gocr		gocr		$(_ "a basic optical character recognition")
    1.95 -tesseract	tesseract-ocr	$(_ "a better optical character recognition")
    1.96 -EOT
    1.97 -		[ "$suggested" ] &&
    1.98 -		msg tip "$(_ "You may need to install:") <ol>$suggested</ol>"
    1.99  		cat <<EOT
   1.100  <section>
   1.101  	<header>
   1.102 @@ -239,7 +265,7 @@
   1.103  
   1.104  <table style="width:100%">
   1.105  <tr>
   1.106 -<td>
   1.107 +<td title="Sets the file format for the scanned image">
   1.108  <fieldset><legend>$(_ 'Format')</legend>
   1.109  <select name="format" size=1>
   1.110  $(imgformat list)
   1.111 @@ -254,48 +280,63 @@
   1.112  	params="$({
   1.113  cat "$(echo $device | sed 's/,.*//').log" 2> /dev/null ||
   1.114  scanimage --help -d "$(echo $device | sed 's/,.*//')"
   1.115 -} | awk '
   1.116 +} | dos2unix | sed 's|\[=| [|;s/||/|/g' | awk '
   1.117  function minmax()
   1.118  {
   1.119 +	inactive=1
   1.120  	if (match($2,"[0-9]")) {
   1.121  		i=$2; sub(/\.\..*/,"",i)
   1.122  		j=$2; sub(/.*\.\./,"",j)
   1.123  		sub(/\..*/,"",j); sub(/[dm%].*/,"",j)
   1.124  		k=$0; sub(/.* \[/,"",k); sub(/\].*/,"",k)
   1.125 -		print $1 " " int(k) " " int(i) " " int(j)
   1.126 +		printf("\n%s",$1 " " int(k) " " int(i) " " int(j))
   1.127 +		inactive=0
   1.128  	}
   1.129  }
   1.130  
   1.131  function enum()
   1.132  {
   1.133  	i=$0
   1.134 +	inactive=1
   1.135  	if (index(i,"|")) {
   1.136 -		sub(/^ *--*[a-z]* */,"",i)
   1.137 +		sub(/^ *--*[a-z-]* */,"",i)
   1.138 +		sub(/\[\(/,"",i); sub(/\)\]/,"",i)
   1.139  		sub(/dpi .*/,"",i); gsub(/ \[.*\].*/,"",i)
   1.140  		k=$0; sub(/.* \[/,"",k); sub(/\].*/,"",k)
   1.141  		gsub(/ /,"=",k)
   1.142 -		print $1 " " k " enum " i
   1.143 +		gsub(/ /,"=",i)
   1.144 +		printf("\n%s",$1 " " k " enum " i)
   1.145 +		inactive=0
   1.146  	}
   1.147  	else minmax()
   1.148  }
   1.149  
   1.150 -/Options specific to device/ { parse=1 }
   1.151  {
   1.152 +	if (/scanimage --help/) end=1
   1.153 +	if (end != 0) next
   1.154 +	if (/:$/) parse=0
   1.155 +	if (/Scan mode/ || /Mode/ || /Advanced/ || /Geometry/) parse=1
   1.156  	if (parse != 1) next
   1.157 -	if (/\[inactive\]/) next
   1.158 +	if (/\[inactive\]/) { inactive=1; next }
   1.159  	if (match("-l-t-x-y", $1)) minmax()
   1.160 -	if (match("--resolution--brightness--contrast--source--mode", $1)) enum()
   1.161 -}
   1.162 -' | sed 's/||/|/g')"
   1.163 +	else if (/^    --/) enum()
   1.164 +	else if (!/:$/ && inactive == 0) printf(" %s",$0)
   1.165 +} END { print "" }
   1.166 +' | sed 1d)"
   1.167  fi
   1.168 +echo "<!-- $params -->"
   1.169  output="$(n=$(echo "$params" | wc -l); echo "$params" | \
   1.170 -while read name def min max ; do
   1.171 -	name="${name##*-}"
   1.172 +while read name def min max help; do
   1.173 +	name="${name#-}"
   1.174 +	name="${name#-}"
   1.175 +	name="${name//-/_}"
   1.176 +	help="$(echo $help | sed 's|  | |g;s|"|\&#34|g')"
   1.177  	def="${def//=/ }"
   1.178 +	max="${max//=/ }"
   1.179  	if [ "$min" == "enum" ]; then
   1.180  		res_min=1000000
   1.181  		res_max=0
   1.182 -		echo "<td><fieldset><legend>$name</legend>"
   1.183 +		echo "<td title=\"$help\"><fieldset><legend>$name</legend>"
   1.184  		echo -n "<select name=\"$name\" size=1"
   1.185  		[ "$name" == "resolution" ] && echo -n " onchange=showGeometry()"
   1.186  		echo ">"
   1.187 @@ -339,7 +380,7 @@
   1.188  EOT
   1.189  		esac
   1.190  		[ "$name" == "resolution" ] && f="$f onchange=showGeometry()"
   1.191 -		echo "<td>$f type=\"text\" title=\"$min .. $max\" size=4 maxlength=4>$u"
   1.192 +		echo "<td>$f type=\"text\" title=\"$min .. $max. $help\" size=4 maxlength=4>$u"
   1.193  		res_min=$min
   1.194  		res_max=$max
   1.195  	fi