summaryrefslogtreecommitdiffstats
path: root/i18npool/source/localedata/data/sort-formats.awk
blob: 1ac040ddb75d85a1a66bb7392d67a874253b9508 (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
#!/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 sort-formats-by-formatindex.awk [-v group=1] ll_CC.xml
#
# Sort the LC_FORMAT child elements FormatElement and their children by
# formatindex="..." value for easier comparison between locales.
# If -v group=1 is given, the output is sorted by usage groups first, then by
# formatindex. This could be the final sorting to commit.
# Output goes to stdout.

BEGIN {
    file = ""
    usage["FIXED_NUMBER"] = 1
    usage["SCIENTIFIC_NUMBER"] = 2
    usage["PERCENT_NUMBER"] = 3
    usage["CURRENCY"] = 4
    usage["DATE"] = 5
    usage["TIME"] = 6
    usage["DATE_TIME"] = 7
    group = (group ? 1 : 0)     # -v group=... given or not
}

file != FILENAME {
    file = FILENAME
    informats = 0
    currusage = 0
    currformat = 0
    inFormatElement = 0
    delete formats
    currleader = 0
    delete leaders
}

/<LC_FORMAT[ >]/ {
    if (!/\/>/)
        informats = 1
    print
    next
}

informats && /<\/LC_FORMAT>/ {
    PROCINFO["sorted_in"] = "@ind_num_asc"
    for (u in formats)
    {
        if (isarray(formats[u]))
        {
            for (f in formats[u])
            {
                if (isarray(formats[u][f]))
                {
                    for (i in formats[u][f])
                        print formats[u][f][i]
                }
                else
                {
                    # Something unhandled, adapt code.
                    print "XXX formats[u][f] error: " formats[u][f]
                }
            }
        }
        else
        {
            # Something unhandled, adapt code.
            print "XXX formats[u] error: " formats[u]
        }
    }
    informats = 0
}

{
    if (!informats)
    {
        print
        next
    }
}

/<FormatElement / {
    if (group)
    {
        split( $0, a, / usage="/)
        split( a[2], b, /"/)
        currusage = usage[b[1]]
    }
    else
    {
        currusage = 0
    }
    split( $0, a, / formatindex="/)
    split( a[2], b, /"/)
    currformat = b[1]
    child = 0   # 1-based
    for (l in leaders)
        formats[currusage][currformat][++child] = leaders[l]
    delete leaders
    currleader = 0
    formats[currusage][currformat][++child] = $0
    inFormatElement = 1
    next
}

/<DateAcceptancePattern[ >]/ {
    print
    next
}

# Prefix a leading comment (or even an element) to the next FormatElement.
!inFormatElement {
    leaders[++currleader] = $0
    next
}

# Associate any element or comment with the current FormatElement.
{
    formats[currusage][currformat][++child] = $0
}

/<\/FormatElement>/ {
    inFormatElement = 0
}

END {
}

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