home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / MAPTYPES.C < prev    next >
C/C++ Source or Header  |  1996-04-17  |  75KB  |  1,718 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY813*/
  3. /*   maptypes.c                                                              */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*   Mapping funtions for types from other formats to the internal format.   */
  8. /*                                                                           */
  9. /* History:                                                                  */
  10. /*...                                                                        */
  11. /*... 03/01/93  813   Selwyn    Changes for HL02/HL03.                       */
  12. /*****************************************************************************/
  13. #include "all.h"
  14.  
  15. /*****************************************************************************/
  16. /* MapHLLTypes()                                                          813*/
  17. /*                                                                           */
  18. /* Description:                                                              */
  19. /*                                                                           */
  20. /*   Map the HLL types records into the Internal Types format.               */
  21. /*                                                                           */
  22. /* (Unlike symbols and line numbers mapping functions, the internal types    */
  23. /*  table is allocated within this function as the size of the internal      */
  24. /*  table is difficult to find upfront because of the presence of various    */
  25. /*  variable length fields)                                                  */
  26. /*                                                                           */
  27. /* Parameters:                                                               */
  28. /*   RawTable       (input)  - Pointer to the raw types table.               */
  29. /*   mptr           (input)  - Pointer to the MODULE structure.              */
  30. /*                                                                           */
  31. /* Return:                                                                   */
  32. /*   None.                                                                   */
  33. /*                                                                           */
  34. /* Assumptions:                                                              */
  35. /*                                                                           */
  36. /* - Raw symbol table has already been loaded into the memory.               */
  37. /* - It is the responsibility of this function to allocate memory for the    */
  38. /*   Internal types table and return a pointer to the table after mapping.   */
  39. /* - This function would free the memory allocated for the Raw Table.        */
  40. /*****************************************************************************/
  41. #define CHUNKSIZE   0XFFFF
  42. #define HWMARKSIZE  0X1000
  43. uchar  *MapHLLTypes( uchar *RawTable, MODULE *pModule )
  44. {
  45.   Trec   *HLLptr=NULL;
  46.   Trec   *Mapptr=NULL;
  47.   uint   IntRecLength = 0;
  48.   uint   HLLRecLength = 0;
  49.   uint   IntTableLength = 0;
  50.   uint   RecIDLen = 0;
  51.   uchar  *IntTypeTable = NULL;
  52.   uchar  *EndOfTable = NULL;
  53.   static uint  UpperLimit;
  54.   static uchar *Scratch = NULL;
  55.  
  56.  
  57.   USHORT      *pNumMembers;
  58.   BOOL         IsMappingClass;
  59.   TD_TYPELIST *pListRec;
  60.   ULONG        IntBufSize;
  61.  
  62.   /***************************************************************************/
  63.   /* The Raw types table is first mapped to a scratch area and then copied to*/
  64.   /* the internal table. This is done because the size of the internal table */
  65.   /* is difficult to be determined upfront. A scratch area of 64k bytes is   */
  66.   /* allocated at first and is extended whenever needed.                     */
  67.   /***************************************************************************/
  68.   if( Scratch != NULL )
  69.    Tfree(Scratch);
  70.  
  71.   IntBufSize = CHUNKSIZE;
  72.   UpperLimit = CHUNKSIZE - HWMARKSIZE;
  73.   Scratch    = Talloc( IntBufSize );
  74.   /***************************************************************************/
  75.   /* Adjust for skipping the "01" at the start of each record in all formats */
  76.   /* except HLL Level 3.                                                     */
  77.   /***************************************************************************/
  78.   RecIDLen = 1;
  79.   if( (pModule->DbgFormatFlags.Typs == TYPE104_HL03) ||
  80.       (pModule->DbgFormatFlags.Typs == TYPE104_HL04)
  81.     )
  82.     RecIDLen = 0;
  83.  
  84.   /***************************************************************************/
  85.   /* Scan through from start to end of the raw table. Depending on the type  */
  86.   /* of the record, copy the information accordingly to the internal types   */
  87.   /* table.                                                                  */
  88.   /***************************************************************************/
  89.   HLLptr         = (Trec *)(RawTable + RecIDLen);
  90.   Mapptr         = (Trec *)Scratch;
  91.   EndOfTable     = RawTable + pModule->TypeLen;
  92.   pNumMembers    = NULL;
  93.   pListRec       = NULL;
  94.   IsMappingClass = FALSE;
  95.  
  96.   while( ((uchar *)HLLptr) < EndOfTable )
  97.   {
  98.     IntRecLength = HLLRecLength = 0;
  99.     switch( HLLptr->RecType )
  100.     {
  101.       case T_STRUCT:                    /* Structure record.          (0x79) */
  102.       {
  103.         TD_STRUCT *pIntStruct = (TD_STRUCT *)Mapptr;
  104.         HL_STRUCT *pHLLStruct = (HL_STRUCT *)((uchar *)HLLptr + 3);
  105.  
  106.         /*********************************************************************/
  107.         /* The Type qualifier field is not mapped.                           */
  108.         /*********************************************************************/
  109.         IntRecLength = HLLptr->RecLen - 3;
  110.         HLLRecLength = HLLptr->RecLen;
  111.  
  112.         pIntStruct->RecLen        = IntRecLength;
  113.         pIntStruct->RecType       = HLLptr->RecType;
  114.         pIntStruct->ByteSize      = pHLLStruct->ByteSize;
  115.         pIntStruct->NumMembers    = pHLLStruct->NumMembers;
  116.         pIntStruct->TypeListIndex = pHLLStruct->TypeListIndex;
  117.         pIntStruct->NameListIndex = pHLLStruct->NameListIndex;
  118.         pIntStruct->NameLen       = pHLLStruct->NameLen;
  119.         strncpy( pIntStruct->Name, pHLLStruct->Name, pHLLStruct->NameLen );
  120.  
  121.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  122.         HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  123.         IntTableLength += (IntRecLength + 2);
  124.       }
  125.       break;
  126.  
  127.       case T_CLASS:
  128.       {
  129.        int       NumBytes;
  130.        USHORT    EncLength;
  131.        TD_CLASS *pIntClass;
  132.        HL_CLASS *pHLLClass;
  133.  
  134.        pIntClass    = (TD_CLASS *)Mapptr;
  135.        pHLLClass    = (HL_CLASS *)((uchar *)HLLptr + 3);
  136.        HLLRecLength = HLLptr->RecLen;
  137.        EncLength    = GetEncLength(&(pHLLClass->EncLen), &NumBytes);
  138.        IntRecLength = sizeof(TD_CLASS) - 3 + EncLength;
  139.  
  140.        pIntClass->NameLen  = EncLength;
  141.        strncpy( pIntClass->Name,
  142.                  ( (char *)&(pHLLClass->EncLen) ) + NumBytes,
  143.                  EncLength );
  144.  
  145.        pIntClass->RecLen        = IntRecLength;
  146.        pIntClass->RecType       = HLLptr->RecType;
  147.        pIntClass->TypeQual      = pHLLClass->TypeQual;
  148.        pIntClass->ByteSize      = pHLLClass->ByteSize;
  149.        pIntClass->NumMembers    = pHLLClass->NumMembers;
  150.        pIntClass->ItemListIndex = pHLLClass->TypeListIndex;
  151.  
  152. //     DumpClassRecord( pIntClass );
  153.  
  154.        IsMappingClass = TRUE;
  155.        pNumMembers    = &pIntClass->NumMembers;
  156.  
  157.        Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  158.        HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  159.        IntTableLength += (IntRecLength + 2 );
  160.       }
  161.       break;
  162.  
  163.       case T_MEMFNC:                    /* Member Function             0x45  */
  164.       {
  165.        int        NumBytes;
  166.        USHORT     EncLength;
  167.        TD_MEMFNC *pIntMemFnc;
  168.        HL_MEMFNC *pHLLMemFnc;
  169.        UCHAR     *pEncLen = NULL;
  170.        ULONG      VirtNo  = 0;
  171.  
  172.        pIntMemFnc   = (TD_MEMFNC *)Mapptr;
  173.        pHLLMemFnc   = (HL_MEMFNC *)((uchar *)HLLptr + 3);
  174.        HLLRecLength = HLLptr->RecLen;
  175.  
  176.        /**********************************************************************/
  177.        /* - the member function may be virtual or non-virtual                */
  178.        /* - if virtual, get the virtual index.                               */
  179.        /* - define a ptr to the enc name.                                    */
  180.        /**********************************************************************/
  181.        if( IsVirtual(pHLLMemFnc) )
  182.        {
  183.         UCHAR *pVirtNo = NULL;
  184.         UINT  junksize;
  185.  
  186.         pVirtNo = &(pHLLMemFnc->fid.vTableIndex.FidSpan);
  187.         pEncLen  = GetField( pVirtNo, (void *)&VirtNo, &junksize);
  188.        }
  189.        else
  190.         pEncLen = (UCHAR*)&pHLLMemFnc->fid.EncLen;
  191.  
  192.        /**********************************************************************/
  193.        /* - calculate the enc length.                                        */
  194.        /* - calculate the internal record length.                            */
  195.        /**********************************************************************/
  196.        EncLength    = GetEncLength((ENCLEN*)pEncLen, &NumBytes);
  197.        IntRecLength = sizeof(TD_MEMFNC) - 3 + EncLength;
  198.  
  199.        /**********************************************************************/
  200.        /* - fill in the internal record fields.                              */
  201.        /**********************************************************************/
  202.        pIntMemFnc->RecLen      = IntRecLength;
  203.        pIntMemFnc->RecType     = HLLptr->RecType;
  204.        pIntMemFnc->TypeQual    = pHLLMemFnc->TypeQual;
  205.        pIntMemFnc->Protection  = pHLLMemFnc->Protection;
  206.        pIntMemFnc->FuncType    = pHLLMemFnc->FuncType;
  207.        pIntMemFnc->SubRecIndex = pHLLMemFnc->SubRecIndex;
  208.        pIntMemFnc->vTableIndex = VirtNo;
  209.        pIntMemFnc->NameLen     = EncLength;
  210.  
  211.        strncpy( pIntMemFnc->Name, pEncLen + NumBytes, EncLength );
  212.  
  213. //     DumpMemFncRecord( pIntMemFnc );
  214.  
  215.        Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  216.        HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  217.        IntTableLength += (IntRecLength + 2 );
  218.       }
  219.       break;
  220.  
  221.       case T_CLSMEM:                    /* Class Member                0x46  */
  222.       {
  223.        int        NumBytes;
  224.        TD_CLSMEM *pIntClsMem;
  225.        HL_CLSMEM *pHLLClsMem;
  226.        UCHAR     *pOffset;
  227.        ULONG      Offset;
  228.        char      *pName;
  229.        char      *pStaticName;
  230.        char      *pMemberName;
  231.        USHORT     StaticNameLen;
  232.        USHORT     MemberNameLen;
  233.        UINT       junksize;
  234.  
  235.        pIntClsMem   = (TD_CLSMEM *)Mapptr;
  236.        pHLLClsMem   = (HL_CLSMEM *)((uchar *)HLLptr + 3);
  237.        HLLRecLength = HLLptr->RecLen;
  238.  
  239.        pOffset      = &(pHLLClsMem->FidSpan);
  240.        Offset       = 0;
  241.        pName        = GetField( pOffset, (void *)&Offset, &junksize);
  242.        if( IsStatic(pHLLClsMem) || IsVtable(pHLLClsMem))
  243.        {
  244.         pStaticName    = pName;
  245.         StaticNameLen  = GetEncLength((ENCLEN*)pStaticName, &NumBytes);
  246.         pStaticName   += NumBytes;
  247.         pName          = pStaticName + StaticNameLen;
  248.        }
  249.        else
  250.        {
  251.         pStaticName    = NULL;
  252.         StaticNameLen  = 0;
  253.         pName         += 1;
  254.        }
  255.  
  256.        pMemberName    = pName;
  257.        MemberNameLen  = GetEncLength((ENCLEN*)pMemberName, &NumBytes);
  258.        pMemberName   += NumBytes;
  259.        IntRecLength   = sizeof(TD_CLSMEM) -
  260.                         sizeof(Trec) + 1  -
  261.                         sizeof(pIntClsMem->Name) -
  262.                         sizeof(pIntClsMem->NameLen);
  263.  
  264.        if( pStaticName )
  265.         IntRecLength  += sizeof(pIntClsMem->NameLen) + StaticNameLen;
  266.  
  267.        if( pMemberName )
  268.         IntRecLength  += sizeof(pIntClsMem->NameLen) + MemberNameLen;
  269.  
  270.        /**********************************************************************/
  271.        /* - fill in the internal record fields.                              */
  272.        /**********************************************************************/
  273.        pIntClsMem->RecLen      = IntRecLength;
  274.        pIntClsMem->RecType     = HLLptr->RecType;
  275.        pIntClsMem->TypeQual    = pHLLClsMem->TypeQual;
  276.        pIntClsMem->Protection  = pHLLClsMem->Protection;
  277.        pIntClsMem->TypeIndex   = pHLLClsMem->TypeIndex;
  278.        pIntClsMem->Offset      = Offset;
  279.        pName = (char*)&pIntClsMem->NameLen;
  280.        if( IsStatic(pHLLClsMem) )
  281.        {
  282.         *(USHORT*)pName  = StaticNameLen;
  283.         strncpy( pName+2, pStaticName, StaticNameLen );
  284.         pName += StaticNameLen + 2;
  285.        }
  286.        *(USHORT*)pName  = MemberNameLen;
  287.        strncpy( pName+2, pMemberName, MemberNameLen );
  288.  
  289. //     DumpClsMemRecord( pIntClsMem );
  290.  
  291.        Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  292.        HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  293.        IntTableLength += (IntRecLength + 2 );
  294.       }
  295.       break;
  296.  
  297.       case T_BSECLS:                    /* Base Class                  0x41  */
  298.       {
  299.        TD_BSECLS *pIntBseCls;
  300.        HL_BSECLS *pHLLBseCls;
  301.        UCHAR     *pOffset;
  302.        ULONG      Offset;
  303.        UINT       junksize;
  304.  
  305.        pIntBseCls   = (TD_BSECLS *)Mapptr;
  306.        pHLLBseCls   = (HL_BSECLS *)((uchar *)HLLptr + 3);
  307.        HLLRecLength = HLLptr->RecLen;
  308.  
  309.        pOffset      = &(pHLLBseCls->FidSpan);
  310.        Offset       = 0;
  311.  
  312.        GetField( pOffset, (void *)&Offset, &junksize);
  313.  
  314.        IntRecLength   = sizeof(TD_BSECLS) - sizeof(Trec) + 1;
  315.  
  316.        /**********************************************************************/
  317.        /* - fill in the internal record fields.                              */
  318.        /**********************************************************************/
  319.        pIntBseCls->RecLen      = IntRecLength;
  320.        pIntBseCls->RecType     = HLLptr->RecType;
  321.        pIntBseCls->TypeQual    = pHLLBseCls->TypeQual;
  322.        pIntBseCls->Protection  = pHLLBseCls->Protection;
  323.        pIntBseCls->TypeIndex   = pHLLBseCls->TypeIndex;
  324.        pIntBseCls->Offset      = Offset;
  325.  
  326. //     DumpBseClsRecord( pIntBseCls );
  327.  
  328.        Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  329.        HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  330.        IntTableLength += (IntRecLength + 2 );
  331.       }
  332.       break;
  333.  
  334.       case T_CLSDEF:                    /* ClassDef                    0x43  */
  335.       {
  336.        TD_CLSDEF *pIntClsDef;
  337.        HL_CLSDEF *pHLLClsDef;
  338.  
  339.        pIntClsDef   = (TD_CLSDEF *)Mapptr;
  340.        pHLLClsDef   = (HL_CLSDEF *)((uchar *)HLLptr + 3);
  341.        HLLRecLength = HLLptr->RecLen;
  342.        IntRecLength = sizeof(TD_CLSDEF) - sizeof(Trec) + 1;
  343.  
  344.        /**********************************************************************/
  345.        /* - fill in the internal record fields.                              */
  346.        /**********************************************************************/
  347.        pIntClsDef->RecLen      = IntRecLength;
  348.        pIntClsDef->RecType     = HLLptr->RecType;
  349.        pIntClsDef->TypeQual    = pHLLClsDef->TypeQual;
  350.        pIntClsDef->Protection  = pHLLClsDef->Protection;
  351.        pIntClsDef->TypeIndex   = pHLLClsDef->TypeIndex;
  352.        pIntClsDef->ClassType   = pHLLClsDef->ClassType;
  353.  
  354. //     DumpClsDefRecord( pIntClsDef );
  355.  
  356.        Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  357.        HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  358.        IntTableLength += (IntRecLength + 2 );
  359.       }
  360.       break;
  361.  
  362.       case T_REF:                    /* Reference                   0x48  */
  363.       {
  364.        TD_REF *pIntRef;
  365.        HL_REF *pHLLRef;
  366.  
  367.        pIntRef      = (TD_REF *)Mapptr;
  368.        pHLLRef      = (HL_REF *)((uchar *)HLLptr + 3);
  369.        HLLRecLength = HLLptr->RecLen;
  370.  
  371.        IntRecLength   = sizeof(TD_REF) - sizeof(Trec) + 1;
  372.  
  373.        /**********************************************************************/
  374.        /* - fill in the internal record fields.                              */
  375.        /**********************************************************************/
  376.        pIntRef->RecLen      = IntRecLength;
  377.        pIntRef->RecType     = HLLptr->RecType;
  378.        pIntRef->TypeIndex   = pHLLRef->TypeIndex;
  379.  
  380.        Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  381.        HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  382.        IntTableLength += (IntRecLength + 2 );
  383.       }
  384.       break;
  385.  
  386.       case T_FRIEND:
  387.       {
  388.        int       NumBytes;
  389.        USHORT    EncLength;
  390.        TD_FRIEND *pIntFriend;
  391.        HL_FRIEND *pHLLFriend;
  392.  
  393.        pIntFriend   = (TD_FRIEND *)Mapptr;
  394.        pHLLFriend   = (HL_FRIEND *)((uchar *)HLLptr + 3);
  395.        HLLRecLength = HLLptr->RecLen;
  396.        EncLength    = GetEncLength(&(pHLLFriend->EncLen), &NumBytes);
  397.        IntRecLength = sizeof(TD_FRIEND) - 3 + EncLength;
  398.  
  399.        pIntFriend->NameLen  = EncLength;
  400.        strncpy( pIntFriend->Name,
  401.                  ( (char *)&(pHLLFriend->EncLen) ) + NumBytes,
  402.                  EncLength );
  403.  
  404.        pIntFriend->RecLen    = IntRecLength;
  405.        pIntFriend->RecType   = HLLptr->RecType;
  406.        pIntFriend->TypeQual  = pHLLFriend->TypeQual;
  407.        pIntFriend->TypeIndex = pHLLFriend->TypeIndex;
  408.  
  409. //     DumpFriendRecord( pIntFriend );
  410.  
  411.        Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  412.        HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  413.        IntTableLength += (IntRecLength + 2 );
  414.       }
  415.       break;
  416.  
  417.       case T_BITFLD:                    /* Bit fields.                (0x5C) */
  418.       {
  419.         TD_BITFLD *pIntBitfld = (TD_BITFLD *)Mapptr;
  420.         HL_BITFLD *pHLLBitfld = (HL_BITFLD *)((uchar *)HLLptr + 3);
  421.  
  422.         IntRecLength = sizeof( TD_BITFLD ) - 2;
  423.         HLLRecLength = HLLptr->RecLen;
  424.  
  425.         /*********************************************************************/
  426.         /* - Type qualifier field is mapped to the flags field.              */
  427.         /* - Base type field in the internal types record is set to 0x86     */
  428.         /*   (TYPE_ULONG 32 Bit).                                            */
  429.         /*********************************************************************/
  430.         pIntBitfld->RecLen   = IntRecLength;
  431.         pIntBitfld->RecType  = HLLptr->RecType;
  432.         pIntBitfld->Flags    = pHLLBitfld->TypeQual;
  433.         pIntBitfld->Offset   = pHLLBitfld->Offset;
  434.         pIntBitfld->BitSize  = pHLLBitfld->BitSize[0];
  435.         pIntBitfld->BaseType = TYPE_ULONG;
  436.  
  437.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  438.         HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  439.         IntTableLength += (IntRecLength + 2);
  440.         break;
  441.       }
  442.  
  443.       case T_TYPDEF:                    /* Typedef                    (0x5D) */
  444.       {
  445.         TD_USERDEF *pIntUserDef = (TD_USERDEF *)Mapptr;
  446.         HL_USERDEF *pHLLUserDef = (HL_USERDEF *)((uchar *)HLLptr + 3);
  447.  
  448.         IntRecLength = HLLptr->RecLen - 2;
  449.         HLLRecLength = HLLptr->RecLen;
  450.  
  451.         pIntUserDef->RecLen    = IntRecLength;
  452.         pIntUserDef->RecType   = HLLptr->RecType;
  453.         pIntUserDef->TypeIndex = pHLLUserDef->TypeIndex;
  454.         pIntUserDef->NameLen   = pHLLUserDef->NameLen;
  455.         strncpy( pIntUserDef->Name, pHLLUserDef->Name, pHLLUserDef->NameLen );
  456.  
  457.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  458.         HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  459.         IntTableLength += (IntRecLength + 2);
  460.         break;
  461.       }
  462.  
  463.       case T_PROC:                      /* Procedure.                 (0x75) */
  464.       case T_ENTRY:                     /* Entry.                     (0x53) */
  465.       case T_FUNCTION:                  /* Function.                  (0x54) */
  466.       {
  467.         TD_PROC *pIntProc = (TD_PROC *)Mapptr;
  468.         HL_PROC *pHLLProc = (HL_PROC *)((uchar *)HLLptr + 3);
  469.  
  470.         IntRecLength = HLLptr->RecLen - 2;
  471.         HLLRecLength = HLLptr->RecLen;
  472.  
  473.         pIntProc->RecType       = T_PROC;
  474.         pIntProc->RecLen        = IntRecLength;
  475.         pIntProc->Flags         = pHLLProc->TypeQual;
  476.         pIntProc->NumParams     = pHLLProc->NumParams;
  477.         pIntProc->MaxParams     = pHLLProc->MaxParams;
  478.         pIntProc->ReturnType    = pHLLProc->ReturnType;
  479.         pIntProc->ParmListIndex = pHLLProc->ParmListIndex;
  480.  
  481.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  482.         HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  483.         IntTableLength += (IntRecLength + 2);
  484.         break;
  485.       }
  486.  
  487.       case T_ARRAY:                     /* Array.                     (0x78) */
  488.       {
  489.         TD_ARRAY *pIntArray = (TD_ARRAY *)Mapptr;
  490.         HL_ARRAY *pHLLArray = (HL_ARRAY *)((uchar *)HLLptr + 3);
  491.  
  492.         IntRecLength = HLLptr->RecLen - 2;
  493.         HLLRecLength = HLLptr->RecLen;
  494.  
  495.         pIntArray->RecLen     = IntRecLength;
  496.         pIntArray->RecType    = HLLptr->RecType;
  497.         pIntArray->Flags      = pHLLArray->TypeQual;
  498.         pIntArray->ByteSize   = pHLLArray->ByteSize;
  499.         pIntArray->ElemType   = pHLLArray->ElemType;
  500.         pIntArray->NameLen    = pHLLArray->NameLen;
  501.         strncpy( pIntArray->Name, pHLLArray->Name, pHLLArray->NameLen );
  502.         pIntArray->BoundsTypeIndex = pHLLArray->BoundsTypeIndex;
  503.  
  504.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  505.         HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  506.         IntTableLength += (IntRecLength + 2);
  507.         break;
  508.       }
  509.  
  510.       case T_PTR:                       /* Pointer.                   (0x7A) */
  511.       {
  512.         TD_POINTER *pIntPointer = (TD_POINTER *)Mapptr;
  513.         HL_POINTER *pHLLPointer = (HL_POINTER *)((uchar *)HLLptr + 3);
  514.  
  515.         if( HLLptr->RecLen > 5 )
  516.           IntRecLength = HLLptr->RecLen - 1;
  517.         else
  518.           IntRecLength = HLLptr->RecLen + 1;
  519.         HLLRecLength = HLLptr->RecLen;
  520.  
  521.         /*********************************************************************/
  522.         /* - Type qualifier field is mapped to the flags field.              */
  523.         /*********************************************************************/
  524.         pIntPointer->RecLen    = IntRecLength;
  525.         pIntPointer->RecType   = HLLptr->RecType;
  526.         pIntPointer->Flags     = pHLLPointer->TypeQual;
  527.         pIntPointer->TypeIndex = pHLLPointer->TypeIndex;
  528.  
  529.         if( HLLRecLength > 5 )
  530.         {
  531.           pIntPointer->NameLen   = pHLLPointer->NameLen;
  532.           strncpy( pIntPointer->Name, pHLLPointer->Name, pHLLPointer->NameLen );
  533.         }
  534.         else
  535.           pIntPointer->NameLen = 0;
  536.  
  537.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  538.         HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  539.         IntTableLength += (IntRecLength + 2);
  540.         break;
  541.       }
  542.  
  543.       case T_SCALAR:                    /* Scalar.                    (0x51) */
  544.       {
  545.         TD_SCALAR *pIntScalar = (TD_SCALAR *)Mapptr;
  546.         HL_SCALAR *pHLLEnum   = (HL_SCALAR *)((uchar *)HLLptr + 3);
  547.  
  548.         HLLRecLength = HLLptr->RecLen;
  549.         pIntScalar->RecType  = HLLptr->RecType;
  550.         pIntScalar->DataType = pHLLEnum->DataType;
  551.         pIntScalar->RecLen   = IntRecLength = sizeof( TD_SCALAR ) - 2;
  552.  
  553.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  554.         HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  555.         IntTableLength += (IntRecLength + 2);
  556.         break;
  557.       }
  558.  
  559.       case T_ENUM:                      /* Enums.                     (0x7B) */
  560.       {
  561.         #define  INTENUMSTRUCTLEN  15
  562.  
  563.         uchar  *TablePtr    = NULL;
  564.         uint    FieldLength = 0;
  565.  
  566.         TD_ENUM *pIntEnum = (TD_ENUM *)Mapptr;
  567.         HL_ENUM *pHLLEnum = (HL_ENUM *)((uchar *)HLLptr + 3);
  568.  
  569.         HLLRecLength = HLLptr->RecLen;
  570.         pIntEnum->RecType       = HLLptr->RecType;
  571.         pIntEnum->DataType      = pHLLEnum->DataType;
  572.         pIntEnum->NameListIndex = pHLLEnum->MemListIndex;
  573.  
  574.         /*********************************************************************/
  575.         /* - Lower and Upper bound fields are of variable size in the raw    */
  576.         /*   table but are of fixed size (4 bytes) in the internal table.    */
  577.         /* - Get field function is used to get the value of the variable size*/
  578.         /*   fields and to increment the table pointer beyond those fields.  */
  579.         /* - "INTENUMSTRUCTLEN" is the length of the internal Enum record    */
  580.         /*   length without the name field.                                  */
  581.         /*********************************************************************/
  582.         TablePtr = ((uchar *)HLLptr + sizeof( HL_ENUM ) + sizeof( Trec ));
  583.         pIntEnum->LBound = pIntEnum->UBound = 0;
  584.         TablePtr = GetField( TablePtr, (void *)&(pIntEnum->LBound),
  585.                              &FieldLength );
  586.         TablePtr = GetField( TablePtr, (void *)&(pIntEnum->UBound),
  587.                              &FieldLength );
  588.         /*********************************************************************/
  589.         /* - Skip the FID string (0x82).                                     */
  590.         /* - Copy the name length and the name fields.                       */
  591.         /*********************************************************************/
  592.         TablePtr++;
  593.         pIntEnum->NameLen = *TablePtr++;
  594.         strncpy( pIntEnum->Name, TablePtr, pIntEnum->NameLen );
  595.         IntRecLength = INTENUMSTRUCTLEN + pIntEnum->NameLen;
  596.         pIntEnum->RecLen = IntRecLength;
  597.  
  598.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  599.         HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  600.         IntTableLength += (IntRecLength + 2);
  601.         break;
  602.       }
  603.  
  604.       case T_LIST:                      /* List.                      (0x7F) */
  605.       {
  606.         uchar *HLLTablePtr = NULL;
  607.         uchar *IntTablePtr = NULL;
  608.         int    ListRecLen  = 0;
  609.  
  610.         uchar  TypeQual  = *((uchar *)HLLptr + 3);
  611.  
  612.         HLLRecLength = ListRecLen = HLLptr->RecLen;
  613.         IntRecLength = 0;
  614.         IntTablePtr = ((uchar *)Mapptr + sizeof( Trec ));
  615.         HLLTablePtr = ((uchar *)HLLptr + sizeof( Trec ) + 2);
  616.         pListRec    = (TD_TYPELIST*)Mapptr;
  617.  
  618.         /*********************************************************************/
  619.         /* - Type qualifier field tells whether the list is a Namelist or    */
  620.         /*   a Typelist.                                                     */
  621.         /*********************************************************************/
  622.         switch( TypeQual )
  623.         {
  624.           case LIST_ST_TYPES:           /* Type List                  (0x01) */
  625.           {
  626.             int  i = 0;
  627.             TD_TYPELIST *pIntTypeList = (TD_TYPELIST *)Mapptr;
  628.  
  629.             pIntTypeList->RecType = HLLptr->RecType;
  630.             pIntTypeList->Flags   = LIST_ST_TYPES;
  631.             /*****************************************************************/
  632.             /* - subtract type (0x7F), type qual and FID index field lengths.*/
  633.             /*****************************************************************/
  634.             ListRecLen -= 3;
  635.             while( ListRecLen > 0 )
  636.             {
  637.               pIntTypeList->TypeIndex[i++] = *((ushort *)HLLTablePtr);
  638.               /***************************************************************/
  639.               /* - get past the index (2 bytes) and the FID index (1 byte).  */
  640.               /***************************************************************/
  641.               HLLTablePtr += 3;
  642.               ListRecLen  -= 3;
  643.             }
  644.             /*****************************************************************/
  645.             /* - Calculate the size of the internal record based on the num  */
  646.             /*   of entries in the list + type (1 byte) + type qual (1 byte).*/
  647.             /*****************************************************************/
  648.             IntRecLength = pIntTypeList->RecLen = (2 * i) + 2;
  649.             break;
  650.           }
  651.  
  652.           case LIST_ST_ENUM:            /* Name List  (Enums)         (0x03) */
  653.           case LIST_ST_NAMES:           /* Name List  (Structs)       (0x02) */
  654.           {
  655.             ushort  NameLen   = 0;
  656.             uint    OffsetLen = 0;
  657.             ulong   Offset    = 0;
  658.             Trec    *pIntNameList = (Trec *)Mapptr;
  659.  
  660.             /*****************************************************************/
  661.             /* - Name list does not have a structure defined like type list  */
  662.             /*   because of the variable length name fields. So it has to be */
  663.             /*   mapped into the table in a byte by byte basis.              */
  664.             /*****************************************************************/
  665.             pIntNameList->RecType = HLLptr->RecType;
  666.             *IntTablePtr = LIST_ST_NAMES;
  667.             IntTablePtr++;
  668.             /*****************************************************************/
  669.             /* - subtract type (0x7F), type qual and FID index field lengths.*/
  670.             /*****************************************************************/
  671.             ListRecLen -= 3;
  672.             IntRecLength = 2;
  673.             while( ListRecLen > 0 )
  674.             {
  675.               /***************************************************************/
  676.               /* - Copy the name length and the name.                        */
  677.               /* - Calculate the cummulative record length by adding lengths */
  678.               /*   of each item in the list.                                 */
  679.               /***************************************************************/
  680.               *((ushort *)IntTablePtr) = NameLen = *HLLTablePtr;
  681.               IntTablePtr += 2;
  682.               HLLTablePtr++;
  683.               ListRecLen--;
  684.  
  685.               strncpy( IntTablePtr, HLLTablePtr, NameLen );
  686.               IntTablePtr = IntTablePtr + NameLen;
  687.               HLLTablePtr = HLLTablePtr + NameLen;
  688.               ListRecLen  = ListRecLen  - NameLen;
  689.  
  690.               Offset = 0;
  691.               /***************************************************************/
  692.               /* The offset field in the name list is of variable length, so */
  693.               /* call getfield to get the value of the offset and to move    */
  694.               /* HLLTablePtr to the next field.                              */
  695.               /***************************************************************/
  696.               {
  697.                /**************************************************************/
  698.                /* optimization bug workaround.                               */
  699.                /**************************************************************/
  700.                UCHAR *tptr = NULL;
  701.                tptr = GetField( HLLTablePtr, (void *)&Offset, &OffsetLen );
  702.                HLLTablePtr = tptr;
  703.               }
  704.               *((ulong *)IntTablePtr) = Offset;
  705.               IntTablePtr += 4;
  706.               IntRecLength += (NameLen + 6);
  707.               ListRecLen -= (OffsetLen + 1);
  708.  
  709.               HLLTablePtr++;
  710.               ListRecLen--;
  711.             }
  712.             pIntNameList->RecLen = IntRecLength;
  713.             break;
  714.           }
  715.           default:
  716.             break;
  717.         }
  718.  
  719.         /*********************************************************************/
  720.         /* IntRecLength will be zero in case of PROC LIST or ENUM LIST which */
  721.         /* are not currently supported. so in those cases insert a NULL      */
  722.         /* record into the internal table and skip the entire list record.   */
  723.         /*********************************************************************/
  724.         if( IntRecLength )
  725.           Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  726.         else
  727.         {
  728.           IntRecLength = sizeof( Trec ) - 2;
  729.  
  730.           Mapptr->RecLen  = IntRecLength;
  731.           Mapptr->RecType = T_NULL;
  732.           Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  733.         }
  734.  
  735.         IntTableLength += (IntRecLength + 2);
  736.         HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  737.         if( IsMappingClass )
  738.         {
  739.          if( HLLptr->RecType != T_BSECLS )
  740.          {
  741.           UCHAR *pTempList;
  742.           UCHAR *cp;
  743.           int    TypeIndexSize;
  744.  
  745.           /*******************************************************************/
  746.           /* Come here to add an item to a base class list.                  */
  747.           /* - bump the number of members in the class.                      */
  748.           /* - make a temp copy of the current list.                         */
  749.           /* - stuff a 0 typeindex into the list.                            */
  750.           /* - append the temp list.                                         */
  751.           /* - adjust the list RecLen field.                                 */
  752.           /* - adjust the internal table size.                               */
  753.           /* - free temp memory.                                             */
  754.           /*******************************************************************/
  755.           TypeIndexSize = sizeof(pListRec->TypeIndex[0]);
  756.           *pNumMembers += 1;
  757.  
  758.           cp = (UCHAR*)pListRec + sizeof(TD_TYPELIST) - TypeIndexSize;
  759.  
  760.           pTempList = Talloc(pListRec->RecLen);
  761.           memcpy(pTempList, cp, pListRec->RecLen);
  762.  
  763.           *(USHORT*)cp = 0;
  764.  
  765.           memcpy(cp+TypeIndexSize, pTempList, pListRec->RecLen);
  766.  
  767.           pListRec->RecLen  += TypeIndexSize;
  768.           IntTableLength    += TypeIndexSize;
  769.  
  770.           Mapptr = (Trec *)((UCHAR *)Mapptr + TypeIndexSize);
  771.  
  772.           Tfree(pTempList);
  773.          }
  774.          IsMappingClass = FALSE;
  775.          pListRec       = NULL;
  776.          pNumMembers    = NULL;
  777.         }
  778.       }
  779.       break;                            /* T_LIST break                      */
  780.  
  781.       default:
  782.       {
  783.         /*********************************************************************/
  784.         /* In case of the record types which are not currently supported, we */
  785.         /* insert a NULL record into the internal table and skip the record. */
  786.         /*********************************************************************/
  787.         HLLRecLength = HLLptr->RecLen;
  788.         IntRecLength = sizeof( Trec ) - 2;
  789.  
  790.         Mapptr->RecLen  = IntRecLength;
  791.         Mapptr->RecType = T_NULL;
  792.  
  793.         HLLptr = (Trec *)((uchar *)HLLptr + HLLRecLength + 2 + RecIDLen);
  794.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  795.         IntTableLength += (IntRecLength + 2);
  796.         break;
  797.       }
  798.     }
  799.  
  800.     /*************************************************************************/
  801.     /* If there is danger that the scratch buffer could overflow for this    */
  802.     /* subsection, reallocate the scratch area and copy the internal table   */
  803.     /* info into the new scratch area.                                       */
  804.     /*************************************************************************/
  805.     if( IntTableLength > UpperLimit )
  806.     {
  807.       UCHAR  *TempBuffer = NULL;
  808.  
  809.       IntBufSize +=  CHUNKSIZE;
  810.       UpperLimit +=  CHUNKSIZE;
  811.       TempBuffer  =  Talloc( IntBufSize );
  812.       memcpy( TempBuffer, Scratch, IntTableLength );
  813.       Tfree( Scratch );
  814.       Scratch = TempBuffer;
  815.       Mapptr = (Trec *)(Scratch + IntTableLength);
  816.     }
  817.   }
  818.   /***************************************************************************/
  819.   /* Once we are through with the mapping for a module,                      */
  820.   /* - Change the length in the MODULE structure to the internal table length*/
  821.   /* - Allocate memory for the internal types table.                         */
  822.   /* - Copy the internal table from the scratch area.                        */
  823.   /* - Return a pointer to the internal types table.                         */
  824.   /***************************************************************************/
  825.   pModule->TypeLen = IntTableLength;
  826.   IntTypeTable = Talloc( IntTableLength );
  827.   memcpy( IntTypeTable, Scratch, IntTableLength );
  828.   Tfree( RawTable );
  829.   return( IntTypeTable );
  830. }
  831.  
  832. /*****************************************************************************/
  833. /* GetField()                                                                */
  834. /*                                                                           */
  835. /* Description:                                                              */
  836. /*                                                                           */
  837. /*   Gets the value of a variable length numeric leaf.                       */
  838. /*                                                                           */
  839. /* Parameters:                                                               */
  840. /*                                                                           */
  841. /*   Buffer       - Points to the start of the variable length leaf.         */
  842. /*   FieldValue   - buffer in which the field value is returned.             */
  843. /*   FieldLength  - buffer in which the field length is returned.            */
  844. /*                                                                           */
  845. /* Return:                                                                   */
  846. /*   Buffer which points to the next field in the record.                    */
  847. /*                                                                           */
  848. /* Assumptions:                                                              */
  849. /*                                                                           */
  850. /* - The buffer points to the start of the variable length numeric leaf.     */
  851. /*                                                                           */
  852. /*****************************************************************************/
  853. UCHAR *GetField( UCHAR *buffer, void *FieldValue, UINT *FieldLength )
  854. {
  855.   if( *buffer & 0x80 )
  856.   {
  857.     switch( *buffer )
  858.     {
  859.       case 0x88:
  860.         *((char *)FieldValue) = *((char *)(buffer + 1));
  861.         *FieldLength = 1;
  862.         return( buffer + 2 );
  863.  
  864.       case 0x8B:
  865.         *((uchar *)FieldValue) = *(buffer + 1);
  866.         *FieldLength = 1;
  867.         return( buffer + 2 );
  868.  
  869.       case 0x85:
  870.         *((short *)FieldValue) = *((short *)(buffer + 1));
  871.         *FieldLength = 2;
  872.         return( buffer + 3 );
  873.  
  874.       case 0x89:
  875.         *((ushort *)FieldValue) = *((ushort *)(buffer + 1));
  876.         *FieldLength = 2;
  877.         return( buffer + 3 );
  878.  
  879.       case 0x86:
  880.         *((long *)FieldValue) = *((long *)(buffer + 1));
  881.         *FieldLength = 4;
  882.         return( buffer + 5 );
  883.  
  884.       case 0x8A:
  885.         *((ulong *)FieldValue) = *((ulong *)(buffer + 1));
  886.         *FieldLength = 4;
  887.         return( buffer + 5 );
  888.     }
  889.   }
  890.   else
  891.   {
  892.     *((uchar *)FieldValue) = *buffer;
  893.     *FieldLength = 1;
  894.     return( buffer + 1 );
  895.   }
  896.   return(0);
  897. }
  898.  
  899. /*****************************************************************************/
  900. /* MapMSTypes()                                                           813*/
  901. /*                                                                           */
  902. /* Description:                                                              */
  903. /*                                                                           */
  904. /*   Map the Microsoft types records into the Internal Types format.         */
  905. /*                                                                           */
  906. /* (Unlike symbols and line numbers mapping functions, the internal types    */
  907. /*  table is allocated within this function as the size of the internal      */
  908. /*  table is difficult to find upfront because of the presence of various    */
  909. /*  variable length fields)                                                  */
  910. /*                                                                           */
  911. /* Parameters:                                                               */
  912. /*   RawTable       (input)  - Pointer to the raw types table.               */
  913. /*   mptr           (input)  - Pointer to the MODULE structure.              */
  914. /*                                                                           */
  915. /* Return:                                                                   */
  916. /*   None.                                                                   */
  917. /*                                                                           */
  918. /* Assumptions:                                                              */
  919. /*                                                                           */
  920. /* - Raw symbol table has already been loaded into the memory.               */
  921. /*                                                                           */
  922. /*****************************************************************************/
  923. uchar  *MapMSTypes( uchar *RawTable, MODULE *pModule )                  /*813*/
  924. {
  925.   Trec   *MSptr;
  926.   Trec   *Mapptr;
  927.   uint   IntRecLength;
  928.   uint   MSRecLength;
  929.   uint   IntTableLength = 0;
  930.   uint   RecIDLen;
  931.   uchar  *IntTypeTable;
  932.   uchar  *EndOfTable;
  933.   static uint  UpperLimit = 60000;
  934.   static uchar *Scratch = NULL;
  935.  
  936.   /***************************************************************************/
  937.   /* The Raw types table is first mapped to a scratch area and then copied to*/
  938.   /* the internal table. This is done because the size of the internal table */
  939.   /* is difficult to be determined upfront. A scratch area of 64k bytes is   */
  940.   /* allocated at first and is extended whenever needed.                     */
  941.   /***************************************************************************/
  942.   if( !Scratch )
  943.     Scratch = Talloc( 65535 );
  944.  
  945.   RecIDLen = 1;
  946.  
  947.   /***************************************************************************/
  948.   /* Scan through from start to end of the raw table. Depending on the type  */
  949.   /* of the record, copy the information accordingly to the internal types   */
  950.   /* table.                                                                  */
  951.   /***************************************************************************/
  952.   MSptr  = (Trec *)(RawTable + RecIDLen);
  953.   Mapptr = (Trec *)Scratch;
  954.   EndOfTable = RawTable + pModule->TypeLen;
  955.  
  956.   while( ((uchar *)MSptr) < EndOfTable )
  957.   {
  958.     IntRecLength = MSRecLength = 0;
  959.     switch( MSptr->RecType )
  960.     {
  961.       case T_STRUCT:                    /* Structure.                 (0x79) */
  962.       {
  963.         #define  INTSTRUCTLEN  13
  964.         uchar  *TablePtr;
  965.         uint   FieldLength;
  966.         uint   BitLen = 0;
  967.         TD_STRUCT *pIntStruct = (TD_STRUCT *)Mapptr;
  968.         MS_STRUCT *pMSStruct;
  969.  
  970.         /*********************************************************************/
  971.         /* - The structure record has "size" field in bits and is also a     */
  972.         /*   variable length field. The "NumMembers" field is also variable  */
  973.         /*   size. so call "GetField" to get the values of those fields.     */
  974.         /* - A structure is defined for the remaining fields.                */
  975.         /* - "INTSTRUCTLEN" gives the length of the internal structure record*/
  976.         /*   without the name field.                                         */
  977.         /*********************************************************************/
  978.         MSRecLength  = MSptr->RecLen;
  979.         TablePtr = ((uchar *)MSptr + sizeof( Trec ));
  980.  
  981.         pIntStruct->RecType = MSptr->RecType;
  982.         TablePtr = GetField( TablePtr, (void *)&BitLen,
  983.                              &FieldLength );
  984.         pIntStruct->ByteSize = BitLen / 8;
  985.         pIntStruct->NumMembers = 0;
  986.         TablePtr = GetField( TablePtr, (void *)&(pIntStruct->NumMembers),
  987.                              &FieldLength );
  988.         pMSStruct = (MS_STRUCT *)TablePtr;
  989.  
  990.         pIntStruct->TypeListIndex = pMSStruct->TypeListIndex;
  991.         pIntStruct->NameListIndex = pMSStruct->NameListIndex;
  992.         pIntStruct->NameLen       = pMSStruct->NameLen;
  993.         strncpy( pIntStruct->Name, pMSStruct->Name, pMSStruct->NameLen );
  994.         IntRecLength = pIntStruct->RecLen = INTSTRUCTLEN + pIntStruct->NameLen;
  995.  
  996.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  997.         MSptr = (Trec *)((uchar *)MSptr + MSRecLength + 2 + RecIDLen);
  998.         IntTableLength += (IntRecLength + 2);
  999.         break;
  1000.       }
  1001.  
  1002.       case T_BITFLD:                    /* Bit Field.                 (0x5C) */
  1003.       {
  1004.         #define SIGNED_FLAG     0x02
  1005.  
  1006.         TD_BITFLD *pIntBitfld = (TD_BITFLD *)Mapptr;
  1007.         MS_BITFLD *pMSBitfld  = (MS_BITFLD *)((uchar *)MSptr + 3);
  1008.  
  1009.         IntRecLength = sizeof( TD_BITFLD ) - 2;
  1010.         MSRecLength = MSptr->RecLen;
  1011.  
  1012.         pIntBitfld->RecLen   = IntRecLength;
  1013.         pIntBitfld->RecType  = MSptr->RecType;
  1014.  
  1015.         pIntBitfld->Flags    = 0;
  1016.         pIntBitfld->Offset   = pMSBitfld->Offset;
  1017.         pIntBitfld->BitSize  = pMSBitfld->BitSize;
  1018.  
  1019.         switch( pMSBitfld->BaseType )
  1020.         {
  1021.           case 0x7D:
  1022.           case 0x7C:
  1023.             if( pModule->DbgFormatFlags.Typs == TYPE103_CL386 )
  1024.               pIntBitfld->BaseType = TYPE_ULONG;
  1025.             else
  1026.               pIntBitfld->BaseType = TYPE_USHORT;
  1027.             break;
  1028.  
  1029.           case 0x6F:
  1030.             pIntBitfld->BaseType = TYPE_UCHAR;
  1031.             break;
  1032.         }
  1033.         /*********************************************************************/
  1034.         /* Flags are set based on the "BaseType" field in the raw record.    */
  1035.         /*********************************************************************/
  1036.         if( pMSBitfld->BaseType == TFLD_INT )
  1037.           pIntBitfld->Flags |= SIGNED_FLAG;
  1038.  
  1039.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  1040.         MSptr = (Trec *)((uchar *)MSptr + MSRecLength + 2 + RecIDLen);
  1041.         IntTableLength += (IntRecLength + 2);
  1042.         break;
  1043.       }
  1044.  
  1045.       case T_TYPDEF:                    /* TypeDef.                   (0x5D) */
  1046.       {
  1047.         TD_USERDEF *pIntUserDef = (TD_USERDEF *)Mapptr;
  1048.         MS_USERDEF *pMSUserDef  = (MS_USERDEF *)((uchar *)MSptr + 3);
  1049.  
  1050.         IntRecLength = MSptr->RecLen - 1;
  1051.         MSRecLength  = MSptr->RecLen;
  1052.  
  1053.         pIntUserDef->RecLen    = IntRecLength;
  1054.         pIntUserDef->RecType   = MSptr->RecType;
  1055.  
  1056.         /*********************************************************************/
  1057.         /* - Change the "A*" in the 0:16 pointer type indexes to "E*".       */
  1058.         /*********************************************************************/
  1059.         if( pModule->DbgFormatFlags.Typs != TYPE103_CL386 )
  1060.           pIntUserDef->TypeIndex =
  1061.                               GetInternal0_16PtrIndex( pMSUserDef->TypeIndex );
  1062.         else
  1063.           pIntUserDef->TypeIndex = pMSUserDef->TypeIndex;
  1064.         pIntUserDef->NameLen   = pMSUserDef->NameLen;
  1065.         strncpy( pIntUserDef->Name, pMSUserDef->Name, pMSUserDef->NameLen );
  1066.  
  1067.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  1068.         MSptr = (Trec *)((uchar *)MSptr + MSRecLength + 2 + RecIDLen);
  1069.         IntTableLength += (IntRecLength + 2);
  1070.         break;
  1071.       }
  1072.  
  1073.       case T_PROC:                      /* Procedure.                 (0x75) */
  1074.       case T_ENTRY:                     /* Entry.                     (0x53) */
  1075.       case T_FUNCTION:                  /* Function.                  (0x54) */
  1076.       {
  1077.         #define  ARGSRTOL   0x01
  1078.         #define  CALLERPOPS 0x02
  1079.         #define  FUNC32BIT  0x04
  1080.         #define  FARCALL    0x08
  1081.  
  1082.         uchar  CallingConv;
  1083.         TD_PROC *pIntProc = (TD_PROC *)Mapptr;
  1084.         MS_PROC *pMSProc  = (MS_PROC *)((uchar *)MSptr + 3);
  1085.  
  1086.         IntRecLength = sizeof( TD_PROC ) - 2;
  1087.         MSRecLength = MSptr->RecLen;
  1088.  
  1089.         pIntProc->RecType = T_PROC;
  1090.         pIntProc->RecLen  = IntRecLength;
  1091.         pIntProc->Flags   = 0;
  1092.  
  1093.         /*********************************************************************/
  1094.         /* Take care of the FID_VOID (0x81) in case of C2 1.1. The return    */
  1095.         /* type field is not present in the raw table record.                */
  1096.         /*********************************************************************/
  1097.         if( pMSProc->FID_ReturnType == FLDID_VOID )
  1098.         {
  1099.           uchar *RecordPtr = (uchar *)&(pMSProc->ReturnType);
  1100.  
  1101.           CallingConv = *RecordPtr;
  1102.           pIntProc->ReturnType    = TYPE_VOID;
  1103.           pIntProc->NumParams     = *(RecordPtr + 1);
  1104.           pIntProc->ParmListIndex = *(ushort *)(RecordPtr + 3);
  1105.         }
  1106.         else
  1107.         {
  1108.           CallingConv = pMSProc->CallConv;
  1109.           pIntProc->NumParams     = pMSProc->NumParams;
  1110.           pIntProc->ReturnType    = pMSProc->ReturnType;
  1111.           pIntProc->ParmListIndex = pMSProc->ParmListIndex;
  1112.         }
  1113.  
  1114.         /*********************************************************************/
  1115.         /* The flags are set based on the "Calling Convention" field in the  */
  1116.         /* raw table record.                                                 */
  1117.         /*********************************************************************/
  1118.         switch( CallingConv )
  1119.         {
  1120.           case 0x63:
  1121.             pIntProc->Flags |= ARGSRTOL;
  1122.             pIntProc->Flags |= CALLERPOPS;
  1123.             break;
  1124.  
  1125.           case 0x96:
  1126.             pIntProc->Flags |= FARCALL;
  1127.             break;
  1128.  
  1129.           default:
  1130.             break;
  1131.         }
  1132.  
  1133.         /*********************************************************************/
  1134.         /* In case of CL386 do the following corrections:                    */
  1135.         /*                                                                   */
  1136.         /*   VOID PTR        0xBC  ===>  0xB7                                */
  1137.         /*   VOID            0x9C  ===>  0x9C                                */
  1138.         /*                   0xDC  ===>  0xD7                                */
  1139.         /*********************************************************************/
  1140.         if( pModule->DbgFormatFlags.Typs == TYPE103_CL386 )
  1141.         {
  1142.           pIntProc->Flags |= FUNC32BIT;
  1143.           switch( pIntProc->ReturnType )
  1144.           {
  1145.             case 0xBC:
  1146.               pIntProc->ReturnType = 0xB7;
  1147.               break;
  1148.             case 0x9C:
  1149.               pIntProc->ReturnType = 0x97;
  1150.               break;
  1151.             case 0xDC:
  1152.               pIntProc->ReturnType = 0xD7;
  1153.               break;
  1154.           }
  1155.  
  1156.           switch( pIntProc->ParmListIndex )
  1157.           {
  1158.             case 0xBC:
  1159.               pIntProc->ParmListIndex = 0xB7;
  1160.               break;
  1161.             case 0x9C:
  1162.               pIntProc->ParmListIndex = 0x97;
  1163.               break;
  1164.             case 0xDC:
  1165.               pIntProc->ParmListIndex = 0xD7;
  1166.               break;
  1167.           }
  1168.         }
  1169.         pIntProc->MaxParams = 0;
  1170.  
  1171.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  1172.         MSptr  = (Trec *)((uchar *)MSptr + MSRecLength + 2 + RecIDLen);
  1173.         IntTableLength += (IntRecLength + 2);
  1174.         break;
  1175.       }
  1176.  
  1177.       case T_ARRAY:                     /* Array.                     (0x78) */
  1178.       {
  1179.         #define  INTARRAYLEN  12
  1180.  
  1181.         uchar  *TablePtr;
  1182.         uint   FieldLength;
  1183.         uint   BitLen = 0;
  1184.         TD_ARRAY *pIntArray = (TD_ARRAY *)Mapptr;
  1185.         MS_ARRAY *pMSArray;
  1186.  
  1187.         MSRecLength = MSptr->RecLen;
  1188.  
  1189.         /*********************************************************************/
  1190.         /* The length field is a variable size numeric leaf. so call GetField*/
  1191.         /* to get the value. A structure is defined for the remaining fields.*/
  1192.         /*********************************************************************/
  1193.         TablePtr = (uchar *)MSptr + 3;
  1194.         TablePtr = GetField( TablePtr, (void *)&BitLen, &FieldLength );
  1195.         pIntArray->ByteSize = BitLen / 8;
  1196.         if( FieldLength > 1 )
  1197.           FieldLength++;
  1198.         pMSArray = (MS_ARRAY *)TablePtr;
  1199.  
  1200.         pIntArray->RecLen   = MSptr->RecLen + (4 - FieldLength) + 4;
  1201.         pIntArray->RecType  = MSptr->RecType;
  1202.         /*********************************************************************/
  1203.         /* - Change the "A*" in the 0:16 pointer type indexes to "E*".       */
  1204.         /*********************************************************************/
  1205.         if( pModule->DbgFormatFlags.Typs != TYPE103_CL386 )
  1206.           pIntArray->ElemType =
  1207.                               GetInternal0_16PtrIndex( pMSArray->ElemType );
  1208.         else
  1209.           pIntArray->ElemType = pMSArray->ElemType;
  1210.         pIntArray->NameLen  = 0;
  1211.  
  1212.         /*********************************************************************/
  1213.         /* The name field in the array type record is an optional field. so  */
  1214.         /* copy the name only if the name field is present in the record.    */
  1215.         /*********************************************************************/
  1216.         if( MSRecLength > (FieldLength + 5) )
  1217.         {
  1218.           pIntArray->NameLen  = pMSArray->NameLen;
  1219.           strncpy( pIntArray->Name, pMSArray->Name, pMSArray->NameLen );
  1220.           pIntArray->RecLen   = MSptr->RecLen + (4 - FieldLength) - 1 +
  1221.                                 pMSArray->NameLen;
  1222.         }
  1223.         IntRecLength = pIntArray->RecLen;
  1224.         pIntArray->BoundsTypeIndex = 0;
  1225.         pIntArray->Flags = 0;
  1226.  
  1227.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  1228.         MSptr = (Trec *)((uchar *)MSptr + MSRecLength + 2 + RecIDLen);
  1229.         IntTableLength += (IntRecLength + 2);
  1230.         break;
  1231.       }
  1232.  
  1233.       case T_PTR:                       /* Pointer.                   (0x7A) */
  1234.       {
  1235.         TD_POINTER *pIntPointer = (TD_POINTER *)Mapptr;
  1236.         MS_POINTER *pMSPointer = (MS_POINTER *)((uchar *)MSptr + 3);
  1237.  
  1238.         IntRecLength = MSptr->RecLen - 1;
  1239.         MSRecLength = MSptr->RecLen;
  1240.  
  1241.         pIntPointer->RecLen  = IntRecLength;
  1242.         pIntPointer->RecType = MSptr->RecType;
  1243.         /*********************************************************************/
  1244.         /* The flags field is set based on the "Model" field and the type of */
  1245.         /* the compiler.                                                     */
  1246.         /*********************************************************************/
  1247.         switch( pMSPointer->Model )
  1248.         {
  1249.           case 0x74:
  1250.             if( pModule->DbgFormatFlags.Typs == TYPE103_CL386 )
  1251.               pIntPointer->Flags = PTR_0_32;
  1252.             else
  1253.               pIntPointer->Flags = PTR_0_16;
  1254.             break;
  1255.  
  1256.           case 0x5E:
  1257.           case 0x73:
  1258.             if( pModule->DbgFormatFlags.Typs == TYPE103_CL386 )
  1259.               pIntPointer->Flags = PTR_0_32;
  1260.             else
  1261.               pIntPointer->Flags = PTR_16_16;
  1262.             break;
  1263.         }
  1264.  
  1265.         /*********************************************************************/
  1266.         /* - Change the "A*" in the 0:16 pointer type indexes to "E*".       */
  1267.         /*********************************************************************/
  1268.         if( pModule->DbgFormatFlags.Typs != TYPE103_CL386 )
  1269.           pIntPointer->TypeIndex = GetInternal0_16PtrIndex(
  1270.                                      pMSPointer->TypeIndex );
  1271.         else
  1272.           pIntPointer->TypeIndex = pMSPointer->TypeIndex;
  1273.         /*********************************************************************/
  1274.         /* The Name field in the pointer record is optional. We still copy   */
  1275.         /* some junk into the internal table record. The redundant info is   */
  1276.         /* over written by the next record as the incrementing the internal  */
  1277.         /* table pointer according to the size of the record takes care of   */
  1278.         /* this problem !!!.                                                 */
  1279.         /*********************************************************************/
  1280.         pIntPointer->NameLen   = pMSPointer->NameLen;
  1281.         strncpy( pIntPointer->Name, pMSPointer->Name, pMSPointer->NameLen );
  1282.  
  1283.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  1284.         MSptr = (Trec *)((uchar *)MSptr + MSRecLength + 2 + RecIDLen);
  1285.         IntTableLength += (IntRecLength + 2);
  1286.         break;
  1287.       }
  1288.  
  1289.       case T_ENUM:                      /* Enums.                     (0x7B) */
  1290.       {
  1291.         #define  INTSCLRSTRUCTLEN  15
  1292.  
  1293.         uchar  *TablePtr;
  1294.         uint   FieldLength;
  1295.         ushort *IntDataType;
  1296.         TD_SCALAR *pIntScalar = (TD_SCALAR *)Mapptr;
  1297.         TD_ENUM   *pIntEnum   = (TD_ENUM *)Mapptr;
  1298.         MS_SCALAR *pMSScalar  = (MS_SCALAR *)((uchar *)MSptr + 3);
  1299.  
  1300.         MSRecLength = MSptr->RecLen;
  1301.         /*********************************************************************/
  1302.         /* We have a special case of a enum record in Microsoft format (7B)  */
  1303.         /* which is similar to our internal scalar record. So if we come     */
  1304.         /* across such a enum record map it to our internal scalar record    */
  1305.         /* which is of type 0x51.                                            */
  1306.         /*********************************************************************/
  1307.         if( MSptr->RecLen == 3 )
  1308.         {
  1309.           pIntScalar->RecType = T_SCALAR;
  1310.           pIntScalar->RecLen  = IntRecLength = sizeof( TD_SCALAR ) - 2;
  1311.           IntDataType = &(pIntScalar->DataType);
  1312.         }
  1313.         else
  1314.         {
  1315.           pIntEnum->RecType = MSptr->RecType;
  1316.           IntDataType = &(pIntEnum->DataType);
  1317.         }
  1318.         /*********************************************************************/
  1319.         /* The Datatype field is set based on the "BaseType" field in the raw*/
  1320.         /* record and the length of the scalar.                              */
  1321.         /*********************************************************************/
  1322.         switch( pMSScalar->BaseType )
  1323.         {
  1324.           case TFLD_INT:
  1325.             switch( pMSScalar->BitLength )
  1326.             {
  1327.               case 0x08:
  1328.                 *IntDataType = TYPE_CHAR;
  1329.                 break;
  1330.  
  1331.               case 0x10:
  1332.                 *IntDataType = TYPE_SHORT;
  1333.                 break;
  1334.  
  1335.               case 0x20:
  1336.                 *IntDataType = TYPE_LONG;
  1337.                 break;
  1338.             }
  1339.             break;
  1340.  
  1341.           case TFLD_UINT:
  1342.             switch( pMSScalar->BitLength )
  1343.             {
  1344.               case 0x08:
  1345.                 *IntDataType = TYPE_UCHAR;
  1346.                 break;
  1347.  
  1348.               case 0x10:
  1349.                 *IntDataType = TYPE_USHORT;
  1350.                 break;
  1351.  
  1352.               case 0x20:
  1353.                 *IntDataType = TYPE_ULONG;
  1354.                 break;
  1355.             }
  1356.             break;
  1357.  
  1358.           case TFLD_CHAR:
  1359.             *IntDataType = TYPE_CHAR;
  1360.             break;
  1361.         }
  1362.  
  1363.         if( MSptr->RecLen > 3 )
  1364.         {
  1365.           pIntEnum->NameLen = pMSScalar->NameLen;
  1366.           strncpy( pIntEnum->Name, pMSScalar->Name, pIntEnum->NameLen );
  1367.  
  1368.           TablePtr = ((uchar *)MSptr + 7 + pMSScalar->NameLen );
  1369.           TablePtr++;
  1370.           pIntEnum->NameListIndex = *(ushort *)TablePtr;
  1371.           TablePtr += 2;
  1372.           /*******************************************************************/
  1373.           /* - Lower and Upper bound fields are of variable size in the raw  */
  1374.           /*   table but are of fixed size (4 bytes) in the internal table.  */
  1375.           /* - Get field function is used to get the value of the var size   */
  1376.           /*   fields and to increment the table pointer beyond those fields.*/
  1377.           /* - "INTSCLRSTRUCTLEN" is the length of the internal scalar record*/
  1378.           /*   length without the name field.                                */
  1379.           /*******************************************************************/
  1380.           pIntEnum->LBound = pIntEnum->UBound = 0;
  1381.           TablePtr = GetField( TablePtr, (void *)&(pIntEnum->LBound),
  1382.                                &FieldLength );
  1383.           TablePtr = GetField( TablePtr, (void *)&(pIntEnum->UBound),
  1384.                                &FieldLength );
  1385.           IntRecLength = INTSCLRSTRUCTLEN + pIntEnum->NameLen;
  1386.           pIntEnum->RecLen = IntRecLength;
  1387.         }
  1388.  
  1389.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  1390.         MSptr = (Trec *)((uchar *)MSptr + MSRecLength + 2 + RecIDLen);
  1391.         IntTableLength += (IntRecLength + 2);
  1392.         break;
  1393.       }
  1394.  
  1395.       case T_LIST:                      /* Lists.                     (0x7F) */
  1396.       {
  1397.         uchar *MSTablePtr;
  1398.         uchar *IntTablePtr;
  1399.         int  ListRecLen;
  1400.         uchar FIDIndex = *((uchar *)MSptr + 3);
  1401.  
  1402.         MSRecLength = ListRecLen = MSptr->RecLen;
  1403.         IntRecLength = 0;
  1404.         IntTablePtr = ((uchar *)Mapptr + sizeof( Trec ));
  1405.         MSTablePtr  = ((uchar *)MSptr + sizeof( Trec ) + 1);
  1406.  
  1407.         /*********************************************************************/
  1408.         /* Unlike HLL records where lists are differentiated using "TypeQual"*/
  1409.         /* field, MS records are differentiated using FID indexes.           */
  1410.         /*********************************************************************/
  1411.         switch( FIDIndex )
  1412.         {
  1413.           case 0x83:                    /* Type List                  (0x83) */
  1414.           {
  1415.             int  i = 0;
  1416.             TD_TYPELIST *pIntTypeList = (TD_TYPELIST *)Mapptr;
  1417.  
  1418.             pIntTypeList->RecType = MSptr->RecType;
  1419.             pIntTypeList->Flags   = LIST_ST_TYPES;
  1420.             /*****************************************************************/
  1421.             /* - subtract type (0x7F) and FID index field lengths.           */
  1422.             /*****************************************************************/
  1423.             ListRecLen -= 2;
  1424.             while( ListRecLen > 0 )
  1425.             {
  1426.               /***************************************************************/
  1427.               /* - if the complex type == 0, then set it to void.            */
  1428.               /*                                                             */
  1429.               /* Note: This should not happen;however, complex types == 0    */
  1430.               /*       show up in T_LIST records in IBM C/2 1.1.             */
  1431.               /*                                                             */
  1432.               /***************************************************************/
  1433.               if( *(ushort *)MSTablePtr == 0 )
  1434.                 *(ushort *)MSTablePtr = TYPE_VOID;
  1435.               /***************************************************************/
  1436.               /* - Change the "A*" in the 0:16 pointer type indexes to "E*". */
  1437.               /***************************************************************/
  1438.               if( pModule->DbgFormatFlags.Typs != TYPE103_CL386 )
  1439.                 pIntTypeList->TypeIndex[i++] = GetInternal0_16PtrIndex(
  1440.                                                *((ushort *)MSTablePtr) );
  1441.               else
  1442.                 pIntTypeList->TypeIndex[i++] = *((ushort *)MSTablePtr);
  1443.               MSTablePtr += 3;
  1444.               ListRecLen -= 3;
  1445.             }
  1446.             /*****************************************************************/
  1447.             /* - Calculate the size of the internal record based on the num  */
  1448.             /*   of entries in the list + type (1 byte) + type qual (1 byte).*/
  1449.             /*****************************************************************/
  1450.             IntRecLength = pIntTypeList->RecLen = (2 * i) + 2;
  1451.             break;
  1452.           }
  1453.  
  1454.           case 0x82:                    /* Name List.                 (0x82) */
  1455.           {
  1456.             ushort  NameLen;
  1457.             ushort  AdjustLen;
  1458.             uint    OffsetLen;
  1459.             ulong   Offset;
  1460.             Trec    *pIntNameList = (Trec *)Mapptr;
  1461.  
  1462.             /*****************************************************************/
  1463.             /* - Name list does not have a structure defined like type list  */
  1464.             /*   because of the variable length name fields. So it has to be */
  1465.             /*   mapped into the table in a byte by byte basis.              */
  1466.             /*****************************************************************/
  1467.             pIntNameList->RecType = MSptr->RecType;
  1468.             *IntTablePtr = LIST_ST_NAMES;
  1469.             IntTablePtr++;
  1470.             /*****************************************************************/
  1471.             /* - subtract type (0x7F) and FID index field lengths.           */
  1472.             /*****************************************************************/
  1473.             ListRecLen  -= 2;
  1474.             IntRecLength = 2;
  1475.             while( ListRecLen > 0 )
  1476.             {
  1477.               /***************************************************************/
  1478.               /* - Copy the name length and the name.                        */
  1479.               /* - Calculate the cummulative record length by adding lengths */
  1480.               /*   of each item in the list.                                 */
  1481.               /***************************************************************/
  1482.               *((ushort *)IntTablePtr) = NameLen = *MSTablePtr;
  1483.               if( NameLen == 0 )
  1484.               {
  1485.                 MSptr = (Trec *)EndOfTable;
  1486.                 break;
  1487.               }
  1488.               IntTablePtr += 2;
  1489.               MSTablePtr++;
  1490.               ListRecLen--;
  1491.  
  1492.               strncpy( IntTablePtr, MSTablePtr, NameLen );
  1493.               IntTablePtr += NameLen;
  1494.               MSTablePtr  += NameLen;
  1495.               ListRecLen  -= NameLen;
  1496.  
  1497.               Offset = 0;
  1498.               /***************************************************************/
  1499.               /* The offset field in the name list is of variable length, so */
  1500.               /* call getfield to get the value of the offset and to move    */
  1501.               /* MSTablePtr to the next field.                               */
  1502.               /***************************************************************/
  1503.               AdjustLen = 0;
  1504.               if( *MSTablePtr & 0x80 )
  1505.                 AdjustLen = 1;
  1506.  
  1507.               MSTablePtr = GetField( MSTablePtr, (void *)&Offset, &OffsetLen );
  1508.               *((ulong *)IntTablePtr) = Offset;
  1509.               IntTablePtr += 4;
  1510.               IntRecLength += (NameLen + 6);
  1511.               ListRecLen -= (OffsetLen + AdjustLen);
  1512.  
  1513.               MSTablePtr++;
  1514.               ListRecLen--;
  1515.             }
  1516.             pIntNameList->RecLen = IntRecLength;
  1517.             break;
  1518.           }
  1519.  
  1520.           default:
  1521.             break;
  1522.         }
  1523.  
  1524.         /*********************************************************************/
  1525.         /* IntRecLength will be zero in case of PROC LIST or ENUM LIST which */
  1526.         /* are not currently supported. so in those cases insert a NULL      */
  1527.         /* record into the internal table and skip the entire list record.   */
  1528.         /*********************************************************************/
  1529.         if( IntRecLength )
  1530.           Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  1531.         else
  1532.         {
  1533.           IntRecLength = sizeof( Trec ) - 2;
  1534.  
  1535.           Mapptr->RecLen  = IntRecLength;
  1536.           Mapptr->RecType = T_NULL;
  1537.           Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  1538.         }
  1539.  
  1540.         IntTableLength += (IntRecLength + 2);
  1541.         if( (uchar *)MSptr != EndOfTable )
  1542.           MSptr = (Trec *)((uchar *)MSptr + MSRecLength + 2 + RecIDLen);
  1543.         break;
  1544.       }
  1545.  
  1546.       case T_SKIP:                      /* Skip record.               (0x90) */
  1547.       {
  1548.         TD_SKIP *pIntSkip = (TD_SKIP *)Mapptr;
  1549.         MS_SKIP *pMSSkip  = (MS_SKIP *)((uchar *)MSptr + 3);
  1550.  
  1551.         IntRecLength = sizeof( TD_SKIP ) - 2;
  1552.         MSRecLength  = MSptr->RecLen;
  1553.  
  1554.         pIntSkip->RecLen   = IntRecLength;
  1555.         pIntSkip->RecType  = MSptr->RecType;
  1556.         pIntSkip->NewIndex = pMSSkip->NewIndex;
  1557.  
  1558.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  1559.         MSptr  = (Trec *)((uchar *)MSptr + MSRecLength + 2 + RecIDLen);
  1560.         IntTableLength += (IntRecLength + 2);
  1561.         break;
  1562.       }
  1563.  
  1564.       default:
  1565.       {
  1566.         /*********************************************************************/
  1567.         /* In case of the record types which are not currently supported, we */
  1568.         /* insert a NULL record into the internal table and skip the record. */
  1569.         /*********************************************************************/
  1570.         MSRecLength = MSptr->RecLen;
  1571.         IntRecLength = sizeof( Trec ) - 2;
  1572.  
  1573.         Mapptr->RecLen  = IntRecLength;
  1574.         Mapptr->RecType = T_NULL;
  1575.  
  1576.         MSptr = (Trec *)((uchar *)MSptr + MSRecLength + 2 + RecIDLen);
  1577.         Mapptr = (Trec *)((uchar *)Mapptr + IntRecLength + 2);
  1578.         IntTableLength += (IntRecLength + 2);
  1579.         break;
  1580.       }
  1581.     }
  1582.  
  1583.     /*************************************************************************/
  1584.     /* If there is danger that the scratch buffer could overflow for this    */
  1585.     /* subsection, reallocate the scratch area and copy the internal table   */
  1586.     /* info into the new scratch area.                                       */
  1587.     /*************************************************************************/
  1588.     if( IntTableLength > UpperLimit )
  1589.     {
  1590.       uchar  *TempBuffer;
  1591.  
  1592.       UpperLimit += 20000;
  1593.       TempBuffer = Talloc( UpperLimit + 5000 );
  1594.       memcpy( TempBuffer, Scratch, IntTableLength );
  1595.       Tfree( Scratch );
  1596.       Scratch = TempBuffer;
  1597.       Mapptr = (Trec *)(Scratch + IntTableLength);
  1598.     }
  1599.   }
  1600.   /***************************************************************************/
  1601.   /* Once we are through with the mapping for a module,                      */
  1602.   /* - Change the length in the MODULE structure to the internal table length*/
  1603.   /* - Allocate memory for the internal types table.                         */
  1604.   /* - Copy the internal table from the scratch area.                        */
  1605.   /* - Return a pointer to the internal types table.                         */
  1606.   /***************************************************************************/
  1607.   pModule->TypeLen = IntTableLength;
  1608.   IntTypeTable = Talloc( IntTableLength );
  1609.   memcpy( IntTypeTable, Scratch, IntTableLength );
  1610.   Tfree( RawTable );
  1611.   return( IntTypeTable );
  1612. }
  1613.  
  1614. /*****************************************************************************/
  1615. /* GetInternal0_16PtrIndex()                                              813*/
  1616. /*                                                                           */
  1617. /* Description:                                                              */
  1618. /*                                                                           */
  1619. /*   Convert the NEAR (A* 0:16) pointers to the internal type indexes (E*).  */
  1620. /*   Convert the HUGE (E*) pointers to FAR (C* 16:16) pointers.              */
  1621. /*                                                                           */
  1622. /* Parameters:                                                               */
  1623. /*                                                                           */
  1624. /*   TypeIndex    (input) - Type index input.                                */
  1625. /*                                                                           */
  1626. /* Return:                                                                   */
  1627. /*                                                                           */
  1628. /* - NEAR (A* 0:16) pointers are converted to internal type indexes (E*).    */
  1629. /* - HUGE (E*) pointers are converted to FAR (C* 16:16) pointers.            */
  1630. /* - For the rest the original type index is returned.                       */
  1631. /*                                                                           */
  1632. /*****************************************************************************/
  1633. ushort  GetInternal0_16PtrIndex( ushort TypeIndex )
  1634. {
  1635.   if( TypeIndex >= 512 )
  1636.    return(TypeIndex);
  1637.  
  1638.   if( ((TypeIndex & 0xF0) == 0xA0) || (TypeIndex == 0xB7) )
  1639.     return( TypeIndex | 0x40 );
  1640.   else
  1641.   if( (TypeIndex & 0xF0) == 0xE0 )
  1642.     return( TypeIndex & 0xDF );
  1643.   else
  1644.     return( TypeIndex );
  1645. }
  1646.  
  1647. /*****************************************************************************/
  1648. /* GetEncLength()                                                            */
  1649. /*                                                                           */
  1650. /* Description:                                                              */
  1651. /*                                                                           */
  1652. /*   Decode an encoded length. Determine how many bytes(1/2) are in          */
  1653. /*   the encoded length.                                                     */
  1654. /*                                                                           */
  1655. /* Parameters:                                                               */
  1656. /*                                                                           */
  1657. /*   pEncLen     -> to 1/2 byte encoded length                               */
  1658. /*   pNumBytes   -> to receiver of number(1/2) of bytes used in encoded len. */
  1659. /*                                                                           */
  1660. /* Return:                                                                   */
  1661. /*                                                                           */
  1662. /*   EncLength                                                               */
  1663. /*                                                                           */
  1664. /*****************************************************************************/
  1665. USHORT GetEncLength( ENCLEN *pEncLen, int *pNumBytes )
  1666. {
  1667.  UCHAR  ENC_1stByte;
  1668.  UCHAR  ENC_2ndByte;
  1669.  USHORT EncLength;
  1670.  int    NumBytes;
  1671.  
  1672.  EncLength   = 0;
  1673.  NumBytes    = 0;
  1674.  ENC_1stByte = pEncLen->ENC_1stByte;
  1675.  ENC_2ndByte = pEncLen->ENC_2ndByte;
  1676.  
  1677.  if(TestBit(ENC_1stByte, 7 ))
  1678.  {
  1679.   EncLength = (ENC_1stByte & 0x7f) + ENC_2ndByte;
  1680.   NumBytes  = 2;
  1681.  }
  1682.  else
  1683.  {
  1684.   EncLength = ENC_1stByte;
  1685.   NumBytes  = 1;
  1686.  }
  1687.  
  1688.  *pNumBytes = NumBytes;
  1689.  return(EncLength);
  1690. }
  1691.  
  1692. #define VIRTUAL_MASK  0x10
  1693. BOOL IsVirtual( HL_MEMFNC *pHLLMemFnc )
  1694. {
  1695.  if( pHLLMemFnc->TypeQual & VIRTUAL_MASK )
  1696.   return(TRUE);
  1697.  else
  1698.   return(FALSE);
  1699. }
  1700.  
  1701. #define STATIC_MASK  0x01
  1702. BOOL IsStatic( HL_CLSMEM *pHLLClsMem )
  1703. {
  1704.  if( pHLLClsMem->TypeQual & STATIC_MASK )
  1705.   return(TRUE);
  1706.  else
  1707.   return(FALSE);
  1708. }
  1709.  
  1710. #define VTABLE_MASK  0x02
  1711. BOOL IsVtable( HL_CLSMEM *pHLLClsMem )
  1712. {
  1713.  if( pHLLClsMem->TypeQual & VTABLE_MASK )
  1714.   return(TRUE);
  1715.  else
  1716.   return(FALSE);
  1717. }
  1718.