Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python2.5 |
| 2 | """This script reads struct |
| 3 | |
| 4 | Author ykk |
| 5 | Date Jan 2010 |
| 6 | """ |
| 7 | import sys |
| 8 | import getopt |
| 9 | import cpythonize |
| 10 | import cheader |
| 11 | |
| 12 | def usage(): |
| 13 | """Display usage |
| 14 | """ |
| 15 | print "Usage "+sys.argv[0]+" <options> header_files... output_file\n"+\ |
| 16 | "Options:\n"+\ |
| 17 | "-h/--help\n\tPrint this usage guide\n"+\ |
| 18 | "" |
| 19 | |
| 20 | #Parse options and arguments |
| 21 | try: |
| 22 | opts, args = getopt.getopt(sys.argv[1:], "h", |
| 23 | ["help"]) |
| 24 | except getopt.GetoptError: |
| 25 | usage() |
| 26 | sys.exit(2) |
| 27 | |
| 28 | #Parse options |
| 29 | for opt,arg in opts: |
| 30 | if (opt in ("-h","--help")): |
| 31 | usage() |
| 32 | sys.exit(0) |
| 33 | else: |
| 34 | print "Unhandled option :"+opt |
| 35 | sys.exit(2) |
| 36 | |
| 37 | #Check there is at least 1 input file with 1 output file |
| 38 | if (len(args) < 2): |
| 39 | usage() |
| 40 | sys.exit(2) |
| 41 | |
| 42 | ch = cheader.cheaderfile(args[:-1]) |
| 43 | py = cpythonize.pythonizer(ch) |
| 44 | fileRef = open(args[len(args)-1], "w") |
| 45 | for l in py.pycode(): |
| 46 | fileRef.write(l+"\n") |
| 47 | fileRef.close() |
| 48 | |