#
# genmap_greek.py: Greek (ISO-8859-7) Character Map Generater
#
# Copyright (C) 2003 Hye-Shik Chang <perky@FreeBSD.org>.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# $Id: genmap_schinese.py,v 1.1.1.1 2003/09/24 17:47:07 perky Exp $
#

from genmap_support import *

LATIN7_MAPRANGE = range(0xa0, 0x100)

try:
    latin7map = open('8859-7.TXT')
except IOError:
    print "=>> Please download mapping table from http://www.unicode." \
          "org/Public/MAPPINGS/ISO8859/8859-7.TXT"
    raise SystemExit

print "Loading Mapping File..."
latin7decmap = loadmap(latin7map, sbcs=1)

omap = open('map_iso8859_7.h', 'w')
printcopyright(omap)
print "Generating ISO-8859-7 decode map..."

print >> omap, "static const short _iso8859_7_dechigh[%d] = {" % (
    LATIN7_MAPRANGE[-1] - LATIN7_MAPRANGE[0] + 1)
cvbuf = []
decmap = latin7decmap[0]
for c in LATIN7_MAPRANGE:
    if decmap.has_key(c):
        cvbuf.append('0x%04x' % decmap[c])
    else:
        cvbuf.append('UNIINV')

    if len(cvbuf) >= 8:
        print >> omap, ', '.join(cvbuf) + ','
        del cvbuf[:]
print >> omap, "};"

encmap = {}
for k, v in latin7decmap[0].iteritems():
    encmap[v] = k

for i in range(0, 0x400):
    if not encmap.has_key(i):
        print hex(i), "=============="
    else:
        print hex(i), hex(encmap[i]), hex(i-encmap[i])

print "\nDone!"
# ex: ts=8 sts=4 et
