source: trunk/third/perl/embed.pl @ 10724

Revision 10724, 2.4 KB checked in by ghudson, 27 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r10723, which included commits to RCS files with non-trunk default branches.
  • Property svn:executable set to *
Line 
1#!/usr/bin/perl -w
2
3require 5.003;
4
5sub 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
20readsyms %global, 'global.sym';
21readsyms %interp, 'interp.sym';
22readsyms %compat3, 'compat3.sym';
23
24sub 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}
29sub embed ($) {
30    my ($sym) = @_;
31    hide($sym, "Perl_$sym");
32}
33sub multon ($) {
34    my ($sym) = @_;
35    hide($sym, "(curinterp->I$sym)");
36}
37sub multoff ($) {
38    my ($sym) = @_;
39    hide("I$sym", $sym);
40}
41
42unlink 'embed.h';
43open(EM, '> embed.h')
44    or die "Can't create embed.h: $!\n";
45
46print 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
68END
69
70for $sym (sort keys %global) {
71    print EM embed($sym) unless $compat3{$sym};
72}
73
74print EM <<'END';
75
76/* Hide global symbols that 5.003 revealed? */
77
78#ifndef BINCOMPAT3
79
80END
81
82for $sym (sort keys %global) {
83    print EM embed($sym) if $compat3{$sym};
84}
85
86print EM <<'END';
87
88#endif /* !BINCOMPAT3 */
89
90#endif /* EMBED */
91
92/* Put interpreter-specific symbols into a struct? */
93
94#ifdef MULTIPLICITY
95
96END
97
98for $sym (sort keys %interp) {
99    print EM multon($sym);
100}
101
102print EM <<'END';
103
104#else   /* !MULTIPLICITY */
105
106END
107
108for $sym (sort keys %interp) {
109    print EM multoff($sym);
110}
111
112print EM <<'END';
113
114/* Hide interpreter-specific symbols? */
115
116#ifdef EMBED
117
118END
119
120for $sym (sort keys %interp) {
121    print EM embed($sym) if $compat3{$sym};
122}
123
124print EM <<'END';
125
126/* Hide interpreter symbols that 5.003 revealed? */
127
128#ifndef BINCOMPAT3
129
130END
131
132for $sym (sort keys %interp) {
133    print EM embed($sym) unless $compat3{$sym};
134}
135
136print EM <<'END';
137
138#endif /* !BINCOMPAT3 */
139
140#endif /* EMBED */
141
142#endif /* MULTIPLICITY */
143END
144
Note: See TracBrowser for help on using the repository browser.