Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / i18npool / source / localedata / data / sort-formats.awk
blob1ac040ddb75d85a1a66bb7392d67a874253b9508
1 #!/usr/bin/gawk -f
2 # -*- Mode: awk; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
4 # This file is part of the LibreOffice project.
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 sort-formats-by-formatindex.awk [-v group=1] ll_CC.xml
12 # Sort the LC_FORMAT child elements FormatElement and their children by
13 # formatindex="..." value for easier comparison between locales.
14 # If -v group=1 is given, the output is sorted by usage groups first, then by
15 # formatindex. This could be the final sorting to commit.
16 # Output goes to stdout.
18 BEGIN {
19 file = ""
20 usage["FIXED_NUMBER"] = 1
21 usage["SCIENTIFIC_NUMBER"] = 2
22 usage["PERCENT_NUMBER"] = 3
23 usage["CURRENCY"] = 4
24 usage["DATE"] = 5
25 usage["TIME"] = 6
26 usage["DATE_TIME"] = 7
27 group = (group ? 1 : 0) # -v group=... given or not
30 file != FILENAME {
31 file = FILENAME
32 informats = 0
33 currusage = 0
34 currformat = 0
35 inFormatElement = 0
36 delete formats
37 currleader = 0
38 delete leaders
41 /<LC_FORMAT[ >]/ {
42 if (!/\/>/)
43 informats = 1
44 print
45 next
48 informats && /<\/LC_FORMAT>/ {
49 PROCINFO["sorted_in"] = "@ind_num_asc"
50 for (u in formats)
52 if (isarray(formats[u]))
54 for (f in formats[u])
56 if (isarray(formats[u][f]))
58 for (i in formats[u][f])
59 print formats[u][f][i]
61 else
63 # Something unhandled, adapt code.
64 print "XXX formats[u][f] error: " formats[u][f]
68 else
70 # Something unhandled, adapt code.
71 print "XXX formats[u] error: " formats[u]
74 informats = 0
78 if (!informats)
80 print
81 next
85 /<FormatElement / {
86 if (group)
88 split( $0, a, / usage="/)
89 split( a[2], b, /"/)
90 currusage = usage[b[1]]
92 else
94 currusage = 0
96 split( $0, a, / formatindex="/)
97 split( a[2], b, /"/)
98 currformat = b[1]
99 child = 0 # 1-based
100 for (l in leaders)
101 formats[currusage][currformat][++child] = leaders[l]
102 delete leaders
103 currleader = 0
104 formats[currusage][currformat][++child] = $0
105 inFormatElement = 1
106 next
109 /<DateAcceptancePattern[ >]/ {
110 print
111 next
114 # Prefix a leading comment (or even an element) to the next FormatElement.
115 !inFormatElement {
116 leaders[++currleader] = $0
117 next
120 # Associate any element or comment with the current FormatElement.
122 formats[currusage][currformat][++child] = $0
125 /<\/FormatElement>/ {
126 inFormatElement = 0
129 END {
132 # vim:set shiftwidth=4 softtabstop=4 expandtab: