Merge branch '33-multi-output-loop-fix' into master

This commit is contained in:
Raman Gupta 2021-08-06 17:48:02 -04:00
commit 2cfa7f6899

33
scan
View File

@ -271,23 +271,34 @@ else
MODE="--mode '$MODE'" MODE="--mode '$MODE'"
fi fi
eval scanadf -d \'"$DEVICE"\' $MAXPAGE $PGHEIGHT $PGWIDTH -S $SCRIPT --script-wait --resolution $RESOLUTION $MODE $DESKEW $CROP $DRIVER_OPTION $SOURCE -o $TMP_DIR/scan-%04d eval scanadf -d \'"$DEVICE"\' $MAXPAGE $PGHEIGHT $PGWIDTH -S $SCRIPT --script-wait --resolution $RESOLUTION $MODE $DESKEW $CROP $DRIVER_OPTION $SOURCE -o $TMP_DIR/scan-%04d
# Simulate empty page scanner outputs for debugging
#convert xc:none -page Letter $TMP_DIR/scan-0001.pdf
shopt -s extglob nullglob shopt -s extglob nullglob
pdffiles=($TMP_DIR/scan-[0-9]*.pdf) pdffiles=($TMP_DIR/scan-[0-9]*.pdf)
numscans=${#pdffiles[@]} numscans=${#pdffiles[@]}
if [[ $numscans > 0 ]]; then if (( numscans > 0 )); then
echo "Processing $numscans pages" echo "Processing $numscans pages"
if [[ $numscans > $TRUNCPAGE && $TRUNCPAGE > 0 ]]; then if (( TRUNCPAGE > 0 )); then
for x in ${pdffiles[@]:$numscans-$TRUNCPAGE:$TRUNCPAGE}; do rm "$x"; done; truncpage=$TRUNCPAGE
pdffiles=(${pdffiles[@]:0:$numscans-$TRUNCPAGE}) if (( numscans < TRUNCPAGE )); then
echo "Truncated $TRUNCPAGE pages" truncpage=$numscans
fi fi
if [[ $numscans > 1 && $USEARRAY == 1 ]]; then for x in ${pdffiles[@]:$numscans-$truncpage:$truncpage}; do rm "$x"; done;
echo "Naming pdfs based on output list..." pdffiles=(${pdffiles[@]:0:$numscans-$truncpage})
echo "Truncated $truncpage pages"
let "numscans = numscans - truncpage"
fi
if (( numscans <= 0 )); then
echo "Found no scans."
exit 0
fi
if (( numscans > 1 && USEARRAY == 1 )); then
output_count=${#OUTPUT[@]} output_count=${#OUTPUT[@]}
echo "Naming $numscans pdfs based on output list of $output_count names..."
index=0 index=0
while [[ "$index" < "$output_count" ]]; do while (( index < output_count && numscans > index )); do
let "scanno = $index + 1" let "scanno = index + 1"
if [[ -f "${OUTPUT[$index]}" ]]; then if [[ -f "${OUTPUT[$index]}" ]]; then
mv "${OUTPUT[$index]}" "${OUTPUT[$index]}.orig" mv "${OUTPUT[$index]}" "${OUTPUT[$index]}.orig"
if [[ $APPEND == 1 ]]; then if [[ $APPEND == 1 ]]; then
@ -303,9 +314,9 @@ if [[ $numscans > 0 ]]; then
else else
mv $TMP_DIR/scan-*(0)$scanno.pdf "${OUTPUT[$index]}" mv $TMP_DIR/scan-*(0)$scanno.pdf "${OUTPUT[$index]}"
fi fi
let "index = $index + 1" let "index = index + 1"
done done
elif [[ $numscans > 1 || $APPEND == 1 ]]; then elif (( numscans > 1 || APPEND == 1 )); then
echo "Concatenating pdfs..." echo "Concatenating pdfs..."
if [[ -f "$OUTPUT" ]]; then if [[ -f "$OUTPUT" ]]; then
mv "$OUTPUT" "${OUTPUT}.orig" mv "$OUTPUT" "${OUTPUT}.orig"