Changeset 1941 for proto


Ignore:
Timestamp:
Feb 17, 2012, 5:50:13 PM (7 years ago)
Author:
cameron
Message:

Option basis_pattern for charset compiler

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/charsetcompiler/charset_compiler.py

    r1200 r1941  
    33#  Character Class Compiler
    44#
    5 #  Version 0.7 - August 14, 2009
    6 #     Adding generation of Python code;  parabix 2 definitions
    7 #  Copyright (c) 2007, Robert D. Cameron
     5#  Version 0.8 - Feb. 17, 2012
     6#     Add command-line option for specifying basis_pattern
     7#  Copyright (c) 2007-12, Robert D. Cameron
    88#  All rights reserved.
    99#
     
    3030#  3. Code Generator Objects
    3131#
    32 import sys
     32import sys, optparse
    3333import re, binascii, string
    3434
     
    242242
    243243def bit_var(n):
     244    global options
    244245#    return 'bit[%i]' % n
    245     return 'basis_bits.bit_%i' % n
     246    return options.basis_pattern % n
    246247def make_bitv(n):
    247248    return Var(bit_var(n))
     
    574575    return CharSetDef(chardef.name, cdefs, chardef.complemented)
    575576
     577
     578
    576579def main():
    577     if len(sys.argv) == 2:
     580
     581    global options
     582    # Option definition
     583    option_parser = optparse.OptionParser(usage='python %prog [options] <input file>', version='0.8')
     584
     585    option_parser.add_option('-b', '--basis_pattern',
     586                             dest='basis_pattern',
     587                             type='string',
     588                             default='basis_bits.bit_%i',
     589                             help='pattern for basis bit streams; default: basis_bits.bit_%i',
     590                             )
     591    options, args = option_parser.parse_args(sys.argv[1:])
     592
     593    # Positional arguments
     594    if len(args) == 1:
    578595        # if the specified argument is not in the DefinitionSet, then assume that it's a filename
    579         if sys.argv[1] not in DefinitionSet:
     596        if args[0] not in DefinitionSet:
    580597            #define the characters in the list
    581             defs = charset_input_parser.input_chardef(sys.argv[1])
     598            defs = charset_input_parser.input_chardef(args[0])
    582599                                               
    583600            #print chardeflist2simd(defs)
    584601            print chardeflist2py(defs)
    585602        else:
    586             #print chardeflist2simd(DefinitionSet[sys.argv[1]])
    587             print chardeflist2py(DefinitionSet[sys.argv[1]])
    588     elif len(sys.argv) == 3 and sys.argv[2] == 'EBCDIC':
    589         defs = ascii2ebcdic_chardeflist(DefinitionSet[sys.argv[1]])
     603            #print chardeflist2simd(DefinitionSet[args[1]])
     604            print chardeflist2py(DefinitionSet[args[1]])
     605    elif len(args) == 2 and args[1] == 'EBCDIC':
     606        defs = ascii2ebcdic_chardeflist(DefinitionSet[sys.argv[0]])
    590607        print chardeflist2simd(defs)
    591608    else:
    592         print "Usage python charset_compiler.py <name> [EBCDIC]"
    593         for k in DefinitionSet.keys(): print k
     609        option_parser.print_usage()
    594610
    595611if __name__ == "__main__": main()
     612
Note: See TracChangeset for help on using the changeset viewer.