Scroll to navigation

coccigrep(1) General Commands Manual coccigrep(1)


coccigrep - semantic grep for the C programming language


coccigrep [OPTIONS] -t TYPE [FILE...]


coccigrep is a semantic grep for the C programming language. It is based on coccinelle and can be used to find where a given structure is used in C source files. coccigrep depends on the spatch program which comes with coccinelle.


Display options

Print NUM lines of trailing context after matching line.
Print NUM lines of leading context before matching line.
Colorize output (needs pygments).
Print NUM lines of output context.
Colorize format for output. FORMAT is term or html.

Search options

Match operations that involve the field ATTRIBUTE of the structure given with option -t.
Activate coccinelle C++ support.
Specify the kind of operation to look for. The available values for OPERATION are:

Any access to an ATTRIBUTE.
Any function call for which one of the parameters is of type TYPE (as defined with -t). In this operation, the option -a sets the name of the function to match and does not refer to an attribute.
Any operation wich changes the value of an ATTRIBUTE.
Any boolean test where an ATTRIBUTE appears.
Any statement where the type TYPE (as defined with -t) appears. This OPERATION does not need to look for an ATTRIBUTE thus it ignores option -a.

The default operation is used if -a is not given, or deref if it is. Depending on your environment, more OPERATIONs may be available. See option -L for information about OPERATION listing.

C type to look for.

Editor options

Emacs output.
Vim output.

Program information

Print usage message and exit.
List available OPERATIONs. Use together with -v to get detailed information about listed OPERATIONs.
Verbose output (including coccinelle errors).
Print the version number of coccigrep.

Other options

Number of cpus to use.
Semantic patch to use.
File containing a list of input files.


The operation option could lead to some missed match because the semantic patches used internally may need some improvements. Use options -L together with -v to get detailed information about available operations.

Please report issues to <>. All ideas are welcome.


1. Find where in a set of files the structure Packet is used:
	$ coccigrep -t Packet *c

2. Finds where in a set of files the datalink attribute is used in the structure Packet: $ coccigrep -t Packet -a datalink *c
3. Finds where the datalink attribute of Packet is set: $ coccigrep -t Packet -a datalink -o set source*c


~/.coccigrep Configuration file for coccigrep.



Project homepage: <>

October 16, 2011 version 1.3