From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <50b59f5636d86f429e34fa95be148715@plan9.bell-labs.com> To: 9fans@cse.psu.edu Subject: Re: Fwd: Re: [9fans] samuel (fwd) From: "Russ Cox" MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Fri, 1 Mar 2002 11:04:50 -0500 Topicbox-Message-UUID: 5da8659e-eaca-11e9-9e20-41e7f4b1d025 I just looked at the cscope documentation. As Rob said, you can get 90% of cscope from grep -n, which is convenient to alias as `g': g% cat g #!/bin/rc flags=() while(! ~ $#* 1 && ~ $1 -*){ flags=($flags $1); shift } switch($#*){ case 0 echo 'usage: g [flags] pattern [files]' >[1=2] exit usage case 1 grep -n $flags -- $1 *.[Cbchm] *.cc *.py *.tex *.ms /dev/null \ |[2] {grep -v '^grep: can''t open \*' >[1=2]; status=''} case * grep -n $flags -- $* /dev/null } The set of files in ``case 1'' changes from person to person. My acme window tags are littered with g this and g '^that'. If you don't mind typing small regular expressions like '^that' and your source code conforms to the ``function names in definitions start at the beginning of the line'' convention, then you can usually get by without cscope. If you want to remember a little more, you could try adding some stuff to g to find function/macro declarations: g% cat h #!/bin/rc rfork e if( ~ $#* 0){ echo 'usage: h name [files]' >[1=2] exit usage } pattern=$1 shift files=($*) if(~ $#files 0) files=(*.h ../port/*.h /sys/include/*.h /sys/include/*/*.h) datadef='^[a-z].*[ ]'^$pattern^'\(' definedef='^#define[ ]+'^$pattern^'[ ]' g '('^$datadef^')|('^$definedef^')' $files \ |[2] {grep -v '^grep: can''t open ' >[1=2]; status=''} g% or data definitions: g% cat def #!/bin/rc rfork e if( ~ $#* 0){ echo 'usage: def name [files]' >[1=2] exit usage } pattern=$1 shift files=($*) g '^[ ]*[a-zA-Z0-9_]+[ a-zA-Z0-9,]*[, ]'^$pattern^'($|[^a-zA-Z0-9_])' $files g% or uses of a particular symbol: g% cat sym #!/bin/rc rfork e if( ~ $#* 0){ echo 'usage: sym name [files]' >[1=2] exit usage } pattern=$1 shift files=($*) g '(^|[^a-zA-Z0-9_])'^$pattern^'($|[^a-zA-Z0-9_])' $files g% I wrote these last three in a hurry last night just for fun, inspired by having seen something similar a while back in a screen shot in the help paper, but I'm not sure whether I'll actually use them or just stick with g. h might be useful since it provides a different set of default files. def and sym seem less useful, since g usually turns up what I want with a minimum of noise. The other nice thing about g instead of cscope-like things is that your searches can be arbitrary regexps rather than whatever cscope happens to provide; for example, how do you g 'dmactl = 0' in cscope? Russ