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