VirtualBox

Changeset 59735 in vbox


Ignore:
Timestamp:
Feb 19, 2016 2:28:13 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105599
Message:

USBIdDatabaseGenerator: Inline the generated source code strings - easier to read in my opinion.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/USBIdDatabaseGenerator.cpp

    r59734 r59735  
    2222#include <stdio.h>
    2323
    24 #include <fstream>
    25 #include <iostream>
    26 #include <iomanip>
    2724#include <algorithm>
    2825#include <map>
     
    5956static bool g_fVerbose = false;
    6057
    61 static const char * const header =
    62     "/** @file\n"
    63     " * USB device vendor and product ID database - Autogenerated from <stupid C++ cannot do %s>\n"
    64     " */\n"
    65     "\n"
    66     "/*\n"
    67     " * Copyright (C) 2015-2016 Oracle Corporation\n"
    68     " *\n"
    69     " * This file is part of VirtualBox Open Source Edition(OSE), as\n"
    70     " * available from http ://www.virtualbox.org. This file is free software;\n"
    71     " * you can redistribute it and / or modify it under the terms of the GNU\n"
    72     " * General Public License(GPL) as published by the Free Software\n"
    73     " * Foundation, in version 2 as it comes in the \"COPYING\" file of the\n"
    74     " * VirtualBox OSE distribution.VirtualBox OSE is distributed in the\n"
    75     " * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.\n"
    76     " */"
    77     "\n"
    78     "\n"
    79     "#include \"USBIdDatabase.h\"\n"
    80     "\n";
    81 static const char * const product_header =
    82     "/**\n"
    83     " * USB devices aliases array.\n"
    84     " * Format: VendorId, ProductId, Vendor Name, Product Name\n"
    85     " * The source of the list is http://www.linux-usb.org/usb.ids\n"
    86     " */\n"
    87     "USBIDDBPROD const USBIdDatabase::s_aProducts[] =\n"
    88     "{\n";
    89 const char * const product_part2 =
    90     "};\n"
    91     "\n"
    92     "\nconst RTBLDPROGSTRREF USBIdDatabase::s_aProductNames[] =\n"
    93     "{\n";
    94 const char * const product_footer =
    95     "};\n"
    96     "\n"
    97     "const size_t USBIdDatabase::s_cProducts = RT_ELEMENTS(USBIdDatabase::s_aProducts);\n";
    98 
    99 const char * const vendor_header =
    100     "\nUSBIDDBVENDOR const USBIdDatabase::s_aVendors[] =\n"
    101     "{\n";
    102 const char * const vendor_part2 =
    103     "};\n"
    104     "\n"
    105     "\nconst RTBLDPROGSTRREF USBIdDatabase::s_aVendorNames[] =\n"
    106     "{\n";
    107 const char * const vendor_footer =
    108     "};\n"
    109     "\n"
    110     "const size_t USBIdDatabase::s_cVendors = RT_ELEMENTS(USBIdDatabase::s_aVendors);\n";
    111 
    112 const char * const start_block = "# Vendors, devices and interfaces. Please keep sorted.";
    113 const char * const end_block = "# List of known device classes, subclasses and protocols";
     58const char * const g_pszStartBlock = "# Vendors, devices and interfaces. Please keep sorted.";
     59const char * const g_pszEndBlock   = "# List of known device classes, subclasses and protocols";
    11460
    11561
     
    14793
    14894typedef std::vector<ProductRecord> ProductsSet;
    149 typedef std::vector<VendorRecord> VendorsSet;
     95typedef std::vector<VendorRecord>  VendorsSet;
    15096
    15197
     
    15399*   Global Variables                                                                                                             *
    154100*********************************************************************************************************************************/
    155 ProductsSet g_products;
    156 VendorsSet g_vendors;
     101static ProductsSet g_products;
     102static VendorsSet g_vendors;
    157103
    158104/** The size of all the raw strings, including terminators. */
     
    185131 * Input file parsing.
    186132 */
    187 int ParseAlias(char *pszLine, size_t& id, std::string& desc)
     133static int ParseAlias(char *pszLine, size_t& id, std::string& desc)
    188134{
    189135    /* First there's a hexadeciman number. */
     
    223169}
    224170
    225 bool IsCommentOrEmptyLine(const char *pszLine)
     171static bool IsCommentOrEmptyLine(const char *pszLine)
    226172{
    227173    pszLine = RTStrStripL(pszLine);
     
    229175}
    230176
    231 int ParseUsbIds(PRTSTREAM instream)
     177static int ParseUsbIds(PRTSTREAM instream)
    232178{
    233179    /*
     
    249195            if (!fLookingForData)
    250196            {
    251                 if (!strstr(szLine, end_block))
     197                if (!strstr(szLine, g_pszEndBlock))
    252198                {
    253199                    if (!IsCommentOrEmptyLine(szLine))
     
    281227                    return RTEXITCODE_SUCCESS;
    282228            }
    283             else if (strstr(szLine, start_block))
     229            else if (strstr(szLine, g_pszStartBlock))
    284230                fLookingForData = false;
    285231        }
     
    291237}
    292238
     239static void WriteSourceFile(FILE *pOut, const char *argv0, PBLDPROGSTRTAB pStrTab)
     240{
     241    fprintf(pOut,
     242            "/** @file\n"
     243            " * USB device vendor and product ID database - Autogenerated by %s\n"
     244            " */\n"
     245            "\n"
     246            "/*\n"
     247            " * Copyright (C) 2015-2016 Oracle Corporation\n"
     248            " *\n"
     249            " * This file is part of VirtualBox Open Source Edition(OSE), as\n"
     250            " * available from http ://www.virtualbox.org. This file is free software;\n"
     251            " * you can redistribute it and / or modify it under the terms of the GNU\n"
     252            " * General Public License(GPL) as published by the Free Software\n"
     253            " * Foundation, in version 2 as it comes in the \"COPYING\" file of the\n"
     254            " * VirtualBox OSE distribution.VirtualBox OSE is distributed in the\n"
     255            " * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.\n"
     256            " */"
     257            "\n"
     258            "\n"
     259            "#include \"USBIdDatabase.h\"\n"
     260            "\n",
     261            argv0);
     262
     263    BldProgStrTab_WriteStringTable(pStrTab, pOut, "", "USBIdDatabase::s_", "StrTab");
     264
     265    fputs("/**\n"
     266          " * USB devices aliases array.\n"
     267          " * Format: VendorId, ProductId, Vendor Name, Product Name\n"
     268          " * The source of the list is http://www.linux-usb.org/usb.ids\n"
     269          " */\n"
     270          "USBIDDBPROD const USBIdDatabase::s_aProducts[] =\n"
     271          "{\n", pOut);
     272    for (ProductsSet::iterator itp = g_products.begin(); itp != g_products.end(); ++itp)
     273        fprintf(pOut, "    { 0x%04x },\n", itp->productID);
     274    fputs("};\n"
     275          "\n"
     276          "\n"
     277          "const RTBLDPROGSTRREF USBIdDatabase::s_aProductNames[] =\n"
     278          "{\n", pOut);
     279    for (ProductsSet::iterator itp = g_products.begin(); itp != g_products.end(); ++itp)
     280        fprintf(pOut, "{ 0x%06x, 0x%02x },\n", itp->StrRef.offStrTab, itp->StrRef.cchString);
     281    fputs("};\n"
     282          "\n"
     283          "const size_t USBIdDatabase::s_cProducts = RT_ELEMENTS(USBIdDatabase::s_aProducts);\n"
     284          "\n", pOut);
     285
     286    fputs("USBIDDBVENDOR const USBIdDatabase::s_aVendors[] =\n"
     287          "{\n", pOut);
     288    for (VendorsSet::iterator itv = g_vendors.begin(); itv != g_vendors.end(); ++itv)
     289        fprintf(pOut, "    { 0x%04x, 0x%04x, 0x%04x },\n", itv->vendorID, itv->iProduct, itv->cProducts);
     290    fputs("};\n"
     291          "\n"
     292          "\n"
     293          "const RTBLDPROGSTRREF USBIdDatabase::s_aVendorNames[] =\n"
     294          "{\n", pOut);
     295    for (VendorsSet::iterator itv = g_vendors.begin(); itv != g_vendors.end(); ++itv)
     296        fprintf(pOut, "{ 0x%06x, 0x%02x },\n", itv->StrRef.offStrTab, itv->StrRef.cchString);
     297    fputs("};\n"
     298          "\n"
     299          "const size_t USBIdDatabase::s_cVendors = RT_ELEMENTS(USBIdDatabase::s_aVendors);\n"
     300          "\n", pOut);
     301}
    293302
    294303static int usage(FILE *pOut, const char *argv0)
     
    445454        return RTMsgErrorExit((RTEXITCODE)ERROR_OPEN_FILE, "Error opening '%s' for writing", pszOutFile);
    446455
    447     fputs(header, pOut);
    448     BldProgStrTab_WriteStringTable(&StrTab, pOut, "", "USBIdDatabase::s_", "StrTab");
    449 
    450     fputs(product_header, pOut);
    451     for (ProductsSet::iterator itp = g_products.begin(); itp != g_products.end(); ++itp)
    452         fprintf(pOut, "    { 0x%04x },\n", itp->productID);
    453 
    454     fputs(product_part2, pOut);
    455     for (ProductsSet::iterator itp = g_products.begin(); itp != g_products.end(); ++itp)
    456         fprintf(pOut, "{ 0x%06x, 0x%02x },\n", itp->StrRef.offStrTab, itp->StrRef.cchString);
    457     fputs(product_footer, pOut);
    458 
    459     fputs(vendor_header, pOut);
    460     for (VendorsSet::iterator itv = g_vendors.begin(); itv != g_vendors.end(); ++itv)
    461         fprintf(pOut, "    { 0x%04x, 0x%04x, 0x%04x },\n", itv->vendorID, itv->iProduct, itv->cProducts);
    462     fputs(vendor_part2, pOut);
    463     for (VendorsSet::iterator itv = g_vendors.begin(); itv != g_vendors.end(); ++itv)
    464         fprintf(pOut, "{ 0x%06x, 0x%02x },\n", itv->StrRef.offStrTab, itv->StrRef.cchString);
    465     fputs(vendor_footer, pOut);
     456    WriteSourceFile(pOut, argv[0], &StrTab);
    466457
    467458    if (ferror(pOut))
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette