#
# regex routines (PUBLIC DOMAIN)
#
# by:	Ozan S. Yigit (oz)
#	Dept. of Computer Science
#	York University
#
# Applicable to BSD:
#
# If you have the generic(?) regex routines
# than you can compare the timings of these
# routines to the generic ones by:
#
#	make times
#
# which will create two rudimentary greps
# lgrep and ogrep. lgrep will use the generic
# regex routines, and ogrep will use oz version
# of regex. Several patterns will be searched
# in /usr/dict/words, and the output of the greps
# will be compared. [for reasons of sanity]
#
# Surely, you will note, the time tests are somewhat
# biased, since /usr/dict/words contain *short* lines,
# thereby the real-life case of searching a complex
# expression within a long line is not covered. You
# will find, however, that the PD regex routines will
# search *as fast* as the generic ones in most
# cases, and about 10% slower in some cases, when
# tested with files containing *long* lines. 
# 
CFLAGS = -O
#
# test patterns
#
PAT1 = '[d-f]zz*.*m'
PAT2 = 'fo[ornt]*.*b[a-d]*'
PAT3 = '.th.'
PAT4 = '\(ab\)[a-d]*\1'
PAT5 = 'burp'

FILE = /usr/dict/words
OUTD = /tmp/

RSRC = regex.o re_fail.o

regex:  libregex.a
	@echo "lib done"

libregex.a:	$(RSRC)
	ar rv libregex.a $(RSRC)
	ranlib libregex.a

rlint:
	lint -phc regex.c

debug:
	cc -O -DDEBUG -o ogrep grep.c regex.c re_fail.c

lgrep:  grep.o
	cc -o lgrep grep.o

ogrep:  grep.o $(RSRC)
	cc -o ogrep grep.o $(RSRC)

times:  lgrep ogrep
	@echo generic regex vs oz regex
	@echo pattern: $(PAT1)
	time ogrep $(PAT1) $(FILE) >$(OUTD)ogrep.out
	time lgrep $(PAT1) $(FILE) >$(OUTD)lgrep.out
	@echo output differences:
	-diff $(OUTD)ogrep.out $(OUTD)lgrep.out
	@echo "---"
	@echo pattern: $(PAT2)
	time ogrep $(PAT2) $(FILE) >$(OUTD)ogrep.out
	time lgrep $(PAT2) $(FILE) >$(OUTD)lgrep.out
	@echo output differences:
	-diff $(OUTD)ogrep.out $(OUTD)lgrep.out
	@echo "---"
	echo pattern: $(PAT3)
	time ogrep $(PAT3) $(FILE) >$(OUTD)ogrep.out
	time lgrep $(PAT3) $(FILE) >$(OUTD)lgrep.out
	@echo output differences:
	-diff $(OUTD)ogrep.out $(OUTD)lgrep.out
	@echo "---"
	echo pattern: $(PAT4)
	time ogrep $(PAT4) $(FILE) >$(OUTD)ogrep.out
	time lgrep $(PAT4) $(FILE) >$(OUTD)lgrep.out
	@echo output differences:
	-diff $(OUTD)ogrep.out $(OUTD)lgrep.out
	@echo "---"
	echo pattern: $(PAT5)
	time ogrep $(PAT5) $(FILE) >$(OUTD)ogrep.out
	time lgrep $(PAT5) $(FILE) >$(OUTD)lgrep.out
	@echo output differences:
	-diff $(OUTD)ogrep.out $(OUTD)lgrep.out
	@echo "---"
	@rm $(OUTD)ogrep.out $(OUTD)lgrep.out
