]> git.saurik.com Git - apple/security.git/blob - SecurityServer/generate.pl
Security-163.tar.gz
[apple/security.git] / SecurityServer / generate.pl
1 #!/usr/bin/perl
2 #
3 #
4 #
5 use strict;
6
7 my $disclaimer = "Automatically generated - do not edit on penalty of futility!";
8
9
10 # arguments
11 my ($configfile, $out_h, $out_cpp, $types) = @ARGV;
12
13
14 # open configuration file
15 open(CFG, "$configfile") || die "$configfile: $!";
16
17 # open and load cssmtypes file
18 open(TYPES, "$types") || die "$types: $!";
19 $/=undef;
20 my $types_h = <TYPES>;
21 close(TYPES); $/="\n";
22
23 # open output files
24 open(H, ">$out_h") || die "$out_h: $!";
25 open(CPP, ">$out_cpp") || die "$out_cpp: $!";
26
27 # cautionary headings to each file
28 print H <<EOH;
29 //
30 // Flipping bytes for SecurityServer transition.
31 // $disclaimer
32 //
33 EOH
34
35 print CPP <<EOC;
36 //
37 // Flipping bytes for SecurityServer transition.
38 // $disclaimer
39 //
40 EOC
41
42 # process generation instructions
43 while (<CFG>) {
44 chomp;
45 next if /^[ ]*#/;
46 next if /^[ ]*$/;
47
48 my @args = split;
49 $_ = shift @args;
50 my ($cssmName, @aliases) = split /\//;
51
52 print H "void flip($cssmName &obj);\n";
53 for my $alias (@aliases) {
54 print H "inline void flip($alias &obj) { flip(static_cast<$cssmName &>(obj)); }\n";
55 }
56
57 next if ($args[0] eq 'CUSTOM');
58
59 if ($args[0] eq '*') {
60 # extract definition from types file
61 my ($list) = $types_h =~ /{\s+([^}]+)\s+}\s*$cssmName,/;
62 die "cannot find struct definition for $cssmName in $types" unless $list;
63 @args = $list =~ /([A-Za-z0-9_]+);/gm;
64 }
65
66 print CPP "void flip($cssmName &obj)\n{\n";
67 for my $field (@args) {
68 print CPP "\tflip(obj.$field);\n";
69 }
70 print CPP "}\n\n";
71 }