]> gitweb.hhaalo.de Git - scantopdf.git/commitdiff
change add ocr extra file
authorBastian Dehn <hhaalo@arcor.de>
Fri, 3 Apr 2026 12:26:56 +0000 (14:26 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 3 Apr 2026 12:26:56 +0000 (14:26 +0200)
Makefile
src/addocr.sh [new file with mode: 0644]
src/scanbasic.sh

index 876564179c0c70ae627c56d4d2359fd71c7aae5a..36a30c4d148fd7d9b9ce3c2ca997d3b0b165bd54 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,7 @@ SHAREDIR = usr/local/share
 
 all: test package
 
-test:
+test: $(BUILDDIR)/parts/scanbasic.sh
        ./tests/scanbasic.bats
 
 build: $(PACKAGEDIR)/$(BINDIR)/scantopdf \
@@ -31,6 +31,7 @@ clean:
 ################################################################################
 
 $(BUILDDIR)/parts/scanbasic.sh: \
+       $(SRCDIR)/addocr.sh \
        $(SRCDIR)/scanbasic.sh
 
        mkdir -p $(@D)
diff --git a/src/addocr.sh b/src/addocr.sh
new file mode 100644 (file)
index 0000000..8997962
--- /dev/null
@@ -0,0 +1,41 @@
+optimize()
+{
+       local input="$1"
+       local output="$input-out"
+
+       [ -n "$input" ] \
+               || errlog "missing input" \
+               || return $?
+
+       qpdf --linearize $input $output \
+               || errlog "could not linearize $input" \
+               || return $?
+       mv $output $input \
+               || errlog "could not rename $output to $input" \
+               || return $?
+}
+
+addocr()
+{
+       local input="$1"
+       local jobs="$2"
+       local output="$input-out"
+       jobs=${jobs:=1}
+
+       [ -n "$input" ] \
+               || errlog "missing input" \
+               || return $?
+
+       echo "ℹ️  INFO: adding ocr on file $input"
+       ocrmypdf --quiet --jobs $(nproc) --language deu $input $output \
+               || errlog "could not add ocr on $input" \
+                       || return $?
+
+       [ ! -f $output ] && return 0
+
+       mv $output $input \
+               || errlog "could not rename $output to $input" \
+               || return $?
+       optimize $input \
+               || return $?
+}
index 7eeb2a33e4613ba4f242e9dde1c61857deea9d51..db199acbd7fed3970633e1ab7e8d4ed51dbb5044 100644 (file)
@@ -1,3 +1,4 @@
+#include "addocr.sh"
 errlog()
 {
        local lastexit=$?
@@ -48,48 +49,6 @@ convert_tiff_to_pdf()
        rm $tiff
 }
 
-optimize()
-{
-       local input="$1"
-       local output="$input-out"
-
-       [ -n "$input" ] \
-               || errlog "missing input" \
-               || return $?
-
-       qpdf --linearize $input $output \
-               || errlog "could not linearize $input" \
-               || return $?
-       mv $output $input \
-               || errlog "could not rename $output to $input" \
-               || return $?
-}
-
-addocr()
-{
-       local input="$1"
-       local jobs="$2"
-       local output="$input-out"
-       jobs=${jobs:=1}
-
-       [ -n "$input" ] \
-               || errlog "missing input" \
-               || return $?
-
-       echo "ℹ️  INFO: adding ocr on file $input"
-       ocrmypdf --quiet --jobs $(nproc) --language deu $input $output \
-               || errlog "could not add ocr on $input" \
-                       || return $?
-
-       [ ! -f $output ] && return 0
-
-       mv $output $input \
-               || errlog "could not rename $output to $input" \
-               || return $?
-       optimize $input \
-               || return $?
-}
-
 createonepdf()
 {
        local output=$1