From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu From: "Douglas A. Gwyn" Message-ID: <3D109DEB.9E9EB8C9@null.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit References: <3D104980.16646.51DF597@localhost> Subject: Re: [9fans] Sam / text search query Date: Wed, 19 Jun 2002 15:37:25 +0000 Topicbox-Message-UUID: b3a2a5f4-eaca-11e9-9e20-41e7f4b1d025 Andrew Simmons wrote: > ... my brain locks up and turns to custard when faced with > regular expressions beyond a minimal level of complexity. The best approach for developing structural r.e.s seems to be to think of "layers of context", first establishing the crudest approximate context (location), then adding more r.e.s to successively refine the context until precisely the desired region is selected. Then invoke the action, not forgetting that the "s" command supports \(...\) etc. which is good for rearranging the order of pieces of the selection. Also use sam's "u" (undo) while successively refining context to back out any attempts that don't work as you hoped. The following was extracted from a typical MUVES project package Makefile; it creates source listings that include usage counts in front of each line, great for checking test coverage: # CAUTION: The following procedure requires Rob Pike's "sam" text editor. $(PCFILES): $(HFILES) $(CFILES) $(OBJS) $(TEST).o # $(CFILES) is overkill @( c=`echo $@ | sed 's/^P\.//'`; \ o=`basename $$c .c`.o; \ $(CTRACE) $$c > T.$$c; \ $(CC) -c T.$$c; \ mv $$o B.$$o && mv T.$$o $$o; \ $(CC) $(LDFLAGS) -o $(TEST) $(TEST).o $(OBJS) $(TLIBES); \ ./$(TEST) 2> X.$$c; \ rm -f $(TEST) T.$$o && mv B.$$o $$o; \ grep '^ *[1-9][0-9]* ' < X.$$c \ | sed 's/^ *\([1-9][0-9]*\).*/\1/' \ | sort > L.$$c; \ rm -f X.$$c; \ ( echo ',x/t_ct_\("\\\\n *[1-9][0-9]* /{'; \ echo 'x/[1-9][0-9]*/p\n/\\n/p'; \ echo '}\nq\n' \ ) | sam -d T.$$c | sort -u > A.$$c; \ ( echo f P.$$c; \ echo ',x/^/c/ /'; \ uniq -c L.$$c \ | sed 's;^\( *[1-9][0-9]*\) \([1-9][0-9]*\);\2i/\1/;'; \ uniq L.$$c | comm -13 - A.$$c | sed 's;.*;&i/ 0/;'; \ echo 'w\nq\n' \ ) | sam -d $$c; \ rm -f [ALT].$$c \ )