Franco Masotti 4 years ago
parent
commit
5bfbaf82aa
  1. 4
      fbopt
  2. 46
      spectrscan

4
fbopt

@ -90,7 +90,7 @@ main()
# See some comments below.
declare -a argc=("${!1}")
local getopt_short_options='hi:mrstu::'
local getopt_short_options='hi:m:r:s:tu::'
local getopt_long_options='help,imagemagick:,list-modes,list-resolutions,list-sources,mode:,print-flags,resolution:,source:,two-sided,two-sided-reverse,unpaper::'
# Set the default values for the flags.
@ -178,7 +178,7 @@ main()
&& return 0
[ "${help}" = 'true' ] && show_help && return 0
# Override values of optional parameters.
[ -z "${flag_f}" ] && flag_f='true'
[ -z "${unpaper}" ] && unpaper='true'
# From now on you should call a function or an external program
# using the values of the flag variables.

46
spectrscan

@ -23,7 +23,7 @@
#
set -x
#set -e
TMP_DIR="$(pwd)/.spectrscan-$RANDOM"
SRC_DIR="$(pwd)"
@ -31,14 +31,13 @@ check_software()
{
which \
scanimage \
unapaper \
unpaper \
awk \
convert \
pdftk \
parallel \
file \
pamfix \
netpbm
pamfix
} 1>/dev/null 2>/dev/null
scan()
@ -79,13 +78,13 @@ exists_output_file()
if [ -f "$SRC_DIR"/"$output_file" ]; then
if [ "$(file --mime-type "$SRC_DIR"/"$output_file" \
| awk '{ print $2 }')" = "application/pdf" ]; then
printf "true"
printf 'true'
else
# Not a pdf file.
printf "error"
fi
else
printf "false"
printf 'false'
fi
}
@ -98,22 +97,23 @@ convert_single()
pamfix -truncate "$filE" > "$filE".tmp.pnm.bis
if [ "$imagemagick_options" != "true" ] \
&& [ "$imagemagick_options" != "false" ]; then
convert $imagemagick_options "$filE".tmp.pnm.bis "$filE".tmp.pnm
if [ "${imagemagick_options}" != 'false' ]; then
convert ${imagemagick_options} "$filE".tmp.pnm.bis "$filE".tmp.pnm
else
mv "$filE".tmp.pnm.bis "$filE".tmp.pnm
fi
if [ "$unpaper_options" = "true" ]; then
if [ "${unpaper_options}" = 'true' ]; then
unpaper --overwrite -q "$filE".tmp.pnm "$filE".pnm
elif [ "$unpaper_options" = "false" ]; then
elif [ "${unpaper_options}" = 'false' ]; then
mv "$filE".tmp.pnm "$filE".pnm
else
unpaper --overwrite -q $unpaper_options "$filE".tmp.pnm "$filE".pnm
unpaper --overwrite -q ${unpaper_options} "$filE".tmp.pnm "$filE".pnm
fi
#
# OCR stuff goes here.
#
convert -compress lzw "$filE".pnm "$filE".pdf
@ -142,7 +142,7 @@ pdf_cat()
pdftk *.pdf cat output "$output_file".tmp
# O(1)
if [ "$(exists_output_file)" = "true" ]; then
if [ "$(exists_output_file)" = 'true' ]; then
cp "$SRC_DIR"/"$output_file" "$SRC_DIR"/."$output_file"
@ -151,7 +151,7 @@ pdf_cat()
rm "$SRC_DIR"/."$output_file"
elif [ "$(exists_output_file)" = "false" ]; then
elif [ "$(exists_output_file)" = 'false' ]; then
mv "$output_file".tmp "$SRC_DIR"/"$output_file"
else
printf "[ERROR]\n" 1>&2-
@ -196,17 +196,22 @@ check_supported_parameters()
fi
done
if [ $counter -eq 0 ]; then
printf "ERROR: Supported $parameter: ${!parameter_full_name}\n" 1>&2-
printf "error: supported $parameter: ${!parameter_full_name}\n" 1>&2-
return 1
fi
}
cleanup()
{
rm -rf "$TMP_DIR"
}
chain()
{
mkdir "$TMP_DIR"
pushd "$TMP_DIR"
if [ "$odd_even" = "true" ]; then
if [ "$odd_even" = 'true' ]; then
scan "odd" \
&& printf "%s\n" 'turn the paper(s) and hit return when ready' \
&& read \
@ -216,8 +221,8 @@ chain()
fi
# Feeder out of documents.
if [ $? -eq 7 ]; then
printf "No paper inserted\n" 1>&2
if [ ${?} -eq 7 ]; then
cleanup
return 1
fi
@ -226,17 +231,16 @@ chain()
cleanup
popd
rm -rf "$TMP_DIR"
}
preliminary_checks()
{
# Leak all variables to avoid passing them every time.
imagemagick="${1}"
imagemagick_options="${1}"
mode="${2}"
resolution="${3}"
source="${4}"
unpaper="${5}"
unpaper_options="${5}"
output_file="${6}"
# Get the parameters and check that the scanner is connected.
supported_params="$(get_supported_parameters)"