Changeset 59735 in vbox
- Timestamp:
- Feb 19, 2016 2:28:13 AM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 105599
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/USBIdDatabaseGenerator.cpp
r59734 r59735 22 22 #include <stdio.h> 23 23 24 #include <fstream>25 #include <iostream>26 #include <iomanip>27 24 #include <algorithm> 28 25 #include <map> … … 59 56 static bool g_fVerbose = false; 60 57 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"; 58 const char * const g_pszStartBlock = "# Vendors, devices and interfaces. Please keep sorted."; 59 const char * const g_pszEndBlock = "# List of known device classes, subclasses and protocols"; 114 60 115 61 … … 147 93 148 94 typedef std::vector<ProductRecord> ProductsSet; 149 typedef std::vector<VendorRecord> VendorsSet;95 typedef std::vector<VendorRecord> VendorsSet; 150 96 151 97 … … 153 99 * Global Variables * 154 100 *********************************************************************************************************************************/ 155 ProductsSet g_products;156 VendorsSetg_vendors;101 static ProductsSet g_products; 102 static VendorsSet g_vendors; 157 103 158 104 /** The size of all the raw strings, including terminators. */ … … 185 131 * Input file parsing. 186 132 */ 187 int ParseAlias(char *pszLine, size_t& id, std::string& desc)133 static int ParseAlias(char *pszLine, size_t& id, std::string& desc) 188 134 { 189 135 /* First there's a hexadeciman number. */ … … 223 169 } 224 170 225 bool IsCommentOrEmptyLine(const char *pszLine)171 static bool IsCommentOrEmptyLine(const char *pszLine) 226 172 { 227 173 pszLine = RTStrStripL(pszLine); … … 229 175 } 230 176 231 int ParseUsbIds(PRTSTREAM instream)177 static int ParseUsbIds(PRTSTREAM instream) 232 178 { 233 179 /* … … 249 195 if (!fLookingForData) 250 196 { 251 if (!strstr(szLine, end_block))197 if (!strstr(szLine, g_pszEndBlock)) 252 198 { 253 199 if (!IsCommentOrEmptyLine(szLine)) … … 281 227 return RTEXITCODE_SUCCESS; 282 228 } 283 else if (strstr(szLine, start_block))229 else if (strstr(szLine, g_pszStartBlock)) 284 230 fLookingForData = false; 285 231 } … … 291 237 } 292 238 239 static 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 } 293 302 294 303 static int usage(FILE *pOut, const char *argv0) … … 445 454 return RTMsgErrorExit((RTEXITCODE)ERROR_OPEN_FILE, "Error opening '%s' for writing", pszOutFile); 446 455 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); 466 457 467 458 if (ferror(pOut))
Note:
See TracChangeset
for help on using the changeset viewer.