lslR.in 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #! /bin/sh
  2. # Based on previous version of lslR
  3. # Modified by Tomas Novak <tnovak@ipex.cz> April 2000
  4. # (to allow spaces in filenames)
  5. #
  6. # It's assumed that lslR was generated in C locale.
  7. LC_ALL=C
  8. export LC_ALL=C
  9. AWK=@AWK@
  10. mclslRfs_list () {
  11. case "$1" in
  12. *.lzma) MYCAT="lzma -dc";;
  13. *.xz) MYCAT="xz -dc";;
  14. *.bz2) MYCAT="bzip2 -dc";;
  15. *.gz) MYCAT="gzip -dc";;
  16. *.z) MYCAT="gzip -dc";;
  17. *.Z) MYCAT="gzip -dc";;
  18. *) MYCAT="cat";;
  19. esac
  20. $MYCAT "$1" | $AWK '
  21. BEGIN {
  22. dir="";
  23. empty=1;
  24. rx = "[^ ]+[ ]+";
  25. # Pattern to match 7 first fields.
  26. rx7 = "^" rx rx rx rx rx rx "[^ ]+[ ]";
  27. # Pattern to match 8 first fields.
  28. rx8 = "^" rx rx rx rx rx rx rx "[^ ]+[ ]";
  29. }
  30. /^total\ [0-9]*$/ { next }
  31. /^$/ { empty=1; next }
  32. empty==1 && /:$/ {
  33. empty=0
  34. if ($0 ~ /^\//) dir=substr($0, 2);
  35. else dir=$0;
  36. if (dir ~ /\/:$/) sub(/:$/, "", dir);
  37. else sub(/:$/, "/", dir);
  38. if (dir ~ /^[ ]/) dir="./"dir;
  39. next;
  40. }
  41. ( NF > 7 ) {
  42. empty=0
  43. # gensub() is not portable.
  44. name=$0
  45. i=index($6, "-")
  46. if (i) {
  47. sub(rx7, "", name)
  48. NF = 7
  49. $6=substr($6,i+1)"-"substr($6,1,i-1)
  50. }
  51. else {
  52. sub(rx8, "", name)
  53. NF = 8
  54. }
  55. printf "%s %s%s\n", $0, dir, name
  56. }
  57. {
  58. empty=0
  59. }'
  60. }
  61. case "$1" in
  62. list) mclslRfs_list "$2"; exit 0;;
  63. esac
  64. exit 1