1#!/usr/bin/gawk -f
2# *************************************************************
3#
4#  Licensed to the Apache Software Foundation (ASF) under one
5#  or more contributor license agreements.  See the NOTICE file
6#  distributed with this work for additional information
7#  regarding copyright ownership.  The ASF licenses this file
8#  to you under the Apache License, Version 2.0 (the
9#  "License"); you may not use this file except in compliance
10#  with the License.  You may obtain a copy of the License at
11#
12#    http://www.apache.org/licenses/LICENSE-2.0
13#
14#  Unless required by applicable law or agreed to in writing,
15#  software distributed under the License is distributed on an
16#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17#  KIND, either express or implied.  See the License for the
18#  specific language governing permissions and limitations
19#  under the License.
20#
21# *************************************************************
22# Usage: gawk -f linkermapfile-check.awk *.map *.xml
23# Order of *.map *.xml is important, otherwise all symbols are reported to be
24# missing.
25# Checks if all symbols of all locale data are present in the symbol scoping
26# linker mapfiles.  Any output indicates a missing symbol, ../localedata.cxx is
27# grep'ed to indicate the library to which mapfile the symbol should be added.
28# Author: Eike Rathke <er@openoffice.org>
29
30BEGIN {
31    bAnyMissing = 0
32    file = ""
33    nMap = 0
34    nMaps = 0
35    nPublics = 0
36    sPublic[nPublics++] = "getAllCalendars_"
37    sPublic[nPublics++] = "getAllCurrencies_"
38    sPublic[nPublics++] = "getAllFormats0_"
39    bOptional[nPublics] = 1     # getAllFormats1 most times not present
40    sPublic[nPublics++] = "getAllFormats1_"
41    sPublic[nPublics++] = "getBreakIteratorRules_"
42    sPublic[nPublics++] = "getCollationOptions_"
43    sPublic[nPublics++] = "getCollatorImplementation_"
44    sPublic[nPublics++] = "getContinuousNumberingLevels_"
45    sPublic[nPublics++] = "getForbiddenCharacters_"
46    sPublic[nPublics++] = "getLCInfo_"
47    sPublic[nPublics++] = "getLocaleItem_"
48    sPublic[nPublics++] = "getOutlineNumberingLevels_"
49    sPublic[nPublics++] = "getReservedWords_"
50    sPublic[nPublics++] = "getSearchOptions_"
51    sPublic[nPublics++] = "getTransliterations_"
52    sPublic[nPublics++] = "getIndexAlgorithm_"
53    sPublic[nPublics++] = "getUnicodeScripts_"
54    sPublic[nPublics++] = "getFollowPageWords_"
55}
56
57file != FILENAME {
58    file = FILENAME
59    if ( file ~ /\.map$/ )
60    {
61        sMapFile[nMaps] = file
62        nMap = nMaps
63        ++nMaps
64    }
65    else if ( file ~ /\.xml$/ )
66    {
67        bOut = 0
68        n = split( file, arr, /[:\\\/.]/ )
69        locale = arr[n-1]
70        for ( i=0; i<nPublics; ++i )
71        {
72            symbol = sPublic[i] locale ";"
73            bFound = 0
74            for ( j=0; j<nMaps && !bFound; ++j )
75            {
76                if ( sSymbol[j,symbol] )
77                    bFound = 1
78            }
79            if ( !bFound && bOptional[i] )
80            {
81                print symbol " not present but optional"
82                bFound = 1
83            }
84            if ( !bFound )
85            {
86                if ( !bOut )
87                {
88                    search = "\"" locale "\""
89                    while ( !bOut && (getline <"../localedata.cxx") > 0 )
90                    {
91                        if ( $0 ~ search )
92                        {
93                            bOut = 1
94                            print "../localedata.cxx says this should go into: " $0
95                        }
96                    }
97                    close( "../localedata.cxx" )
98                    if ( !bOut )
99                        print "../localedata.cxx doesn't indicate to which lib this belongs to:"
100                    bOut = 1
101                }
102                print symbol
103            }
104        }
105        if ( bOut)
106        {
107            printf("\n")
108            bAnyMissing = 1
109        }
110        nextfile
111    }
112    else
113        nextfile
114}
115
116# only reached if .map file encountered, read in symbols
117{
118    if ( $1 ~ /;$/ )
119        sSymbol[nMap,$1] = 1
120}
121
122END {
123    if ( !bAnyMissing )
124        print "All good." >>"/dev/stderr"
125}
126