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