~luxferre/Bopher-NG

7bd6a03e91291b0437b9e4dd5549ad1f977dcc1b — Luxferre 1 year, 6 months ago 8060459
improved list2map.sh a bit
1 files changed, 5 insertions(+), 1 deletions(-)

M tools/list2map.sh
M tools/list2map.sh => tools/list2map.sh +5 -1
@@ 21,6 21,7 @@ typequery() { # external command wrapper to fetch the file's MIME type
while read -rs fpath; do # fully line-based operation
  ftype="$(typequery "$fpath")" # MIME type here
  bname="${fpath##*/}" # basename here
  desc="$bname" # default to the basename
  [[ "$bname" == "$INDEXFILE" ]] && continue # skip index map
  etype=9 # default map entry type is binary until proven otherwise
  esel="${fpath##$RDIR}" # if RDIR is empty, they are the same


@@ 29,7 30,10 @@ while read -rs fpath; do # fully line-based operation
    esel="${esel}/${INDEXFILE}" # update the selector
  elif [[ "${ftype%%/*}" == 'text' ]]; then # update etype for text files
    etype=0
    read -rsd$'\r' desc < "$fpath" # read the first file line as the description/title
    desc="${desc##*([[:blank:]])}" # remove leading whitespace
    desc="${desc%%*([[:blank:]])}" # remove trailing whitespace
  fi
  # output the RFC-compliant Gophermap line
  printf '%s%s\t%s\t%s\t%s\r\n' "$etype" "$bname" "$esel" "$THOST" "$TPORT" 
  printf '%s%s\t%s\t%s\t%s\r\n' "$etype" "$desc" "$esel" "$THOST" "$TPORT" 
done