$ERR_H="cssmerr.h";
$APPLE_ERR_H="cssmapple.h";
$SOURCEDIR=$ARGV[0]; $TARGETDIR=$ARGV[1]; @INPUTFILES=@ARGV[2 .. 9999];
$TABLES="$TARGETDIR/errorcodes.gen";
$tabs = "\t\t\t"; $warning = "This file was automatically generated. Do not edit on penalty of futility!";
open(ERR, "$SOURCEDIR/$ERR_H") or die "Cannot open $ERR_H: $^E";
open(APPLE_ERR, "$SOURCEDIR/$APPLE_ERR_H") or die "Cannot open $APPLE_ERR_H: $^E";
$/=undef; $errors = <ERR> . <APPLE_ERR>;
close(ERR); close(APPLE_ERR);
@fullErrors = $errors =~ /^\s+CSSMERR_([A-Z_]+)/gm;
@convertibles = $errors =~ /^\s+CSSM_ERRCODE_([A-Z_]+)\s*=\s*([0-9xXA-Fa-f]+)/gm;
while ($name = shift @convertibles) {
$value = shift @convertibles or die;
$convErrors[hex $value] = $name;
};
open(ERR, "cat " . join(" ", @INPUTFILES) . "|") or die "Cannot open error header files";
$/=undef; $_ = <ERR>;
@kcerrors = /err((?:Sec|Authorization)\w+)\s*=\s*-?\d+/gm;
close(ERR);
open(OUT, ">$TABLES") or die "Cannot write $TABLES: $^E";
select OUT;
print <<HDR;
//
// CSSM error code tables.
// $warning
//
static const Mapping errorList[] = {
HDR
foreach $name (@fullErrors) {
print " { CSSMERR_$name, \"$name\" },\n";
};
foreach $err (@kcerrors) {
print " { err$err, \"$err\" },\n";
};
print <<MID;
};
static const char * const convErrorList [] = {
MID
for ($n = 0; $n <= $#convErrors; $n++) {
if ($name = $convErrors[$n]) {
print " \"$name\",\n";
} else {
print " NULL,\n";
};
};
print "};\n";
close(OUT);
select(STDOUT);
$nFull = $#fullErrors + 1;
$nConv = $#convertibles + 1;
print "$nFull errors available to error translation functions.\n";