Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Using regexes is not reliable, doubly not with egrep, unless you follow some conventions and don't do anything too hard.</p> <p>Consider:</p> <pre><code>void * function( int a, void (*pointer)(const char *, int, double), double d ) </code></pre> <p>This declaration is spread over 6 lines - and egrep only looks at one line at a time.</p> <p>This declaration contains 5 commas and 3 parameters.</p> <p>If you put enough restrictions on the code you are searching, you can probably get an approximation to what you are after, but C and C++ are both very hard to analyze. And I'm not even thinking about macros that invoke the function for you.</p> <hr> <p>Your proposed solution has a number of flaws, even after solving the problem with the extraneous backslashes (diagnosed correctly by Tim Pietzcker):</p> <pre><code>egrep "find" * | egrep "\([^,]*,[^,]*,[^,]*\)" </code></pre> <p>This will discover lines such as:</p> <pre><code>find(1, 2, 3); int extra_find(int a, int b, int c) { ... } extraordinary(find, 3, 21); printf("find: %.*s\n", 13, "heliotrope"); for (find(1); printf("%d %d\n", 1, 2); x++) for (x(find, 1); b &lt; max(c, d); i++) /* find(1,2,3) */ </code></pre> <p>Only one of those is a function definition, and that still isn't one of the outputs you wanted.</p> <p>If you can play with Perl (or Python) or any tool with PCRE (Perl-Compatible Regular Expressions) or equivalent, then you can do things like ensure that on a single line the word 'find' appears followed by an open parenthesis, a sequence of 'type name' values separated by commas and white space, and a close parenthesis.</p> <pre><code>perl -ne 'print if m/\bfind\s*\(\w+\s+\w+(\s*,\s*\w+\s+\w+){2}\s*\)/' </code></pre> <p>But that doesn't handle pointers, arrays, qualifiers like 'const', or pointers to functions (or references, if you are using C++), or structures referenced by 'struct somename varname', or function definitions protected against macro expansion (<code>int (getchar)(int c)</code>), or ... And it still doesn't distinguish between declarations and definitions!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload