From 72947e82fef1800d50e6d317fbfd7be05aaebf6b Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Fri, 28 Apr 2017 11:23:55 +0200 Subject: Add group option, group by usage attribute Change-Id: Ib20d6ca4bad6f15999abdd93b74ccb3e82a664d6 --- i18npool/source/localedata/data/sort-formats.awk | 68 ++++++++++++++++++++---- 1 file changed, 59 insertions(+), 9 deletions(-) (limited to 'i18npool') 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 } /]/ { @@ -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>/ { } // { 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 { -- cgit