- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- extract info from C header files
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2005 08:51 AM
тАО03-11-2005 08:51 AM
extract info from C header files
I've looked at PERL modules but I can't find anything that does this simply.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2005 03:56 AM
тАО03-13-2005 03:56 AM
Re: extract info from C header files
How about using the C compiler to generate a full listing with symbols and just parse that output?
For example a C source with:
$ type tmp.c
#include
#include
and a perl parser:
$ type h.pl
print "\n-- $1 --\n" if (/\sTag: (struct \w+)/);
if (/(\s*)(\S+)\s+\d+\s+(\d+\s\s|\d+\sbits).*Offset=([\.0-9]+).*\)\s+(.*)$/) {
$union_offset = $4."+" if ($5 eq "union ");
$union = (length($1) > 1) ? $union_offset : "";
printf "$1$2/$5/$3/$union$4\n";
}
With the following command:
$ pipe cc/list=sys$output/show=symbols tmp | perl -n h.pl
Will deliver:
-- struct fabdef --
fab$b_bid/unsigned char /1 /0
fab$b_bln/unsigned char /1 /1
fab$r_ifi_overlay/union /2 /2
fab$w_ifi/unsigned short /2 /2+0
:
fabdef$$_fill_9/unsigned int /4 /76
-- struct namdef --
-- struct rab64def --
rab64$b_bid/unsigned char /1 /0
rab64$b_bln/unsigned char /1 /1
:
rab64$r_rfa_overlay/union /6 /16
rab64$w_rfa/array of unsigned short /6 /16+0
rab64$r_rfa_fields/struct /6 /16+0
rab64$l_rfa0/unsigned int /4 /16+0
rab64$w_rfa4/unsigned short /2 /16+4
:
Now there are may be a few things to potentially fixup, around dealing spaces, and with bits and offsets in unions, but maybe this is all you need already ?!
If you do want more, your first step will probably be to put the 'automatic' $1 .. $5 variables in names variables like:
$spaces=$1; $name=$2; $size=$3; $offset=$4; $type=$5
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2005 02:08 AM
тАО03-14-2005 02:08 AM
Re: extract info from C header files
Regards, Barry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2005 07:48 AM
тАО03-14-2005 07:48 AM
Re: extract info from C header files
>> This is a little deep for me
Ooops, I read "I've looked at PERL modules" and assumed a certain familirity.
The example given should work. Does it not?
Anyway, let me explain a little bit.
The C listing file, when /show=symb is active will have entries like:
#fabdef 399 80 Long Tag: struct fabdef
# fab$b_bid 401 1 Byte Member: (Offset=0) unsigned char
# fab$b_bln 402 1 Byte Member: (Offset=1) unsigned char
# fab$r_ifi_overlay 412 2 Byte Member: (Offset=2) union
# fab$r_ifi_bits 411 2 Byte Member: (Of
fset=0) struct
So now for the script. First the struct name. This is picked up by:
print "\n-- $1 --\n" if (/\sTag: (struct \w+)/);
Find the text "Tag: "... start remembering "(" if there is "struct " followed by some number of word characters (\w+). Stop remembering ")". Print what was remembered in $1.
If we wanted the structure size, the change the line to look for decimals (line number), whitspace (\s+) and remember the next set of decimals: ( (\d+) ):
print "\n-- $2 -- $1 bytes --\n" if (/\d+\s+(\d+).*Tag: (struct \w+)/);
and it will print:
-- struct fabdef -- 80 bytes --
The main line is admittedly convoluted.
if (/(\s*)(\S+)\s+\d+\s+(\d+\s\s|\d+\sbits).*Offset=([\.0-9]+).*\)\s+(.*)$/) {
Here are some parts:
(\s*) = Remember the first whitespace in $1
(\S+) = Remember the non-whitespace (name!) in $2
\s+\d+\s+ = look for, but ignore whitespace-decimal-whitespace
(\d+\s\s|\d+\sbits) = Look for and remember in $3 (size!) some decimals + whitespace OR decimals plust " bits"
.*Offset=([\.0-9]+).*\) = 'anything' followed by "Offset=" then remember in $4 (offset) any sequence of numbers or a period
\s+(.*)$/ = finally look for a space (after those numbers) then remember everything up to the end of line in $5 (type).
The next lines deal with the fact that the listing counts offsets from union starting with 0 in that union.
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2005 07:59 AM
тАО03-14-2005 07:59 AM
Re: extract info from C header files
I've worked with regular expressions but have never had the courage to do one this complex...mine are in a million steps!
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2005 05:24 PM
тАО03-14-2005 05:24 PM
Re: extract info from C header files
http://kodos.sourceforge.net/
see an example at
http://kodos.sourceforge.net/help/example.html
ps: ignore my attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2005 04:24 AM
тАО03-17-2005 04:24 AM