]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/generator.pl
3 # generator.pl - derive various and sundry C++ code from the CDSA header files
6 # perl generator.pl input-directory output-directory
8 # Perry The Cynic, Fall 1999.
11 $APPLE_ERR_H="cssmapple.h";
13 $SOURCEDIR=$ARGV[0]; # directory with inputs
16 $TABLES="$TARGETDIR/errorcodes.gen"; # error name tables
18 $tabs = "\t\t\t"; # argument indentation (noncritical)
19 $warning = "This file was automatically generated. Do not edit on penalty of futility!";
23 # Parse CSSM error header and build table of all named codes
25 open(ERR
, "$SOURCEDIR/$ERR_H") or die "Cannot open $ERR_H: $^E";
26 open(APPLE_ERR
, "$SOURCEDIR/$APPLE_ERR_H") or die "Cannot open $APPLE_ERR_H: $^E";
27 $/=undef; # big gulp mode
28 $errors = <ERR
> . <APPLE_ERR
>;
29 close(ERR
); close(APPLE_ERR
);
31 @fullErrors = $errors =~ /^\s+CSSMERR_([A-Z_]+)/gm;
32 @convertibles = $errors =~ /^\s+CSSM_ERRCODE_([A-Z_]+)\s*=\s*([0-9xXA-Fa-f]+)/gm;
34 while ($name = shift @convertibles) {
35 $value = shift @convertibles or die;
36 $convErrors[hex $value] = $name;
40 # Now we will generate the error name tables.
42 open(OUT
, ">$TABLES") or die "Cannot write $TABLES: $^E";
47 // CSSM error code tables.
50 static const Mapping errorList[] = {
52 foreach $name (@fullErrors) {
53 print " { CSSMERR_$name, \"$name\" },\n";
58 static const char * const convErrorList [] = {
60 for ($n = 0; $n <= $#convErrors; $n++) {
61 if ($name = $convErrors[$n]) {
62 print " \"$name\",\n";
72 $nFull = $#fullErrors + 1;
73 $nConv = $#convertibles + 1;
74 print "$nFull errors available to error translation functions.\n";