blob: 373b6574d9587a3e90ab911611132601db1aed41 [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
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
Reid Spencera60ff2e2004-07-26 22:52:44 +000031# greps.
Reid Spencer8141e372004-09-20 07:21:19 +000032
33if test $# -lt 1 ; then
34 echo "Usage: llvmdo [-dirs "DIRNAMES..."] PROGRAM ARGS...";
35 exit 1;
36fi
37
38if test "$1" = "-dirs" ; then
39 LLVMDO_DIRS="$2";
40 shift ; shift
41elif test -z "$LLVMDO_DIRS" ; then
Reid Spencer33709e52004-09-20 08:00:09 +000042 LLVMDO_DIRS="include lib tools utils runtime autoconf docs test examples projects"
Reid Spencer8141e372004-09-20 07:21:19 +000043fi
Reid Spencera60ff2e2004-07-26 22:52:44 +000044PROGRAM=`which $1`
Reid Spencer8141e372004-09-20 07:21:19 +000045if test ! -x "$PROGRAM" ; then
Reid Spencera60ff2e2004-07-26 22:52:44 +000046 echo "Can't execute $1"
47 exit 1
48fi
49shift;
50ARGS="$*"
Reid Spencer8141e372004-09-20 07:21:19 +000051TOPDIR=`pwd | sed -e 's#\(.*/llvm\).*#\1#'`
Reid Spencera60ff2e2004-07-26 22:52:44 +000052if test -d "$TOPDIR" ; then
53 cd $TOPDIR
Reid Spencer8141e372004-09-20 07:21:19 +000054 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 \( \
Reid Spencer33709e52004-09-20 08:00:09 +000066 \( \
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 \) \
Reid Spencer8141e372004-09-20 07:21:19 +000096 \! -name '.*' \
Reid Spencera60ff2e2004-07-26 22:52:44 +000097 \! -name '*~' \
98 \! -name '#*' \
Reid Spencera60ff2e2004-07-26 22:52:44 +000099 \! -name 'Sparc.burm.c' \
100 \! -name 'llvmAsmParser.cpp' \
101 \! -name 'llvmAsmParser.h' \
102 \! -name 'FileParser.cpp' \
103 \! -name 'FileParser.h' \
Reid Spencer8141e372004-09-20 07:21:19 +0000104 \! -name 'StackerParser.h' \
105 \! -name 'StackerParser.cpp' \
106 -exec $PROGRAM $ARGS {} \; \
107 \)
Reid Spencera60ff2e2004-07-26 22:52:44 +0000108else
109 echo "Can't find LLVM top directory in $TOPDIR"
110fi
Reid Spencer8141e372004-09-20 07:21:19 +0000111