head	1.18;
access;
symbols;
locks; strict;
comment	@# @;


1.18
date	2011.11.21.09.45.47;	author dunc;	state Exp;
branches;
next	1.17;

1.17
date	2007.10.11.21.49.43;	author dunc;	state Exp;
branches;
next	1.16;

1.16
date	2007.08.02.03.49.42;	author dunc;	state Exp;
branches;
next	1.15;

1.15
date	2007.01.21.21.23.23;	author dunc;	state Exp;
branches;
next	1.14;

1.14
date	2004.07.31.00.53.17;	author dunc;	state Exp;
branches;
next	1.13;

1.13
date	2003.08.28.07.29.50;	author dunc;	state Exp;
branches;
next	1.12;

1.12
date	2003.08.15.06.44.59;	author dunc;	state Exp;
branches;
next	1.11;

1.11
date	2003.08.15.06.26.24;	author dunc;	state Exp;
branches;
next	1.10;

1.10
date	2003.03.03.01.12.50;	author dunc;	state Exp;
branches;
next	1.9;

1.9
date	2003.01.14.21.58.02;	author dunc;	state Exp;
branches;
next	1.8;

1.8
date	2002.04.30.22.11.39;	author dunc;	state Exp;
branches;
next	1.7;

1.7
date	99.08.21.04.52.13;	author dunc;	state Exp;
branches;
next	1.6;

1.6
date	99.08.08.03.26.39;	author dunc;	state Exp;
branches;
next	1.5;

1.5
date	98.08.15.07.35.38;	author dunc;	state Exp;
branches;
next	1.4;

1.4
date	98.06.17.01.36.34;	author dunc;	state Exp;
branches;
next	1.3;

1.3
date	98.05.27.03.51.26;	author dunc;	state Exp;
branches;
next	1.2;

1.2
date	98.05.25.02.39.11;	author dunc;	state Exp;
branches;
next	1.1;

1.1
date	98.04.15.01.33.02;	author dunc;	state Exp;
branches;
next	;


desc
@Search current tree for tokens in source files
@


1.18
log
@grave elimination
@
text
@#!/bin/sh
#set -x

# Runs the show
main()
{
  try_gnu_args
  set_personality || exit 1

# Had to inline the next bit, coz it uses shift & args are local to functions
if [ -z "$1" ];then
  echo "Usage: $j <string> [<grep option>,...]" >&2
  exit 1
else
  k="$1"
  shift
fi

do_the_grep "$@@"
}

# Sets fiddly gnu arg iff we have gnu grep
try_gnu_args()
{
  grep --version >/dev/null 2>&1
  [ $? -eq 0 ] && n=-noleaf || n=
}

# Check for good invocation.
# sfl is designed to be symlinked to - which synlink is used determines behaviour.
# list of symlinks:
# lrwxrwxrwx  1 dunc users    3 2004-09-30 22:12 afl -> sfl
# lrwxrwxrwx  1 dunc users    3 2004-09-30 22:12 aflc -> sfl
# lrwxrwxrwx  1 dunc users    3 2004-09-30 22:12 afll -> sfl
# lrwxrwxrwx  1 dunc users    3 2004-09-30 22:12 afllc -> sfl
# -rwxr-xr-x  1 dunc users 1183 2006-05-04 07:59 sfl
# lrwxrwxrwx  1 root root     3 2004-09-30 22:12 sflc -> sfl
# lrwxrwxrwx  1 root root     3 2004-09-30 22:12 sfll -> sfl
# lrwxrwxrwx  1 root root     3 2004-09-30 22:12 sfllc -> sfl
# lrwxrwxrwx  1 root root     3 2004-09-30 22:12 ufl -> sfl
# lrwxrwxrwx  1 root root     3 2004-09-30 22:12 uflc -> sfl
# lrwxrwxrwx  1 root root     3 2004-09-30 22:12 ufll -> sfl
# lrwxrwxrwx  1 root root     3 2004-09-30 22:12 ufllc -> sfl
set_personality()
{
  j=$(basename $0)
  case $j in
  u*)
    f='.. -maxdepth 2 -mindepth 2'
    w=w
    ;;
  s*)
    f=.
    w=w
    ;;
  a*)
    f=.
    w=""
    ;;
  *)
    echo bad symlink of sfl to $j
    return 1
    ;;
  esac
  case $j in
  ?fl)
    i=''
    ;;
  ?fll)
    i=''
    f="$f -follow"
    ;;
  ?flc)
    i=i
    ;;
  ?fllc)
    i=i
    f="$f -follow"
    ;;
  *)
    echo bad symlink of sfl to $j
    return 1
    ;;
  esac
  return 0
}

# Actually do the grep
do_the_grep()
{
  find $f $n -depth -type f \( \
    -name "*.c" \
    -o -name "*.cpp" \
    -o -name "*.cxx" \
    -o -name "*.cc" \
    -o -name "*.f" \
    -o -name "*.for" \
    -o -name "*.S" \
    -o -name "*.h" \
    -o -name "*.java" \
    -o -name "*.exp" \
    -o -name "*.tcl" \
    -o -name "*.expect" \
    -o -name "*.pl" \
    -o -iname "makefile" \
    -o -name "Kconfig" \
    -o -name "make-file" \
    -o -name "*.i" \
    -o -name "*.l" \
    -o -name "*.lex" \
    -o -name "*.y" \
    -o -name "*.yacc" \
    -o -name "*.sh" \
    \) -print|sed -e 's/ /\\ /g'|xargs -n 32 -r -e grep -${i}s${w}n "$@@" -- "$k" /dev/null
}
main "$@@"
@


1.17
log
@fixed typo in comment
@
text
@d46 1
a46 1
  j=`basename $0`
@


1.16
log
@Added Kconfig to file list; tolerate spaces in dir names
@
text
@d88 1
a88 1
# Actually do the gep
@


1.15
log
@Tarted up for ee response
@
text
@d106 1
d114 1
a114 1
    \) -print|xargs -n 32 -r -e grep -${i}s${w}n "$@@" -- "$k" /dev/null
@


1.14
log
@Replace .terse with .exp (expect); cater for spaces in arg
@
text
@d3 8
a10 3
# Assume gnu find in next line
n=-noleaf
j=`basename $0`
d18 98
a115 61
case $j in
u*)
  f='.. -maxdepth 2 -mindepth 2'
  w=w
  ;;
s*)
  f=.
  w=w
  ;;
a*)
  f=.
  w=""
  ;;
*)
  echo bad symlink of sfl to $j
  exit 1
  ;;
esac
case $j in
?fl)
  i=''
  ;;
?fll)
  i=''
  f="$f -follow"
  ;;
?flc)
  i=i
  ;;
?fllc)
  i=i
  f="$f -follow"
  ;;
*)
  echo bad symlink of sfl to $j
  exit 1
  ;;
esac
find $f $n -depth -type f \( \
  -name "*.c" \
  -o -name "*.cpp" \
  -o -name "*.cxx" \
  -o -name "*.cc" \
  -o -name "*.f" \
  -o -name "*.for" \
  -o -name "*.S" \
  -o -name "*.h" \
  -o -name "*.java" \
  -o -name "*.exp" \
  -o -name "*.tcl" \
  -o -name "*.expect" \
  -o -name "*.pl" \
  -o -iname "makefile" \
  -o -name "make-file" \
  -o -name "*.i" \
  -o -name "*.l" \
  -o -name "*.lex" \
  -o -name "*.y" \
  -o -name "*.yacc" \
  -o -name "*.sh" \
  \) -print|xargs -n 32 -r -e grep -${i}s${w}n "$@@" -- "$k" /dev/null
@


1.13
log
@Add .lex & .yacc
@
text
@d61 1
a61 1
  -o -name "*.terse" \
d73 1
a73 1
  \) -print|xargs -n 32 -r -e grep -${i}s${w}n "$@@" -- $k /dev/null
@


1.12
log
@afl &c. do non-token search
@
text
@d69 1
d71 1
@


1.11
log
@Also search (dfa) make-file's
@
text
@d2 1
d16 1
d20 5
d71 1
a71 1
  \) -print|xargs -n 32 -r -e grep -${i}swn "$@@" -- $k /dev/null
@


1.10
log
@Allow appending of grep options
@
text
@d59 1
@


1.9
log
@Added suffices .i .l .y .sh
@
text
@d5 7
d63 1
a63 1
  \) -print|xargs -n 32 -r -e grep -${i}swn -- $1 /dev/null
@


1.8
log
@Look in .cc files & makefiles
@
text
@d52 4
@


1.7
log
@Convert to using xargs (thanks DW!)
@
text
@d41 1
d51 1
@


1.6
log
@Guard against filenames starting "-"
@
text
@d50 1
a50 1
  \) -exec grep -${i}swn -- $1 "{}" /dev/null \;
@


1.5
log
@Also search Perl sources
@
text
@d50 1
a50 1
  \) -exec grep -${i}swn $1 "{}" /dev/null \;
@


1.4
log
@Also search ".expect" scripts
@
text
@d49 1
@


1.3
log
@Recognise Fortran suffix ".for"
@
text
@d48 1
@


1.2
log
@Linked to by all other sf*, uf*; also look in FORTRAN sources
@
text
@d42 1
@


1.1
log
@Initial revision
@
text
@d2 46
a47 1
find . -depth -type f \( -name "*.c" -o -name "*.cpp" -o -name "*.cxx" -o -name "*.S" -o -name "*.h" -o -name "*.java" -o -name "*.terse" -o -name "*.tcl" \) -exec grep -swn $1 "{}" /dev/null \;
@
