summaryrefslogtreecommitdiffstats
path: root/i18npool/source/localedata/data/list-dateacceptancepattern.awk
blob: 3c86923e2b84ef7138b8ff625b90c3c431f7f88d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/gawk -f
# -*- Mode: awk; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Usage: gawk -f list-dateacceptancepattern.awk *.xml [--sep [--html]]
#
# Outputs three lists of locales, one with DateAcceptancePattern elements
# defined, one with inherited LC_FORMAT elements and thus date patterns, and
# one where no DateAcceptancePattern are defined.
#
# If --sep is given, display date separator for each locale.
# If --html is given as the last parameter, format output suitable for
# inclusion in HTML.

BEGIN {
    html = 0
    if (ARGV[ARGC-1] == "--html") {
        html = 1
        --ARGC
    }
    sep = 0
    if (ARGV[ARGC-1] == "--sep") {
        sep = 1
        --ARGC
    }
    file = ""
    offlocale = 0
    offpatterncount = 1
    offinherit = 2
    offbequeath = 3
    offdatesep = 4
    offdateformat = 5
    offpatterns = 6
}


file != FILENAME {
    if (file)
        endFile()
    file = FILENAME
    patterncount = 0
    inherited = ""
    formatelement = 0
    datesep = ""
    dateformat = ""
}

/<DateAcceptancePattern>/ {
    split( $0, a, /<|>/ )
    patterns[patterncount++] = a[3]
}

# pattern inherited as well
/<LC_FORMAT[^>]* ref="[^>"]+"[^>]*>/ {
    split( $0, a, /.* ref="|"/ )
    inherited = a[2]
}

/<FormatElement[^>]* formatindex="21"[^>]*>/ { formatelement = 1 }
/<FormatCode>/ {
    if (formatelement)
    {
        formatelement = 0
        split( $0, a, /<|>/ )
        split( a[3], b, /[0-9A-Za-z\[\~\]]+/ )
        datesep = b[2]
        dateformat = a[3]
    }
}


END {
    if (file)
        endFile()

    fillAllInherited()

    PROCINFO["sorted_in"] = "@ind_str_asc"

    if (html)
        print "<p>"
    else
        print ""
    printLine( "Trailing + indicates that another locale inherits from this." )
    if (sep)
        printLine( "Appended is the locale's date separator and edit format code." )
    printLine("")
    printLine( "Locales with explicit DateAcceptancePattern elements:" )
    if (html)
    {
        print "<ul>"
        for (i in LocaleList)
        {
            if (LocaleList[i][offpatterns][0])
            {
                print "  <li> " getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale])
                print "  <ul>"
                for (p = 0; p < LocaleList[i][offpatterncount]; ++p)
                {
                    print "    <li> " LocaleList[i][offpatterns][p]
                }
                print "  </ul>"
            }
        }
        print "</ul>"
        print "\n<p>"
    }
    else
    {
        for (i in LocaleList)
        {
            if (LocaleList[i][offpatterns][0])
            {
                print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale])
                for (p = 0; p < LocaleList[i][offpatterncount]; ++p)
                {
                    print "    " LocaleList[i][offpatterns][p]
                }
            }
        }
        print "\n"
    }

    printLine( "Locales inheriting patterns:" )
    if (html)
    {
        for (i in LocaleList)
        {
            if (LocaleList[i][offinherit] && LocaleList[i][offpatterncount])
                print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) "&nbsp;&nbsp;&nbsp; "
        }
        print "\n<p>"
    }
    else
    {
        for (i in LocaleList)
        {
            if (LocaleList[i][offinherit] && LocaleList[i][offpatterncount])
                print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale])
        }
        print "\n"
    }

    printLine( "Locales without explicit DateAcceptancePattern elements:" )
    printLine( "(one implicit full date pattern is always generated)" )
    if (html)
    {
        print "<p>"
        for (i in LocaleList)
        {
            if (!LocaleList[i][offpatterncount])
                print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) "&nbsp;&nbsp;&nbsp; "
        }
    }
    else
    {
        for (i in LocaleList)
        {
            if (!LocaleList[i][offpatterncount])
                print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale])
        }
    }
}


function printLine( text ) {
    print text
    if (html)
        print "<br>"
}


function endFile(       locale ) {
    locale =  getLocale( file)
    LocaleList[locale][offlocale] = locale
    LocaleList[locale][offpatterncount] = patterncount
    LocaleList[locale][offdatesep] = datesep
    LocaleList[locale][offdateformat] = dateformat
    if (patterncount)
    {
        for ( i=0; i<patterncount; ++i )
        {
            LocaleList[locale][offpatterns][i] = patterns[i]
        }
    }
    else if (inherited)
        LocaleList[locale][offinherit] = inherited
}


function getLocale( file,       tmp ) {
    tmp = file
    gsub( /.*\//, "", tmp )
    gsub( /\.xml/, "", tmp )
    return tmp
}


function fillInherited( locale ) {
    LocaleList[locale][offbequeath] = 1
    if (!LocaleList[locale][offpatterncount] && LocaleList[locale][offinherit])
        LocaleList[locale][offpatterncount] = fillInherited( LocaleList[locale][offinherit])
    return LocaleList[locale][offpatterncount]
}


function fillAllInherited(      i ) {
    for (i in LocaleList)
    {
        LocaleList[i][offbequeath] = 0
    }
    for (i in LocaleList)
    {
        if (!LocaleList[i][offpatterncount] && LocaleList[i][offinherit])
            LocaleList[i][offpatterncount] = fillInherited( LocaleList[i][offinherit])
    }
}


function getInheritance( str, locale ) {
    if (LocaleList[locale][offbequeath])
        str = str " +"
    if (LocaleList[locale][offinherit])
        str = getInheritance( str " = " LocaleList[locale][offinherit], LocaleList[locale][offinherit])
    else if (sep)
        str = str "\t'" LocaleList[locale][offdatesep] "'  (" LocaleList[locale][offdateformat] ")"
    return str
}

# vim:set shiftwidth=4 softtabstop=4 expandtab: