Ticket #1921: lslR.in

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