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