blob: eb696184711bb1448e43b1ac76db6e240fb3cc3b [file] [log] [blame]
Reid Spencera60ff2e2004-07-26 22:52:44 +00001#!/bin/sh
Reid Spencer33709e52004-09-20 08:00:09 +00002##===- 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
Reid Spencer9610fc92004-09-20 08:04:13 +000023# searched. By default, everything is searched. Note that you must use quotes
24# around the list of directory names. After that you simply specify whatever
25# program you want to run against each file and the arguments to give it. The
26# PROGRAM will be given the file name as its last argument.
27##===----------------------------------------------------------------------===##
Reid Spencer8141e372004-09-20 07:21:19 +000028
29if test $# -lt 1 ; then
30 echo "Usage: llvmdo [-dirs "DIRNAMES..."] PROGRAM ARGS...";
31 exit 1;
32fi
33
34if test "$1" = "-dirs" ; then
35 LLVMDO_DIRS="$2";
36 shift ; shift
37elif test -z "$LLVMDO_DIRS" ; then
Reid Spencer33709e52004-09-20 08:00:09 +000038 LLVMDO_DIRS="include lib tools utils runtime autoconf docs test examples projects"
Reid Spencer8141e372004-09-20 07:21:19 +000039fi
Reid Spencera60ff2e2004-07-26 22:52:44 +000040PROGRAM=`which $1`
Reid Spencer8141e372004-09-20 07:21:19 +000041if test ! -x "$PROGRAM" ; then
Reid Spencera60ff2e2004-07-26 22:52:44 +000042 echo "Can't execute $1"
43 exit 1
44fi
45shift;
46ARGS="$*"
Reid Spencer8141e372004-09-20 07:21:19 +000047TOPDIR=`pwd | sed -e 's#\(.*/llvm\).*#\1#'`
Reid Spencera60ff2e2004-07-26 22:52:44 +000048if test -d "$TOPDIR" ; then
49 cd $TOPDIR
Reid Spencer8141e372004-09-20 07:21:19 +000050 find $LLVMDO_DIRS -type f \
51 \( \
52 -path 'docs/doxygen/*' -o \
53 -path 'docs/CommandGuide/html/*' -o \
54 -path 'docs/CommandGuide/man/*' -o \
55 -path 'docs/CommandGuide/ps/*' -o \
56 -path 'docs/CommandGuide/man/*' -o \
57 -path 'docs/HistoricalNotes/*' -o \
58 -path 'utils/Burg/*' -o \
59 -path 'docs/img/*' -o \
60 -path '*/.libs/*' \
61 \) -prune -o \( \
Reid Spencer33709e52004-09-20 08:00:09 +000062 \( \
63 -name '*.cpp' -o \
64 -name '*.h' -o \
65 -name '*.def' -o \
66 -name '*.c' -o \
67 -name '*.l' -o \
68 -name '*.y' -o \
69 -name '*.td' -o \
70 -name '*.py' -o \
71 -name '*.pl' -o \
72 -name '*.sh' -o \
73 -name '*.lst' -o \
74 -name '*.pod' -o \
75 -name '*.html' -o \
76 -name '*.css' -o \
77 -name '*.cfg' -o \
78 -name '*.cc' -o \
79 -name '*.txt' -o \
80 -name '*.TXT' -o \
81 -name '*.el' -o \
82 -name '*.m4' -o \
83 -name '*.in' -o \
84 -name '*.ac' -o \
85 -name '*.tr' -o \
86 -name '*.vim' -o \
87 -name '*.gnuplot' -o \
88 -name 'Make*' -o \
89 -path 'test/*.ll' -o \
90 -path 'runtime/*.ll' \
91 \) \
Reid Spencer8141e372004-09-20 07:21:19 +000092 \! -name '.*' \
Reid Spencera60ff2e2004-07-26 22:52:44 +000093 \! -name '*~' \
94 \! -name '#*' \
Reid Spencera60ff2e2004-07-26 22:52:44 +000095 \! -name 'Sparc.burm.c' \
96 \! -name 'llvmAsmParser.cpp' \
97 \! -name 'llvmAsmParser.h' \
98 \! -name 'FileParser.cpp' \
99 \! -name 'FileParser.h' \
Reid Spencer8141e372004-09-20 07:21:19 +0000100 \! -name 'StackerParser.h' \
101 \! -name 'StackerParser.cpp' \
102 -exec $PROGRAM $ARGS {} \; \
103 \)
Reid Spencera60ff2e2004-07-26 22:52:44 +0000104else
105 echo "Can't find LLVM top directory in $TOPDIR"
106fi
Reid Spencer8141e372004-09-20 07:21:19 +0000107