LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

program to get list of functions in a *.C file

I want to write a C program in labwindows to read the list of functions available in a *.c file. Can any one help me with the logic/ program for the same.
0 Kudos
Message 1 of 7
(4,016 Views)
There's a tool that already does this in CVI - it's the compiler 🙂

How are you going to identify function declarations unless you fully parse the file?

I think you can get the CVI compiler to put out a symbol table, or you could use the source browser - I imagine it uses the compiler to construct its call trees.  Maybe you can invoke the compiler programmatically (there's an ActiveX controler for it now) and get it to dump the functions into a map or log file.

Menchar
0 Kudos
Message 2 of 7
(3,980 Views)
I actually need a program to do this. I do not want to use the compiler to do this. The program will be used as a separate standalone utility, which will  be used by another project. Ultimately the entire project  will go into a distribution kit.
0 Kudos
Message 3 of 7
(3,971 Views)
You might have a look at a cross referencing tool like cxref ( http://www.gedanken.demon.co.uk/cxref/ ) .
0 Kudos
Message 4 of 7
(3,966 Views)

One method is to parse the C file as a compiler does, looking for the list of symbols that make up the declaration section of the c function.  For example,

<type> <fn name> ( <type> <var name> ....) {

It might be sufficient to just detect "<type><fn name> (", this might be sufficient to be uniquely identified as a function.

For this you can use the ANSI character manipulation commands in CVI.

Pseudocode for a simple parser:

open file as a stream
while not EOF, get next character {
    build characters into a recognizable token, which could be a <type>, a <fn name>, a symbol "(){},;"
    once a sequence of tokens is recognized that matches the target <type><fn name>(, then you have found a function name --> handle this
    if no sequence of interest, and if the detected sequence is handled, let while loop repeat until EOF 
}
close the input file

Best regards,

KC

 

 

 

0 Kudos
Message 5 of 7
(3,950 Views)
You might also want to find a good book or article on compiler design, to talk about the aspects of parsing that will apply to what you are doing, such as handling whitespace, etc.  Best of luck!
0 Kudos
Message 6 of 7
(3,947 Views)

Following on in the same theme, Googling for C parser finds any number of hits on the web, many of which are free to use (depending on circumstances). If I were you, I'd pick a couple that looked as if they were close to what you wanted to do and see if you could modify them appropriately.

 

--
Martin
Certified CVI Developer
0 Kudos
Message 7 of 7
(3,934 Views)