Пример #1
0
def main():
    """
    Main function.
    """
    opt = Options()
    opt.parse(sys.argv[1:])
    if opt.Verbose:
        print(print_parameters(opt))
    if opt.Action == opt.Action_Check_String:
        crc = check_string(opt)
        print("0x%x" % crc)
    if opt.Action == opt.Action_Check_Hex_String:
        crc = check_hexstring(opt)
        print("0x%x" % crc)
    if opt.Action == opt.Action_Check_File:
        crc = check_file(opt)
        print("0x%x" % crc)
    if opt.Action in set([
            opt.Action_Generate_H, opt.Action_Generate_C,
            opt.Action_Generate_C_Main, opt.Action_Generate_Table
    ]):
        mp = MacroParser(opt)
        if opt.Action == opt.Action_Generate_H:
            in_str = "$h_template"
        elif opt.Action == opt.Action_Generate_C:
            in_str = "$c_template"
        elif opt.Action == opt.Action_Generate_C_Main:
            in_str = "$c_template\n\n$main_template"
        elif opt.Action == opt.Action_Generate_Table:
            in_str = "$crc_table_init"
        else:
            sys.stderr.write(
                "%s: error: unknown action. Please file a bug report!\n" %
                sys.argv[0])
            sys.exit(1)
        mp.parse(in_str)
        if opt.OutputFile == None:
            print(mp.out_str)
        else:
            try:
                out_file = open(opt.OutputFile, "w")
                out_file.write(mp.out_str)
                out_file.close()
            except IOError:
                sys.stderr.write("%s: error: cannot write to file %s\n" %
                                 (sys.argv[0], opt.OutputFile))
                sys.exit(1)
    return 0
Пример #2
0
def print_parameters(opt):
    """
    Generate a string with the options pretty-printed (used in the --verbose mode).
    """
    in_str  = ""
    in_str += "Width        = $crc_width\n"
    in_str += "Poly         = $crc_poly\n"
    in_str += "ReflectIn    = $crc_reflect_in\n"
    in_str += "XorIn        = $crc_xor_in\n"
    in_str += "ReflectOut   = $crc_reflect_out\n"
    in_str += "XorOut       = $crc_xor_out\n"
    in_str += "Algorithm    = $crc_algorithm\n"

    mp = MacroParser(opt)
    mp.parse(in_str)
    return mp.out_str
Пример #3
0
def print_parameters(opt):
    """
    Generate a string with the options pretty-printed (used in the --verbose mode).
    """
    in_str  = ""
    in_str += "Width        = $crc_width\n"
    in_str += "Poly         = $crc_poly\n"
    in_str += "ReflectIn    = $crc_reflect_in\n"
    in_str += "XorIn        = $crc_xor_in\n"
    in_str += "ReflectOut   = $crc_reflect_out\n"
    in_str += "XorOut       = $crc_xor_out\n"
    in_str += "Algorithm    = $crc_algorithm\n"

    mp = MacroParser(opt)
    mp.parse(in_str)
    return mp.out_str
Пример #4
0
def main( a ):
    """
    Main function.
    """
    opt = Options()
    #print(sys.argv[1:])
    opt.parse(a)
    
    if opt.Verbose:
        print(print_parameters(opt))
    if opt.Action == opt.Action_Check_String:
        crc = check_string(opt)
    if opt.Action == opt.Action_Check_Hex_String:
        crc = check_hexstring(opt)
        #print("0x%x" % crc)
    if opt.Action == opt.Action_Check_File:
        crc = check_file(opt)
        #print("0x%x" % crc)
    if opt.Action in set([opt.Action_Generate_H, opt.Action_Generate_C, opt.Action_Generate_C_Main, opt.Action_Generate_Table]):
        mp = MacroParser(opt)
        if opt.Action == opt.Action_Generate_H:
            in_str = "$h_template"
        elif opt.Action == opt.Action_Generate_C:
            in_str = "$c_template"
        elif opt.Action == opt.Action_Generate_C_Main:
            in_str = "$c_template\n\n$main_template"
        elif opt.Action == opt.Action_Generate_Table:
            in_str = "$crc_table_init"
        else:
            sys.stderr.write("%s: error: unknown action. Please file a bug report!\n" % sys.argv[0])
            sys.exit(1)
        mp.parse(in_str)
        if opt.OutputFile == None:
            print(mp.out_str)
        else:
            try:
                out_file = open(opt.OutputFile, "w")
                out_file.write(mp.out_str)
                out_file.close()
            except IOError:
                sys.stderr.write("%s: error: cannot write to file %s\n" % (sys.argv[0], opt.OutputFile))
                sys.exit(1)
    return crc
Пример #5
0
def main():
    """
    Main function.
    """
    opt = Options()
    opt.parse(sys.argv[1:])
    if opt.verbose:
        print(print_parameters(opt))
    if opt.action == opt.action_check_str:
        crc = check_string(opt)
        print("{0:#x}".format(crc))
    if opt.action == opt.action_check_hex_str:
        crc = check_hexstring(opt)
        print("{0:#x}".format(crc))
    if opt.action == opt.action_check_file:
        crc = check_file(opt)
        print("{0:#x}".format(crc))
    if opt.action in set([
            opt.action_generate_h, opt.action_generate_c,
            opt.action_generate_c_main, opt.action_generate_table
    ]):
        parser = MacroParser(opt)
        if opt.action == opt.action_generate_h:
            in_str = "$h_template"
        elif opt.action == opt.action_generate_c:
            in_str = "$c_template"
        elif opt.action == opt.action_generate_c_main:
            in_str = "$c_template\n\n$main_template"
        elif opt.action == opt.action_generate_table:
            in_str = "$crc_table_init"
        else:
            sys.stderr.write(
                "{0:s}: error: unknown action. Please file a bug report!\n".
                format(sys.argv[0]))
            sys.exit(1)
        parser.parse(in_str)
        if opt.output_file == None:
            print(parser.out_str)
        else:
            write_file(opt.output_file, parser.out_str)
    return 0
Пример #6
0
def main():
    """
    Main function.
    """
    opt = Options()
    opt.parse(sys.argv[1:])
    if opt.verbose:
        print(print_parameters(opt))
    if opt.action == opt.action_check_str:
        crc = check_string(opt)
        print("{0:#x}".format(crc))
    if opt.action == opt.action_check_hex_str:
        crc = check_hexstring(opt)
        print("{0:#x}".format(crc))
    if opt.action == opt.action_check_file:
        crc = check_file(opt)
        print("{0:#x}".format(crc))
    if opt.action in set([
            opt.action_generate_h, opt.action_generate_c, opt.action_generate_c_main,
            opt.action_generate_table]):
        parser = MacroParser(opt)
        if opt.action == opt.action_generate_h:
            in_str = "$h_template"
        elif opt.action == opt.action_generate_c:
            in_str = "$c_template"
        elif opt.action == opt.action_generate_c_main:
            in_str = "$c_template\n\n$main_template"
        elif opt.action == opt.action_generate_table:
            in_str = "$crc_table_init"
        else:
            sys.stderr.write(
                "{0:s}: error: unknown action. Please file a bug report!\n".format(sys.argv[0]))
            sys.exit(1)
        parser.parse(in_str)
        if opt.output_file == None:
            print(parser.out_str)
        else:
            write_file(opt.output_file, parser.out_str)
    return 0