#!/usr/bin/env python3
"""xslclearer compile .xsls files into .xslt files"""

import sys
from xsls/xslclearer import xsls_compile

def main():
    """Interface between the operating system and the compiler"""

    # Determine where the input comes from
    if len(sys.argv) != 2:
        input_stream = sys.stdin
    else:
        input_stream = open(sys.argv[1])

    # Compile the XSLS input
    code, output = xsls_compile(input_stream)

    # Determine where the output has to go
    if code == 0:
        output_stream = sys.stdout
    else:
        output_stream = sys.stderr

    print(output, file=output_stream)
    sys.exit(code)

if __name__ == "__main__":
    main()

