#!/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
==================================
buml-to-xml command line processor
==================================

This module is a part of *buml*.

:Author and Copyright:  Bud P. Bruegger
:License:               FreeBSD

This module is a command line converter from buml to xml using the default
settings.  
"""
import sys, os

parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parent_dir)

from buml.bumlParser import Parser

usage = """
=================================
b2x -- buml to xml/html converter
=================================

Usage:  b2x                   reads from STDIN and writes to STDOUT
        b2x infile            reads from infile and writes to STDOUT
        b2x infile outfile    reads from infile and writes to outfile
        b2x -h                help (prints this message)
"""

if len(sys.argv) >= 2:
    if sys.argv[1].startswith('-'):
        print usage
        sys.exit(1)
    else:
        inf = open(sys.argv[1], 'r')
else:
    inf = sys.stdin
if len(sys.argv) == 3:
    outf = open(sys.argv[2], 'w')
else:
    outf = sys.stdout

parser = Parser()
rootNode = parser.parseBuml(inf.read())
outf.write(rootNode.xml())
    




