]> git.ipfire.org Git - thirdparty/openssl.git/blob - util/mkstack.pl
This change will cause builds (by default) to not use different STACK
[thirdparty/openssl.git] / util / mkstack.pl
1 #!/usr/local/bin/perl -w
2 #
3 # This is a utility that searches out "DECLARE_STACK_OF()"
4 # declarations in header files, and updates/creates/replaces
5 # the corresponding macro declarations that follow it. The
6 # reason is that with "DEBUG_SAFESTACK" defined, each type
7 # will generate 19 functions, all type-safe variants of the
8 # base "sk_***" functions for the general STACK type. Without
9 # DEBUG_SAFESTACK defined, we need to macro define all the
10 # "type'd sk_##type##_***" functions as mapping directly to
11 # the standard sk_*** equivalents. As it's not generally
12 # possible to have macros that generate macros, we need to
13 # control this from the "outside", here in this script.
14 #
15 # Geoff Thorpe, June, 2000 (with massive Perl-hacking
16 # help from Steve Robb)
17
18 my $type_thing;
19 my $recurse = 0;
20 my @files = @ARGV;
21
22 while (@ARGV) {
23 my $arg = $ARGV[0];
24 if($arg eq "-recurse") {
25 $recurse = 1;
26 shift @ARGV;
27 } else {
28 last;
29 }
30 }
31
32 if($recurse) {
33 @source = (<crypto/*.[ch]>, <crypto/*/*.[ch]>, <rsaref/*.[ch]>, <ssl/*.[ch]>);
34 } else {
35 @source = @ARGV;
36 }
37
38 foreach $file (@source) {
39 # After "Configure" has been run, we need to make sure we don't
40 # overwrite symbollic links with new header files!
41 next if -l $file;
42
43 # Open the .c/.h file for reading
44 open(IN, "< $file") || die "Can't open $file for reading: $!";
45 open(OUT, "> $file.tmp") || die "Can't open $file.tmp for writing: $!";
46
47 select(OUT);
48 process_the_file();
49
50 close(OUT);
51 close(IN);
52
53 unlink($file);
54 rename("$file.tmp", $file);
55 }
56
57 sub process_the_file {
58
59 my $inside_block = 0;
60 my $output_defines = 0;
61
62 while(<IN>) {
63 if (/^DECLARE_STACK_OF\(([^)]+)\)/) {
64 $type_thing = $1;
65 $output_defines = 1;
66 }
67 if (m|^/\* This block of defines is updated by a perl script, please do not touch! \*/|) {
68 $inside_block = 1;
69 }
70 if (m|^/\* End of perl script block, you may now edit :-\) \*/|) {
71 $inside_block = 0;
72 } elsif ($inside_block == 0) {
73 print;
74 }
75 if($output_defines == 1) {
76 print <<EOF;
77 /* This block of defines is updated by a perl script, please do not touch! */
78 #ifndef DEBUG_SAFESTACK
79 #define sk_${type_thing}_new(a) sk_new((int (*) \\
80 (const char * const *, const char * const *))(a))
81 #define sk_${type_thing}_new_null() sk_new_null()
82 #define sk_${type_thing}_free(a) sk_free(a)
83 #define sk_${type_thing}_num(a) sk_num(a)
84 #define sk_${type_thing}_value(a,b) ((${type_thing} *) \\
85 sk_value((a),(b)))
86 #define sk_${type_thing}_set(a,b,c) ((${type_thing} *) \\
87 sk_set((a),(b),(char *)(c)))
88 #define sk_${type_thing}_zero(a) sk_zero(a)
89 #define sk_${type_thing}_push(a,b) sk_push((a),(char *)(b))
90 #define sk_${type_thing}_unshift(a,b) sk_unshift((a),(b))
91 #define sk_${type_thing}_find(a,b) sk_find((a), (char *)(b))
92 #define sk_${type_thing}_delete(a,b) ((${type_thing} *) \\
93 sk_delete((a),(b)))
94 #define sk_${type_thing}_delete_ptr(a,b) ((${type_thing} *) \\
95 sk_delete_ptr((a),(char *)(b)))
96 #define sk_${type_thing}_insert(a,b,c) sk_insert((a),(char *)(b),(c))
97 #define sk_${type_thing}_set_cmp_func(a,b) ((int (*) \\
98 (const ${type_thing} * const *,const ${type_thing} * const *)) \\
99 sk_set_cmp_func((a),(int (*) \\
100 (const char * const *, const char * const *))(b)))
101 #define sk_${type_thing}_dup(a) sk_dup(a)
102 #define sk_${type_thing}_pop_free(a,b) sk_pop_free((a),(void (*)(void *))(b))
103 #define sk_${type_thing}_shift(a) ((${type_thing} *)sk_shift(a))
104 #define sk_${type_thing}_pop(a) ((${type_thing} *)sk_pop(a))
105 #define sk_${type_thing}_sort(a) sk_sort(a)
106 #endif /* !DEBUG_SAFESTACK */
107 /* End of perl script block, you may now edit :-) */
108 EOF
109 $output_defines = 0;
110 }
111 }
112 }