From 4cf5e5450db6b8c7b7971574d5c2578f78ed2640 Mon Sep 17 00:00:00 2001
From: Mooffie <mooffie@gmail.com>
Date: Tue, 27 Dec 2016 13:40:24 +0200
Subject: [PATCH 1/2] Ticket #3747: extfs: hp48: fix float truncation.
Some printf implementations can't process with %d anything other than integers.
We solve this by re-using the awk snippet for this purpose. This makes
hp48_retsize() unecessary. And hp48_retdir() too.
(The "case" statement was left unindented to, hopefully, not affect diff's
output much. This aesthetic issue will be fixed in a following patch.)
---
src/vfs/extfs/helpers/hp48+.in | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/src/vfs/extfs/helpers/hp48+.in b/src/vfs/extfs/helpers/hp48+.in
index 25da24a..838f565 100644
a
|
b
|
done |
40 | 40 | echo QUIT)| $KERMIT -B >/dev/null |
41 | 41 | } |
42 | 42 | |
43 | | hp48_retdir() |
44 | | { |
45 | | echo "$1" |
46 | | } |
47 | | |
48 | | hp48_retsize() |
49 | | { |
50 | | printf "%d" "$2" 2>/dev/null |
51 | | } |
52 | | |
53 | 43 | # |
54 | 44 | # Parses the reply to the DIRECTORY command. |
55 | 45 | # |
… |
… |
HP48_DIRS= |
78 | 68 | read -r INPUT |
79 | 69 | while [ "x$INPUT" != "xEOF" ] |
80 | 70 | do |
81 | | case `echo "$INPUT" | $AWK '{if (int($2)) if ($3 == "Directory") print "dir";else print "file"}'` in |
82 | | dir) HP48_DIRS="$HP48_DIRS `hp48_retdir $INPUT`" |
83 | | printf "drwxr-xr-x 1 %-8d %-8d %8d %s %s\n" 0 0 `hp48_retsize $INPUT` "$NOW" "$HP48_CDIR/`hp48_retdir $INPUT`";; |
84 | | file) printf "%crw-r--r-- 1 %-8d %-8d %8d %s %s\n" '-' 0 0 `hp48_retsize $INPUT` "$NOW" "$HP48_CDIR/`hp48_retdir $INPUT`";; |
| 71 | set -- $INPUT |
| 72 | |
| 73 | obj_name=$1 |
| 74 | obj_size=$2 |
| 75 | obj_type=$3 |
| 76 | |
| 77 | obj_size=`echo $obj_size | $AWK '{ print int($0) }'` # Truncates floats to ints; anything else to "0". |
| 78 | |
| 79 | if [ "$obj_size" != "0" ]; then # Skips the 1st reply line (purportedly there aren't zero-size files b/c, according to resource [4], the size is "including name"). |
| 80 | case "$obj_type" in |
| 81 | Directory) HP48_DIRS="$HP48_DIRS $obj_name" |
| 82 | printf "drwxr-xr-x 1 %-8d %-8d %8d %s %s\n" 0 0 $obj_size "$NOW" "$HP48_CDIR/$obj_name";; |
| 83 | *) printf "%crw-r--r-- 1 %-8d %-8d %8d %s %s\n" '-' 0 0 $obj_size "$NOW" "$HP48_CDIR/$obj_name";; |
85 | 84 | esac |
| 85 | fi |
| 86 | |
86 | 87 | read -r INPUT |
87 | 88 | done |
88 | 89 | for HP48_DIR in $HP48_DIRS; |
… |
… |
done |
96 | 97 | |
97 | 98 | hp48_list() |
98 | 99 | { |
| 100 | # It's hard to see why this "EOF" thing is needed. The loop above can be changed to "while read -r obj_name ...". @TODO. |
99 | 101 | { hp48_cmd "DIRECTORY"; echo; echo EOF; } | hp48_parser |
100 | 102 | } |
101 | 103 | |