File:  [MW Coherent from dump] / coherent / a / usr / man / COHERENT / cgrep
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent



cgrep                        Command                        cgrep




Pattern search for C source programs

ccggrreepp [-ccllnnssAA] [-rr _n_e_w] _e_x_p_r_e_s_s_i_o_n _f_i_l_e ...

ccggrreepp is a  string-search utility.  It resembles its cousins ggrreepp
and eeggrreepp, 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.  ccggrreepp allows you to
search for  a variable named  `i' without finding  every `if' and
`int' in your program.  ccggrreepp 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 ccggrreepp can recognize, see the
Lexicon entry for eeggrreepp.

ccggrreepp tests names that include the `.' and `->' operators against
_e_x_p_r_e_s_s_i_o_n. Thus, to look for ppttrr->vvaall, type:


        cgrep "ptr->val" x.c


This finds  ppttrr->vvaall 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  -AA 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 ssttrruuccttuurree.mmeemmbbeerr, 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 *****

ccggrreepp recognizes the following command-line options:

-cc   Print  all  comments  in  each  _f_i_l_e.  This  form  takes  no
     expression.

-ll   List  only the  names of  the files  in which  _e_x_p_r_e_s_s_i_o_n is
     found.

-nn   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




-rr   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 ppttrr->vvaall.   When -rr is  used and the
     input is ssttddiinn, a new file will always be created as ssttddoouutt.

-ss   Print  all  strings   in  each  _f_i_l_e.  This  form  takes  no
     expression.

-AA   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 -AA  option to  the cccc  command, and  lets you
     build a MicroEMACS  script to make systematic changes to the
     source  file.  To  exit  MicroEMACS and  prevent ccggrreepp  from
     searching further, <ccttrrll-UU> <ccttrrll-XX> <ccttrrll-CC>.

***** Examples *****

The command


        cgrep tmp *.c


will  find  the  variable  name  ttmmpp,  but not  ttmmppnnaammee,  or  any
occurrence of ttmmpp in a string or comment.

The script


        cgrep -c < myfile.c | wc -l


count the lines of comments in mmyyffiillee.cc.

The command


        cgrep "x|abc|d" *.c


will find  xx, aabb, dd.  Note this is  a regular expressions  with a
surrounding  ``^(  )$'' which  is  applied  to every  identifier.
Thus, rreegg* will not match rreeggiisstteerr, but rreegg.* will.

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

ccoommmmaannddss, eeggrreepp, ggrreepp, mmee







COHERENT Lexicon                                           Page 2



unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.