Merge branch '1858_segfault_in_search'
[midnight-commander.git] / vfs / extfs / ulha.in
blob0b5735cb2077462c28d472344c8bca55ed406ff0
1 #! /bin/sh
4 # LHa Virtual filesystem executive v0.1
5 # Copyright (C) 1996, 1997 Joseph M. Hinkle
6 # May be distributed under the terms of the GNU Public License
7 # <jhinkle@rockisland.com>
10 # Code for mc_lha_fs_run() suggested by:
11 # Jan 97 Zdenek Kabelac <kabi@informatics.muni.cz>
13 # Tested with mc 3.5.18 and gawk 3.0.0 on Linux 2.0.0
14 # Tested with lha v1.01 and lharc v1.02
15 # Information and sources for other forms of lha/lzh appreciated
17 # Nota bene:
18 # There are several compression utilities which produce *.lha files.
19 # LHArc and LHa in exist several versions, and their listing output varies.
20 # Another variable is the architecture on which the compressed file was made.
21 # This program attempts to sort out the variables known to me, but it is likely
22 # to display an empty panel if it encounters a mystery.
23 # In that case it will be useful to execute this file from the command line:
24 # ./lha list Mystery.lha
25 # to examine the output directly on the console. The output string must be
26 # precisely in the format described in the README in this directory.
27 # Caveat emptor.
28 # Learn Latin.
30 # Define your awk
31 AWK=@AWK@
33 # Define which archiver you are using with appropriate options
34 LHA_LIST="lha lq"
35 LHA_GET="lha pq"
36 LHA_PUT="lha aq"
38 # The 'list' command executive
40 mc_lha_fs_list()
42 # List the contents of the archive and sort it out
43 $LHA_LIST "$1" | $AWK -v uid=`id -nu` -v gid=`id -ng` '
44 # Strip a leading '/' if present in a filepath
45 $(NF) ~ /^\// { $(NF) = substr($NF,2) }
46 # Print the line this way if there is no permission string
47 $1 ~ /^\[.*\]/ {
48 # Invent a generic permission
49 $1 = ($NF ~ /\/$/) ? "drwxr-xr-x":"-rwxr--r--";
50 # Print it
51 printf "%s 1 %-8s %-8s %-8d %s %s %s %s\n",
52 $1, uid, gid, $2, $4, $5, $6, $7;
53 # Get the next line of the list
54 next;
56 # Do it this way for a defined permission
57 $1 !~ /^\[.*\]/ {
58 # If the permissions and UID run together
59 if ($1 ~ /\//) {
60 $8 = $7;
61 $7 = $6;
62 $6 = $5;
63 $5 = $4;
64 $3 = $2;
65 $2 = substr($1,10);
66 $1 = substr($1,1,9);
68 # If the permission string is missing a type
69 if (length($1) == 9) {
70 if ($NF ~ /\/$/)
71 $1 = ("d" $1);
72 else
73 $1 = ("-" $1);
75 # UID:GID might not be the same as on your system so print numbers
76 # Well, that is the intent. At the moment mc is translating them.
77 split($2, id, "/");
78 printf "%s 1 %-8d %-8d %-8d %s %s %s %s\n",
79 $1, id[1], id[2], $3, $5, $6, $7, $8;
80 # Get the next line of the list
81 next;
87 # The 'copyout' command executive to copy displayed files to a destination
89 mc_lha_fs_copyout()
91 $LHA_GET "$1" "$2" > "$3"
94 # The 'copyin' command executive to add something to the archive
96 mc_lha_fs_copyin ()
98 NAME2=`basename "$2"`; DIR2=${2%$NAME2}
99 NAME3=`basename "$3"`; DIR3=${3%$NAME3}
101 cd "${DIR3}"
103 ONE2=${2%%/*}
104 [ -n "${ONE2}" ] || exit 1
105 [ -e "${ONE2}" ] && exit 1
107 [ -e "${DIR2}" ] || mkdir -p "${DIR2}"
108 ln "$3" "$2" || exit 1
110 $LHA_PUT "$1" "$2"
111 rm -r "${ONE2}"
114 # The 'run' command executive to run a command from within an archive
116 mc_lha_fs_run()
118 TMPDIR=`mktemp -d "${MC_TMPDIR:-/tmp}/mctmpdir-ulha.XXXXXX"` || exit 1
119 trap "rm -rf \"$TMPDIR\"; exit 0" 1 2 3 4 15
120 TMPCMD=$TMPDIR/run
121 $LHA_GET "$1" "$2" > $TMPCMD
122 chmod a+x "$TMPCMD"
123 "$TMPCMD"
124 rm -rf "$TMPDIR"
128 # The main routine
129 umask 077
131 cmd="$1"
132 shift
134 case "$cmd" in
135 list) mc_lha_fs_list "$@" ;;
136 copyout) mc_lha_fs_copyout "$@" ;;
137 copyin) mc_lha_fs_copyin "$@" ;;
138 run) mc_lha_fs_run "$@" ;;
139 *) exit 1 ;;
140 esac
142 exit 0