Changeset 57338 in vbox
- Timestamp:
- Aug 14, 2015 5:51:13 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Config.kmk
r57335 r57338 552 552 endif 553 553 # Whether to generate a database of USB vendor IDs and device IDs into VBoxSVC. 554 #VBOX_WITH_MAIN_USB_ID_DATABASE = 1554 VBOX_WITH_MAIN_USB_ID_DATABASE = 1 555 555 # The recompiler. 556 556 VBOX_WITH_REM = 1 -
trunk/src/VBox/Main/include/USBIdDatabase.h
r57185 r57338 79 79 { 80 80 Product lookFor = { USBKEY(vendorId, productId) }; 81 Product* it = std::lower_bound(productArray, productArray + products_size + 1, lookFor, ProductLess());81 Product* it = std::lower_bound(productArray, productArray + products_size, lookFor, ProductLess()); 82 82 return lookFor.key == it->key ? it->product : NULL; 83 83 } … … 86 86 { 87 87 Vendor lookFor = { vendorID }; 88 Vendor* it = std::lower_bound(vendorArray, vendorArray + vendors_size + 1, lookFor, VendorLess());88 Vendor* it = std::lower_bound(vendorArray, vendorArray + vendors_size, lookFor, VendorLess()); 89 89 return lookFor.vendorID == it->vendorID ? it->vendor : NULL; 90 90 } -
trunk/src/VBox/Main/src-server/USBIdDatabaseGenerator.cpp
r57034 r57338 19 19 20 20 #include <iprt/string.h> 21 #include <iprt/stream.h> 21 22 22 23 using namespace std; 23 24 24 25 const char* header = "/*\n\ 25 * Copyright(C) 2005 - 2015 Oracle Corporation\n\26 *\n\27 * This file is part of VirtualBox Open Source Edition(OSE), as\n\28 * available from http ://www.virtualbox.org. This file is free software;\n\29 * you can redistribute it and / or modify it under the terms of the GNU\n\30 * General Public License(GPL) as published by the Free Software\n\31 * Foundation, in version 2 as it comes in the \"COPYING\" file of the\n\32 * VirtualBox OSE distribution.VirtualBox OSE is distributed in the\n\33 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.\n\34 *\n\35 */\36 \n\37 \n\38 #include \"USBIdDatabase.h\"\n\39 \n\40 /** USB devices aliases array.\n\41 * Format: VendorId, ProductId, Vendor Name, Product Name\n\42 * The source of the list is http://www.linux-usb.org/usb.ids\n\43 */\n\44 Product AliasDictionary::productArray[] = { \n";26 * Copyright(C) 2005 - 2015 Oracle Corporation\n\ 27 *\n\ 28 * This file is part of VirtualBox Open Source Edition(OSE), as\n\ 29 * available from http ://www.virtualbox.org. This file is free software;\n\ 30 * you can redistribute it and / or modify it under the terms of the GNU\n\ 31 * General Public License(GPL) as published by the Free Software\n\ 32 * Foundation, in version 2 as it comes in the \"COPYING\" file of the\n\ 33 * VirtualBox OSE distribution.VirtualBox OSE is distributed in the\n\ 34 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.\n\ 35 *\n\ 36 */\ 37 \n\ 38 \n\ 39 #include \"USBIdDatabase.h\"\n\ 40 \n\ 41 /** USB devices aliases array.\n\ 42 * Format: VendorId, ProductId, Vendor Name, Product Name\n\ 43 * The source of the list is http://www.linux-usb.org/usb.ids\n\ 44 */\n\ 45 Product AliasDictionary::productArray[] = { \n"; 45 46 46 47 const char* footer = "};\n\ 47 \n\48 const size_t AliasDictionary::products_size = sizeof(AliasDictionary::productArray) / sizeof(Product); \n";48 \n\ 49 const size_t AliasDictionary::products_size = sizeof(AliasDictionary::productArray) / sizeof(Product); \n"; 49 50 50 51 const char* vendor_header = "\nVendor AliasDictionary::vendorArray[] = { \n"; … … 53 54 const size_t AliasDictionary::vendors_size = sizeof(AliasDictionary::vendorArray) / sizeof(Vendor);"; 54 55 55 const wchar_t* start_block = L"# interface interface_name <-- two tabs";56 const wchar_t* end_block = L"# List of known device classes, subclasses and protocols";56 const char* start_block = "# interface interface_name <-- two tabs"; 57 const char* end_block = "# List of known device classes, subclasses and protocols"; 57 58 58 59 #define USBKEY(vendorId, productId) (((vendorId) << 16) | (productId)) … … 68 69 { 69 70 size_t vendorID; 70 wstring vendor;71 string vendor; 71 72 }; 72 73 … … 76 77 size_t vendorID; 77 78 size_t productID; 78 wstring product;79 string product; 79 80 }; 80 81 … … 99 100 } 100 101 101 string conv(const wstring& src) 102 { 103 string res; 104 char* buf = NULL; 105 106 if (RTUtf16ToLatin1((PRTUTF16)src.c_str(), &buf) == VINF_SUCCESS) 107 { 108 size_t len = strlen(buf); 109 for (size_t i = 0; i < len; i++) 110 { 111 if (buf[i] == '"') 112 buf[i] = '\''; 113 } 114 res = buf; 115 RTStrFree(buf); 102 string conv(const string& src) 103 { 104 string res = src; 105 for (size_t i = 0; i < res.length(); i++) 106 { 107 switch (res[i]) 108 { 109 case '"': 110 case '\\': res.insert(i++, "\\"); 111 } 116 112 } 117 113 return res; … … 126 122 } 127 123 128 wostream& operator <<(wostream& stream, const ProductRecord product)129 {130 stream << L"{USBKEY(0x" << hex << product.vendorID131 << L", 0x" << product.productID << L"), "132 << L"\"" << product.product.c_str() << L"\" }," << endl;133 return stream;134 }135 136 124 ostream& operator <<(ostream& stream, const VendorRecord vendor) 137 125 { 138 126 stream << "{0x" << hex << vendor.vendorID 139 127 << ", \"" << conv(vendor.vendor).c_str() << "\" }," << endl; 140 return stream;141 }142 143 wostream& operator <<(wostream& stream, const VendorRecord vendor)144 {145 stream << L"{0x" << hex << vendor.vendorID146 << L", \"" << vendor.vendor.c_str() << L"\" }," << endl;147 128 return stream; 148 129 } … … 165 146 166 147 167 int ParseAlias(const wstring& src, size_t& id, wstring& desc)168 { 169 int i = 0;148 int ParseAlias(const string& src, size_t& id, string& desc) 149 { 150 unsigned int i = 0; 170 151 int idx = 0; 171 wstring sin;172 173 if (s wscanf(src.c_str(), L"%x", &i) != 1)152 string sin; 153 154 if (sscanf(src.c_str(), "%x", &i) != 1) 174 155 return ERROR_IN_PARSE_LINE; 175 156 176 size_t index = src.find_first_of( L" \t", 1);177 index = src.find_first_not_of( L" \t", index);157 size_t index = src.find_first_of(" \t", 1); 158 index = src.find_first_not_of(" \t", index); 178 159 179 160 if (index == string::npos) … … 187 168 } 188 169 189 bool IsCommentOrEmptyLine(const wstring& str) 190 { 191 size_t index = str.find_first_not_of(L" \t");// skip left spaces 192 return index == string::npos || str[index] == L'#'; 193 } 194 195 int ParseUsbIds(wifstream& instream) 170 bool IsCommentOrEmptyLine(const string& str) 171 { 172 size_t index = str.find_first_not_of(" \t");// skip left spaces 173 return index == string::npos || str[index] == '#'; 174 } 175 176 bool getline(PRTSTREAM instream, string& resString) 177 { 178 const size_t szBuf = 4096; 179 char buf[szBuf] = { 0 }; 180 181 int rc = RTStrmGetLine(instream, buf, szBuf); 182 if (RT_SUCCESS(rc)) 183 { 184 resString = buf; 185 return true; 186 } 187 else if (rc != VERR_EOF) 188 { 189 cerr << "Warning: Invalid line in file. Error: " << hex << rc << endl; 190 } 191 return false; 192 } 193 194 int ParseUsbIds(PRTSTREAM instream) 196 195 { 197 196 State::Value state = State::lookForStartBlock; 198 wstring line;197 string line; 199 198 int res = 0; 200 VendorRecord vendor = { 0, L"" };199 VendorRecord vendor = { 0, "" }; 201 200 202 201 while (state != State::finished && getline(instream, line)) … … 228 227 return ERROR_WRONG_FILE_FORMAT; 229 228 } 230 ProductRecord product = { 0, vendor.vendorID, 0, L"" };229 ProductRecord product = { 0, vendor.vendorID, 0, "" }; 231 230 if (ParseAlias(line.substr(1), product.productID, product.product) != 0) 232 231 { … … 274 273 } 275 274 ofstream fout; 276 wifstreamfin;275 PRTSTREAM fin; 277 276 g_products.reserve(20000); 278 277 g_vendors.reserve(3500); 279 278 280 279 char* outName = NULL; 280 int rc = 0; 281 281 for (int i = 1; i < argc; i++) 282 282 { … … 287 287 } 288 288 289 fin.open(argv[i]); 290 if (!fin.is_open()) 289 if (RT_FAILURE(rc = RTStrmOpen(argv[i], "r", &fin))) 291 290 { 292 291 cerr << "Format: " << argv[0] << 293 292 " [linux.org usb list file] [custom usb list file] [-o output file]" << endl; 294 cerr << "Error: Can not open file '" << argv[i] << "'. "<< endl;293 cerr << "Error: Can not open file '" << argv[i] << "'. Error: " << hex << rc << endl; 295 294 return ERROR_OPEN_FILE; 296 295 } … … 301 300 cerr << "Error in parsing USB devices file '" << 302 301 argv[i] << "'" << endl; 303 fin.close();302 RTStrmClose(fin); 304 303 return res; 305 304 } 306 fin.close();305 RTStrmClose(fin); 307 306 } 308 307 … … 311 310 312 311 // validate that all records are unique 313 ProductsSet::iterator it = adjacent_find(g_products.begin(), g_products.end());314 if (it != g_products.end())315 { 316 cerr << " Error: Duplicate alias detected. " << *it<< endl;317 return ERROR_DUPLICATE_ENTRY;312 ProductsSet::iterator ita = adjacent_find(g_products.begin(), g_products.end()); 313 if (ita != g_products.end()) 314 { 315 cerr << "Warning: Duplicate alias detected. " << *ita << endl; 316 return 0; 318 317 } 319 318 … … 336 335 337 336 fout << header; 338 for (ProductsSet::iterator it = g_products.begin(); it != g_products.end(); ++it)339 { 340 fout << *it ;337 for (ProductsSet::iterator itp = g_products.begin(); itp != g_products.end(); ++itp) 338 { 339 fout << *itp; 341 340 } 342 341 fout << footer; 343 342 344 343 fout << vendor_header; 345 for (VendorsSet::iterator it = g_vendors.begin(); it != g_vendors.end(); ++it)346 { 347 fout << *it ;344 for (VendorsSet::iterator itv = g_vendors.begin(); itv != g_vendors.end(); ++itv) 345 { 346 fout << *itv; 348 347 } 349 348 fout << vendor_footer;
Note:
See TracChangeset
for help on using the changeset viewer.