genEDB.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #! /usr/bin/env python2.7
  2. SUBSYS = 'Enc'
  3. MAPPREFIX = 'StdMap_'
  4. OUTDIR = 'out'
  5. import sys, os, string
  6. import gen1, mapA, mappy, util
  7. def isSDBCS (r):
  8. for eord, uord in r:
  9. if eord >= 65536:
  10. return False
  11. return True
  12. def loadMap (format, db):
  13. if format == 'A':
  14. fh = open(db, 'rb')
  15. x = mapA.getMap(fh)
  16. fh.close()
  17. elif format == 'pySBCS':
  18. x = mappy.getMap(db, 'SBCS')
  19. elif format == 'pyDBCS':
  20. x = mappy.getMap(db, 'DBCS')
  21. else:
  22. assert False
  23. return x
  24. def main ():
  25. done = {}
  26. while True:
  27. line = sys.stdin.readline()
  28. if line == '':
  29. break
  30. line = line.strip()
  31. if (len(line) > 0) and (line[0] != '#'):
  32. # print line
  33. enc, format, db, refComment = line.split(': ')
  34. enc = enc.strip()
  35. format = format.strip()
  36. db = db.strip()
  37. refComment = refComment.strip()
  38. assert not done.has_key(enc)
  39. done[enc] = True
  40. x = loadMap(format, db)
  41. if type(x) is not str:
  42. r, e = x
  43. assert len(r) > 0
  44. assert isSDBCS(r) # not implemented
  45. x = util.normEnc(enc)
  46. fName = os.path.join(OUTDIR, MAPPREFIX + x + '.txt')
  47. modName = SUBSYS + MAPPREFIX + x
  48. head0 = "Source: %s" % (refComment,)
  49. mod = gen1.gen(modName, r, e, head0=head0)
  50. fh = open(fName, 'wb')
  51. fh.write(mod)
  52. fh.close()
  53. else:
  54. print 'can not process %s %s %s: %s' % (enc, format, db, x)
  55. if __name__ == '__main__':
  56. main()