xref: /llvm-project-15.0.7/llvm/utils/llvmgrep (revision 2946cd70)
10277fd7bSReid Spencer#!/bin/sh
25ef171a5SReid Spencer##===- utils/llvmgrep - Counts Lines Of Code -----------------*- Script -*-===##
35ef171a5SReid Spencer#
4*2946cd70SChandler Carruth# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*2946cd70SChandler Carruth# See https://llvm.org/LICENSE.txt for license information.
6*2946cd70SChandler Carruth# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
75ef171a5SReid Spencer#
85ef171a5SReid Spencer##===----------------------------------------------------------------------===##
95ef171a5SReid Spencer#
105ef171a5SReid Spencer# This script searches your srcdir for an egrep style pattern. This can quickly
115ef171a5SReid Spencer# help you build a list of the places you need to modify when changing a header
125ef171a5SReid Spencer# or other "global" name. The only argument is the pattern you want to search
135ef171a5SReid Spencer# for. It should be quoted to escape shell interpretation of the pattern's
145ef171a5SReid Spencer# special characters.
155ef171a5SReid Spencer#
165ef171a5SReid Spencer# Note that the implementation is based on llvmdo. See that script for more
175ef171a5SReid Spencer# details.
185ef171a5SReid Spencer##===----------------------------------------------------------------------===##
195ef171a5SReid Spencer
20235c1555SReid Spencerif test "$1" = "-topdir" ; then
21235c1555SReid Spencer  TOPDIR="$2"
22235c1555SReid Spencer  shift; shift;
23235c1555SReid Spencerelse
24719c3835SReid Spencer  TOPDIR=`llvm-config --src-root`
25235c1555SReid Spencerfi
26235c1555SReid Spencer
270277fd7bSReid Spencerif test -d "$TOPDIR" ; then
280277fd7bSReid Spencer  cd $TOPDIR
2950a425a5SReid Spencer  case `uname -s` in
3050a425a5SReid Spencer    SunOS) grep_cmd="ggrep -H -n" ;;
316a6a30d5SEric Christopher    Linux|Darwin) grep_cmd="egrep -H -n" ;;
3250a425a5SReid Spencer    *) grep_cmd="egrep -l -n" ;;
3350a425a5SReid Spencer  esac
34235c1555SReid Spencer  ./utils/llvmdo -topdir "$TOPDIR" \
35e849956dSChris Lattner    -dirs "include lib tools utils docs examples test unittests projects cmake" $grep_cmd "$*"
3637e0ba96SReid Spencerelse
37235c1555SReid Spencer  echo "Can't find LLVM top directory"
380277fd7bSReid Spencerfi
39