1#!/usr/bin/gawk -f
2# *************************************************************
3#
4#  Licensed to the Apache Software Foundation (ASF) under one
5#  or more contributor license agreements.  See the NOTICE file
6#  distributed with this work for additional information
7#  regarding copyright ownership.  The ASF licenses this file
8#  to you under the Apache License, Version 2.0 (the
9#  "License"); you may not use this file except in compliance
10#  with the License.  You may obtain a copy of the License at
11#
12#    http://www.apache.org/licenses/LICENSE-2.0
13#
14#  Unless required by applicable law or agreed to in writing,
15#  software distributed under the License is distributed on an
16#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17#  KIND, either express or implied.  See the License for the
18#  specific language governing permissions and limitations
19#  under the License.
20#
21# *************************************************************
22#// Usage: gawk -f list-locales.awk *.xml
23#// Simply create a verbose list of known locales as stated in XML files.
24#// Author: Eike Rathke <erack@sun.com>
25
26BEGIN {
27    file = ""
28    count = 0
29}
30
31function init_locale() {
32    lcinfo = 0
33    inlang = 0
34    incoun = 0
35    language = ""
36    country = ""
37}
38
39FILENAME != file {
40    printEntry()
41    file = FILENAME
42    ++count
43    init_locale()
44}
45
46{
47    if ( !lcinfo )
48    {
49        if ( /<LC_INFO>/ )
50            lcinfo = 1
51        next
52    }
53    if ( /<\/LC_INFO>/ )
54    {
55        lcinfo = 0
56        next
57    }
58    if ( /<Language>/ )
59        inlang = 1
60    if ( inlang && /<DefaultName>/ )
61    {
62        split( $0, x, /<|>/ )
63        language = x[3]
64    }
65    if ( /<\/Language>/ )
66        inlang = 0
67    if ( /<Country>/ )
68        incoun = 1
69    if ( incoun && /<DefaultName>/ )
70    {
71        split( $0, x, /<|>/ )
72        country = x[3]
73    }
74    if ( /<\/Country>/ )
75        incoun = 0
76}
77
78END {
79    printEntry()
80    print "\n" count " locales"
81}
82
83function printEntry() {
84    if ( file )
85    {
86        tmp = file
87        gsub( /.*\//, "", tmp )
88        gsub( /\.xml/, "", tmp )
89        split( tmp, iso, /_/ )
90        if ( iso[2] )
91            printf( "%3s_%2s: %s - %s\n", iso[1], iso[2], language, country )
92        else
93            printf( "%3s %2s: %s   %s\n", iso[1], iso[2], language, country )
94    }
95}
96