Click here to Skip to main content
15,891,688 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Everybody,

I am new to python and trying to learn it while working.

I need to find out the function name along with the parameters from a list of "*.C" Files using python regular expressions.

Example:
static void FunctionNameInC(const boolean_T *UnitDelay1_l, const
    boolean_T *UnitDelay2_n)
{


Desired output is :
Function Name: FunctionNameInC
ParametrsList: const boolean_T *UnitDelay1_l, const
    boolean_T *UnitDelay2_n


So far what I have tried is
import re
result=re.findall(r'\(\w+','static void FunctionNameInC(const boolean_T *UnitDelay1_l, const boolean_T *UnitDelay2_n)')
print result 


output:
['(const']

which is far from acceptable,how to proceed with this?

(1) Problems I am facing, how do I recognize any line in a "*.c" file as a function definition . I thought of using the sequence "){" as identifying a function name,but my "C" code format is inconsistent at times it is
"){"
and at times it is
")\n{"
, how do I solve this issue in regex expression ,cause when I tried using in between
'\(\n\w+'
it failed horribly.
(2) Assuming problem 1 is over ,how will I backtrack in the string to print the function name,although I have tried using the
"^"
thing ,but to no success.

Any help is highly appreciated.

Regards
Nihar.

What I have tried:

So far what I have tried is
<pre>import re
result=re.findall(r'\(\w+','static void FunctionNameInC(const boolean_T *UnitDelay1_l, const boolean_T *UnitDelay2_n)')
print result 


output:
['(const']
Posted
Comments
Richard MacCutchan 8-Oct-18 11:30am    
Functions in C are reasonably free form so it is unlikely that you can create a regex to catch every variation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900