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