]>
Commit | Line | Data |
---|---|---|
bac41a7b A |
1 | #!/usr/bin/perl |
2 | # | |
3 | # generator.pl - derive various and sundry C++ code from the CDSA header files | |
4 | # | |
5 | # Usage: | |
6 | # perl generator.pl input-directory output-directory | |
7 | # | |
8 | # Perry The Cynic, Fall 1999. | |
9 | # | |
10 | $ERR_H="cssmerr.h"; | |
11 | $APPLE_ERR_H="cssmapple.h"; | |
12 | ||
13 | $SOURCEDIR=$ARGV[0]; # directory with inputs | |
14 | ||
15 | (${D}) = $SOURCEDIR =~ m@([/:])@; # guess directory delimiter | |
16 | sub macintosh() { return ${D} eq ':'; } | |
17 | ||
18 | if( macintosh() ){ | |
19 | $TARGETDIR=$ARGV[2]; # directory for outputs | |
20 | } | |
21 | else{ | |
22 | $TARGETDIR=$ARGV[1]; | |
23 | } | |
24 | ||
25 | $TABLES="$TARGETDIR${D}errorcodes.gen"; # error name tables | |
26 | ||
27 | $tabs = "\t\t\t"; # argument indentation (noncritical) | |
28 | $warning = "This file was automatically generated. Do not edit on penalty of futility!"; | |
29 | ||
30 | ||
31 | # | |
32 | # Parse CSSM error header and build table of all named codes | |
33 | # | |
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); | |
40 | ||
41 | @fullErrors = $errors =~ /^\s+CSSMERR_([A-Z_]+)/gm; | |
42 | @convertibles = $errors =~ /^\s+CSSM_ERRCODE_([A-Z_]+)\s*=\s*([0-9xXA-Fa-f]+)/gm; | |
43 | ||
44 | while ($name = shift @convertibles) { | |
45 | $value = shift @convertibles or die; | |
46 | $convErrors[hex $value] = $name; | |
47 | }; | |
48 | ||
49 | # | |
50 | # Now we will generate the error name tables. | |
51 | # | |
52 | open(OUT, ">$TABLES") or die "Cannot write $TABLES: $^E"; | |
53 | select OUT; | |
54 | ||
55 | print <<HDR; | |
56 | // | |
57 | // CSSM error code tables. | |
58 | // $warning | |
59 | // | |
60 | static const Mapping errorList[] = { | |
61 | HDR | |
62 | foreach $name (@fullErrors) { | |
63 | print " { CSSMERR_$name, \"$name\" },\n"; | |
64 | }; | |
65 | print <<MID; | |
66 | }; | |
67 | ||
68 | static const char * const convErrorList [] = { | |
69 | MID | |
70 | for ($n = 0; $n <= $#convErrors; $n++) { | |
71 | if ($name = $convErrors[$n]) { | |
72 | print " \"$name\",\n"; | |
73 | } else { | |
74 | print " NULL,\n"; | |
75 | }; | |
76 | }; | |
77 | print "};\n"; | |
78 | ||
79 | close(OUT); | |
80 | select(STDOUT); | |
81 | ||
82 | $nFull = $#fullErrors + 1; | |
83 | $nConv = $#convertibles + 1; | |
84 | print "$nFull errors available to error translation functions.\n"; |