Ticket #3747: 3747-0001-extfs-hp48-fix-float-truncation--ALTERNATIVE.patch

File 3747-0001-extfs-hp48-fix-float-truncation--ALTERNATIVE.patch, 2.4 KB (added by mooffie, 8 years ago)
  • src/vfs/extfs/helpers/hp48+.in

    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 
    4040echo QUIT)| $KERMIT -B >/dev/null 
    4141} 
    4242 
    43 hp48_retdir() 
    44 { 
    45 echo "$1" 
    46 } 
    47  
    48 hp48_retsize() 
    49 { 
    50 printf "%d" "$2" 2>/dev/null 
    51 } 
    52  
    5343# 
    5444# Parses the reply to the DIRECTORY command. 
    5545# 
    HP48_DIRS= 
    7868read -r INPUT 
    7969while [ "x$INPUT" != "xEOF" ] 
    8070do 
    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";; 
    8584    esac 
     85    fi 
     86 
    8687    read -r INPUT 
    8788done 
    8889for HP48_DIR in $HP48_DIRS; 
    done 
    9697 
    9798hp48_list() 
    9899{ 
     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. 
    99101{ hp48_cmd "DIRECTORY"; echo; echo EOF; } | hp48_parser 
    100102} 
    101103