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