X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=kll.py;h=2ddd35a672ec0d627efb9d7669fda02cb3972bdb;hb=97ae458c4bdb28daecf1c69e4adeec0448b4b54a;hp=ca91da01cac80f109640cc415ec44efe2779d12d;hpb=a005ad49ad33f6f000066ee225474da31ac6d5d1;p=kiibohd-kll.git diff --git a/kll.py b/kll.py index ca91da0..2ddd35a 100755 --- a/kll.py +++ b/kll.py @@ -2,7 +2,7 @@ # KLL Compiler # Keyboard Layout Langauge # -# Copyright (C) 2014 by Jacob Alexander +# Copyright (C) 2014-2015 by Jacob Alexander # # This file is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -61,12 +61,17 @@ argparse._ = textFormatter_gettext ### Argument Parsing ### +def checkFileExists( filename ): + if not os.path.isfile( filename ): + print ( "{0} {1} does not exist...".format( ERROR, filename ) ) + sys.exit( 1 ) + def processCommandLineArgs(): # Setup argument processor pArgs = argparse.ArgumentParser( usage="%(prog)s [options] ...", description="Generates .h file state tables and pointer indices from KLL .kll files.", - epilog="Example: {0} TODO".format( os.path.basename( sys.argv[0] ) ), + epilog="Example: {0} mykeyboard.kll -d colemak.kll -p hhkbpro2.kll -p symbols.kll".format( os.path.basename( sys.argv[0] ) ), formatter_class=argparse.RawTextHelpFormatter, add_help=False, ) @@ -78,17 +83,20 @@ def processCommandLineArgs(): # Optional Arguments pArgs.add_argument( '-b', '--backend', type=str, default="kiibohd", help="Specify target backend for the KLL compiler.\n" - "Default: kiibohd" ) + "Default: kiibohd\n" + "Options: kiibohd, json" ) + pArgs.add_argument( '-d', '--default', type=str, nargs='+', + help="Specify .kll files to layer on top of the default map to create a combined map." ) pArgs.add_argument( '-p', '--partial', type=str, nargs='+', action='append', help="Specify .kll files to generate partial map, multiple files per flag.\n" "Each -p defines another partial map.\n" "Base .kll files (that define the scan code maps) must be defined for each partial map." ) - pArgs.add_argument( '-t', '--template', type=str, default="templates/kiibohdKeymap.h", + pArgs.add_argument( '-t', '--templates', type=str, nargs='+', help="Specify template used to generate the keymap.\n" - "Default: templates/kiibohdKeymap.h" ) - pArgs.add_argument( '-o', '--output', type=str, default="templateKeymap.h", + "Default: " ) + pArgs.add_argument( '-o', '--outputs', type=str, nargs='+', help="Specify output file. Writes to current working directory by default.\n" - "Default: generatedKeymap.h" ) + "Default: " ) pArgs.add_argument( '-h', '--help', action="help", help="This message." ) @@ -96,24 +104,26 @@ def processCommandLineArgs(): args = pArgs.parse_args() # Parameters - defaultFiles = args.files + baseFiles = args.files + defaultFiles = args.default partialFileSets = args.partial + if defaultFiles is None: + defaultFiles = [] if partialFileSets is None: partialFileSets = [[]] # Check file existance + for filename in baseFiles: + checkFileExists( filename ) + for filename in defaultFiles: - if not os.path.isfile( filename ): - print ( "{0} {1} does not exist...".format( ERROR, filename ) ) - sys.exit( 1 ) + checkFileExists( filename ) for partial in partialFileSets: for filename in partial: - if not os.path.isfile( filename ): - print ( "{0} {1} does not exist...".format( ERROR, filename ) ) - sys.exit( 1 ) + checkFileExists( filename ) - return (defaultFiles, partialFileSets, args.backend, args.template, args.output) + return (baseFiles, defaultFiles, partialFileSets, args.backend, args.templates, args.outputs) @@ -156,7 +166,7 @@ def tokenize( string ): ## Map Arrays macros_map = Macros() -variable_dict = dict() +variables_dict = Variables() capabilities_dict = Capabilities() @@ -246,6 +256,9 @@ def make_seqString( token ): def make_string( token ): return token[1:-1] +def make_unseqString( token ): + return token[1:-1] + def make_number( token ): return int( token, 0 ) @@ -312,6 +325,21 @@ def oneLayerFlatten( items ): return mainList + # Capability arguments may need to be expanded (e.g. 1 16 bit argument needs to be 2 8 bit arguments for the state machine) +def capArgExpander( items ): + newArgs = [] + # For each defined argument in the capability definition + for arg in range( 0, len( capabilities_dict[ items[0] ][1] ) ): + argLen = capabilities_dict[ items[0] ][1][ arg ][1] + num = items[1][ arg ] + byteForm = num.to_bytes( argLen, byteorder='little' ) # XXX Yes, little endian from how the uC structs work + + # For each sub-argument, split into byte-sized chunks + for byte in range( 0, argLen ): + newArgs.append( byteForm[ byte ] ) + + return tuple( [ items[0], tuple( newArgs ) ] ) + # Expand ranges of values in the 3rd dimension of the list, to a list of 2nd lists # i.e. [ sequence, [ combo, [ range ] ] ] --> [ [ sequence, [ combo ] ],