Reputation: 1144
I need to extract the names of functions defined in a C source file given as parameter to the script. I'm not very familiar to PowerShell but shouldn't be something like this:
If ($FileExists -eq $True)
{
select-string $args[0] -pattern "\(void\|double\|char\|int\) \.*(.*)"
}
Upvotes: 0
Views: 533
Reputation: 52639
I'd define the list of file extensions that you want to search in and use them in the Include parameter, then pipe to select-string and extract the capturing group matches.
dir -Path C:\c-program -Include *.h, *.c -Recurse | Select-String -Pattern '(void|double|char|int) (\w+)\(' | % {$_.Matches[0].Groups[2].Value}
Here's a canned example using function names from wikipedia:
'void incInt(int *y)','int main(int argc, char* args[])','int subtract(int x, int y)' | Select-String -Pattern '(void|double|char|int) (\w+)\(' | % {$_.Matches[0].Groups[2].Value}
Upvotes: 2