|
|
1.1 root 1:
2:
3: cgrep Command cgrep
4:
5:
6:
7:
8: Pattern search for C source programs
9:
10: ccggrreepp [-ccllnnssAA] [-rr _n_e_w] _e_x_p_r_e_s_s_i_o_n _f_i_l_e ...
11:
12: ccggrreepp is a string-search utility. It resembles its cousins ggrreepp
13: and eeggrreepp, except that it is specially designed to be used with C
14: source files. It checks all C identifiers against _e_x_p_r_e_s_s_i_o_n and
15: prints all lines in which it finds a match. ccggrreepp allows you to
16: search for a variable named `i' without finding every `if' and
17: `int' in your program. ccggrreepp defines an ``identifier'' to be any
18: variable name or C keyword. _e_x_p_r_e_s_s_i_o_n can be a regular
19: expression; if it includes wildcard characters or `|'s, you must
20: ``quote it'' to protect it against being modified by the shell.
21: For details on the expressions that ccggrreepp can recognize, see the
22: Lexicon entry for eeggrreepp.
23:
24: ccggrreepp tests names that include the `.' and `->' operators against
25: _e_x_p_r_e_s_s_i_o_n. Thus, to look for ppttrr->vvaall, type:
26:
27:
28: cgrep "ptr->val" x.c
29:
30:
31: This finds ppttrr->vvaall even if it contains spaces, comments, or is
32: spread across lines. If it is spread across lines, it will be
33: reported on the line that contains the last token. The only
34: exception is if you include the -AA option, in which case it will
35: be reported on the line which contains the first token. This is
36: to simplify MicroEMACS macros, as will be described below.
37:
38: To find ssttrruuccttuurree.mmeemmbbeerr, type:
39:
40:
41: cgrep "structure\.member"
42:
43:
44: because `.' in a regular expression matches any character.
45:
46: Do not include spaces in any pattern. Only identifiers and `.'
47: or `->' between identifiers are included in the tokens checked
48: for pattern-matching.
49:
50: ***** Command-line Options *****
51:
52: ccggrreepp recognizes the following command-line options:
53:
54: -cc Print all comments in each _f_i_l_e. This form takes no
55: expression.
56:
57: -ll List only the names of the files in which _e_x_p_r_e_s_s_i_o_n is
58: found.
59:
60: -nn Prefix each line in which _e_x_p_r_e_s_s_i_o_n is found with its line
61: number in the file.
62:
63:
64: COHERENT Lexicon Page 1
65:
66:
67:
68:
69: cgrep Command cgrep
70:
71:
72:
73:
74: -rr Replace all expression matches with _n_e_w. This option may
75: not be used with any others, and it can only match simple
76: tokens, not items like ppttrr->vvaall. When -rr is used and the
77: input is ssttddiinn, a new file will always be created as ssttddoouutt.
78:
79: -ss Print all strings in each _f_i_l_e. This form takes no
80: expression.
81:
82: -AA Write all lines in which _e_x_p_r_e_s_s_i_o_n is found into a
83: temporary file. Then, call MicroEMACS with its error option
84: to process the source file, with the contents of the
85: temporary file serving as an ``error'' list. This option
86: resembles the -AA option to the cccc command, and lets you
87: build a MicroEMACS script to make systematic changes to the
88: source file. To exit MicroEMACS and prevent ccggrreepp from
89: searching further, <ccttrrll-UU> <ccttrrll-XX> <ccttrrll-CC>.
90:
91: ***** Examples *****
92:
93: The command
94:
95:
96: cgrep tmp *.c
97:
98:
99: will find the variable name ttmmpp, but not ttmmppnnaammee, or any
100: occurrence of ttmmpp in a string or comment.
101:
102: The script
103:
104:
105: cgrep -c < myfile.c | wc -l
106:
107:
108: count the lines of comments in mmyyffiillee.cc.
109:
110: The command
111:
112:
113: cgrep "x|abc|d" *.c
114:
115:
116: will find xx, aabb, dd. Note this is a regular expressions with a
117: surrounding ``^( )$'' which is applied to every identifier.
118: Thus, rreegg* will not match rreeggiisstteerr, but rreegg.* will.
119:
120: ***** See Also *****
121:
122: ccoommmmaannddss, eeggrreepp, ggrreepp, mmee
123:
124:
125:
126:
127:
128:
129:
130: COHERENT Lexicon Page 2
131:
132:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.