1#!/usr/bin/gawk -f
2#// Usage: gawk -f list-locales.awk *.xml
3#// Simply create a verbose list of known locales as stated in XML files.
4#// Author: Eike Rathke <erack@sun.com>
5
6BEGIN {
7    file = ""
8    count = 0
9}
10
11function init_locale() {
12    lcinfo = 0
13    inlang = 0
14    incoun = 0
15    language = ""
16    country = ""
17}
18
19FILENAME != file {
20    printEntry()
21    file = FILENAME
22    ++count
23    init_locale()
24}
25
26{
27    if ( !lcinfo )
28    {
29        if ( /<LC_INFO>/ )
30            lcinfo = 1
31        next
32    }
33    if ( /<\/LC_INFO>/ )
34    {
35        lcinfo = 0
36        next
37    }
38    if ( /<Language>/ )
39        inlang = 1
40    if ( inlang && /<DefaultName>/ )
41    {
42        split( $0, x, /<|>/ )
43        language = x[3]
44    }
45    if ( /<\/Language>/ )
46        inlang = 0
47    if ( /<Country>/ )
48        incoun = 1
49    if ( incoun && /<DefaultName>/ )
50    {
51        split( $0, x, /<|>/ )
52        country = x[3]
53    }
54    if ( /<\/Country>/ )
55        incoun = 0
56}
57
58END {
59    printEntry()
60    print "\n" count " locales"
61}
62
63function printEntry() {
64    if ( file )
65    {
66        tmp = file
67        gsub( /.*\//, "", tmp )
68        gsub( /\.xml/, "", tmp )
69        split( tmp, iso, /_/ )
70        if ( iso[2] )
71            printf( "%3s_%2s: %s - %s\n", iso[1], iso[2], language, country )
72        else
73            printf( "%3s %2s: %s   %s\n", iso[1], iso[2], language, country )
74    }
75}
76