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