Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / i18npool / source / localedata / data / list-dateacceptancepattern.awk
blob75f5db113b6d4908e2bf4a3b81a7cb3283c27fc5
1 #!/usr/bin/gawk -f
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
18 # inclusion in HTML.
20 BEGIN {
21 html = 0
22 if (ARGV[ARGC-1] == "--html") {
23 html = 1
24 --ARGC
26 sep = 0
27 if (ARGV[ARGC-1] == "--sep") {
28 sep = 1
29 --ARGC
31 file = ""
32 offlocale = 0
33 offpatterncount = 1
34 offinherit = 2
35 offbequeath = 3
36 offdatesep = 4
37 offdateformat = 5
38 offpatterns = 6
42 file != FILENAME {
43 if (file)
44 endFile()
45 file = FILENAME
46 patterncount = 0
47 inherited = ""
48 formatelement = 0
49 datesep = ""
50 dateformat = ""
53 /<DateAcceptancePattern>/ {
54 split( $0, a, /<|>/ )
55 patterns[patterncount++] = a[3]
58 # pattern inherited as well
59 /<LC_FORMAT[^>]* ref="[^>"]+"[^>]*>/ {
60 split( $0, a, /.* ref="|"/ )
61 inherited = a[2]
64 /<FormatElement[^>]* formatindex="21"[^>]*>/ { formatelement = 1 }
65 /<FormatCode>/ {
66 if (formatelement)
68 formatelement = 0
69 split( $0, a, /<|>/ )
70 split( a[3], b, /[0-9A-Za-z\[\~\]]+/ )
71 datesep = b[2]
72 dateformat = a[3]
77 END {
78 if (file)
79 endFile()
81 fillAllInherited()
83 PROCINFO["sorted_in"] = "@ind_str_asc"
85 if (html)
86 print "<p>"
87 else
88 print ""
89 printLine( "Trailing + indicates that another locale inherits from this." )
90 if (sep)
91 printLine( "Appended is the locale's date separator and edit format code." )
92 printLine("")
93 printLine( "Locales with explicit DateAcceptancePattern elements:" )
94 if (html)
96 print "<ul>"
97 for (i in LocaleList)
99 if (LocaleList[i][offpatterns][0])
101 print " <li> " getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale])
102 print " <ul>"
103 for (p = 0; p < LocaleList[i][offpatterncount]; ++p)
105 print " <li> " LocaleList[i][offpatterns][p]
107 print " </ul>"
110 print "</ul>"
111 print "\n<p>"
113 else
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]
126 print "\n"
129 printLine( "Locales inheriting patterns:" )
130 if (html)
132 for (i in LocaleList)
134 if (LocaleList[i][offinherit] && LocaleList[i][offpatterncount])
135 print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) "&nbsp;&nbsp;&nbsp; "
137 print "\n<p>"
139 else
141 for (i in LocaleList)
143 if (LocaleList[i][offinherit] && LocaleList[i][offpatterncount])
144 print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale])
146 print "\n"
149 printLine( "Locales without explicit DateAcceptancePattern elements:" )
150 printLine( "(one implicit full date pattern is always generated)" )
151 if (html)
153 print "<p>"
154 for (i in LocaleList)
156 if (!LocaleList[i][offpatterncount])
157 print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) "&nbsp;&nbsp;&nbsp; "
160 else
162 for (i in LocaleList)
164 if (!LocaleList[i][offpatterncount])
165 print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale])
171 function printLine( text ) {
172 print text
173 if (html)
174 print "<br>"
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
184 if (patterncount)
186 for ( i=0; i<patterncount; ++i )
188 LocaleList[locale][offpatterns][i] = patterns[i]
191 else if (inherited)
192 LocaleList[locale][offinherit] = inherited
196 function getLocale( file, tmp ) {
197 tmp = file
198 gsub( /.*\//, "", tmp )
199 gsub( /\.xml/, "", tmp )
200 return 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])
227 str = str " +"
228 if (LocaleList[locale][offinherit])
229 str = getInheritance( str " = " LocaleList[locale][offinherit], LocaleList[locale][offinherit])
230 else if (sep)
231 str = str "\t'" LocaleList[locale][offdatesep] "' (" LocaleList[locale][offdateformat] ")"
232 return str
235 # vim:set shiftwidth=4 softtabstop=4 expandtab: