a45fef2
#!/usr/bin/python3
a45fef2
#
a45fef2
# This script turns localedata/SUPPORTED (whose path is passed as the
a45fef2
# first argument) into a normalized list of LANGUAGE "_" REGION pairs.
a45fef2
# (If there is no REGION defined, only LANGUAGE is used.)  The list
a45fef2
# is written to standard output, with one element per line.
a45fef2
a45fef2
import sys
a45fef2
a45fef2
supported, = sys.argv[1:]
a45fef2
a45fef2
# Pairs seen so far.  Used to suppress duplicates.
a45fef2
seen = set()
a45fef2
with open(supported) as inp:
a45fef2
    for line in inp:
a45fef2
        if line.startswith("#") or line == "SUPPORTED-LOCALES=\\\n":
a45fef2
            # Comment or prefix.
a45fef2
            continue
a45fef2
        if not line.endswith(" \\\n"):
a45fef2
            raise IOError("line without continuation: " + repr(line))
a45fef2
        try:
a45fef2
            slash = line.index("/")
a45fef2
        except ValueError:
a45fef2
            raise IOError("line without slash: " + repr(line))
a45fef2
        spec = line[:slash]
a45fef2
        for separator in ".@":
a45fef2
            try:
a45fef2
                # Strip charset, variant specifiers.
a45fef2
                spec = spec[:spec.index(separator)]
a45fef2
            except ValueError:
a45fef2
                pass
a45fef2
        seen.add(spec)
a45fef2
a45fef2
# The C locale does not correspond to a language.
a45fef2
seen.remove("C")
a45fef2
a45fef2
# The glibc source file is not sorted.
a45fef2
for spec in sorted(seen):
a45fef2
    print(spec)
a45fef2
print() # The Lua generator produces a trailing newline.