]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
braille: Fix handling non-printable characters 5/head
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Tue, 14 Nov 2017 01:01:57 +0000 (02:01 +0100)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Tue, 14 Nov 2017 01:01:57 +0000 (02:01 +0100)
BRF files may contain SUBs for EOF, which we should just ignore, or FFs,
which we should just print.  Other non-printable characters are not supposed
to appear.

filter/braille/drivers/index/textbrftoindexv3.in

index af46c8ab3672029b8cf3cb21d1d57e5fa68960d5..8ec0a1fb700f3febd617f35bb105dd7b7a375e31 100755 (executable)
@@ -61,6 +61,31 @@ then
     do
       # Strip CRs
       LINE=${LINE//$'\015'}
+      # Ignore SUBs
+      LINE=${LINE//$'\032'}
+
+      # Interpret FFs
+      while [ -n "$LINE" -a -z "${LINE/#$'\014'*}" ]
+      do
+        printf "\\f"
+       LINE=${LINE#$'\014'}
+      done
+
+      # Make sure there is nothing else we don't process
+      if [ -n "$LINE" ]
+      then
+       if [ -z "${LINE/*[$'\001'-$'\037'$'\177']*}" ]
+       then
+         echo "ERROR: unsupported control character in BRF file" >&2
+         exit 1
+       fi
+       if [ -z "${LINE/*[$'\200'-$'\377']*}" ]
+       then
+         echo "ERROR: unsupported non-ASCII character in BRF file" >&2
+         exit 1
+       fi
+      fi
+
       CHARS=$(printf %s "$LINE" | wc -c)
       if [ "$CHARS" -gt 127 ]
       then