The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
SSH doesn't pick up user's project from /etc/project kurgan SUN Solaris 2 05-21-2008 09:52 AM
Repository Backup Using Unix MANISH KU UNIX for Advanced & Expert Users 0 07-04-2007 10:34 PM
backup repository in cvs murad.jaber SUN Solaris 9 06-03-2007 04:15 AM
How to count the record count in an EBCDIC file. oracle8 UNIX for Dummies Questions & Answers 1 07-26-2006 04:22 PM
Repository of HP-UX 10.20 packages markos UNIX for Dummies Questions & Answers 1 03-05-2005 03:54 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-13-2005
Registered User
 

Join Date: Jan 2005
Posts: 29
how to count # of functions in a c/c++ project repository

hi,
does anyone know how to count # of functions in a c/c++ project repository using bash or csh?
is there a mixture of grep/wc/and redirecting operators.

say for instance there is a proj directory called Foo with subfolders A,B,C.
Reply With Quote
Forum Sponsor
  #2  
Old 05-16-2005
Registered User
 

Join Date: Feb 2005
Location: Coimbatore, Tamilnadu, India
Posts: 119
You can try as,

find <dir> -name "*.c" | xargs grep "();" | wc

Try out.
Reply With Quote
  #3  
Old 05-16-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
muthu,

Wouldnt your query look for zero argument functions ?

I was thinking of something on the lines of ctags.

Have to read up the man page of ctags.

Vino
Reply With Quote
  #4  
Old 05-16-2005
Registered User
 

Join Date: Feb 2005
Location: Coimbatore, Tamilnadu, India
Posts: 119
I am sorry. It will not work. One simple way is, if you use debugging symbols in object then you can use gdb <object> gdb> info function
it will give.

Using bash have to think some good ways.
Reply With Quote
  #5  
Old 05-16-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Try this

ctags --c-types=f *.c

will produce a tags file.

cat tags | wc -l

Since there are some extra lines in tags( i think 4-5 lines), this will give you a close count.

vino
Reply With Quote
  #6  
Old 05-16-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
This should work.

Current directory is your foo directory:

Code:
prompt> ctags --c-types=f -R
prompt> sed -e '/[ ]*m$/d' -e '/TAG/d' <tags>functions
prompt> cat functions | wc -l
Explanation for the above.

ctags with --c-types=f will collect all the functions for you.

-R will recursivly go into sub-dir a,b,c.

sed is needed to remove the TAG entries introduced by ctags
Also to remove all lines ending with m i.e.
from man ctags
m class, struct, or union members


functions is the file that holds all the functions under foo

And finally wc -l gives you the count you are looking for.

Have a look at man ctags. Will help you if you have constraints other than functions.

Vino
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0