| 1 |
#!/usr/bin/gawk -f |
| 2 |
# -*- Mode: awk; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 3 |
# |
| 4 |
# This file is part of the LibreOffice project. |
| 5 |
# |
| 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/. |
| 9 |
|
| 10 |
# Usage: gawk -f sort-formats-by-formatindex.awk [-v group=1] ll_CC.xml |
| 11 |
# |
| 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. |
| 17 |
|
| 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 |
| 28 |
} |
| 29 |
|
| 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 |
| 39 |
} |
| 40 |
|
| 41 |
/<LC_FORMAT[ >]/ { |
| 42 |
if (!/\/>/) |
| 43 |
informats = 1 |
| 44 |
print |
| 45 |
next |
| 46 |
} |
| 47 |
|
| 48 |
informats && /<\/LC_FORMAT>/ { |
| 49 |
PROCINFO["sorted_in"] = "@ind_num_asc" |
| 50 |
for (u in formats) |
| 51 |
{ |
| 52 |
if (isarray(formats[u])) |
| 53 |
{ |
| 54 |
for (f in formats[u]) |
| 55 |
{ |
| 56 |
if (isarray(formats[u][f])) |
| 57 |
{ |
| 58 |
for (i in formats[u][f]) |
| 59 |
print formats[u][f][i] |
| 60 |
} |
| 61 |
else |
| 62 |
{ |
| 63 |
# Something unhandled, adapt code. |
| 64 |
print "XXX formats[u][f] error: " formats[u][f] |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
else |
| 69 |
{ |
| 70 |
# Something unhandled, adapt code. |
| 71 |
print "XXX formats[u] error: " formats[u] |
| 72 |
} |
| 73 |
} |
| 74 |
informats = 0 |
| 75 |
} |
| 76 |
|
| 77 |
{ |
| 78 |
if (!informats) |
| 79 |
{ |
| 80 |
print |
| 81 |
next |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
/<FormatElement / { |
| 86 |
if (group) |
| 87 |
{ |
| 88 |
split( $0, a, / usage="/) |
| 89 |
split( a[2], b, /"/) |
| 90 |
currusage = usage[b[1]] |
| 91 |
} |
| 92 |
else |
| 93 |
{ |
| 94 |
currusage = 0 |
| 95 |
} |
| 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 |
| 107 |
} |
| 108 |
|
| 109 |
/<DateAcceptancePattern[ >]/ { |
| 110 |
print |
| 111 |
next |
| 112 |
} |
| 113 |
|
| 114 |
# Prefix a leading comment (or even an element) to the next FormatElement. |
| 115 |
!inFormatElement { |
| 116 |
leaders[++currleader] = $0 |
| 117 |
next |
| 118 |
} |
| 119 |
|
| 120 |
# Associate any element or comment with the current FormatElement. |
| 121 |
{ |
| 122 |
formats[currusage][currformat][++child] = $0 |
| 123 |
} |
| 124 |
|
| 125 |
/<\/FormatElement>/ { |
| 126 |
inFormatElement = 0 |
| 127 |
} |
| 128 |
|
| 129 |
END { |
| 130 |
} |
| 131 |
|
| 132 |
# vim:set shiftwidth=4 softtabstop=4 expandtab: |