1#!/usr/bin/gawk -f
2# Usage: gawk -f linkermapfile-check.awk *.map *.xml
3# Order of *.map *.xml is important, otherwise all symbols are reported to be
4# missing.
5# Checks if all symbols of all locale data are present in the symbol scoping
6# linker mapfiles.  Any output indicates a missing symbol, ../localedata.cxx is
7# grep'ed to indicate the library to which mapfile the symbol should be added.
8# Author: Eike Rathke <er@openoffice.org>
9
10BEGIN {
11    bAnyMissing = 0
12    file = ""
13    nMap = 0
14    nMaps = 0
15    nPublics = 0
16    sPublic[nPublics++] = "getAllCalendars_"
17    sPublic[nPublics++] = "getAllCurrencies_"
18    sPublic[nPublics++] = "getAllFormats0_"
19    bOptional[nPublics] = 1     # getAllFormats1 most times not present
20    sPublic[nPublics++] = "getAllFormats1_"
21    sPublic[nPublics++] = "getBreakIteratorRules_"
22    sPublic[nPublics++] = "getCollationOptions_"
23    sPublic[nPublics++] = "getCollatorImplementation_"
24    sPublic[nPublics++] = "getContinuousNumberingLevels_"
25    sPublic[nPublics++] = "getForbiddenCharacters_"
26    sPublic[nPublics++] = "getLCInfo_"
27    sPublic[nPublics++] = "getLocaleItem_"
28    sPublic[nPublics++] = "getOutlineNumberingLevels_"
29    sPublic[nPublics++] = "getReservedWords_"
30    sPublic[nPublics++] = "getSearchOptions_"
31    sPublic[nPublics++] = "getTransliterations_"
32    sPublic[nPublics++] = "getIndexAlgorithm_"
33    sPublic[nPublics++] = "getUnicodeScripts_"
34    sPublic[nPublics++] = "getFollowPageWords_"
35}
36
37file != FILENAME {
38    file = FILENAME
39    if ( file ~ /\.map$/ )
40    {
41        sMapFile[nMaps] = file
42        nMap = nMaps
43        ++nMaps
44    }
45    else if ( file ~ /\.xml$/ )
46    {
47        bOut = 0
48        n = split( file, arr, /[:\\\/.]/ )
49        locale = arr[n-1]
50        for ( i=0; i<nPublics; ++i )
51        {
52            symbol = sPublic[i] locale ";"
53            bFound = 0
54            for ( j=0; j<nMaps && !bFound; ++j )
55            {
56                if ( sSymbol[j,symbol] )
57                    bFound = 1
58            }
59            if ( !bFound && bOptional[i] )
60            {
61                print symbol " not present but optional"
62                bFound = 1
63            }
64            if ( !bFound )
65            {
66                if ( !bOut )
67                {
68                    search = "\"" locale "\""
69                    while ( !bOut && (getline <"../localedata.cxx") > 0 )
70                    {
71                        if ( $0 ~ search )
72                        {
73                            bOut = 1
74                            print "../localedata.cxx says this should go into: " $0
75                        }
76                    }
77                    close( "../localedata.cxx" )
78                    if ( !bOut )
79                        print "../localedata.cxx doesn't indicate to which lib this belongs to:"
80                    bOut = 1
81                }
82                print symbol
83            }
84        }
85        if ( bOut)
86        {
87            printf("\n")
88            bAnyMissing = 1
89        }
90        nextfile
91    }
92    else
93        nextfile
94}
95
96# only reached if .map file encountered, read in symbols
97{
98    if ( $1 ~ /;$/ )
99        sSymbol[nMap,$1] = 1
100}
101
102END {
103    if ( !bAnyMissing )
104        print "All good." >>"/dev/stderr"
105}
106