]>
Commit | Line | Data |
---|---|---|
b1ab9ed8 A |
1 | #!/usr/bin/perl |
2 | # | |
3 | # Copyright (c) 2003-2004 Apple Computer, Inc. All Rights Reserved. | |
4 | # | |
5 | # @APPLE_LICENSE_HEADER_START@ | |
6 | # | |
7 | # This file contains Original Code and/or Modifications of Original Code | |
8 | # as defined in and that are subject to the Apple Public Source License | |
9 | # Version 2.0 (the 'License'). You may not use this file except in | |
10 | # compliance with the License. Please obtain a copy of the License at | |
11 | # http://www.opensource.apple.com/apsl/ and read it before using this | |
12 | # file. | |
13 | # | |
14 | # The Original Code and all software distributed under the License are | |
15 | # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
16 | # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
17 | # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
18 | # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
19 | # Please see the License for the specific language governing rights and | |
20 | # limitations under the License. | |
21 | # | |
22 | # @APPLE_LICENSE_HEADER_END@ | |
23 | # | |
24 | # generatorX.pl - create error strings files from the Security header files | |
25 | # | |
26 | # Usage: | |
27 | # perl generatorX.pl input-directory output-directory <files> | |
28 | # | |
29 | # Currently supported files are SecBase.h, SecureTransport.h and Authorization.h | |
30 | # | |
31 | # perl generatorX.pl `pwd` `pwd` SecBase2.h SecureTransport2.h Authorization.h | |
32 | # | |
33 | # Input will be like: | |
34 | # | |
35 | # errSSLProtocol = -9800, /* SSL protocol error */ | |
36 | # errSSLNegotiation = -9801, /* Cipher Suite negotiation failure */ | |
37 | # | |
38 | # Output should be like (in Unicode): | |
39 | # | |
40 | # /* errSSLProtocol */ | |
41 | # "-9800" = "SSL protocol error"; | |
42 | # | |
43 | # /* errSSLNegotiation */ | |
44 | # "-9801" = "Cipher Suite negotiation failure"; | |
45 | # | |
46 | # Note that the list of errors must be numerically unique across all input files, or the strings file | |
47 | # will be invalid.Comments that span multiple lines will be ignored, as will lines with no comment. C++ | |
48 | # style comments are not supported. | |
49 | # | |
50 | ||
51 | use Encode; | |
52 | ||
53 | $SOURCEDIR=$ARGV[0]; # directory with error headers | |
54 | $TARGETDIR=$ARGV[1]; # where to put the output file | |
55 | @INPUTFILES=@ARGV[2 .. 9999]; # list of input files | |
56 | ||
57 | $TABLES="$TARGETDIR/SecErrorMessages.strings"; # error strings | |
58 | ||
59 | $tabs = "\t\t\t"; # argument indentation (noncritical) | |
60 | $warning = "This file was automatically generated. Do not edit on penalty of futility!"; | |
61 | ||
62 | # | |
63 | # Parse error headers and build array of all relevant lines | |
64 | # | |
65 | ||
66 | open(ERR, "cat " . join(" ", @INPUTFILES) . "|") or die "Cannot open error header files"; | |
67 | $/=undef; # big gulp mode | |
68 | $_ = <ERR>; | |
69 | @errorlines = m{(?:^\s*)(err[Sec|Authorization|SSL]\w+)(?:\s*=\s*)(-?\d+)(?:\s*,?\s*)(?:/\*\s*)(.*)(?:\*/)(?:$\s*)}gm; | |
70 | close(ERR); | |
71 | ||
72 | $nFull = $#errorlines / 3; | |
73 | ||
74 | # | |
75 | # Now we will generate the error name tables. | |
76 | # | |
77 | open(OUT, ">$TABLES") or die "Cannot write $TABLES: $^E"; | |
78 | ||
79 | # Print warning comment | |
80 | $msg = "//\n// Security error code tables.\n// $warning\n//\n"; | |
81 | ||
82 | # Print the error messages | |
83 | while ($errx = shift @errorlines) | |
84 | { | |
85 | $value = shift @errorlines; # or die; | |
86 | $str = shift @errorlines; # or die; | |
87 | $str =~ s/\s*$//; # drop trailing white space | |
88 | if ( $value != 0) # can't output duplicate error codes | |
89 | { | |
90 | $msg = $msg . "\n/* $errx */\n\"$value\" = \"$str\";\n"; | |
91 | } | |
92 | }; | |
93 | $msg = $msg . "\n"; | |
94 | $output = encode("UTF-16", $msg, Encode::FB_PERLQQ); | |
95 | print OUT "$output"; | |
96 | ||
97 | close(OUT); | |
98 | select(STDOUT); |