File: multiple-64

package info (click to toggle)
printer-driver-indexbraille 1.2.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 168 kB
  • sloc: ansic: 90; makefile: 64; sh: 62
file content (81 lines) | stat: -rw-r--r-- 2,794 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
commit 87d7e6a14d6ccef9c24dc8d30cfa1da4d1847af2
Author: Simon Aittamaa <simon@indexbraille.com>
Date:   Thu Oct 5 09:39:57 2017 +0200

    Fix'd multiple-of-64 workaround.
    
    This was working for the index-direct-braille filter, but broken in
    the index-braille.sh filter.

diff --git a/filter/index-braille.sh.in b/filter/index-braille.sh.in
index d3516aa..1535e8e 100644
--- a/filter/index-braille.sh.in
+++ b/filter/index-braille.sh.in
@@ -21,14 +21,13 @@ fi
 
 # Check for required utilities, otherwise disable file-length patching (since
 # if till fail).
-WC=`which wc`
-AWK=`which awk`
+STAT=`which stat`
 EXPR=`which expr`
-if test -z "${WC}" -o -z "${AWK}" -o -z "${EXPR}"
+if test -z "${STAT}" -o -z "${EXPR}"
 then
 	# Some utility is missing, inform user.
 	echo "INFO: Utilities missing, file-length patching is disabled." >> /dev/stderr
-	echo "INFO: WC='${WC}', AWK='${AWK}', EXPR='${EXPR}'." >> /dev/stderr
+	echo "INFO: STAT='${STAT}', EXPR='${EXPR}'." >> /dev/stderr
 	PATCH_FILE_LENGTH=0
 fi
 
@@ -36,11 +35,13 @@ fi
 if test $PATCH_FILE_LENGTH -ne 0
 then
 	# Patch the file lenght, if required.
-	FILE_LENGTH=`wc -c $FILENAME|awk '{print $1}'`
-	if test ! -z $FILE_LENGTH
+	FILE_LENGTH=`$STAT -c %s "${FILENAME}"`
+	if test -z $FILE_LENGTH
 	then
 		echo "INFO: Unable to read file-length, file-length patching is disabled." >> /dev/stderr
 		PATCH_FILE_LENGTH=0
+    else
+        echo "DEBUG: File-length $FILE_LENGTH" >> /dev/stderr
 	fi
 fi
 
@@ -60,7 +61,7 @@ do
 	if test $PATCH_FILE_LENGTH -ne 0
 	then
 		# We sent FILE_LENGTH + SUB-character.
-		TRANSFERED_BYTES="${TRANSFERED_BYTES} + ${FILE_LENGTH} + 1"
+        TRANSFERED_BYTES=`$EXPR $TRANSFERED_BYTES + $FILE_LENGTH + 1`
 	fi
 
 	# Decrease COPIES by one, if expr doesn't exists, we don't support
@@ -69,6 +70,8 @@ do
 	COPIES=`$EXPR $COPIES - 1`
 done
 
+echo "DEBUG: Transfer-length (unpatched): $FILE_LENGTH" >> /dev/stderr
+
 # Check the length of the transfer, if the lenght of the transfer is a
 # multiple of 64, add an extra SUB character. This is due to the kernel
 # module (at91_udc.c) uses the length of a transfer to determine if the
@@ -83,13 +86,12 @@ done
 # Patch the transfer, if enabled and required.
 if test $PATCH_FILE_LENGTH -ne 0
 then
-	TRANSFERED_BYTES=`$EXPR $TRANSFERED_BYTES`
-	TRANSFERED_BYTES_MOD64=`$EXPR $FILE_LENGTH % 64`
+	TRANSFERED_BYTES_MOD64=`$EXPR $TRANSFERED_BYTES % 64`
 	if test $TRANSFERED_BYTES_MOD64 -eq 0
 	then
 		# Extra ASCII sub to ensure that the transfer length module 64
 		# is not 0.
-		echo "INFO: Patching file to avoid transfer length modulo-64 bug (length was $FILE_LENGTH)." >> /dev/stderr
+		echo "INFO: Patching print-data to avoid transfer length modulo-64 bug (length was $TRANSFERED_BYTES)." >> /dev/stderr
 		printf "\032"
 	fi
 fi