Friday, 15 February 2013

c - How to count number of lines in a function -



c - How to count number of lines in a function -

i need count number of lines in function in file. have next inputs.

inputs:

name of file, name of function

required output:

number of lines in function

example:

int main() { line1; line2; line3; } int func() { line1 line2 line3 line4 line5 if(---) //line 6 { //line 7 line 8 line 9 } //line10 }

so above illustration should homecoming 10 if pass file name , function name "func"

kindly suggest way it...

code has strict format, indent source files

indent -kr -bap -nce -i8 -ts8 -sob -l80 -ss -bs -npsl -bl -bli0 file.c

awk + substr($0,1,1) match '{' , '}'

awk -f"," '{ if( index(v_func,$0)<10 ) { findfunc=1; } if( findfunc == 1) { if( substr($0,1,1) == "{" ) { linecnt=0; } else if(substr($0,1,1) == "}" ) { print linecnt; } else { linecnt = linecnt+1; } } }' v_func=$2 $1

c perl

No comments:

Post a Comment