Fixed to actually work correctly and be the basis for other tools by
[oota-llvm.git] / utils / llvmdo
1 #!/bin/sh
2 # This is useful because it prints out all of the source files.  Useful for
3 # greps.
4
5 if test $# -lt 1 ; then
6   echo "Usage: llvmdo [-dirs "DIRNAMES..."] PROGRAM ARGS...";
7   exit 1;
8 fi
9
10 if test "$1" = "-dirs" ; then
11   LLVMDO_DIRS="$2";
12   shift ; shift
13 elif test -z "$LLVMDO_DIRS" ; then
14   LLVMDO_DIRS="include lib tools test utils docs examples projects"
15 fi
16 PROGRAM=`which $1`
17 if test ! -x "$PROGRAM" ; then
18   echo "Can't execute $1"
19   exit 1
20 fi
21 shift;
22 ARGS="$*"
23 TOPDIR=`pwd | sed -e 's#\(.*/llvm\).*#\1#'`
24 if test -d "$TOPDIR" ; then
25   cd $TOPDIR
26   find $LLVMDO_DIRS -type f \
27     \( \
28       -path 'docs/doxygen/*' -o \
29       -path 'docs/CommandGuide/html/*' -o \
30       -path 'docs/CommandGuide/man/*' -o \
31       -path 'docs/CommandGuide/ps/*' -o \
32       -path 'docs/CommandGuide/man/*' -o \
33       -path 'docs/HistoricalNotes/*' -o \
34       -path 'utils/Burg/*' -o \
35       -path 'docs/img/*' -o \
36       -path '*/.libs/*' \
37     \) -prune  -o \( \
38          -name '*.[cdhyltp]*' \
39       \! -name '.*' \
40       \! -name '*~' \
41       \! -name '#*' \
42       \! -name '*.d' \
43       \! -name '*.dir' \
44       \! -name '*.flc' \
45       \! -name '*.inc' \
46       \! -name '*.ll' \
47       \! -name '*.llx' \
48       \! -name '*.la' \
49       \! -name '*.lo' \
50       \! -name 'Sparc.burm.c' \
51       \! -name 'llvmAsmParser.cpp' \
52       \! -name 'llvmAsmParser.h' \
53       \! -name 'FileParser.cpp' \
54       \! -name 'FileParser.h' \
55       \! -name 'StackerParser.h' \
56       \! -name 'StackerParser.cpp' \
57      -exec $PROGRAM $ARGS {} \; \
58     \)
59 else
60   echo "Can't find LLVM top directory in $TOPDIR"
61 fi
62