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