list - prints documented listings
Christian Schlichtherle
chris at attron.ruhr.sub.org
Mon Jan 28 04:38:54 AEST 1991
This is a shell script. It prints a documented listing on it's standard
output.
The original idea to write this was to have a better documented UUCP file
list (/usr/spool/uucppublic/files). I was unlucky with the output of ls(C),
because it gives no information about the contents of the files. So I wrote
this. Of course, it works on every directory.
Chris
#!/bin/sh
# This is a shell archive (shar 3.24)
# made 01/27/1991 17:30 UTC by chris at attron.ruhr.sub.org
# Source directory /u/chris/src/list
#
# existing files WILL be overwritten
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 202 -rw-r--r-- .list
# 476 -r--r--r-- Makefile
# 1775 -r--r--r-- README
# 1581 -r--r--r-- list.sh
#
if touch 2>&1 | fgrep '[-amc]' > /dev/null
then TOUCH=touch
else TOUCH=true
fi
# ============= .list ==============
echo "x - extracting .list (Text)"
sed 's/^X//' << 'SHAR_EOF' > .list &&
X.list Demonstration file for list(C)
XMakefile Makefile for list(C)
XREADME Documentation file for list(C)
Xlist.sh Prints documented listing
Xtestline This line will vanish when executing 'list -u' ;-)
SHAR_EOF
$TOUCH -am 0127181391 .list &&
chmod 0644 .list ||
echo "restore of .list failed"
set `wc -c .list`;Wc_c=$1
if test "$Wc_c" != "202"; then
echo original size 202, current size $Wc_c
fi
# ============= Makefile ==============
echo "x - extracting Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
X#
X# @(#) Makefile 1.1 91/01/27
X#
X# Written 1991 by Christian Schlichtherle
X# (chris at attron.ruhr.sub.org)
X# No copyright until you remove this header. The author
X# disclaims any warranty.
X#
X# Makefile - Makefile for list(C).
X#
X
XOWNER=chris
XGROUP=freak
XMODE=0755
XBIN=/u/bin
X
Xlist: list.sh
X cp $? $@
X chmod $(MODE) $@
X
Xinstall: $(BIN)/list
X
X$(BIN)/list: list
X cp $? $@
X chown $(OWNER) $@
X chgrp $(GROUP) $@
X chmod $(MODE) $@
X
Xuninstall:
X rm -f $(BIN)/list
X
Xclean:
X rm -f list
SHAR_EOF
$TOUCH -am 0127182891 Makefile &&
chmod 0444 Makefile ||
echo "restore of Makefile failed"
set `wc -c Makefile`;Wc_c=$1
if test "$Wc_c" != "476"; then
echo original size 476, current size $Wc_c
fi
# ============= README ==============
echo "x - extracting README (Text)"
sed 's/^X//' << 'SHAR_EOF' > README &&
X
X @(#) README 1.1 91/01/27
X
X Written 1991 by Christian Schlichtherle
X (chris at attron.ruhr.sub.org)
X No copyright unless you remove this header. The author
X disclaims any warranty.
X
X README - Documentation file for list(C).
X
XNAME
X
X list - Prints documented listings.
X
XSYNTAX
X
X list [-A] [<pathname> ...]
X list -u [<directory> ...]
X
XDESCRIPTION
X
X list(C) prints a documented listing on standard output. The
X output is formated. The first field contains the filename,
X the second field the size of the file in bytes. The rest of
X the line contains the description for the file. The lines
X are sorted in increasing ASCII collating sequence (like
X ls(C)). The "-A" option indicates that files beginning with
X a period are listed for non-super users too (like ls(C)).
X
X The description for the files is held in the file ".list"
X in the directory where the file reside. This file is
X formatted as follows: The first field contains the filename
X and the rest of the line contains the description for the
X file. The lines are sorted in increasing ASCII collating
X sequence.
X
X The second form of the command 'list -u [<directory> ...]'
X updates the ".list" file. The lines are sorted, descriptions
X for nonexistent files are thrown away and the output is
X formatted.
X
XFILES
X
X .list Description file for listing
X
XSEE ALSO
X
X ls(C), sort(C), join(C), awk(C)
X
XNOTES
X
X Whitespace in the description field of the ".list" file is
X replaced by a single space character.
X
X Filenames must not contain escape sequences for printf().
X
X If your awk bails out you will have to substitute the line
X "print substr($0, i + 2);" with "print substr($0, i + 2,
X 255);" or "print substr($0, i + 2, length($1) - i - 1);". I
X used this because it shows better performance (need not
X process length($1)).
SHAR_EOF
$TOUCH -am 0127182891 README &&
chmod 0444 README ||
echo "restore of README failed"
set `wc -c README`;Wc_c=$1
if test "$Wc_c" != "1775"; then
echo original size 1775, current size $Wc_c
fi
# ============= list.sh ==============
echo "x - extracting list.sh (Text)"
sed 's/^X//' << 'SHAR_EOF' > list.sh &&
X:
X#
X# @(#) list.sh 1.1 91/01/27
X#
X# Written 1991 by Christian Schlichtherle
X# (chris at attron.ruhr.sub.org)
X# No copyright unless you remove this header. The author
X# disclaims any warranty.
X#
X# list.sh - Bourne shell script for list(C).
X#
X
XPATH=/bin:/usr/bin
XLISTFILE=.list
XTMP=/tmp/upd$$
XUSAGE="usage:\t$0 [-A] [<pathname> ...]\n\t$0 -u [<directory> ...]"
X
Xset -h
X
Xusage() {
X echo $USAGE 1>&2
X exit 1
X}
X
Xlist() {
X if [ $# -gt 1 ]
X then
X ECHO=ECHO
X else
X ECHO=:
X fi
X for FILE in $@
X do
X if [ -d $FILE ]
X then
X $ECHO "\n$FILE:"
X LISTPATH=$FILE/$LISTFILE
X else
X LISTPATH=`dirname $FILE`/$LISTFILE
X fi
X if [ -r $LISTPATH ]
X then
X ls -n $LISTOPT $FILE | join -a1 -j1 9 - $LISTPATH | \
X awk 'NF >= 9 {
X printf "%-14s %7s", $1, $6;
X if (NF > 9)
X for (i = 10; i <= NF; i++)
X printf " %s", $i;
X printf "\n";
X } ' -
X else
X ls -n $FILE | awk '{ printf "%-14s %7s\n", $9, $5; }' -
X fi
X done
X}
X
Xupdate() {
X for FILE in $@
X do
X [ ! -d $FILE ] && {
X echo Not a directory: $FILE
X continue
X }
X trap : 1 2 3 13 15 # save the listfile
X sort $FILE/$LISTFILE > $TMP &&
X ls -A $FILE | join - $TMP | \
X awk ' {
X printf $1;
X if ((i = length($1)) < 8)
X printf "\t\t";
X else
X printf "\t";
X print substr($0, i + 2);
X } ' - > $FILE/$LISTFILE
X rm -f $TMP
X trap '' 1 2 3 13 15
X done
X}
X
XMODE=list
Xfor i in $@
Xdo
X case $i in
X -A) [ $MODE = update ] && usage
X LISTOPT="$LISTOPT -A"
X ;;
X -u) [ "$LISTOPT" ] && usage
X MODE=update
X ;;
X -*) usage
X ;;
X *) break
X ;;
X esac
X shift
Xdone
X
Xset -- ${@:-.}
X$MODE $*
SHAR_EOF
$TOUCH -am 0127182891 list.sh &&
chmod 0444 list.sh ||
echo "restore of list.sh failed"
set `wc -c list.sh`;Wc_c=$1
if test "$Wc_c" != "1581"; then
echo original size 1581, current size $Wc_c
fi
exit 0
--
Snail: Christian Schlichtherle, Elbscheweg 20, 5802 Wetter 4, Germany
Email: chris at attron.ruhr.sub.org Tel.: +49 2335 7550
Politiker an die Front!
More information about the Alt.sources
mailing list