]>
git.saurik.com Git - apple/security.git/blob - Security/libsecurity_cdsa_utilities/lib/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 cdsa headers
14 $TARGETDIR=$ARGV[1]; # where to put the output file
15 @INPUTFILES=@ARGV[2 .. 9999]; # list of input files
17 $TABLES="$TARGETDIR/errorcodes.gen"; # error name tables
19 $tabs = "\t\t\t"; # argument indentation (noncritical)
20 $warning = "This file was automatically generated. Do not edit on penalty of futility!";
24 # Parse CSSM error header and build table of all named codes
26 open(ERR
, "$SOURCEDIR/$ERR_H") or die "Cannot open $ERR_H: $^E";
27 open(APPLE_ERR
, "$SOURCEDIR/$APPLE_ERR_H") or die "Cannot open $APPLE_ERR_H: $^E";
28 $/=undef; # big gulp mode
29 $errors = <ERR
> . <APPLE_ERR
>;
30 close(ERR
); close(APPLE_ERR
);
32 @fullErrors = $errors =~ /^\s+CSSMERR_([A-Z_]+)/gm;
33 @convertibles = $errors =~ /^\s+CSSM_ERRCODE_([A-Z_]+)\s*=\s*([0-9xXA-Fa-f]+)/gm;
35 while ($name = shift @convertibles) {
36 $value = shift @convertibles or die;
37 $convErrors[hex $value] = $name;
42 # Read Keychain-level headers for more error codes (errSecBlahBlah)
44 open(ERR
, "cat " . join(" ", @INPUTFILES) . "|") or die "Cannot open error header files";
45 $/=undef; # still gulping
47 @kcerrors = /err((?:Sec|Authorization)\w+)\s*=\s*-?\d+/gm;
52 # Now we will generate the error name tables.
54 open(OUT
, ">$TABLES") or die "Cannot write $TABLES: $^E";
59 // CSSM error code tables.
62 static const Mapping errorList[] = {
64 foreach $name (@fullErrors) {
65 print " { CSSMERR_$name, \"$name\" },\n";
67 foreach $err (@kcerrors) {
68 print " { err$err, \"$err\" },\n";
73 static const char * const convErrorList [] = {
75 for ($n = 0; $n <= $#convErrors; $n++) {
76 if ($name = $convErrors[$n]) {
77 print " \"$name\",\n";
87 $nFull = $#fullErrors + 1;
88 $nConv = $#convertibles + 1;
89 print "$nFull errors available to error translation functions.\n";