#!/usr/bin/env python

# Copyright (C) 2000, 2001 Intevation GmbH <intevation@intevation.de>
# Author: Bernhard Herzog <bh@intevation.de>
#
# This program is free software under the LGPL (>=v2)
# Read the file COPYING coming with MapIt! for details.

"""Usage: poiconv <icon> <name> [<infile>] [<outfile>]

Read poi definitions from infile and write mapit markerdefs to outfile.
<icon> is used for the icon name and <name> is used as the name for each
marker, effectively putting all markers into the same group. <infile>
and <outfile> are optional and default to stdin and stdout respectively.

"""

__version__="$Revision: 1.4 $"


import sys
from string import split, strip

def convert_file(infile, outfile, icon, name):
    for line in infile.readlines():
        label, x, y = map(strip, split(line, ";"))
        outfile.write("%s,%s,%s,%s,,%s\n" % (x, y, icon, name, label))

def main():
    if len(sys.argv) < 3 or len(sys.argv) > 5:
        print __doc__
        sys.exit(1)
    icon = sys.argv[1]
    name = sys.argv[2]
    if len(sys.argv) > 3:
        infile = open(sys.argv[3])
    else:
        infile = sys.stdin
    if len(sys.argv) > 4:
        outfile = open(sys.argv[4], "w")
    else:
        outfile = sys.stdout
    convert_file(infile, outfile, icon, name)

if __name__ == '__main__':
    main()
