(|l)gpl-2.[01].tex: Remove the `\renewcommand{\theenumi}...' comments.
[cfd] / findlinks.in
CommitLineData
b91e2391 1#! /bin/sh
996a7fd0
MW
2### -*-sh-*-
3###
4### Find files which could be links to the repository
5###
6### (c) 1997 Mark Wooding
7###
b91e2391 8
996a7fd0
MW
9###----- Licensing notice ---------------------------------------------------
10###
11### This file is part of the Common Files Distribution (`common').
12###
13### `Common' is free software; you can redistribute it and/or modify
14### it under the terms of the GNU General Public License as published by
15### the Free Software Foundation; either version 2 of the License, or
16### (at your option) any later version.
17###
18### `Common' is distributed in the hope that it will be useful,
19### but WITHOUT ANY WARRANTY; without even the implied warranty of
20### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21### GNU General Public License for more details.
22###
23### You should have received a copy of the GNU General Public License
24### along with `common'; if not, write to the Free Software Foundation,
25### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
b91e2391 26
996a7fd0 27set -e
b91e2391 28
996a7fd0
MW
29pkgdatadir="@pkgdatadir@"
30VERSION="@VERSION@"
b91e2391 31
996a7fd0
MW
32###--------------------------------------------------------------------------
33### Parse command line arguments.
b91e2391 34
35while [ $# -gt 0 ]; do
996a7fd0 36 case "$1" in
b91e2391 37 -h | --h | --he | --hel | --help)
38 cat <<EOF
39Usage: findlinks
40
41Scans the current directory and any subdirectories, writing the names of
42files which could be linked into the shared files repository to standard
43output. This list could be used as input to the \`mklinks' command.
44EOF
45 exit 0
46 ;;
47 -v | --v | --ve | --ver | --vers | --versi | --versio | --version)
996a7fd0 48 echo "findlinks: Common Files Distribution version $VERSION"
b91e2391 49 exit 0
50 ;;
51 *)
52 echo "findlinks: unknown option \`$1'" >&2
53 exit 1
54 ;;
55 esac
56 shift
996a7fd0 57done
b91e2391 58
996a7fd0
MW
59###--------------------------------------------------------------------------
60### Read the names of all the files I support.
61###
996a7fd0
MW
62### Yes, this is ugly and hacky: well spotted. Shells have a nasty habit of
63### spontaneously forking when redirection gets too hard for them to think
64### about, so instead of something nice along the lines of
65###
66### find ... | while read name; do <build `files'> done
67###
68### I have to stick the whole lot in backticks and echo the result when it's
69### all done. Yuk.
70###
71### Oh, I almost forgot: that colon on the end there, that's to make sure
72### that all the entries are surrounded by colons on both sides, which makes
73### the pattern match in the `case' below work properly.
b91e2391 74
996a7fd0 75files=$(
de8440ce 76 files=:
996a7fd0
MW
77 find "$pkgdatadir" -type f -print | {
78 while read name; do
de8440ce 79 files="$files${name##*/}:"
996a7fd0 80 done
de8440ce 81 echo "$files"
996a7fd0 82 }
de8440ce 83)
b91e2391 84
996a7fd0
MW
85###--------------------------------------------------------------------------
86### Now examine the current directory.
87###
88### Remember to include things which are already linked, so that users can
89### say `findlinks >.links' without any problems.
b91e2391 90
91find . \( -type f -o -type l \) -print | while read name; do
de8440ce 92 base=${name##*/}
b91e2391 93 case "$files" in
de8440ce
MW
94 *:"$base":*)
95 echo "${name#./}"
b91e2391 96 ;;
97 *)
98 esac
de8440ce 99done | sort
996a7fd0
MW
100
101###----- That's all, folks --------------------------------------------------