Optimization: get rid of triple run of isoinfo -d.
[midnight-commander.git] / lib / vfs / mc-vfs / extfs / iso9660.in
blobc78c829a1a06b5f80f6af3e9561731b63b758234
1 #! /bin/sh
3 # ISO9660 VFS for MC by Michael Shigorin <mike@altlinux.org>,
4 # modifications by Grigory Milev <week@altlinux.org>
5 # and Kachalov Anton <mouse@linux.ru.net> April 2003
6 # based on lslR by Tomas Novak <tnovak@ipex.cz> April 2000
7 # -- look there for additional parsing comments if needed
9 # tested to comply with isoinfo 2.0's output
11 test_iso () {
12 CHARSET=`locale charmap 2>/dev/null`
13 if test -z "$CHARSET"; then
14 CHARSET=`locale 2>/dev/null | @GREP@ LC_CTYPE | sed -n -e 's/.*\.\(.*\)"$/\1/p'`
16 if test -n "$CHARSET"; then
17 CHARSET=`echo "$CHARSET" | tr '[A-Z]' '[a-z]' | sed -e 's/^iso-/iso/'`
18 isoinfo -j $CHARSET -i /dev/null 2>&1 | @GREP@ "Iconv not yet supported\|Unknown charset" >/dev/null && CHARSET=
20 if test -n "$CHARSET"; then
21 JOLIET_OPT="-j $CHARSET -J"
22 else
23 JOLIET_OPT="-J"
25 ISOINFO="isoinfo -R"
27 ISOINFO_D_I="`isoinfo -d -i "$1" 2>/dev/null`"
29 echo "$ISOINFO_D_I" | @GREP@ "UCS level 1\|NO Joliet" > /dev/null || ISOINFO="$ISOINFO $JOLIET_OPT"
31 if [ `echo "$ISOINFO_D_I" | @GREP@ "Joliet with UCS level 3 found" | wc -l` = 1 \
32 -a `echo "$ISOINFO_D_I" | @GREP@ "NO Rock Ridge" | wc -l` = 1 ] ; then
33 SEMICOLON="YES"
37 mcisofs_list () {
38 # left as a reminder to implement compressed image support =)
39 case "$1" in
40 *.lzma) MYCAT="lzma -dc";;
41 *.xz) MYCAT="xz -dc";;
42 *.bz2) MYCAT="bzip2 -dc";;
43 *.gz) MYCAT="gzip -dc";;
44 *.z) MYCAT="gzip -dc";;
45 *.Z) MYCAT="gzip -dc";;
46 *) MYCAT="cat";;
47 esac
49 $ISOINFO -l -i "$1" 2>/dev/null | @AWK@ -v SEMICOLON=$SEMICOLON '
50 BEGIN {
51 dir="";
52 # Pattern to match 8 first fields.
53 rx = "[^ ]+[ ]+";
54 rx = "^" rx rx rx rx rx rx rx rx;
55 irx = "^\\[ *-?[0-9]* *[0-9]+\\] +";
57 /^$/ { next }
58 /^d---------/ { next }
59 /^Directory listing of [^ ].*$/ {
60 dir=substr($0, 23);
61 next;
63 { $11 != "" } {
64 name=$0
65 sub(rx, "", name)
66 attr=substr($0, 1, length($0)-length(name))
67 # strip inodes and extra dir entries; fix perms
68 sub(irx, "", name)
69 sub("^---------- 0 0 0", "-r--r--r-- 1 root root", attr)
70 sub(" $", "", name)
71 # for Joliet UCS level 3
72 if (SEMICOLON = "YES") sub(";1$", "", name);
73 ## sub(";[0-9]+$", "", name) ## would break copyout
74 # skip . and ..
75 if (name ~ /^\.\.?/) next;
76 printf "%s%s%s\n", attr, dir, name
77 }'
80 mcisofs_copyout () {
81 if [ "x$SEMICOLON" == "xYES" ]; then
82 $ISOINFO -i "$1" -x "/$2;1" 2>/dev/null > "$3"
83 else
84 $ISOINFO -i "$1" -x "/$2" 2>/dev/null > "$3"
88 LC_ALL=C
90 cmd="$1"
91 shift
93 case "$cmd" in
94 list)
95 test_iso "$@";
96 mcisofs_list "$@";
97 exit 0;;
98 copyout)
99 test_iso "$@";
100 mcisofs_copyout "$@";
101 exit 0;;
102 esac
103 exit 1