michael@0: #!perl -w michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: use strict; michael@0: michael@0: my %constants; michael@0: my $count = 0; michael@0: my $o; michael@0: my @objects = (); michael@0: my @objsize; michael@0: michael@0: $constants{CKO_DATA} = "static const CK_OBJECT_CLASS cko_data = CKO_DATA;\n"; michael@0: $constants{CK_TRUE} = "static const CK_BBOOL ck_true = CK_TRUE;\n"; michael@0: $constants{CK_FALSE} = "static const CK_BBOOL ck_false = CK_FALSE;\n"; michael@0: michael@0: while(<>) { michael@0: my @fields = (); michael@0: my $size; michael@0: michael@0: s/^((?:[^"#]+|"[^"]*")*)(\s*#.*$)/$1/; michael@0: next if (/^\s*$/); michael@0: michael@0: # This was taken from the perl faq #4. michael@0: my $text = $_; michael@0: push(@fields, $+) while $text =~ m{ michael@0: "([^\"\\]*(?:\\.[^\"\\]*)*)"\s? # groups the phrase inside the quotes michael@0: | ([^\s]+)\s? michael@0: | \s michael@0: }gx; michael@0: push(@fields, undef) if substr($text,-1,1) eq '\s'; michael@0: michael@0: if( $fields[0] =~ /BEGINDATA/ ) { michael@0: next; michael@0: } michael@0: michael@0: if( $fields[1] =~ /MULTILINE/ ) { michael@0: $fields[2] = ""; michael@0: while(<>) { michael@0: last if /END/; michael@0: chomp; michael@0: $fields[2] .= "\"$_\"\n"; michael@0: } michael@0: } michael@0: michael@0: if( $fields[1] =~ /UTF8/ ) { michael@0: if( $fields[2] =~ /^"/ ) { michael@0: ; michael@0: } else { michael@0: $fields[2] = "\"" . $fields[2] . "\""; michael@0: } michael@0: michael@0: my $scratch = eval($fields[2]); michael@0: michael@0: $size = length($scratch) + 1; # null terminate michael@0: } michael@0: michael@0: if( $fields[1] =~ /OCTAL/ ) { michael@0: if( $fields[2] =~ /^"/ ) { michael@0: ; michael@0: } else { michael@0: $fields[2] = "\"" . $fields[2] . "\""; michael@0: } michael@0: michael@0: my $scratch = $fields[2]; michael@0: $size = $scratch =~ tr/\\//; michael@0: # no null termination michael@0: } michael@0: michael@0: if( $fields[1] =~ /^CK_/ ) { michael@0: my $lcv = $fields[2]; michael@0: $lcv =~ tr/A-Z/a-z/; michael@0: if( !defined($constants{$fields[2]}) ) { michael@0: $constants{$fields[2]} = "static const $fields[1] $lcv = $fields[2];\n"; michael@0: } michael@0: michael@0: $size = "sizeof($fields[1])"; michael@0: $fields[2] = "&$lcv"; michael@0: } michael@0: michael@0: if( $fields[0] =~ /CKA_CLASS/ ) { michael@0: $count++; michael@0: $objsize[$count] = 0; michael@0: } michael@0: michael@0: @{$objects[$count][$objsize[$count]++]} = ( "$fields[0]", $fields[2], "$size" ); michael@0: michael@0: # print "$fields[0] | $fields[1] | $size | $fields[2]\n"; michael@0: } michael@0: michael@0: doprint(); michael@0: michael@0: sub dudump { michael@0: my $i; michael@0: for( $i = 1; $i <= $count; $i++ ) { michael@0: print "\n"; michael@0: $o = $objects[$i]; michael@0: my @ob = @{$o}; michael@0: my $l; michael@0: my $j; michael@0: for( $j = 0; $j < @ob; $j++ ) { michael@0: $l = $ob[$j]; michael@0: my @a = @{$l}; michael@0: print "$a[0] ! $a[1] ! $a[2]\n"; michael@0: } michael@0: } michael@0: michael@0: } michael@0: michael@0: sub doprint { michael@0: my $i; michael@0: michael@0: print <