1#!/bin/bash 2 3# 4# Copyright (c) 2015-2018 Samuel Thibault <samuel.thibault@ens-lyon.org> 5# 6# Permission is hereby granted, free of charge, to any person obtaining a copy 7# of this software and associated documentation files (the "Software"), to deal 8# in the Software without restriction, including without limitation the rights 9# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10# copies of the Software, and to permit persons to whom the Software is 11# furnished to do so, subject to the following conditions: 12# 13# 14# The above copyright notice and this permission notice shall be included in 15# all copies or substantial portions of the Software. 16# 17# 18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24# THE SOFTWARE. 25# 26 27# Make sure we have enough options 28if [ $# != 5 -a $# != 6 ]; then 29 echo "ERROR: $0 jobid user name nb options [filename]" >&2 30 exit 1 31fi 32 33NB=$4 34OPTIONS=$5 35FILE=$6 36 37case $0 in 38 *indexv3*) . @CUPS_DATADIR@/braille/indexv3.sh ;; 39 *indexv4*) . @CUPS_DATADIR@/braille/indexv4.sh ;; 40 *) echo "ERROR: $0 must be called as somethingindexv3 or somethingindexv4" >&2 41 exit 1 42 ;; 43esac 44 45printf "$INIT" 46 47if [ $LIBLOUIS1 != None -o \ 48 $LIBLOUIS2 != None -o \ 49 $LIBLOUIS3 != None -o \ 50 $LIBLOUIS4 != None ] 51then 52 # software-translated, send to printer in transparent mode 53 echo "INFO: Writing text to Index embosser in transparent mode" >&2 54 if [ -z "$FILE" ] 55 then 56 cat 57 else 58 cat "$FILE" 59 fi | ( 60 IFS=$'\n' read -r LINE 61 EOF=$? 62 while [ "$EOF" = 0 -o -n "$LINE" ] 63 do 64 # Strip CRs 65 LINE=${LINE//$'\015'} 66 # Ignore SUBs 67 LINE=${LINE//$'\032'} 68 # Turn non-breakable spaces into spaces 69 LINE=${LINE//$'\302'$'\240'/ } 70 LINE=${LINE//$'\240'/ } 71 72 # Interpret FFs 73 while [ -n "$LINE" -a -z "${LINE/#$'\014'*}" ] 74 do 75 printf "\\f" 76 LINE=${LINE#$'\014'} 77 done 78 79 # Make sure there is nothing else we don't process 80 if [ -n "$LINE" ] 81 then 82 if [ -z "${LINE/*[$'\000'-$'\037'$'\177']*}" ] 83 then 84 echo "ERROR: unsupported control character in BRF file" >&2 85 fi 86 if [ -z "${LINE/*[$'\200'-$'\377']*}" ] 87 then 88 echo "ERROR: unsupported non-ASCII character in BRF file" >&2 89 fi 90 fi 91 92 CHARS=$(printf %s "$LINE" | wc -c) 93 if [ "$CHARS" -gt 127 ] 94 then 95 # Index printers have a bug with numbers between 128 and 255 in 96 # transparent mode escape sequence. This is normally not a problem since 97 # 128 chars is more than a line worth of text 98 echo "ERROR: Line too long ($CHARS)" >&2 99 exit 1 100 fi 101 if [ "$CHARS" -gt 0 ] 102 then 103 # Enter transparent mode for $CHARS characters 104 printf "\\033\\\\\\x$(printf %02x $CHARS)\\x00" 105 # Echo those $CHARS characters. 106 # First normalize BRF characters (`a-z{|}~ are non-standard). 107 # Drop unicode patterns with dots 7 or 8 in case the liblouis table happened to erroneously emit one 108 # Drop remaining erroneous multibyte characters 109 # Drop remaining erroneous 1-byte characters 110 # Then turn it into Index 6dots sequences. 111 printf %s "$LINE" | \ 112 tr "\`a-z{|}~" "@A-Z\\[\\\\]_" | \ 113 sed -e 's/[⡀⡁⡂⡃⡄⡅⡆⡇⡈⡉⡊⡋⡌⡍⡎⡏⡐⡑⡒⡓⡔⡕⡖⡗⡘⡙⡚⡛⡜⡝⡞⡟⡠⡡⡢⡣⡤⡥⡦⡧⡨⡩⡪⡫⡬⡭⡮⡯⡰⡱⡲⡳⡴⡵⡶⡷⡸⡹⡺⡻⡼⡽⡾⡿⢀⢁⢂⢃⢄⢅⢆⢇⢈⢉⢊⢋⢌⢍⢎⢏⢐⢑⢒⢓⢔⢕⢖⢗⢘⢙⢚⢛⢜⢝⢞⢟⢠⢡⢢⢣⢤⢥⢦⢧⢨⢩⢪⢫⢬⢭⢮⢯⢰⢱⢲⢳⢴⢵⢶⢷⢸⢹⢺⢻⢼⢽⢾⢿⣀⣁⣂⣃⣄⣅⣆⣇⣈⣉⣊⣋⣌⣍⣎⣏⣐⣑⣒⣓⣔⣕⣖⣗⣘⣙⣚⣛⣜⣝⣞⣟⣠⣡⣢⣣⣤⣥⣦⣧⣨⣩⣪⣫⣬⣭⣮⣯⣰⣱⣲⣳⣴⣵⣶⣷⣸⣹⣺⣻⣼⣽⣾⣿]/ /g' | \ 114 sed -e "s/[^] \!\"#$%&'()*+,.\\/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\\\^_[-]/ /g" | \ 115 tr "\000-\037\177\200-\377" " " | \ 116 tr " \!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\[\\\\\\]^_" "\\0V tSQW"$'\004'"gvAT@DP"$'\024'"d"$'\002\006'"\"bB&fF\$a\`Cw4q"$'\020\001\003\021'"1!"$'\023'"3#"$'\022'"2"$'\005\007\025'"5%"$'\027'"7'"$'\026'"6EGrUueRcs0p" 117 fi 118 if [ "$EOF" = 0 ] 119 then 120 printf "\\r\\n" 121 fi 122 IFS=$'\n' read -r LINE 123 EOF=$? 124 done 125 ) 126 if [ $? != 0 ] 127 then 128 printf '\032' 129 exit 1 130 fi 131else 132 # not software-translated, send to printer as such 133 echo "INFO: Writing text to Index embosser" >&2 134 if [ -z "$FILE" ] 135 then 136 cat 137 else 138 cat "$FILE" 139 fi 140fi 141 142printf '\032' 143 144echo "INFO: Ready" >&2 145