2 # -*- Mode: awk; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
4 # Copyright 2012 LibreOffice contributors.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 # Usage: gawk -f list-dateacceptancepattern.awk *.xml [--sep [--html]]
12 # Outputs three lists of locales, one with DateAcceptancePattern elements
13 # defined, one with inherited LC_FORMAT elements and thus date patterns, and
14 # one where no DateAcceptancePattern are defined.
16 # If --sep is given, display date separator for each locale.
17 # If --html is given as the last parameter, format output suitable for
22 if (ARGV[ARGC-1] ==
"--html") {
27 if (ARGV[ARGC-1] ==
"--sep") {
53 /<DateAcceptancePattern
>/ {
55 patterns
[patterncount
++] = a
[3]
58 # pattern inherited as well
59 /<LC_FORMAT
[^
>]* ref=
"[^>"]+"[^>]*>/ {
60 split( $0, a, /.* ref="|"/ )
64 /<FormatElement[^>]* formatindex="21"[^>]*>/ { formatelement = 1 }
70 split( a[3], b, /[0-9A-Za-z\[\~\]]+/ )
83 PROCINFO["sorted_in
"] = "@ind_str_asc
"
89 printLine( "Trailing
+ indicates that another locale inherits from this.
" )
91 printLine( "Appended is the locale
's date separator and edit format code." )
93 printLine( "Locales with explicit DateAcceptancePattern elements:" )
99 if (LocaleList[i][offpatterns][0])
101 print " <li> " getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale])
103 for (p = 0; p < LocaleList[i][offpatterncount]; ++p)
105 print " <li> " LocaleList[i][offpatterns][p]
115 for (i in LocaleList)
117 if (LocaleList[i][offpatterns][0])
119 print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale])
120 for (p = 0; p < LocaleList[i][offpatterncount]; ++p)
122 print " " LocaleList[i][offpatterns][p]
129 printLine( "Locales inheriting patterns:" )
132 for (i in LocaleList)
134 if (LocaleList[i][offinherit] && LocaleList[i][offpatterncount])
135 print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) " "
141 for (i in LocaleList)
143 if (LocaleList[i][offinherit] && LocaleList[i][offpatterncount])
144 print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale])
149 printLine( "Locales without explicit DateAcceptancePattern elements:" )
150 printLine( "(one implicit full date pattern is always generated)" )
154 for (i in LocaleList)
156 if (!LocaleList[i][offpatterncount])
157 print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) " "
162 for (i in LocaleList)
164 if (!LocaleList[i][offpatterncount])
165 print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale])
171 function printLine( text ) {
178 function endFile( locale ) {
179 locale = getLocale( file)
180 LocaleList[locale][offlocale] = locale
181 LocaleList[locale][offpatterncount] = patterncount
182 LocaleList[locale][offdatesep] = datesep
183 LocaleList[locale][offdateformat] = dateformat
186 for ( i=0; i<patterncount; ++i )
188 LocaleList[locale][offpatterns][i] = patterns[i]
192 LocaleList[locale][offinherit] = inherited
196 function getLocale( file, tmp ) {
198 gsub( /.*\//, "", tmp )
199 gsub( /\.xml/, "", tmp )
204 function fillInherited( locale ) {
205 LocaleList[locale][offbequeath] = 1
206 if (!LocaleList[locale][offpatterncount] && LocaleList[locale][offinherit])
207 LocaleList[locale][offpatterncount] = fillInherited( LocaleList[locale][offinherit])
208 return LocaleList[locale][offpatterncount]
212 function fillAllInherited( i ) {
213 for (i in LocaleList)
215 LocaleList[i][offbequeath] = 0
217 for (i in LocaleList)
219 if (!LocaleList[i][offpatterncount] && LocaleList[i][offinherit])
220 LocaleList[i][offpatterncount] = fillInherited( LocaleList[i][offinherit])
225 function getInheritance( str, locale ) {
226 if (LocaleList[locale][offbequeath])
228 if (LocaleList[locale][offinherit])
229 str = getInheritance( str " = " LocaleList[locale][offinherit], LocaleList[locale][offinherit])
231 str = str "\t'" LocaleList[locale][offdatesep] "' (" LocaleList[locale][offdateformat] ")"
235 # vim:set shiftwidth=4 softtabstop=4 expandtab: