]>
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
15 (${D
}) = $SOURCEDIR =~ m
@([/:])@; # guess directory delimiter
16 sub macintosh
() { return ${D
} eq ':'; }
19 $TARGETDIR=$ARGV[2]; # directory for outputs
25 $TABLES="$TARGETDIR${D}errorcodes.gen"; # error name tables
27 $tabs = "\t\t\t"; # argument indentation (noncritical)
28 $warning = "This file was automatically generated. Do not edit on penalty of futility!";
32 # Parse CSSM error header and build table of all named codes
34 open(ERR
, "$SOURCEDIR${D}$ERR_H") or die "Cannot open $ERR_H: $^E";
35 open(APPLE_ERR
, "$SOURCEDIR${D}$APPLE_ERR_H") or die "Cannot open $APPLE_ERR_H: $^E";
36 $/=undef; # big gulp mode
37 $errors = <ERR
> . <APPLE_ERR
>;
38 $errors =~ tr/\012/\015/ if macintosh
;
39 close(ERR
); close(APPLE_ERR
);
41 @fullErrors = $errors =~ /^\s+CSSMERR_([A-Z_]+)/gm;
42 @convertibles = $errors =~ /^\s+CSSM_ERRCODE_([A-Z_]+)\s*=\s*([0-9xXA-Fa-f]+)/gm;
44 while ($name = shift @convertibles) {
45 $value = shift @convertibles or die;
46 $convErrors[hex $value] = $name;
50 # Now we will generate the error name tables.
52 open(OUT
, ">$TABLES") or die "Cannot write $TABLES: $^E";
57 // CSSM error code tables.
60 static const Mapping errorList[] = {
62 foreach $name (@fullErrors) {
63 print " { CSSMERR_$name, \"$name\" },\n";
68 static const char * const convErrorList [] = {
70 for ($n = 0; $n <= $#convErrors; $n++) {
71 if ($name = $convErrors[$n]) {
72 print " \"$name\",\n";
82 $nFull = $#fullErrors + 1;
83 $nConv = $#convertibles + 1;
84 print "$nFull errors available to error translation functions.\n";