This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
tiny perllocale.pod diff for _16
[perl5.git] / embed.pl
1 #!/usr/bin/perl -w
2
3 require 5.003;
4
5 sub readsyms (\%$) {
6     my ($syms, $file) = @_;
7     %$syms = ();
8     local (*FILE, $_);
9     open(FILE, "< $file")
10         or die "embed.pl: Can't open $file: $!\n";
11     while (<FILE>) {
12         s/[ \t]*#.*//;          # Delete comments.
13         if (/^\s*(\S+)\s*$/) {
14             $$syms{$1} = 1;
15         }
16     }
17     close(FILE);
18 }
19
20 readsyms %global, 'global.sym';
21 readsyms %interp, 'interp.sym';
22 readsyms %compat3, 'compat3.sym';
23
24 sub hide ($$) {
25     my ($from, $to) = @_;
26     my $t = int(length($from) / 8);
27     "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
28 }
29 sub embed ($) {
30     my ($sym) = @_;
31     hide($sym, "Perl_$sym");
32 }
33 sub multon ($) {
34     my ($sym) = @_;
35     hide($sym, "(curinterp->I$sym)");
36 }
37 sub multoff ($) {
38     my ($sym) = @_;
39     hide("I$sym", $sym);
40 }
41
42 unlink 'embed.h';
43 open(EM, '> embed.h')
44     or die "Can't create embed.h: $!\n";
45
46 print EM <<'END';
47 /* !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!! 
48    This file is built by embed.pl from global.sym, interp.sym,
49    and compat3.sym.  Any changes made here will be lost!
50 */
51
52 /* (Doing namespace management portably in C is really gross.) */
53
54 /*  EMBED has no run-time penalty, but helps keep the Perl namespace
55     from colliding with that used by other libraries pulled in
56     by extensions or by embedding perl.  Allow a cc -DNO_EMBED
57     override, however, to keep binary compatability with previous
58     versions of perl.
59 */
60 #ifndef NO_EMBED
61 #  define EMBED 1 
62 #endif
63
64 /* Hide global symbols? */
65
66 #ifdef EMBED
67
68 END
69
70 for $sym (sort keys %global) {
71     print EM embed($sym) unless $compat3{$sym};
72 }
73
74 print EM <<'END';
75
76 /* Hide global symbols that 5.003 revealed? */
77
78 #ifndef BINCOMPAT3
79
80 END
81
82 for $sym (sort keys %global) {
83     print EM embed($sym) if $compat3{$sym};
84 }
85
86 print EM <<'END';
87
88 #endif /* !BINCOMPAT3 */
89
90 #endif /* EMBED */
91
92 /* Put interpreter-specific symbols into a struct? */
93
94 #ifdef MULTIPLICITY
95
96 END
97
98 for $sym (sort keys %interp) {
99     print EM multon($sym);
100 }
101
102 print EM <<'END';
103
104 #else   /* !MULTIPLICITY */
105
106 END
107
108 for $sym (sort keys %interp) {
109     print EM multoff($sym);
110 }
111
112 print EM <<'END';
113
114 /* Hide interpreter-specific symbols? */
115
116 #ifdef EMBED
117
118 END
119
120 for $sym (sort keys %interp) {
121     print EM embed($sym) if $compat3{$sym};
122 }
123
124 print EM <<'END';
125
126 /* Hide interpreter symbols that 5.003 revealed? */
127
128 #ifndef BINCOMPAT3
129
130 END
131
132 for $sym (sort keys %interp) {
133     print EM embed($sym) unless $compat3{$sym};
134 }
135
136 print EM <<'END';
137
138 #endif /* !BINCOMPAT3 */
139
140 #endif /* EMBED */
141
142 #endif /* MULTIPLICITY */
143 END
144