Tighten up the specification of what counts as a code file. The previous
[oota-llvm.git] / utils / llvmdo
1 #!/bin/sh
2 ##===- utils/llvmdo - Counts Lines Of Code -------------------*- Script -*-===##
3
4 #                     The LLVM Compiler Infrastructure
5 #
6 # This file was developed by Reid Spencer and is distributed under the 
7 # University of Illinois Open Source License. See LICENSE.TXT for details.
8
9 ##===----------------------------------------------------------------------===##
10 #
11 # This script is a general purpose "apply" function for the source files in LLVM
12 # It uses "find" to locate all the source files and then applies the user's 
13 # command to them. As such, this command is often not used by itself much but
14 # the other find related tools (countloc.sh,llvmgrep,getsrcs.sh) are all based 
15 # on the implementation. This script defines "what is a source file" in LLVM and
16 # so should be maintained if new directories, new file extensions, etc. are 
17 # used in LLVM as it progresses.
18 #
19 # Usage:
20 #  llvmdo [-dirs "DIRNAMES..." PROGRAM ARGS...
21 #
22 # The -dirs argument allows you to specify the set of directories that are 
23 # searched. By default, everything is searched
24 # (excluding certain things), runs "wc -l" on them to get the number of lines in
25 # each file and then sums up and prints the total with awk. 
26 #
27 # The script takes no arguments but does expect to be run from the top llvm
28 # source directory.
29 #
30 # This script is
31 # greps.
32
33 if test $# -lt 1 ; then
34   echo "Usage: llvmdo [-dirs "DIRNAMES..."] PROGRAM ARGS...";
35   exit 1;
36 fi
37
38 if test "$1" = "-dirs" ; then
39   LLVMDO_DIRS="$2";
40   shift ; shift
41 elif test -z "$LLVMDO_DIRS" ; then
42   LLVMDO_DIRS="include lib tools utils runtime autoconf docs test examples projects"
43 fi
44 PROGRAM=`which $1`
45 if test ! -x "$PROGRAM" ; then
46   echo "Can't execute $1"
47   exit 1
48 fi
49 shift;
50 ARGS="$*"
51 TOPDIR=`pwd | sed -e 's#\(.*/llvm\).*#\1#'`
52 if test -d "$TOPDIR" ; then
53   cd $TOPDIR
54   find $LLVMDO_DIRS -type f \
55     \( \
56       -path 'docs/doxygen/*' -o \
57       -path 'docs/CommandGuide/html/*' -o \
58       -path 'docs/CommandGuide/man/*' -o \
59       -path 'docs/CommandGuide/ps/*' -o \
60       -path 'docs/CommandGuide/man/*' -o \
61       -path 'docs/HistoricalNotes/*' -o \
62       -path 'utils/Burg/*' -o \
63       -path 'docs/img/*' -o \
64       -path '*/.libs/*' \
65     \) -prune  -o \( \
66       \( \
67          -name '*.cpp' -o \
68          -name '*.h' -o \
69          -name '*.def' -o \
70          -name '*.c' -o \
71          -name '*.l' -o \
72          -name '*.y' -o \
73          -name '*.td' -o \
74          -name '*.py' -o \
75          -name '*.pl' -o \
76          -name '*.sh' -o \
77          -name '*.lst' -o \
78          -name '*.pod' -o \
79          -name '*.html' -o \
80          -name '*.css' -o \
81          -name '*.cfg' -o \
82          -name '*.cc' -o \
83          -name '*.txt' -o \
84          -name '*.TXT' -o \
85          -name '*.el' -o \
86          -name '*.m4' -o \
87          -name '*.in' -o \
88          -name '*.ac' -o \
89          -name '*.tr' -o \
90          -name '*.vim' -o \
91          -name '*.gnuplot' -o \
92          -name 'Make*' -o \
93          -path 'test/*.ll' -o \
94          -path 'runtime/*.ll' \
95       \) \
96       \! -name '.*' \
97       \! -name '*~' \
98       \! -name '#*' \
99       \! -name 'Sparc.burm.c' \
100       \! -name 'llvmAsmParser.cpp' \
101       \! -name 'llvmAsmParser.h' \
102       \! -name 'FileParser.cpp' \
103       \! -name 'FileParser.h' \
104       \! -name 'StackerParser.h' \
105       \! -name 'StackerParser.cpp' \
106      -exec $PROGRAM $ARGS {} \; \
107     \)
108 else
109   echo "Can't find LLVM top directory in $TOPDIR"
110 fi
111