简体   繁体   中英

Regex for greping C type definition

I have a big bunch of source files and I want to grep through it to find the definition of a specific user-defined type dev_if_type_t . All I know about it so far it's that some functions in the code I'm examining use it as a return value.

Right now I'm using the following:

typedef.*dev_if_type_t|(define|typedef|enum|struct)\s*dev_if_type_t

but it returns no results. Is there another method of C type definition I'm neglecting to mention?

The grep line itself, in the code base's top directory:

grep -rn "typedef.*dev_if_type_t\|\(define\|typedef\|enum\|struct\)\s*dev_if_type_t" *

There could be much more variants of the definition like:

typedef struct {
    /* some code */
} dev_if_type_t;

Some code could also look like this:

#define \
dev_if_type_t int

struct
dev_if_type_t
{
    /* some code */
};

You'll never know.
I would suggest you try it just with grepping dev_if_type_t and using the context option -C <num> of grep to find the definition by yourself.

When using expressions including | don't forget to use egrep (deprecated) or the proper command grep -E ... .

Note that \\| and \\( has a different meaning. Use | and ( for your purpose.

So the correct pattern should be:

grep -Ern "typedef.*dev_if_type_t|(define|typedef|enum|struct)\s*dev_if_type_t" *

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM