grep.sh revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2011 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# David Korn <dgk@research.att.com> #
# #
########################################################################
function err_exit
{
print -u2 -n "\t"
let Errors+=1
}
alias err_exit='err_exit $LINENO'
integer Errors=0
function grep
{
#
# SHELL VERSION OF GREP
#
set -f
while ((1)) # look for grep options
-v*) vflag=1;;
-x*) xflag=1;;
-c*) cflag=1;;
-l*) lflag=1;;
-n*) nflag=1;;
-b*) print 'b option not supported';;
-*) print $0: 'unknown flag';return 2;;
*)
fi
break;;
esac
shift # next argument
done
then fname=''
fi
test "$i" && exec 0< $i # open file if necessary
while read -r line # read in a line
do let n=n+1
$expr) # line matches pattern
let c=c+1 ;;
*) # not a match
if test "$vflag"
fi;;
esac
done
then print -r -- "$i"
fi
done
let tc # set the return value
}
!
then err_exit
fi