diff options
Diffstat (limited to 'util')
| -rwxr-xr-x | util/edid/qedidvendortable.py | 82 |
1 files changed, 64 insertions, 18 deletions
diff --git a/util/edid/qedidvendortable.py b/util/edid/qedidvendortable.py index 0991d75db77..60ec19391ca 100755 --- a/util/edid/qedidvendortable.py +++ b/util/edid/qedidvendortable.py @@ -3,14 +3,14 @@ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import urllib.request +import sys # The original source for this data used to be # 'https://git.fedorahosted.org/cgit/hwdata.git/plain/pnp.ids' # which is discontinued. For now there seems to be a fork at: url = 'https://github.com/vcrhonek/hwdata/raw/master/pnp.ids' # REUSE-IgnoreStart -copyright = """ -// Copyright (C) 2017 Pier Luigi Fiorini <[email protected]> +copyright = """// Copyright (C) 2017 Pier Luigi Fiorini <[email protected]> // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only """ # REUSE-IgnoreEnd @@ -37,43 +37,89 @@ header = """ // #include <QtCore/private/qglobal_p.h> +#include <QtCore/qtypes.h> + +#include <iterator> QT_BEGIN_NAMESPACE +""" -struct VendorTable { +vendorIdHeader = """struct QEdidVendorId { const char id[4]; - const char name[%d]; }; -static const VendorTable q_edidVendorTable[] = {""" +static constexpr QEdidVendorId q_edidVendorIds[] = {""" + +vendorIdFooter = """}; +""" + +vendorNameHeader = """static constexpr char q_edidVendorNames[] = {""" + +vendorNameFooter = """}; +""" + +vendorNameOffsetHeader = """static constexpr %s q_edidVendorNamesOffsets[] = {""" + +vendorNameOffsetFooter = """}; +""" -footer = """}; +footer = """static_assert(std::size(q_edidVendorIds) == std::size(q_edidVendorNamesOffsets)); QT_END_NAMESPACE #endif // QEDIDVENDORTABLE_P_H""" -vendors = {} -max_vendor_length = 0 +# Actual script begins here +vendors = {} + +vendorNameTotalLength = 0 response = urllib.request.urlopen(url) data = response.read().decode('utf-8') for line in data.split('\n'): - l = line.split() if line.startswith('#'): continue - elif len(l) == 0: + elif len(line) == 0: + continue + + l = line.split('\t', 1) + if len(l) == 0: continue - else: - pnp_id = l[0].upper() - vendors[pnp_id] = ' '.join(l[1:]) - if len(vendors[pnp_id]) > max_vendor_length: - max_vendor_length = len(vendors[pnp_id]) + + pnp_id = l[0].upper() + if len(pnp_id) != 3: + sys.exit("Id '%s' is non-conforming" % pnp_id) + vendors[pnp_id] = l[1] + vendorNameTotalLength += len(l[1]) + 1 + +sortedVendorKeys = sorted(vendors.keys()) print(copyright) print(notice) -print(header % (max_vendor_length + 1)) -for pnp_id in sorted(vendors.keys()): - print(' { "%s", "%s" },' % (pnp_id, vendors[pnp_id])) +print(header) + +print(vendorIdHeader) +print(*[(' { "%s" }' % pnp_id) for pnp_id in sortedVendorKeys], sep=",\n") +print(vendorIdFooter) + +print(vendorNameHeader) +print(*[(' "%s\\0"' % vendors[pnp_id]) for pnp_id in sortedVendorKeys], sep="\n") +print(vendorNameFooter) + +if vendorNameTotalLength < 2**16: + print(vendorNameOffsetHeader % "quint16") +elif vendorNameTotalLength < 2**32: + print(vendorNameOffsetHeader % "quint32") +else: + sys.exit("Vendor name table is too big") + +currentOffset = 0 +for pnp_id in sortedVendorKeys: + vendor = vendors[pnp_id] + print(' %d,' % currentOffset) + currentOffset += len(vendor) + 1 + +print(vendorNameOffsetFooter) + print(footer) |
