

cgrep                        Command                        cgrep




Pattern search for C source programs

ccggrreepp [-ccllnnssAA] [-rr _n_e_w] _e_x_p_r_e_s_s_i_o_n _f_i_l_e ...

ccggrreepp is a  string-search utility.  It resembles its cousins ggrreepp
and eeggrreepp, except that it is specially designed to be used with C
source files.  It checks all C identifiers against _e_x_p_r_e_s_s_i_o_n and
prints all lines in which it  finds a match.  ccggrreepp allows you to
search for  a variable named  `i' without finding  every `if' and
`int' in your program.  ccggrreepp defines an ``identifier'' to be any
variable  name  or  C  keyword.   _e_x_p_r_e_s_s_i_o_n  can  be  a  regular
expression; if it  includes wildcard characters or `|'s, you must
``quote it''  to protect it against being  modified by the shell.
For details on the  expressions that ccggrreepp can recognize, see the
Lexicon entry for eeggrreepp.

ccggrreepp tests names that include the `.' and `->' operators against
_e_x_p_r_e_s_s_i_o_n. Thus, to look for ppttrr->vvaall, type:


        cgrep "ptr->val" x.c


This finds  ppttrr->vvaall even if it contains  spaces, comments, or is
spread across  lines.  If it  is spread across lines,  it will be
reported  on the  line that  contains the  last token.   The only
exception is if you include the  -AA option, in which case it will
be reported on the line  which contains the first token.  This is
to simplify MicroEMACS macros, as will be described below.

To find ssttrruuccttuurree.mmeemmbbeerr, type:


        cgrep "structure\.member"


because `.' in a regular expression matches any character.

Do not  include spaces in any pattern.   Only identifiers and `.'
or `->'  between identifiers are  included in the  tokens checked
for pattern-matching.

***** Command-line Options *****

ccggrreepp recognizes the following command-line options:

-cc   Print  all  comments  in  each  _f_i_l_e.  This  form  takes  no
     expression.

-ll   List  only the  names of  the files  in which  _e_x_p_r_e_s_s_i_o_n is
     found.

-nn   Prefix each line in  which _e_x_p_r_e_s_s_i_o_n is found with its line
     number in the file.


COHERENT Lexicon                                           Page 1




cgrep                        Command                        cgrep




-rr   Replace all  expression matches  with _n_e_w.  This  option may
     not be  used with any  others, and it can  only match simple
     tokens, not  items like ppttrr->vvaall.   When -rr is  used and the
     input is ssttddiinn, a new file will always be created as ssttddoouutt.

-ss   Print  all  strings   in  each  _f_i_l_e.  This  form  takes  no
     expression.

-AA   Write  all  lines  in  which  _e_x_p_r_e_s_s_i_o_n  is  found  into  a
     temporary file.  Then, call MicroEMACS with its error option
     to  process  the  source  file,  with  the contents  of  the
     temporary file  serving as  an ``error'' list.   This option
     resembles  the -AA  option to  the cccc  command, and  lets you
     build a MicroEMACS  script to make systematic changes to the
     source  file.  To  exit  MicroEMACS and  prevent ccggrreepp  from
     searching further, <ccttrrll-UU> <ccttrrll-XX> <ccttrrll-CC>.

***** Examples *****

The command


        cgrep tmp *.c


will  find  the  variable  name  ttmmpp,  but not  ttmmppnnaammee,  or  any
occurrence of ttmmpp in a string or comment.

The script


        cgrep -c < myfile.c | wc -l


count the lines of comments in mmyyffiillee.cc.

The command


        cgrep "x|abc|d" *.c


will find  xx, aabb, dd.  Note this is  a regular expressions  with a
surrounding  ``^(  )$'' which  is  applied  to every  identifier.
Thus, rreegg* will not match rreeggiisstteerr, but rreegg.* will.

***** See Also *****

ccoommmmaannddss, eeggrreepp, ggrreepp, mmee







COHERENT Lexicon                                           Page 2


