b91e2391 |
1 | #! /bin/sh |
2 | # -*-sh-*- |
3 | # |
b91e2391 |
4 | # Find files which could be links to the repository |
5 | # |
6 | # (c) 1997 Mark Wooding |
7 | # |
8 | |
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. |
26 | |
b91e2391 |
27 | # --- Configuration variables --- |
28 | |
29 | prefix=@prefix@ |
1f79a056 |
30 | datarootdir=@datarootdir@ |
b91e2391 |
31 | datadir=@datadir@/@PACKAGE@ |
32 | |
33 | # --- Parse command line arguments --- |
34 | |
35 | while [ $# -gt 0 ]; do |
36 | case $1 in |
37 | -h | --h | --he | --hel | --help) |
38 | cat <<EOF |
39 | Usage: findlinks |
40 | |
41 | Scans the current directory and any subdirectories, writing the names of |
42 | files which could be linked into the shared files repository to standard |
43 | output. This list could be used as input to the \`mklinks' command. |
44 | EOF |
45 | exit 0 |
46 | ;; |
47 | -v | --v | --ve | --ver | --vers | --versi | --versio | --version) |
a1af6b50 |
48 | version=`echo '$Revision: 1.3 $' | |
4969747b |
49 | sed -n -e 's;^.*: \([0-9.]*\) *\\$;\1;p'` |
b91e2391 |
50 | echo "findlinks $version; Common Files Distribution version @VERSION@" |
51 | exit 0 |
52 | ;; |
53 | *) |
54 | echo "findlinks: unknown option \`$1'" >&2 |
55 | exit 1 |
56 | ;; |
57 | esac |
58 | shift |
59 | done |
60 | |
61 | # --- Read the names of all the files I support --- |
62 | # |
63 | # Yes, this is ugly and hacky: well spotted. Shells have a nasty habit of |
64 | # spontaneously forking when redirection gets too hard for them to think |
65 | # about, so instead of something nice along the lines of |
66 | # |
67 | # find ... | while read name; do <build `files'> done |
68 | # |
69 | # I have to stick the whole lot in backticks and echo the result when it's |
70 | # all done. Yuk. |
71 | # |
72 | # Oh, I almost forgot: that colon on the end there, that's to make sure that |
73 | # all the entries are surrounded by colons on both sides, which makes the |
74 | # pattern match in the `case' below work properly. |
75 | |
76 | files=` |
77 | files="" |
78 | find $datadir -type f -print | { while read name; do |
79 | files="$files:\`echo $name | sed -e 's;^.*/;;'\`" |
80 | done |
81 | echo $files; } `: |
82 | |
83 | # --- Now examine the current directory --- |
84 | # |
85 | # Remember to include things which are already linked, so that users can say |
86 | # `findlinks >.links' without any problems. |
87 | |
88 | find . \( -type f -o -type l \) -print | while read name; do |
89 | base="`echo $name | sed -e 's;^.*/;;'`" |
90 | case "$files" in |
91 | *:$base:*) |
92 | echo $name |
93 | ;; |
94 | *) |
95 | esac |
96 | done | sed -e 's,^\./,,' | sort |