Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Problem of finding funtion names in any C file

Reply
Thread Tools

Problem of finding funtion names in any C file

 
 
athif2@gmail.com
Guest
Posts: n/a
 
      03-10-2006
I want to be able to find function names from any C file and use that
information to form a hierarchical function call tree, with details on
which line number, file name the function is in. I would like it to
print this function call tree to the console prompt or a file.
Eg;
C file, test.c:

1 int func1()
2 {
3 func3();
4 }
5
6 int func2()
7 {
8 func4();
9 func5();
10 }
11
12
13 int main()
14 {
15
16 func1();
17 func2();
18
19 return 0;
20 }

The function call tree after processing above C file should be :

+main() (line=13, file=test.c)
|_____func1(line=16, file=test.c)
| |_____func3(line=3, file=test.c)
|
|_____func2(line=17, file=test.c)
|_____func4(line=8, file=test.c)
|_____func5(line=9, file=test.c)

If already some tool provides such a listing it would fit my need ?
Any shortcuts to tackle this problem are welcome.

 
Reply With Quote
 
 
 
 
Rod Pemberton
Guest
Posts: n/a
 
      03-10-2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> "Jaspreet" <(E-Mail Removed)> wrote in message

news:(E-Mail Removed) oups.com...
> > Why reinvent the wheel when you have so many wheel manufacturers
> > around. You could use any of the freely available parsers (like ctags).
> > I have been using cscope though.

>
> > I dont know much of ctags but cscope does exactly that (print function
> > name, line number, file name) when it finds a function calling instance
> > in a file.

>
> I want to be able to find function names from any C file and use that
> information to form a hierarchical function call tree, with details on
> which line number, file name the function is in. I would like it to
> print this function call tree to the console prompt or a file.


As Jaspreet pointed out, there are a large number of parsers available.
Some of the specialized ones are check, cproto, cdecl, ctool, cxref, etc. I
think cxref is one of the ones you want. I recall there being another
program on DECUS which would build a complete searchable database from your
source, but I don't know what it was called. Most of these are available
from comp.sources.unix or DECUS.

comp.sources.unix, cxref is in volume1:
http://ftp.sunet.se/pub/usenet/ftp.u....sources.unix/

DECUS:
Index (files unavailable) http://www.decus.org/encompass/software/
Files ftp://ftp.encompassus.org/lib/


Rod Pemberton



 
Reply With Quote
 
 
 
 
athif2@gmail.com
Guest
Posts: n/a
 
      03-11-2006
Thank you all very much for the wealth of information!

 
Reply With Quote
 
Netocrat
Guest
Posts: n/a
 
      03-11-2006
On Fri, 10 Mar 2006 11:33:05 -0500, CBFalconer wrote:
> Netocrat wrote:
>> Keith Thompson wrote:
>>

> ... snip on parsing function names ...
>>>
>>> You'll also miss some legal occurences of function names like:
>>> (printf)("Hello, world\n");
>>> and catch some occurrences of names of function pointer objects.

>>
>> You could also get false positives from string literals:
>> char help_msg[] = "Declare the prototype as int somefunc(int);";

>
> Not if you make the lexical scanner handle complete strings in the first
> place. Pseudocode:
>
> while (EOF != (ch = getnextch())) {
> switch (chclass(ch)) {
> case alpha:
> case '_': acquireid(); break;
> case '"': acquirestring(); break;
> case ' ': break;
> ....
> }
> }


Sure, there are ways to handle it, but as the suggestion stood there were
a few holes. You'd also need to make sure that the scanner didn't count
double-quotes within comments.

--
http://members.dodo.com.au/~netocrat

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
Can I passing a funtion pointer to a FUNTION which point to THE FUNTION? Lee Xuzhang C Programming 5 06-14-2006 06:31 PM
Funtion Problem Steve Bishop Javascript 2 02-11-2004 09:11 PM
Is there a good alternative to Outlook calendar/appointent funtion in a standalone program? say@no.to.spam Computer Support 13 11-26-2003 10:33 AM
Duplicate funtion names - what happens? Randell D. Javascript 5 11-03-2003 08:35 PM



Advertisments