bnc#382137 DocxAttributeOutput: don't store address of local variable
[LibreOffice.git] / solenv / bin / mapgen.pl
blobd336e634551a01eebcd693072d1ddfa931f57001
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
5 # This file is part of the LibreOffice project.
7 # This Source Code Form is subject to the terms of the Mozilla Public
8 # License, v. 2.0. If a copy of the MPL was not distributed with this
9 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 # This file incorporates work covered by the following license notice:
13 # Licensed to the Apache Software Foundation (ASF) under one or more
14 # contributor license agreements. See the NOTICE file distributed
15 # with this work for additional information regarding copyright
16 # ownership. The ASF licenses this file to you under the Apache
17 # License, Version 2.0 (the "License"); you may not use this file
18 # except in compliance with the License. You may obtain a copy of
19 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 # mapgen - generate a map file for Unix libraries
26 #use File::Path;
27 #use File::Copy;
29 #### script id #####
31 ( $script_name = $0 ) =~ s/^.*\b(\w+)\.pl$/$1/;
32 print "$script_name -- version: 1.6\n";
33 print "Multi Platform Enabled Edition\n";
35 #########################
36 # #
37 # Globale Variablen #
38 # #
39 #########################
41 $dump_file = '';
42 $flt_file = '';
43 $map_file = '';
44 $first_string = '';
45 $tab = ' ';
47 #### main ####
49 &get_options;
50 if (!(open (DUMP_FILE, $dump_file))) {
51 &print_error("Unable open $dump_file");
53 if (!(open (FLT_FILE, $flt_file))) {
54 close DUMP_FILE;
55 &print_error("Unable open $flt_file");
57 unlink $map_file;
58 if (!(open (MAP_FILE, ">>$map_file"))) {
59 close DUMP_FILE;
60 close FLT_FILE;
61 &print_error("Unable open $map_file");
64 if ($ENV{OS} eq 'SOLARIS') {
65 &gen_sol;
66 } elsif ($ENV{OS} eq 'LINUX') {
67 &gen_lnx;
68 } else {
69 &print_error ('Environment not set!!');
72 close DUMP_FILE;
73 close FLT_FILE;
74 close MAP_FILE;
76 #### end of main procedure ####
78 #########################
79 # #
80 # Procedures #
81 # #
82 #########################
85 # Generate a map file for solaris
87 sub gen_sol {
88 my %symbols = ();
89 foreach (<DUMP_FILE>) {
90 next if (!(/\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*/));
91 next if (($7 =~ /UNDEF/) || ($7 =~ /ABS/));
92 next if ($5 eq 'LOCL');
93 $symbols{$8}++;
95 &filter_symbols(\%symbols);
99 # Generate a map file for linux
101 sub gen_lnx {
102 my %symbols = ();
103 foreach (<DUMP_FILE>) {
104 next if (!(/^\S+ [A|B|C|D|G|I|N|R|S|T|U|V|W|-|\?|-] (\S+)/));
105 $symbols{$1}++;
107 &filter_symbols(\%symbols);
111 # Filter symbols with filters from $flt_file
113 sub filter_symbols {
114 my $symbols = shift;
115 my $env_section = '';
116 my @filters = ();
117 my @filtered_symbols = ();
118 while (<FLT_FILE>) {
119 s/\r//;
120 s/\n//;
121 $env_section = '1' and next if ((/^# SOLARIS #$/) && ($ENV{OS} eq 'SOLARIS'));
122 $env_section = '1' and next if ((/^# LINUX #$/) && ($ENV{OS} eq 'LINUX'));
123 $env_section = '1' and next if ((/^# FREEBSD #$/) && ($ENV{OS} eq 'FREEBSD'));
124 $env_section = '1' and next if ((/^# NETBSD #$/) && ($ENV{OS} eq 'NETBSD'));
125 $env_section = '1' and next if ((/^# OPENBSD #$/) && ($ENV{OS} eq 'OPENBSD'));
126 $env_section = '1' and next if ((/^# DRAGONFLY #$/) && ($ENV{OS} eq 'DRAGONFLY'));
127 last if ($env_section && ((/^# SOLARIS #$/) || (/^# FREEBSD #$/) || (/^# LINUX #$/) || (/^# NETBSD #$/) || (/^# OPENBSD #$/) (/^# DRAGONFLY #$/)));
128 next if (!$_ || /^#/);
129 push(@filters, $_);
131 foreach my $symbol (keys %$symbols) {
132 my $export = '-';
133 foreach my $filter_str (@filters) {
134 my $add = substr ($filter_str, 0, 1);
135 my $filter = substr($filter_str, 1);
136 if ($symbol =~ /$filter/) {
137 $export = $add;
140 if ($export eq '+') {
141 push(@filtered_symbols, $symbol);
144 &write_mapfile(\@filtered_symbols);
148 # Write a map file
150 sub write_mapfile {
151 my $symbols = shift;
152 print MAP_FILE $first_string . " {\n$tab" . "global:\n";
153 foreach (@$symbols) {
154 print MAP_FILE "$tab$tab$_\;\n";
156 print MAP_FILE "$tab" . "local:\n$tab\*\;\n}\;";
160 # Get all options passed
162 sub get_options {
164 $dump_file = '';
165 $flt_file = '';
166 $map_file = '';
167 my ($arg);
168 &usage() && exit(0) if ($#ARGV == -1);
169 while ($arg = shift @ARGV) {
170 $arg =~ /^-d$/ and $dump_file = shift @ARGV and next;
171 $arg =~ /^-f$/ and $flt_file = shift @ARGV and next;
172 $arg =~ /^-m$/ and $map_file = shift @ARGV and next;
173 $arg =~ /^-h$/ and &usage and exit(0);
174 $arg =~ /^--help$/ and &usage and exit(0);
175 $arg =~ /^-s$/ and $first_string = shift @ARGV and next;
177 if (!$dump_file ||
178 !$flt_file ||
179 !$first_string ||
180 !$map_file) {
181 &usage;
182 exit(1);
186 sub print_error {
187 my $message = shift;
188 print STDERR "\nERROR: $message\n";
189 exit(1)
192 sub usage {
193 print STDERR "\nmapgen:\n";
194 print STDERR "Syntax: mapgen -d dump_file -s first_string -f filter_file -m map_file [-h|--help]\n";