I want to extract comments and want to know from which functions they are. I have lots of such C files as below:
With input:
void main()
{
    //sdgs
    call A;
    /*
    sdfgs
    dfhdfh
    */
    call b;
    some code;
}
/* this function adds
 something */
int add()
{
    //sgsd
    some code;
    //more comments
    some code;
}
Output should be:
void main()
{
    //sdgs
    /*
    sdfgs
    dfhdfh
    */
}
/* this function adds
 something */
int add()
{
    //sgsd
    //more comments
}
Input code is neatly formatted and 'function code' starts after { at next line.
Basically, I just need to know which 'comment' is from which function. Also it should include any other comments above function name or elsewhere. Note: this is different as function names at top level should be there.
To simplify my requirements:
- Print all comments
 - Detect a block containing 
(on the first line, with a single line containing only{at first column after one to three lines and print the lines immediately above.