| 1 | |
| 2 | from __future__ import print_function |
| 3 | |
| 4 | import numbers |
| 5 | |
| 6 | import crcmod.predefined |
| 7 | |
| 8 | table_data = [ |
| 9 | [ "Name", 'name', 32, ], |
| 10 | [ "Polynomial", 'poly', 22, ], |
| 11 | [ "Reversed?", 'reverse', 10, ], |
| 12 | [ "Init-value", 'init', 20, ], |
| 13 | [ "XOR-out", 'xor_out', 20, ], |
| 14 | [ "Check", 'check', 20, ], |
| 15 | ] |
| 16 | |
| 17 | ccitt_defns = [ |
| 18 | 'kermit', |
| 19 | 'crc-ccitt-false', |
| 20 | 'crc-aug-ccitt', |
| 21 | ] |
| 22 | |
| 23 | column_dashes = ' '.join(('=' * table_data_item[2] for table_data_item in table_data)) |
| 24 | print(column_dashes) |
| 25 | print(' '.join(("%-*s" % (table_data_item[2], table_data_item[0]) for table_data_item in table_data)).strip()) |
| 26 | print(column_dashes) |
| 27 | |
| 28 | for defn in crcmod.predefined._crc_definitions: |
| 29 | poly_width = crcmod.crcmod._verifyPoly(defn['poly']) |
| 30 | hex_width = (poly_width + 3) // 4 |
| 31 | defn_data_list = [] |
| 32 | for (header_text, key, width) in table_data: |
| 33 | if isinstance(defn[key], bool): |
| 34 | item = "%s" % (defn[key],) |
| 35 | elif isinstance(defn[key], numbers.Integral): |
| 36 | item = "0x%0*X" % (hex_width, defn[key]) |
| 37 | else: |
| 38 | item = "``%s``" % (defn[key]) |
| 39 | if defn['name'] in ccitt_defns: |
| 40 | item = ' '.join([item, '[#ccitt]_']) |
| 41 | item = "%-*s" % (width, item) |
| 42 | defn_data_list.append(item) |
| 43 | print(' '.join(defn_data_list).strip()) |
| 44 | |
| 45 | print(column_dashes) |