Debian Codegraph @

i18npool/source/localedata/data/list-locales.awk

raw
1 #!/usr/bin/gawk -f
2 #
3 # This file is part of the LibreOffice project.
4 #
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 #
9 # This file incorporates work covered by the following license notice:
10 #
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 #
19 #// Usage: gawk -f list-locales.awk *.xml
20 #// Simply create a verbose list of known locales as stated in XML files.
21 #// Author: Eike Rathke <[email protected]>
22
23 BEGIN {
24 file = ""
25 count = 0
26 }
27
28 function init_locale() {
29 lcinfo = 0
30 inlang = 0
31 incoun = 0
32 language = ""
33 country = ""
34 }
35
36 FILENAME != file {
37 printEntry()
38 file = FILENAME
39 ++count
40 init_locale()
41 }
42
43 {
44 if ( !lcinfo )
45 {
46 if ( /<LC_INFO>/ )
47 lcinfo = 1
48 next
49 }
50 if ( /<\/LC_INFO>/ )
51 {
52 lcinfo = 0
53 next
54 }
55 if ( /<Language>/ )
56 inlang = 1
57 if ( inlang && /<DefaultName>/ )
58 {
59 split( $0, x, /<|>/ )
60 language = x[3]
61 }
62 if ( /<\/Language>/ )
63 inlang = 0
64 if ( /<Country>/ )
65 incoun = 1
66 if ( incoun && /<DefaultName>/ )
67 {
68 split( $0, x, /<|>/ )
69 country = x[3]
70 }
71 if ( /<\/Country>/ )
72 incoun = 0
73 }
74
75 END {
76 printEntry()
77 print "\n" count " locales"
78 }
79
80 function printEntry() {
81 if ( file )
82 {
83 tmp = file
84 gsub( /.*\//, "", tmp )
85 gsub( /\.xml/, "", tmp )
86 n = split( tmp, iso, /_/ )
87 if ( n > 2 )
88 {
89 if (length(iso[1]) == 2)
90 printf(" ")
91 printf( "%s: %s - %s\n", tmp, language, country )
92 }
93 else if ( n == 2 )
94 printf( "%3s_%2s: %s - %s\n", iso[1], iso[2], language, country )
95 else
96 printf( "%3s %2s: %s %s\n", iso[1], iso[2], language, country )
97 }
98 }