diff options
author | Eike Rathke <erack@redhat.com> | 2017-04-28 11:23:55 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-04-28 11:26:11 +0200 |
commit | 72947e82fef1800d50e6d317fbfd7be05aaebf6b (patch) | |
tree | 1c40ea06544e791f0427593aa5fab088e0dc1182 | |
parent | 952faab8ab597e86636324bdb9e8e3090bf025cc (diff) |
Add group option, group by usage attribute
Change-Id: Ib20d6ca4bad6f15999abdd93b74ccb3e82a664d6
-rwxr-xr-x | i18npool/source/localedata/data/sort-formats.awk | 68 |
1 files changed, 59 insertions, 9 deletions
diff --git a/i18npool/source/localedata/data/sort-formats.awk b/i18npool/source/localedata/data/sort-formats.awk index ffd84e4d517e..1ac040ddb75d 100755 --- a/i18npool/source/localedata/data/sort-formats.awk +++ b/i18npool/source/localedata/data/sort-formats.awk @@ -7,21 +7,35 @@ # 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 ll_CC.xml +# 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[ >]/ { @@ -33,17 +47,28 @@ file != FILENAME { informats && /<\/LC_FORMAT>/ { PROCINFO["sorted_in"] = "@ind_num_asc" - for (f in formats) + for (u in formats) { - if (isarray(formats[f])) + if (isarray(formats[u])) { - for (i in formats[f]) - print formats[f][i] + 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 error: " formats[f] + print "XXX formats[u] error: " formats[u] } } informats = 0 @@ -58,11 +83,26 @@ informats && /<\/LC_FORMAT>/ { } /<FormatElement / { - split( $0, a, /formatindex="/) + 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 - formats[currformat][++child] = $0 + for (l in leaders) + formats[currusage][currformat][++child] = leaders[l] + delete leaders + currleader = 0 + formats[currusage][currformat][++child] = $0 + inFormatElement = 1 next } @@ -71,9 +111,19 @@ informats && /<\/LC_FORMAT>/ { 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[currformat][++child] = $0 + formats[currusage][currformat][++child] = $0 +} + +/<\/FormatElement>/ { + inFormatElement = 0 } END { |