$ERR_H="cssmerr.h";
$APPLE_ERR_H="cssmapple.h";
$SOURCEDIR=$ARGV[0];
(${D}) = $SOURCEDIR =~ m@([/:])@; sub macintosh() { return ${D} eq ':'; }
if( macintosh() ){
$TARGETDIR=$ARGV[2]; }
else{
$TARGETDIR=$ARGV[1];
}
$TABLES="$TARGETDIR${D}errorcodes.gen";
$tabs = "\t\t\t"; $warning = "This file was automatically generated. Do not edit on penalty of futility!";
open(ERR, "$SOURCEDIR${D}$ERR_H") or die "Cannot open $ERR_H: $^E";
open(APPLE_ERR, "$SOURCEDIR${D}$APPLE_ERR_H") or die "Cannot open $APPLE_ERR_H: $^E";
$/=undef; $errors = <ERR> . <APPLE_ERR>;
$errors =~ tr/\012/\015/ if macintosh;
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(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";
};
print <<MID;
};
static const char * const convErrorList [] = {
MID
for ($n = 0; $n <= $ if ($name = $convErrors[$n]) {
print " \"$name\",\n";
} else {
print " NULL,\n";
};
};
print "};\n";
close(OUT);
select(STDOUT);
$nFull = $$nConv = $print "$nFull errors available to error translation functions.\n";