VirtualBox

Changeset 59733 in vbox for trunk/src/VBox/Main/include


Ignore:
Timestamp:
Feb 19, 2016 1:42:18 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105597
Message:

USBIdDatabaseGenerator: Share code with oiddb2c.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/USBIdDatabase.h

    r58019 r59733  
    2222#include <iprt/stdint.h>
    2323#include <iprt/cpp/ministring.h>
     24#include <iprt/bldprog-strtab.h>
    2425
    2526
     
    3132
    3233
    33 /**
    34  * USB ID database string table reference.
    35  */
    36 typedef struct USBIDDBSTR
    37 {
    38     /** Offset of the string in the string table. */
    39     uint32_t off : 22;
    40     /** The length of the string. */
    41     uint32_t cch : 10;
    42 } USBIDDBSTR;
    43 AssertCompileSize(USBIDDBSTR, sizeof(uint32_t));
     34AssertCompileSize(RTBLDPROGSTRREF, sizeof(uint32_t));
    4435
    4536
     
    7667{
    7768public: // For assertions and statis in the generator.
    78     /** String table. */
    79     static const char           s_achStrTab[];
    80     /** The size of the string table (for bounds checking). */
    81     static const size_t         s_cchStrTab;
    82 #ifdef USB_ID_DATABASE_WITH_COMPRESSION
    83     /** Dictionary containing the 127 most used substrings (that we managed
    84      * to detect without lousy word based searching). */
    85     static const USBIDDBSTR     s_aCompDict[127];
    86 #endif
     69    /** The compressed string table.   */
     70    static RTBLDPROGSTRTAB const s_StrTab;
    8771
    8872    /** Number of vendors in the two parallel arrays.   */
    89     static const size_t         s_cVendors;
     73    static const size_t          s_cVendors;
    9074    /** Vendor IDs lookup table. */
    91     static const USBIDDBVENDOR  s_aVendors[];
     75    static const USBIDDBVENDOR   s_aVendors[];
    9276    /** Vendor names table running parallel to s_aVendors. */
    93     static const USBIDDBSTR    s_aVendorNames[];
     77    static const RTBLDPROGSTRREF s_aVendorNames[];
    9478
    9579    /** Number of products in the two parallel arrays. */
    96     static const size_t         s_cProducts;
     80    static const size_t          s_cProducts;
    9781    /** Vendor+Product keys for lookup purposes. */
    98     static const USBIDDBPROD    s_aProducts[];
     82    static const USBIDDBPROD     s_aProducts[];
    9983    /** Product names table running parallel to s_aProducts. */
    100     static const USBIDDBSTR    s_aProductNames[];
     84    static const RTBLDPROGSTRREF s_aProductNames[];
    10185
    10286public:
    103     static RTCString returnString(USBIDDBSTR const *pStr)
    104     {
    105         Assert(pStr->cch < s_cchStrTab);
    106         Assert(pStr->off < s_cchStrTab);
    107         Assert(pStr->off + (size_t)pStr->cch < s_cchStrTab);
    108 
    109 #ifdef USB_ID_DATABASE_WITH_COMPRESSION
    110         char        szTmp[USB_ID_DATABASE_MAX_STRING * 2];
    111         char       *pchDst = &szTmp[0];
    112         size_t      cchSrc = pStr->cch;
    113         const char *pchSrc = &s_achStrTab[pStr->off];
    114         Assert(cchSrc <= USB_ID_DATABASE_MAX_STRING);
    115         while (cchSrc-- > 0)
    116         {
    117             unsigned char uch = *pchSrc++;
    118             if (!(uch & 0x80))
    119             {
    120                 *pchDst++ = (char)uch;
    121                 Assert(uch != 0);
    122                 Assert((uintptr_t)(pchDst - &szTmp[0]) < USB_ID_DATABASE_MAX_STRING);
    123             }
    124             else if (uch == 0xff)
    125             {
    126                 RTUNICP uc = ' ';
    127                 int rc = RTStrGetCpNEx(&pchSrc, &cchSrc, &uc);
    128                 AssertStmt(RT_SUCCESS(rc), (uc = '?', pchSrc++, cchSrc--));
    129                 pchDst = RTStrPutCp(pchDst, uc);
    130                 Assert((uintptr_t)(pchDst - &szTmp[0]) < USB_ID_DATABASE_MAX_STRING);
    131             }
    132             else
    133             {
    134                 /* Dictionary reference. No unescaping necessary here. */
    135                 const USBIDDBSTR *pStr2 = &s_aCompDict[uch & 0x7f];
    136                 Assert(pStr2->cch < s_cchStrTab);
    137                 Assert(pStr2->off < s_cchStrTab);
    138                 Assert(pStr2->off + (size_t)pStr->cch < s_cchStrTab);
    139                 Assert((uintptr_t)(&pchDst[pStr2->cch] - &szTmp[0]) < USB_ID_DATABASE_MAX_STRING);
    140                 memcpy(pchDst, &s_achStrTab[pStr2->off], pStr2->cch);
    141                 pchDst += pStr2->cch;
    142             }
    143         }
    144         *pchDst = '\0';
    145         return RTCString(szTmp, pchDst - &szTmp[0]);
    146 #else  /* !USB_ID_DATABASE_WITH_COMPRESSION */
    147         return RTCString(&s_achStrTab[pStr->off], pStr->cch);
    148 #endif /* !USB_ID_DATABASE_WITH_COMPRESSION */
     87    static RTCString returnString(PCRTBLDPROGSTRREF pStr)
     88    {
     89        char szTmp[USB_ID_DATABASE_MAX_STRING * 2];
     90        ssize_t cchTmp = RTBldProgStrTabQueryString(&s_StrTab, pStr->off, pStr->cch, szTmp, sizeof(szTmp));
     91        return RTCString(szTmp, RT_MAX(cchTmp, 0));
    14992    }
    15093
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