9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Russ Cox" <rsc@plan9.bell-labs.com>
To: 9fans@cse.psu.edu
Subject: Re: Fwd: Re: [9fans] samuel (fwd)
Date: Fri,  1 Mar 2002 11:04:50 -0500	[thread overview]
Message-ID: <50b59f5636d86f429e34fa95be148715@plan9.bell-labs.com> (raw)

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



             reply	other threads:[~2002-03-01 16:04 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-01 16:04 Russ Cox [this message]
2002-02-02 17:05 ` Matt H
2002-03-01 17:12   ` Boyd Roberts
2002-03-04 10:04 ` David Rubin
  -- strict thread matches above, loose matches on Subject: below --
2002-03-04 15:24 Bengt Kleberg
2002-03-05  9:41 ` Douglas A. Gwyn
2002-03-05 10:04   ` George Michaelson
2002-03-06  9:51     ` Thomas Bushnell, BSG
2002-03-06 15:56       ` ozan s yigit
2002-03-07  9:56         ` Thomas Bushnell, BSG
2002-03-07 16:46           ` ozan s yigit
2002-03-07 17:55             ` Thomas Bushnell, BSG
2002-03-08  9:59               ` ozan s. yigit
2002-03-06 19:39       ` Andrew Simmons
2002-03-05 10:18   ` Boyd Roberts
2002-03-04 14:41 Russ Cox
2002-03-04 11:43 Bengt Kleberg
2002-03-04 14:02 ` Howard Trickey
2002-03-05  9:41   ` Douglas A. Gwyn
2002-03-05 10:42   ` Boyd Roberts
2002-03-04  0:21 Andrew Simmons
2002-03-05  9:34 ` Boyd Roberts
2002-03-01 17:58 Russ Cox
2002-03-05  9:22 ` Boyd Roberts
2002-03-01 17:29 anothy
2002-03-01 17:13 Bengt Kleberg
2002-03-01 16:15 rob pike
2002-03-04 10:04 ` AMSRL-CI-CN
2002-03-05  9:40   ` ozan s yigit
2002-03-06  9:51     ` Douglas A. Gwyn
     [not found] <rob@plan9.bell-labs.com>
2002-03-01  6:20 ` rob pike
2002-03-01  6:34   ` George Michaelson
2002-03-01 12:04   ` Boyd Roberts
2002-03-01  2:51 Sam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50b59f5636d86f429e34fa95be148715@plan9.bell-labs.com \
    --to=rsc@plan9.bell-labs.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).