michael@0: #!perl
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:
michael@0: $copyright = '/* THIS IS A GENERATED FILE */
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: ';
michael@0:
michael@0: $count = -1;
michael@0: $i = 0;
michael@0:
michael@0: open(INPUT, "<$ARGV[0]") || die "Can't open $ARGV[0]: $!";
michael@0:
michael@0: while() {
michael@0: s/^((?:[^"#]+|"[^"]*")*)(\s*#.*$)/$1/;
michael@0: next if (/^\s*$/);
michael@0:
michael@0: # print;
michael@0:
michael@0: /^([\S]+)\s+([^"][\S]*|"[^"]*")/;
michael@0: $name = $1;
michael@0: $value = $2;
michael@0:
michael@0: if( ($name =~ "FUNCTION") && !($name =~ "CK_FUNCTION") ) {
michael@0: $count++;
michael@0: $x[$count]{name} = $value;
michael@0: $i = 0;
michael@0: } else {
michael@0: if( $count < 0 ) {
michael@0: $value =~ s/"//g;
michael@0: $g{$name} = $value;
michael@0: } else {
michael@0: $x[$count]{args}[$i]{type} = $name;
michael@0: $x[$count]{args}[$i]{name} = $value;
michael@0: $i++;
michael@0: $x[$count]{nargs} = $i; # rewritten each time, oh well
michael@0: }
michael@0: }
michael@0: }
michael@0:
michael@0: close INPUT;
michael@0:
michael@0: # dodump();
michael@0: doprint();
michael@0:
michael@0: sub dodump {
michael@0: for( $j = 0; $j <= $count; $j++ ) {
michael@0: print "CK_RV CK_ENTRY $x[$j]{name}\n";
michael@0: for( $i = 0; $i < $x[$j]{nargs}; $i++ ) {
michael@0: print " $x[$j]{args}[$i]{type} $x[$j]{args}[$i]{name}";
michael@0: if( $i == ($x[$j]{nargs} - 1) ) {
michael@0: print "\n";
michael@0: } else {
michael@0: print ",\n";
michael@0: }
michael@0: }
michael@0: }
michael@0: }
michael@0:
michael@0: sub doprint {
michael@0: open(PROTOTYPE, ">nssckg.h") || die "Can't open nssckg.h: $!";
michael@0: open(TYPEDEF, ">nssckft.h") || die "Can't open nssckft.h: $!";
michael@0: open(EPV, ">nssckepv.h") || die "Can't open nssckepv.h: $!";
michael@0: open(API, ">nssck.api") || die "Can't open nssck.api: $!";
michael@0:
michael@0: select PROTOTYPE;
michael@0:
michael@0: print $copyright;
michael@0: print <