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

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   types.c                                                                 */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*   $$types segment handling routines.                                      */
  8. /*                                                                           */
  9. /*                                                                           */
  10. /* History:                                                                  */
  11. /*                                                                           */
  12. /*****************************************************************************/
  13.  
  14. #include "all.h"                        /* SD86 include files                */
  15.  
  16. extern CmdParms     cmd;                /* start command parms.           403*/
  17.  
  18. /*************************************************************************813*/
  19. /* QTypeName()                                                            813*/
  20. /*                                                                        813*/
  21. /* Description:                                                           813*/
  22. /*                                                                        813*/
  23. /*   Get the tag name, the userdef name, or the primitive name of         813*/
  24. /*   a typeno.                                                            813*/
  25. /*                                                                        813*/
  26. /* Parameters:                                                            813*/
  27. /*                                                                        813*/
  28. /*   typeno     input - primitive or complex type number.                 813*/
  29. /*   mid        input - module in which complex type number is defined.   813*/
  30. /*                                                                        813*/
  31. /* Return:                                                                813*/
  32. /*                                                                        813*/
  33. /*   cp         -> to the type name.                                      813*/
  34. /*              NULL if failure.                                          813*/
  35. /*                                                                        813*/
  36. /* Assumptions:                                                           813*/
  37. /*                                                                        813*/
  38. /*****************************************************************************/
  39. static uchar basetypes[] =                                              /*813*/
  40. {                                                                       /*813*/
  41.  TYPE_CHAR,                             /* 8-bit  signed.                 813*/
  42.  TYPE_SHORT,                            /* 16-bit signed.                 813*/
  43.  TYPE_LONG,                             /* 32-bit signed.                 813*/
  44.  TYPE_UCHAR,                            /* 8-bit  unsigned.               813*/
  45.  TYPE_USHORT,                           /* 16-bit unsigned.               813*/
  46.  TYPE_ULONG,                            /* 32-bit unsigned.               813*/
  47.  TYPE_FLOAT,                            /* 32-bit real.                   813*/
  48.  TYPE_DOUBLE,                           /* 64-bit real.                   813*/
  49.  TYPE_LDOUBLE,                          /* 80-bit real.                   813*/
  50.  TYPE_VOID,                             /* void.                          813*/
  51.  TYPE_PCHAR,                            /* 0:32 near ptr to 8-bit  signed.813*/
  52.  TYPE_PSHORT,                           /* 0:32 near ptr to 16-bit signed.813*/
  53.  TYPE_PLONG,                            /* 0:32 near ptr to 32-bit signed.813*/
  54.  TYPE_PUCHAR,                           /* 0:32 near ptr to 8-bit  unsigne813*/
  55.  TYPE_PUSHORT,                          /* 0:32 near ptr to 16-bit unsigne813*/
  56.  TYPE_PULONG,                           /* 0:32 near ptr to 32-bit unsigne813*/
  57.  TYPE_PFLOAT,                           /* 0:32 near ptr to 32-bit real.  813*/
  58.  TYPE_PDOUBLE,                          /* 0:32 near ptr to 64-bit real.  813*/
  59.  TYPE_PLDOUBLE,                         /* 0:32 near ptr to 80-bit real.  813*/
  60.  TYPE_PVOID,                            /* 0:32 near ptr to void.         813*/
  61.  TYPE_FPCHAR,                           /* far ptr to 8-bit  signed.      813*/
  62.  TYPE_FPSHORT,                          /* far ptr to 16-bit signed.      813*/
  63.  TYPE_FPLONG,                           /* far ptr to 32-bit signed.      813*/
  64.  TYPE_FPUCHAR,                          /* far ptr to 8-bit  unsigned.    813*/
  65.  TYPE_FPUSHORT,                         /* far ptr to 16-bit unsigned.    813*/
  66.  TYPE_FPULONG,                          /* far ptr to 32-bit unsigned.    813*/
  67.  TYPE_FPFLOAT,                          /* far ptr to 32-bit real.        813*/
  68.  TYPE_FPDOUBLE,                         /* far ptr to 64-bit real.        813*/
  69.  TYPE_FPLDOUBLE,                        /* far ptr to 80-bit real.        813*/
  70.  TYPE_FPVOID,                           /* far ptr to void.               813*/
  71.  TYPE_N16PCHAR,                         /* 0:16 near ptr to 8-bit  signed.813*/
  72.  TYPE_N16PSHORT,                        /* 0:16 near ptr to 16-bit signed.813*/
  73.  TYPE_N16PLONG,                         /* 0:16 near ptr to 32-bit signed.813*/
  74.  TYPE_N16PUCHAR,                        /* 0:16 near ptr to 8-bit  unsigne813*/
  75.  TYPE_N16PUSHORT,                       /* 0:16 near ptr to 16-bit unsigne813*/
  76.  TYPE_N16PULONG,                        /* 0:16 near ptr to 32-bit unsigne813*/
  77.  TYPE_N16PFLOAT,                        /* 0:16 near ptr to 32-bit real.  813*/
  78.  TYPE_N16PDOUBLE,                       /* 0:16 near ptr to 64-bit real.  813*/
  79.  TYPE_N16PLDOUBLE,                      /* 0:16 near ptr to 80-bit real.  813*/
  80.  TYPE_N16PVOID                          /* 0:16 near ptr to void.         813*/
  81. };                                                                      /*813*/
  82.  
  83. static char *basenames[] =                                              /*813*/
  84. {                                                                       /*813*/
  85.  "\4\0char"     ,                       /* 8-bit  signed.                 813*/
  86.  "\5\0short"    ,                       /* 16-bit signed.                 813*/
  87.  "\4\0long"     ,                       /* 32-bit signed.                 813*/
  88.  "\5\0uchar"    ,                       /* 8-bit  unsigned.               813*/
  89.  "\6\0ushort"   ,                       /* 16-bit unsigned.               813*/
  90.  "\5\0ulong"    ,                       /* 32-bit unsigned.               813*/
  91.  "\5\0float"    ,                       /* 32-bit real.                   813*/
  92.  "\6\0double"   ,                       /* 64-bit real.                   813*/
  93.  "\7\0ldouble"  ,                       /* 80-bit real.                   813*/
  94.  "\4\0void"     ,                       /* void.                          813*/
  95.  "\5\0char*"    ,                       /* 0:32 near ptr to 8-bit  signed.813*/
  96.  "\6\0short*"   ,                       /* 0:32 near ptr to 16-bit signed.813*/
  97.  "\5\0long*"    ,                       /* 0:32 near ptr to 32-bit signed.813*/
  98.  "\6\0uchar*"   ,                       /* 0:32 near ptr to 8-bit  unsigne813*/
  99.  "\7\0ushort*"  ,                       /* 0:32 near ptr to 16-bit unsigne813*/
  100.  "\6\0ulong*"   ,                       /* 0:32 near ptr to 32-bit unsigne813*/
  101.  "\6\0float*"   ,                       /* 0:32 near ptr to 32-bit real.  813*/
  102.  "\5\0dble*"    ,                       /* 0:32 near ptr to 64-bit real.  813*/
  103.  "\6\0ldble*"   ,                       /* 0:32 near ptr to 80-bit real.  813*/
  104.  "\5\0void*"    ,                       /* 0:32 near ptr to void.         813*/
  105.  "\5\0char*"    ,                       /* far ptr to 8-bit  signed.      813*/
  106.  "\6\0short*"   ,                       /* far ptr to 16-bit signed.      813*/
  107.  "\5\0long*"    ,                       /* far ptr to 32-bit signed.      813*/
  108.  "\6\0uchar*"   ,                       /* far ptr to 8-bit  unsigned.    813*/
  109.  "\7\0ushort*"  ,                       /* far ptr to 16-bit unsigned.    813*/
  110.  "\6\0ulong*"   ,                       /* far ptr to 32-bit unsigned.    813*/
  111.  "\6\0float*"   ,                       /* far ptr to 32-bit real.        813*/
  112.  "\5\0dble*"    ,                       /* far ptr to 64-bit real.        813*/
  113.  "\6\0ldble*"   ,                       /* far ptr to 80-bit real.        813*/
  114.  "\5\0void*"    ,                       /* far ptr to void.               813*/
  115.  "\5\0char*"    ,                       /* 0:16 near ptr to 8-bit  signed.813*/
  116.  "\6\0short*"   ,                       /* 0:16 near ptr to 16-bit signed.813*/
  117.  "\5\0long*"    ,                       /* 0:16 near ptr to 32-bit signed.813*/
  118.  "\6\0uchar*"   ,                       /* 0:16 near ptr to 8-bit  unsigne813*/
  119.  "\6\0short*"   ,                       /* 0:16 near ptr to 16-bit unsigne813*/
  120.  "\6\0ulong*"   ,                       /* 0:16 near ptr to 32-bit unsigne813*/
  121.  "\6\0float*"   ,                       /* 0:16 near ptr to 32-bit real.  813*/
  122.  "\5\0dble*"    ,                       /* 0:16 near ptr to 64-bit real.  813*/
  123.  "\6\0ldble*"   ,                       /* 0:16 near ptr to 80-bit real.  813*/
  124.  "\5\0void*"                            /* 0:16 near ptr to void.         813*/
  125. };                                                                      /*813*/
  126.  
  127. static uchar RecTypes[] =                                               /*813*/
  128. {                                                                       /*813*/
  129.  T_SCALAR,                                                              /*813*/
  130.  T_BITFLD,                                                              /*813*/
  131.  T_TYPDEF,                                                              /*813*/
  132.  T_PROC,                                                                /*813*/
  133.  T_ENTRY,                                                               /*813*/
  134.  T_FUNCTION,                                                            /*813*/
  135.  T_ARRAY,                                                               /*813*/
  136.  T_STRUCT,                                                              /*813*/
  137.  T_PTR,                                                                 /*813*/
  138.  T_ENUM,
  139. };                                                                      /*813*/
  140.  
  141. static char *RecNames[] =                                               /*813*/
  142. {                                                                       /*813*/
  143.  "\6\0scalar"   ,                                                       /*813*/
  144.  "\6\0bitfld"   ,                                                       /*813*/
  145.  "\7\0typedef"  ,                                                       /*813*/
  146.  "\4\0proc"     ,                                                       /*813*/
  147.  "\5\0entry"    ,                                                       /*813*/
  148.  "\4\0func"     ,                                                       /*813*/
  149.  "\5\0array"    ,                                                       /*813*/
  150.  "\6\0struct"   ,                                                       /*813*/
  151.  "\1\0*"        ,                                                       /*813*/
  152.  "\4\0enum"     ,                                                       /*813*/
  153.  "\7\0unknown"                                                          /*813*/
  154. };                                                                      /*813*/
  155.  
  156. #define MAXTYPNAMLEN 32                                                 /*813*/
  157. static uchar ptrtypename[MAXTYPNAMLEN+3];                               /*813*/
  158.                                                                         /*813*/
  159. UCHAR * QtypeName(UINT mid,USHORT typeno)                               /*813*/
  160. {                                                                       /*813*/
  161.  UINT    n;                                                             /*813*/
  162.  Trec   *tp;                                                            /*813*/
  163.  uchar  *cp;                                                            /*813*/
  164.  USHORT  len;                                                           /*813*/
  165.  
  166.  if( typeno < 512 )                                                     /*813*/
  167.  {                                                                      /*813*/
  168.   /***********************************************************************813*/
  169.   /* Get the name of a primitive type no.                                 813*/
  170.   /***********************************************************************813*/
  171.   n = bindex(basetypes,sizeof(basetypes),typeno);                       /*813*/
  172.   if( n < sizeof(basetypes)  )                                          /*813*/
  173.   {                                                                     /*813*/
  174.    cp = basenames[n];                                                   /*813*/
  175.    return( cp );                                                        /*813*/
  176.   }                                                                     /*813*/
  177.  }                                                                      /*813*/
  178.  else                                                                   /*813*/
  179.  {                                                                      /*813*/
  180.   /***********************************************************************813*/
  181.   /* Get the tag/userdef name. If there is no tag or userdef name,        813*/
  182.   /* then use a default name.                                             813*/
  183.   /***********************************************************************813*/
  184.   tp = QtypeRec(mid, typeno);                                           /*813*/
  185.   if( tp )                                                              /*813*/
  186.   {                                                                     /*813*/
  187.    cp = QTagName( tp );                                                 /*813*/
  188.    /**********************************************************************813*/
  189.    /* Append a "*" or "[]" suffix for pointer/array types.                813*/
  190.    /**********************************************************************813*/
  191.    switch( tp->RecType )                                                /*813*/
  192.    {                                                                    /*813*/
  193.     case T_PTR:                                                         /*813*/
  194.       typeno = ((TD_POINTER*)tp)->TypeIndex;                            /*813*/
  195.       if( typeno < 512 )                                                /*813*/
  196.        cp = QtypeName(mid,typeno);                                      /*813*/
  197.                                                                         /*813*/
  198.       len = *(USHORT*)cp + 2;                                           /*813*/
  199.       if( len <= (MAXTYPNAMLEN-2) )                                     /*813*/
  200.       {                                                                 /*813*/
  201.        memcpy(ptrtypename, cp, len );                                   /*813*/
  202.        *(ptrtypename + len) = '*';                                      /*813*/
  203.        *(USHORT*)(cp = ptrtypename) = len + 1;                          /*813*/
  204.       }                                                                 /*813*/
  205.       break;                                                            /*813*/
  206.                                                                         /*813*/
  207.     case T_ARRAY:                                                       /*813*/
  208.       typeno = ((TD_ARRAY*)tp)->ElemType;                               /*813*/
  209.       if( typeno < 512 )                                                /*813*/
  210.        cp = QtypeName(mid,typeno);                                      /*813*/
  211.                                                                         /*813*/
  212.       len = *(USHORT*)cp + 2;                                           /*813*/
  213.       if( len <= (MAXTYPNAMLEN-2) )                                     /*813*/
  214.       {                                                                 /*813*/
  215.        memcpy(ptrtypename, cp, len );                                   /*813*/
  216.        *(ptrtypename + len) = '[';                                      /*813*/
  217.        *(ptrtypename + len+1) = ']';                                    /*813*/
  218.        *(USHORT*)(cp = ptrtypename) = len + 2;                          /*813*/
  219.       }                                                                 /*813*/
  220.       break;                                                            /*813*/
  221.    }                                                                    /*813*/
  222.    return( cp );                                                        /*813*/
  223.   }                                                                     /*813*/
  224.  }                                                                      /*813*/
  225.  return( NULL );                                                        /*813*/
  226. }                                                                       /*813*/
  227.  
  228.  uint
  229. QtypeGroup( uint mid, uint   typeno )
  230. {
  231.     Trec *tp;
  232.  
  233. ReCycle:
  234.     if( (typeno == VALUE_CONSTANT) ||   /* if the type number is fake     243*/
  235.         (typeno == ADDRESS_CONSTANT) )  /* addr const or value const      243*/
  236.          return( TG_CONSTANT );         /* then return TG_CONSTANT        243*/
  237.     if( typeno < 512 )
  238.     {
  239.      if( typeno & PRIMITIVE_PTR )                                       /*112*/
  240.          return( TG_POINTER );
  241.      if( bindex(basetypes, sizeof(basetypes), typeno) < sizeof(basetypes) )
  242.          return( TG_SCALAR );
  243.     }
  244.     else
  245.     {
  246.      tp = QbasetypeRec(mid, typeno);
  247.      if( tp )
  248.      {
  249.          switch( tp->RecType )
  250.          {
  251.            case T_PTR:
  252.              return( TG_POINTER );
  253.            case T_STRUCT:
  254.              return( TG_STRUCT );
  255.            case T_CLASS:
  256.              return( TG_CLASS );
  257.            case T_REF:
  258.              return( TG_REF );
  259.            case T_ARRAY:
  260.              return( TG_ARRAY );
  261.            case T_ENUM:
  262.              return( TG_ENUM );
  263.            case T_BITFLD:
  264.              return( TG_BITFLD );
  265.      /***  case T_LIST: ***/
  266.      /***  case T_PROC: ***/
  267.            /*******************************************************************/
  268.            /* In case of a user def record get the type no from the user   512*/
  269.            /* def record and go to top to process the type no.             512*/
  270.            /*******************************************************************/
  271.            case T_TYPDEF:
  272.              typeno = ((TD_USERDEF*)tp)->TypeIndex;
  273.              goto ReCycle;
  274.  
  275.            case T_CLSDEF:
  276.              typeno = ((TD_CLSDEF*)tp)->TypeIndex;
  277.              goto ReCycle;
  278.          }
  279.      }
  280.     }
  281.     return( TG_UNKNOWN );
  282. }
  283.  
  284.  
  285.  
  286.  int
  287. QstructField(uint mid, UCHAR*pFieldName,uint *offptr,uint *tnoptr)
  288. {
  289.  Trec        *pTrec;
  290.  TD_CLASS    *pClass;
  291.  int          item;
  292.  UCHAR        NameBuf[256];
  293.  BOOL         IsMangled;
  294.  USHORT       NameLength;
  295.  TD_TYPELIST *pClassItemList;
  296.  
  297.     int i, n, rc;                       /* was register.                  112*/
  298.     TD_STRUCT *tp;                                                      /*813*/
  299.     Trec *NameList;
  300.     TD_TYPELIST *TypeList;                                              /*813*/
  301.     uchar *cp;
  302.  
  303.     pTrec = (Trec *)QbasetypeRec( mid, *tnoptr );
  304.     switch(pTrec->RecType)
  305.     {
  306.      case T_CLASS:
  307.      {
  308.       int NumMembers;
  309.  
  310.       pClass         = (TD_CLASS*)pTrec;
  311.       NumMembers     = pClass->NumMembers;
  312.       pClassItemList = (TD_TYPELIST*)QtypeRec(mid, pClass->ItemListIndex);
  313.  
  314.       for( item = 1 ; item <= NumMembers; ++item )
  315.       {
  316.        cp = NULL;
  317.        cp = (UCHAR *)QClassItemList(mid, pClassItemList, NAME, item-1);
  318.        if(cp)
  319.        {
  320.         IsMangled = unmangle( NameBuf + 2, cp + 2 );
  321.  
  322.         if( IsMangled )
  323.         {
  324.          *(USHORT*)NameBuf = strlen(NameBuf + 2 );
  325.          cp = NameBuf;
  326.         }
  327.  
  328.        /*****************************************************************/
  329.        /* When comparing the field names, if the case sensitivity is    */
  330.        /* turned off, compare the names without case sensitivity.       */
  331.        /*****************************************************************/
  332.         NameLength = *(USHORT*)pFieldName + 2;
  333.  
  334.         rc = memcmp(pFieldName, cp, NameLength);
  335.  
  336.         if (rc && !cmd.CaseSens)
  337.           rc = memicmp(pFieldName, cp, NameLength);
  338.         if (rc == 0)
  339.         {
  340.          *offptr = QClassItemList(mid, pClassItemList, MEMBEROFFSET, item-1);
  341.          *tnoptr = QClassItemList(mid, pClassItemList, MEMBERTYPE,   item-1);
  342.          return(TRUE);
  343.         }
  344.        }
  345.       }
  346.      }
  347.      break;
  348.  
  349.      case T_STRUCT:
  350.      {
  351.         if( (tp = (TD_STRUCT*)pTrec)
  352.          && (tp->RecType == T_STRUCT)
  353.          && (TypeList = (TD_TYPELIST*)QtypeRec(mid, tp->TypeListIndex  ))
  354.          && (NameList = QtypeRec(mid, tp->NameListIndex  ))
  355.           ) for( i=1, n = tp->NumMembers; i <= n; ++i )
  356.             {
  357.                 cp = (uchar *) QNameList(NameList,NAME,i-1);
  358.                 if (cp )
  359.                 /*****************************************************************/
  360.                 /* When comparing the field names, if the case sensitivity is    */
  361.                 /* turned off, compare the names without case sensitivity.       */
  362.                 /*****************************************************************/
  363.                 {
  364.                  USHORT NameLength;
  365.  
  366.                  NameLength = *(USHORT*)pFieldName + 2;
  367.  
  368.                    rc = memcmp(pFieldName, cp, NameLength);
  369.                    if (rc && !cmd.CaseSens)
  370.                      rc = memicmp(pFieldName, cp, NameLength);
  371.                    if (rc == 0)
  372.                    {
  373.                       *offptr = QNameList(NameList,MEMBEROFFSET,i-1);
  374.                       *tnoptr = TypeList->TypeIndex[i-1];
  375.                       return(TRUE);
  376.                    }
  377.                 }
  378.             }
  379.      }
  380.      break;
  381.     }
  382.     return(FALSE);
  383. }
  384.  
  385. /* This procedure returns the address of the Nth element of an array */
  386.  int
  387. QarrayItem(uint mid,uint subscript,uint *offptr,uint *tnoptr)
  388. {
  389.     TD_ARRAY *tp;                                                       /*813*/
  390.     uint itemsize;
  391.     USHORT typeno = *(USHORT*)tnoptr;                                   /*813*/
  392.     uint abs_addr;
  393.  
  394.  
  395.     if( QderefType(mid, &typeno) )      /* &ptr[n] evaluates to (ptr + n)    */
  396.     {                                   /*                                   */
  397.      itemsize = QtypeSize(mid, typeno); /*                                   */
  398.      if( itemsize )                     /*                                   */
  399.      {                                  /*                                   */
  400.       abs_addr = DerefPointer(*offptr,mid);                             /*245*/
  401.       if( abs_addr )                                                    /*245*/
  402.       {                                                                 /*245*/
  403.        *offptr = abs_addr + (itemsize * subscript);                     /*245*/
  404.        *tnoptr = typeno;
  405.        return( TRUE );
  406.       }
  407.      }
  408.     /* &array[n] evaluates to (&array[0] + n) */
  409.     }else if( (tp = (TD_ARRAY*)QbasetypeRec(mid, typeno))               /*813*/
  410.         && (tp->RecType == T_ARRAY)                                     /*813*/
  411.         && (itemsize = QtypeSize(mid,typeno = tp->ElemType)) )          /*813*/
  412.     {
  413.         *offptr += itemsize * subscript;
  414.         *tnoptr = typeno;
  415.         return( TRUE );
  416.     }
  417.  
  418.     return( FALSE );
  419. }
  420. /*****************************************************************************/
  421. /* QderefType()                                                              */
  422. /*                                                                           */
  423. /* Description:                                                              */
  424. /*   Dereference a type number.                                              */
  425. /*                                                                           */
  426. /* Parameters:                                                               */
  427. /*   mid       input - module id.                                            */
  428. /*   tnoptr    input/output - where to put the dereferenced type.            */
  429. /*                                                                           */
  430. /* Return:                                                                   */
  431. /*   1         => *tnoptr is the type of the pointer.                        */
  432. /*   0                                                                       */
  433. /*                                                                           */
  434. /* Assumptions:                                                              */
  435. /*                                                                           */
  436. /*****************************************************************************/
  437.                                         /*                                   */
  438.  int                                    /*                                   */
  439. QderefType(uint mid,USHORT *tnoptr)
  440.                                         /* executable module id.             */
  441.                                         /* where to put type for the caller. */
  442. {                                       /*                                   */
  443.  uint typeno;                           /*                                   */
  444.  Trec *tp;                              /*                                   */
  445.                                         /*                                   */
  446.  typeno = *tnoptr;                      /*                                   */
  447.  if(  typeno < 512 )                    /* if this is a primitive type and   */
  448.  {                                      /*                                   */
  449.   if( typeno & PRIMITIVE_PTR )          /* if it's really a pointer to a/*112*/
  450.   {                                     /* primitive type, then convert back */
  451.    *tnoptr = PrimitiveType(typeno);     /* to type and return 1.             */
  452.    return(1);                           /*                                   */
  453.   }                                     /*                                   */
  454.  }                                      /*                                   */
  455.  else                                   /*                                   */
  456.  {                                      /* if it's not primitive, then       */
  457.   tp = QbasetypeRec(mid, typeno);       /* resolve tp to base type.          */
  458.   if( tp && (tp->RecType == T_PTR) )    /* if it's really a pointer to a     */
  459.   {                                     /* base type, then convert back      */
  460.    *tnoptr = ((TD_POINTER*)tp)->TypeIndex;                              /*813*/
  461.    *tnoptr = HandleUserDefs(mid,*tnoptr);/* Get primitive typeno in case  601*/
  462.    return(1);                           /* of primitive user defs.        601*/
  463.   }                                     /*                                   */
  464.  }                                      /*                                   */
  465.  return(0);                             /*                                   */
  466. }                                       /*                                   */
  467.  
  468. /*****************************************************************************/
  469. /* QtypeRec()                                                             813*/
  470. /*                                                                           */
  471. /* Description:                                                              */
  472. /*                                                                           */
  473. /*   Get a pointer to the type record for a typeno.                          */
  474. /*                                                                           */
  475. /* Parameters:                                                               */
  476. /*                                                                           */
  477. /*   mid        input - module id containing the the typeno.                 */
  478. /*   typeno     input - primitive or complex typeno.                         */
  479. /*                                                                           */
  480. /* Return:                                                                   */
  481. /*                                                                           */
  482. /*   tp         -> to a type record.                                         */
  483. /*                                                                           */
  484. /* Assumptions:                                                              */
  485. /*                                                                           */
  486. /*****************************************************************************/
  487. Trec *QtypeRec(uint mid, USHORT typeno)
  488. {
  489.  Trec    *p=NULL;
  490.  uchar   *pend;
  491.  uint     n;
  492.  uint     seglen;
  493.  DEBFILE *pdf;
  494.  
  495.  /****************************************************************************/
  496.  /* If the typeno is primitive, return NULL.                                 */
  497.  /****************************************************************************/
  498.  if( (typeno < 512) ||
  499.      (typeno == VALUE_CONSTANT) ||                                      /*243*/
  500.      (typeno == ADDRESS_CONSTANT) )                                     /*243*/
  501.   return( NULL );
  502.  
  503.  /****************************************************************************/
  504.  /* - Get a ptr to the EXE/DLL with this mid.                                */
  505.  /* - If there is no type segment or the type segment is empty return NULL.  */
  506.  /****************************************************************************/
  507.  pdf = DBFindPdf(mid);
  508.  p = (Trec *)DBTypSeg(mid, &seglen,pdf);
  509.  if( !p || (seglen == 0 ) )
  510.   return( NULL );
  511.  
  512.  /****************************************************************************/
  513.  /* Scan the type segment until we get a ptr to the type record for typeno.  */
  514.  /****************************************************************************/
  515.  for( n=512 , pend = (UCHAR*)p + seglen;
  516.       (UCHAR*)p < pend;
  517.       p = NextTrec(p),
  518.       n = (p->RecType != T_SKIP)?n+1:((TD_SKIP*)p)->NewIndex - 1
  519.     )
  520.  {
  521.   if( n == typeno )
  522.    return(p);
  523.  }
  524.  return(NULL);
  525. }
  526.  
  527. /*****************************************************************************/
  528. /* QbasetypeRec()                                                            */
  529. /*                                                                           */
  530. /* Description:                                                              */
  531. /*                                                                           */
  532. /*   Get a pointer to the type record for a typeno. Scan through T_TYPEDEF   */
  533. /*   records. Return a pointer to a T_TYPEDEF only if contains a primitive   */
  534. /*   typeno.                                                                 */
  535. /*                                                                           */
  536. /* Parameters:                                                               */
  537. /*                                                                           */
  538. /*   mid        input - module id containing the the typeno.                 */
  539. /*   typeno     input - primitive or complex typeno.                         */
  540. /*                                                                           */
  541. /* Return:                                                                   */
  542. /*                                                                           */
  543. /*   tp         -> to a type record.                                         */
  544. /*                                                                           */
  545. /* Assumptions:                                                              */
  546. /*                                                                           */
  547. /*****************************************************************************/
  548. Trec *QbasetypeRec(uint mid, USHORT typeno)
  549. {
  550.  Trec *tp;
  551.  
  552.  tp = QtypeRec(mid, typeno);
  553.  
  554.  for( ; tp; )
  555.  {
  556.   if( tp->RecType == T_TYPDEF )
  557.   {
  558.    typeno = ((TD_USERDEF*)tp)->TypeIndex;
  559.    if( typeno >= 512 )
  560.    {
  561.     tp = QtypeRec(mid, typeno);
  562.     continue;
  563.    }
  564.    else
  565.     break;
  566.   }
  567.   else if( tp->RecType == T_CLSDEF )
  568.   {
  569.    typeno = ((TD_CLSDEF*)tp)->TypeIndex;
  570.    if( typeno >= 512 )
  571.    {
  572.     tp = QtypeRec(mid, typeno);
  573.     continue;
  574.    }
  575.    else
  576.     break;
  577.   }
  578.   else
  579.    break;
  580.  }
  581.  
  582.  return(tp);
  583. }
  584.  
  585. /*****************************************************************************/
  586. /* Qbasetype()                                                               */
  587. /*                                                                           */
  588. /* Description:                                                              */
  589. /*                                                                           */
  590. /*   Get a pointer to the type record for a typeno. Scan through T_TYPEDEF   */
  591. /*   records. Return a pointer to a T_TYPEDEF only if contains a primitive   */
  592. /*   typeno.                                                                 */
  593. /*                                                                           */
  594. /* Parameters:                                                               */
  595. /*                                                                           */
  596. /*   mid        module id containing the the typeno.                         */
  597. /*   typeno     primitive or complex typeno.                                 */
  598. /*                                                                           */
  599. /* Return:                                                                   */
  600. /*                                                                           */
  601. /*   typeno                                                                  */
  602. /*                                                                           */
  603. /* Assumptions:                                                              */
  604. /*                                                                           */
  605. /*****************************************************************************/
  606. USHORT Qbasetype(UINT mid, USHORT typeno)
  607. {
  608.  Trec *tp;
  609.  
  610.  tp = QtypeRec(mid, typeno);
  611.  
  612.  for( ; tp; )
  613.  {
  614.   if( tp->RecType == T_TYPDEF )
  615.   {
  616.    typeno = ((TD_USERDEF*)tp)->TypeIndex;
  617.    if( typeno >= 512 )
  618.    {
  619.     tp = QtypeRec(mid, typeno);
  620.     continue;
  621.    }
  622.    else
  623.     break;
  624.   }
  625.   else if( tp->RecType == T_CLSDEF )
  626.   {
  627.    typeno = ((TD_CLSDEF*)tp)->TypeIndex;
  628.    if( typeno >= 512 )
  629.    {
  630.     tp = QtypeRec(mid, typeno);
  631.     continue;
  632.    }
  633.    else
  634.     break;
  635.   }
  636.   else
  637.    break;
  638.  }
  639.  
  640.  return(typeno);
  641. }
  642.  
  643. /*****************************************************************************/
  644. /* QNameList()                                                            813*/
  645. /*                                                                           */
  646. /* Description:                                                              */
  647. /*                                                                           */
  648. /*   Get an instance of an offset or a pointer to a name from a name list.   */
  649. /*                                                                           */
  650. /* Parameters:                                                               */
  651. /*                                                                           */
  652. /*   tp         input - -> to a name list record.                            */
  653. /*   Request    input - -> Name,offset, or value.                            */
  654. /*   Instance   input - instance of the name, offset or value wanted.(0..N). */
  655. /*                      This guy is 0 base like an array.                    */
  656. /*                                                                           */
  657. /* Return:                                                                   */
  658. /*                                                                           */
  659. /*   pname      -> to the length prefixed name in the record.                */
  660. /*    or                                                                     */
  661. /*   offset        Offset associated with the name. This is returned         */
  662. /*                 if the Request is not NAME.                               */
  663. /*   index         Index in the list of the member with the specified        */
  664. /*                 value passed as a parameter.                              */
  665. /*                                                                           */
  666. /* Assumptions:                                                              */
  667. /*                                                                           */
  668. /*   The instance is within the record. There are no checks to validate      */
  669. /*   that the instance is in range.                                          */
  670. /*                                                                           */
  671. /*****************************************************************************/
  672.  
  673. #define NextName(p)      ((p)+*(USHORT*)(p)+6)
  674. #define MemberOffset(p)  (*  (ULONG*)( (p) + *(USHORT*)(p) + 2) )
  675. #define MemberValue(p)   (*  (ULONG*)( (p) + *(USHORT*)(p) + 2) )
  676.  
  677. ULONG QNameList( Trec *tp, int Request , int InstanceOrValue )
  678. {
  679.  char  *pname;
  680.  char  *pend;
  681.  ULONG  i;
  682.  int    Instance,Value;
  683.  
  684.  /****************************************************************************/
  685.  /*                                                                          */
  686.  /* - Find the desired instance of the name or offset.                       */
  687.  /*                                                                          */
  688.  /*        2          1      1                        4                      */
  689.  /*       ---------- ------ ------ -------- ---//--- ------------            */
  690.  /*      | namelist | 0x7F | flag | name   | name   | offset or  |           */
  691.  /* tp-->| length   |      |      | length |        | value      |           */
  692.  /*       ---------- ------ ------ -------- ---//--- ------------            */
  693.  /*      |                 |       ^                                         */
  694.  /*      |<----Trec------->|       |                                         */
  695.  /*                                |                                         */
  696.  /*            (initial) pname-----                                          */
  697.  /*                                                                          */
  698.  /****************************************************************************/
  699.  pname = (char*)tp + sizeof(Trec) + 1;
  700.  switch( Request )
  701.  {
  702.   case NAME:
  703.   case MEMBEROFFSET:
  704.  
  705.   Instance = InstanceOrValue;
  706.   for(i=0; i<Instance; i++,pname = NextName(pname) ){;}
  707.   if( Request == NAME )
  708.     return((ULONG)pname);
  709.   return( MemberOffset(pname) );
  710.  
  711.   case VALUEINDEX:
  712.   case VERIFYVALUE:
  713.   /****************************************************************************/
  714.   /*                                                                          */
  715.   /* - Find the instance that contains the value passed.                      */
  716.   /* - Return TRUE or FALSE if we're verifying that the value is in the list. */
  717.   /*   We do this because there is no value available to use as a return      */
  718.   /*   code that we can distinguish from a valid value.                       */
  719.   /* - Or, return the index that contains the value.                          */
  720.   /*                                                                          */
  721.   /****************************************************************************/
  722.   pend = (char*)tp + tp->RecLen + 2;
  723.  
  724.   Value = InstanceOrValue;
  725.   for ( i=0 , pname; pname<pend; pname=NextName(pname), i++)
  726.   {
  727.    if( MemberValue(pname) == Value )
  728.    {
  729.     if( Request == VERIFYVALUE )
  730.      return(TRUE);
  731.     return(i);
  732.    }
  733.   }
  734.  }
  735.  return(FALSE);
  736. }
  737. /*****************************************************************************/
  738. /* QtypeSize()                                                            813*/
  739. /*                                                                           */
  740. /* Description:                                                              */
  741. /*                                                                           */
  742. /*   Get the storage size for a typeno.                                      */
  743. /*                                                                           */
  744. /*      Primitive types as taken from the MSC object module format doc.      */
  745. /*                                                                           */
  746. /*      Types 0-511 are reserved. Types 0-255(high byte = 0) have meaning    */
  747. /*      according to the decoding of the following bits:                     */
  748. /*                                                                           */
  749. /*      xxxx xxxx x xx xxx xx                                                */
  750. /*      xxxx xxxx i md typ sz                                                */
  751. /*                                                                           */
  752. /*      i=0 ==> special type don't interpret md,typ,and sz.                  */
  753. /*      i=1 ==> interpret low order 7 bits as follows.                       */
  754. /*                                                                           */
  755. /*      md - Model                                                           */
  756. /*      00 - Direct                                                          */
  757. /*      01 - Near pointer                                                    */
  758. /*      10 - Far pointer                                                     */
  759. /*      11 - Huge pointer                                                    */
  760. /*                                                                           */
  761. /*      type - base type                                                     */
  762. /*      000  - signed                                                        */
  763. /*      001  - unsigned                                                      */
  764. /*      010  - real                                                          */
  765. /*      011  -                                                               */
  766. /*      100  -                                                               */
  767. /*      101  -                                                               */
  768. /*      110  -                                                               */
  769. /*      111  -                                                               */
  770. /*                                                                           */
  771. /*      sz   - size                                                          */
  772. /*      00   - 8-bit                                                         */
  773. /*      01   - 16-bit                                                        */
  774. /*      10   - 32-bit                                                        */
  775. /*      11   -                                                               */
  776. /*                                                                           */
  777. /* Parameters:                                                               */
  778. /*                                                                           */
  779. /*   mid        input - module id containing the typeno.                     */
  780. /*   typeno     input - primitive or complex typeno.                         */
  781. /*                                                                           */
  782. /* Return:                                                                   */
  783. /*                                                                           */
  784. /*   typesize           storage size for the type.                           */
  785. /*                                                                           */
  786. /* Assumptions:                                                              */
  787. /*                                                                           */
  788. /*   The mid contains the typeno.                                            */
  789. /*                                                                           */
  790. /*****************************************************************************/
  791. uint QtypeSize( uint mid, USHORT typeno )
  792. {
  793.  uint typesize=0;
  794.  Trec *p;
  795.  
  796. ReCycle:
  797.  /****************************************************************************/
  798.  /* Handle primitive types.                                                  */
  799.  /****************************************************************************/
  800.  if( typeno < 512 )
  801.  {
  802.   switch(typeno )
  803.   {
  804.     /*************************************************************************/
  805.     /* Primitive types.                                                      */
  806.     /*************************************************************************/
  807.     case TYPE_CHAR:
  808.     case TYPE_UCHAR:
  809.      return(sizeof(char));
  810.  
  811.     case TYPE_SHORT:
  812.     case TYPE_USHORT:
  813.      return(sizeof(short));
  814.  
  815.     case TYPE_LONG:
  816.     case TYPE_ULONG:
  817.      return(sizeof(long));
  818.  
  819.     case TYPE_FLOAT:
  820.      return(sizeof(float));
  821.  
  822.     case TYPE_DOUBLE:
  823.      return(sizeof(double));
  824.  
  825.     case TYPE_LDOUBLE:
  826.     {
  827.      MODULE *pModule = GetPtrToModule( mid, NULL );
  828.  
  829.      if( pModule->DbgFormatFlags.Syms == TYPE104_C600 )
  830.        return( 10 );
  831.      else
  832.        return( sizeof( long double ) );
  833.     }
  834.  
  835.     case TYPE_VOID:
  836.      return(0);
  837.  
  838.     /*************************************************************************/
  839.     /* Primitive 0:32 pointers and 16:16 pointers.                           */
  840.     /*************************************************************************/
  841.     case TYPE_PCHAR    :
  842.     case TYPE_PSHORT   :
  843.     case TYPE_PLONG    :
  844.     case TYPE_PUCHAR   :
  845.     case TYPE_PUSHORT  :
  846.     case TYPE_PULONG   :
  847.     case TYPE_PFLOAT   :
  848.     case TYPE_PDOUBLE  :
  849.     case TYPE_PLDOUBLE :
  850.     case TYPE_PVOID    :
  851.     case TYPE_FPCHAR   :
  852.     case TYPE_FPSHORT  :
  853.     case TYPE_FPLONG   :
  854.     case TYPE_FPUCHAR  :
  855.     case TYPE_FPUSHORT :
  856.     case TYPE_FPULONG  :
  857.     case TYPE_FPFLOAT  :
  858.     case TYPE_FPDOUBLE :
  859.     case TYPE_FPLDOUBLE:
  860.     case TYPE_FPVOID   :
  861.      return(4);
  862.  
  863.     /*************************************************************************/
  864.     /* 0:16 near pointers.                                                   */
  865.     /*************************************************************************/
  866.     case TYPE_N16PCHAR    :
  867.     case TYPE_N16PSHORT   :
  868.     case TYPE_N16PLONG    :
  869.     case TYPE_N16PUCHAR   :
  870.     case TYPE_N16PUSHORT  :
  871.     case TYPE_N16PULONG   :
  872.     case TYPE_N16PFLOAT   :
  873.     case TYPE_N16PDOUBLE  :
  874.     case TYPE_N16PLDOUBLE :
  875.     case TYPE_N16PVOID    :
  876.      return(2);
  877.  
  878.   }
  879.  }
  880.  
  881.  /****************************************************************************/
  882.  /* Handle complex types.                                                    */
  883.  /****************************************************************************/
  884. tryagain:                                                               /*912*/
  885.  p = QbasetypeRec(mid, typeno);
  886.  
  887.  if(p == NULL )                                                         /*828*/
  888.   return(0);/* size=0 */                                                /*828*/
  889.  
  890.  switch( p->RecType )
  891.  {
  892.   case T_BITFLD:
  893.    break;
  894.  
  895.   case T_TYPDEF:
  896.    typeno = ((TD_USERDEF*)p)->TypeIndex;
  897.    goto ReCycle;
  898.  
  899.   case T_PROC:
  900.    typesize = 16;
  901.    break;
  902.  
  903.   case T_ARRAY:
  904.    typesize = ((TD_ARRAY*)p)->ByteSize;
  905.    if( typesize == 0 )                                                  /*912*/
  906.    {                                                                    /*912*/
  907.     typeno = ((TD_ARRAY*)p)->ElemType;                                  /*912*/
  908.     goto tryagain;                                                      /*912*/
  909.    }                                                                    /*912*/
  910.    break;
  911.  
  912.   case T_STRUCT:
  913.    typesize = ((TD_STRUCT*)p)->ByteSize;
  914.    break;
  915.  
  916.   case T_CLASS:
  917.    typesize = ((TD_STRUCT*)p)->ByteSize;
  918.    break;
  919.  
  920.   case T_PTR:
  921.    switch(  ((TD_POINTER*)p)->Flags)
  922.    {
  923.     case PTR_0_32:
  924.     case PTR_16_16:
  925.      typesize = 4;
  926.      break;
  927.  
  928.     case PTR_0_16:
  929.      typesize = 2;
  930.      break;
  931.    }
  932.    break;
  933.  
  934.   case T_ENUM:
  935.    typesize = ((TD_ENUM*)p)->DataType;
  936.    break;
  937.  
  938.  }
  939.  return(typesize);
  940. }
  941.  
  942. /*****************************************************************************/
  943. /* HandleUserDefs()                                                       512*/
  944. /*                                                                           */
  945. /* Description:                                                              */
  946. /*   Returns the primitive typeno from the the userdef records.              */
  947. /*                                                                           */
  948. /* Parameters:                                                               */
  949. /*                                                                           */
  950. /*   Mid        input - module Id                                            */
  951. /*   TypeNo     input - type no                                              */
  952. /*                                                                           */
  953. /* Return:                                                                   */
  954. /*                                                                           */
  955. /*   TypeNo     returns the type number.                                     */
  956. /*                                                                           */
  957. /* Assumptions:                                                              */
  958. /*                                                                           */
  959. /*****************************************************************************/
  960. UINT HandleUserDefs(UINT Mid, UINT TypeNo)
  961. {
  962.  Trec   *tp;
  963.  USHORT  type;
  964.  
  965.  /**************************************************************************/
  966.  /* if the type number is primitive return.                                */
  967.  /**************************************************************************/
  968.  if (TypeNo < 512)
  969.    return(TypeNo);
  970.  
  971.  /**************************************************************************/
  972.  /* get the base type record for this type number. If it is a userdef      */
  973.  /* record and the type number is primitive return the primitive type      */
  974.  /* number or else return the inputed typeno.                              */
  975.  /**************************************************************************/
  976.  tp = QbasetypeRec(Mid, TypeNo);
  977.  if( tp )
  978.  {
  979.   if( tp->RecType == T_TYPDEF)
  980.   {
  981.    type = ((TD_USERDEF *)tp)->TypeIndex;
  982.    if (type < 512)
  983.     return((uint)type);
  984.   }
  985.   else if( tp->RecType == T_CLSDEF )
  986.   {
  987.    type = ((TD_CLSDEF *)tp)->TypeIndex;
  988.    return(type);
  989.   }
  990.  }
  991.  return(TypeNo);
  992. }
  993.  
  994. /*****************************************************************************/
  995. /* QTagName()                                                             813*/
  996. /*                                                                           */
  997. /* Description:                                                              */
  998. /*                                                                           */
  999. /*   Get the name of a complex type.                                         */
  1000. /*                                                                           */
  1001. /* Parameters:                                                               */
  1002. /*                                                                           */
  1003. /*   tp         input - -> to a name list record.                            */
  1004. /*                                                                           */
  1005. /* Return:                                                                   */
  1006. /*                                                                           */
  1007. /*   cp         -> to the length prefixed name.                              */
  1008. /*                                                                           */
  1009. /* Assumptions:                                                              */
  1010. /*                                                                           */
  1011. /*  tp != NULL                                                               */
  1012. /*                                                                           */
  1013. /*****************************************************************************/
  1014.  
  1015. char *QTagName( Trec *tp )
  1016. {
  1017.  char *cp = NULL;
  1018.  
  1019.  /****************************************************************************/
  1020.  /* Return a pointer to the length prefixed name of the tag/userdef.         */
  1021.  /****************************************************************************/
  1022.  switch(tp->RecType)
  1023.  {
  1024.   case T_TYPDEF:
  1025.   {
  1026.    TD_USERDEF* tpx = (TD_USERDEF*)tp;
  1027.  
  1028.    if(tpx->NameLen)
  1029.      cp = (char*)&tpx->NameLen;
  1030.   }
  1031.   break;
  1032.  
  1033.   case T_ARRAY:
  1034.   {
  1035.    TD_ARRAY* tpx = (TD_ARRAY*)tp;
  1036.  
  1037.    if(tpx->NameLen)
  1038.      cp = (char*)&tpx->NameLen;
  1039.   }
  1040.   break;
  1041.  
  1042.   case T_STRUCT:
  1043.   {
  1044.    TD_STRUCT* tpx = (TD_STRUCT*)tp;
  1045.  
  1046.    if(tpx->NameLen)
  1047.      cp = (char*)&tpx->NameLen;
  1048.   }
  1049.   break;
  1050.  
  1051.   case T_CLASS:
  1052.   {
  1053.    TD_CLASS* tpx = (TD_CLASS*)tp;
  1054.  
  1055.    if(tpx->NameLen)
  1056.      cp = (char*)&tpx->NameLen;
  1057.   }
  1058.   break;
  1059.  
  1060.   case T_PTR:
  1061.   {
  1062.    TD_POINTER* tpx = (TD_POINTER*)tp;
  1063.  
  1064.    if(tpx->NameLen)
  1065.      cp = (char*)&tpx->NameLen;
  1066.   }
  1067.   break;
  1068.  
  1069.   case T_ENUM:
  1070.   {
  1071.    TD_ENUM* tpx = (TD_ENUM*)tp;
  1072.  
  1073.    if(tpx->NameLen)
  1074.      cp = (char*)&tpx->NameLen;
  1075.   }
  1076.   break;
  1077.  }
  1078.  /****************************************************************************/
  1079.  /* If we don't find a tag/userdef name,then stuff in the "record" name.     */
  1080.  /****************************************************************************/
  1081.  if( !cp )
  1082.  {
  1083.   int   i;
  1084.  
  1085.   i =  bindex(RecTypes,sizeof(RecTypes),tp->RecType);
  1086.   cp = RecNames[i];
  1087.  }
  1088.  return(cp);
  1089. }
  1090.  
  1091. /*****************************************************************************/
  1092. /* QTypeNumber()                                                          813*/
  1093. /*                                                                           */
  1094. /* Description:                                                              */
  1095. /*                                                                           */
  1096. /*   Find the type number in a mid for a tag name or userdef.                */
  1097. /*                                                                           */
  1098. /* Parameters:                                                               */
  1099. /*                                                                           */
  1100. /*   mid        input  - the module we're searching in.                      */
  1101. /*   cp         input  - -> to the tag/userdef we're searching for.          */
  1102. /*                          (length prefixed.)                               */
  1103. /*   mid4type   output - if mid==0, this is the mid where the user defined   */
  1104. /*                       was found.                                          */
  1105. /*                                                                           */
  1106. /* Return:                                                                   */
  1107. /*                                                                           */
  1108. /*   typeno     the typeno or 0.                                             */
  1109. /*                                                                           */
  1110. /* Assumptions:                                                              */
  1111. /*                                                                           */
  1112. /*****************************************************************************/
  1113. USHORT QtypeNumber(UINT mid, UCHAR *cp, UINT *pmid4type)
  1114. {
  1115.  USHORT   typeno;
  1116.  USHORT   len;
  1117.  UINT     seglen;
  1118.  DEBFILE *pdf;
  1119.  Trec    *tp;
  1120.  Trec    *tpend;
  1121.  UCHAR   *ptag;
  1122.  UINT     mid4type;
  1123.  
  1124.  /****************************************************************************/
  1125.  /* - If the mid==0, then we're probably trying to format an absolute        */
  1126.  /*   address displayed in the data window.                                  */
  1127.  /****************************************************************************/
  1128.  if( mid == 0 )
  1129.  {
  1130.   typeno = QtypeNumberAndMid( cp, &mid4type );
  1131.  
  1132.   if( typeno )
  1133.    *pmid4type = mid4type;
  1134.  
  1135.   return( typeno );
  1136.  
  1137.  }
  1138.  
  1139.  /****************************************************************************/
  1140.  /* - Find the pdf containing the mid.                                       */
  1141.  /* - Get a pointer to the type segment.                                     */
  1142.  /* - Scan the type records looking for the tag/userdef.                     */
  1143.  /****************************************************************************/
  1144.  if( ( pdf = DBFindPdf(mid) ) &&
  1145.      ( tp  = (Trec *)DBTypSeg(mid, &seglen,pdf) ) &&
  1146.        seglen
  1147.    )
  1148.  {
  1149.   typeno = 512;
  1150.   tpend = (Trec*)( (UCHAR*)tp + seglen);
  1151.   for( ; (tp < tpend); ++typeno, tp = NextTrec(tp) )
  1152.   {
  1153.    if( ( ptag = QTagName(tp)) &&
  1154.        ( *(USHORT*)ptag == ( len = *(USHORT*)cp) ) &&
  1155.        ( strnicmp(cp+2,ptag+2,len) == 0 )
  1156.      )
  1157.     return(typeno);
  1158.   }
  1159.  }
  1160.  return(0);
  1161. }
  1162.  
  1163. /*****************************************************************************/
  1164. /* QTypeNumberAndMid()                                                       */
  1165. /*                                                                           */
  1166. /* Description:                                                              */
  1167. /*                                                                           */
  1168. /*   Find the type number and mid for a type name or userdef.                */
  1169. /*                                                                           */
  1170. /* Parameters:                                                               */
  1171. /*                                                                           */
  1172. /*   cp         -> the the type name string.                                 */
  1173. /*   midptr     -> to the receiver of the mid containing the type name.      */
  1174. /*                                                                           */
  1175. /* Return:                                                                   */
  1176. /*                                                                           */
  1177. /*   typeno     the typeno or 0.                                             */
  1178. /*                                                                           */
  1179. /* Assumptions:                                                              */
  1180. /*                                                                           */
  1181. /*****************************************************************************/
  1182. USHORT QtypeNumberAndMid( UCHAR *cp, UINT *midptr )
  1183. {
  1184.  USHORT   typeno;
  1185.  USHORT   len;
  1186.  UINT     seglen;
  1187.  DEBFILE *pdf;
  1188.  Trec    *tp;
  1189.  Trec    *tpend;
  1190.  UCHAR   *ptag;
  1191.  UINT     mid;
  1192.  AFILE   *fp;
  1193.  
  1194.  /****************************************************************************/
  1195.  /* Currenly, this function only gets called when the user is trying to      */
  1196.  /* format an area of memory displayed in the data window using an           */
  1197.  /* absolute address.  The address will usually be of the form               */
  1198.  /* 0xabcdef or 0xf:abcd.                                                    */
  1199.  /*                                                                          */
  1200.  /* - Get the view that is currently in focus.                               */
  1201.  /* - Get the executable containing the view.                                */
  1202.  /****************************************************************************/
  1203.  fp  = Getfp_focus();
  1204.  pdf = fp->pdf;
  1205.  
  1206.  /****************************************************************************/
  1207.  /* - Scan the modules linked into the executable looking for the            */
  1208.  /*   type name.                                                             */
  1209.  /****************************************************************************/
  1210.  for( mid = DBNextMod(0, pdf); mid != 0; mid = DBNextMod(mid, pdf) )
  1211.  {
  1212.   if( ( pdf = DBFindPdf(mid) ) &&
  1213.       ( tp  = (Trec *)DBTypSeg(mid, &seglen,pdf) ) &&
  1214.         seglen
  1215.     )
  1216.   {
  1217.    typeno = 512;
  1218.    tpend = (Trec*)( (UCHAR*)tp + seglen);
  1219.    for( ; (tp < tpend); ++typeno, tp = NextTrec(tp) )
  1220.    {
  1221.     if( ( ptag = QTagName(tp)) &&
  1222.         ( *(USHORT*)ptag == ( len = *(USHORT*)cp) ) &&
  1223.         ( strnicmp(cp+2,ptag+2,len) == 0 )
  1224.       )
  1225.     {
  1226.      /************************************************************************/
  1227.      /* - If we find the type name, then tell the caller which module        */
  1228.      /*   it was found in.                                                   */
  1229.      /************************************************************************/
  1230.      *midptr = mid;
  1231.      return(typeno);
  1232.     }
  1233.    }
  1234.   }
  1235.  }
  1236.  /****************************************************************************/
  1237.  /* - Type name was not found.                                               */
  1238.  /****************************************************************************/
  1239.  return(0);
  1240. }
  1241.  
  1242. /*****************************************************************************/
  1243. /* QClassItemList()                                                          */
  1244. /*                                                                           */
  1245. /* Description:                                                              */
  1246. /*                                                                           */
  1247. /*   Retrieve info for an item in a class member list.                       */
  1248. /*                                                                           */
  1249. /* Parameters:                                                               */
  1250. /*                                                                           */
  1251. /*   mid                                                                     */
  1252. /*   tp         -> to a class item list.                                     */
  1253. /*   Request    What kind of info.                                           */
  1254. /*   ItemNo     Which item in the list.                                      */
  1255. /*                                                                           */
  1256. /* Return:                                                                   */
  1257. /*                                                                           */
  1258. /*   RetVal                                                                  */
  1259. /*                                                                           */
  1260. /* Assumptions:                                                              */
  1261. /*                                                                           */
  1262. /*****************************************************************************/
  1263. ULONG QClassItemList( UINT mid, TD_TYPELIST *tp, int Request , int ItemNo )
  1264. {
  1265.  char   *pList;
  1266.  USHORT  typeno;
  1267.  Trec   *pTrec;
  1268.  ULONG   RetVal = 0;
  1269.  
  1270.  /****************************************************************************/
  1271.  /*                                                                          */
  1272.  /*        2          1      1     2        2        2                       */
  1273.  /*       ---------- ------ ------ -------- -------- -------- --//           */
  1274.  /*      | list     | 0x7F | flag | list   | list   | list   |               */
  1275.  /* tp-->| length   |      |      | item 1 | item 2 | item 3 |               */
  1276.  /*       ---------- ------ ------ -------- -------- -------- --//           */
  1277.  /*      |                 |                                                 */
  1278.  /*      |<----Trec------->|                                                 */
  1279.  /*                                                                          */
  1280.  /****************************************************************************/
  1281.  pList  = (char*)tp + sizeof(Trec) + 1;
  1282.  typeno = ((USHORT*)pList)[ItemNo];
  1283.  
  1284.  if(typeno == 0 )
  1285.   return(0);
  1286.  
  1287.  pTrec  = QtypeRec(mid, typeno);
  1288.  
  1289.  switch( pTrec->RecType )
  1290.  {
  1291.   case T_MEMFNC:
  1292.   {
  1293.    TD_MEMFNC *pMemFnc = (TD_MEMFNC *)pTrec;
  1294.  
  1295.    switch( Request )
  1296.    {
  1297.     case NAME:
  1298.     {
  1299.      RetVal = (ULONG)&(pMemFnc->NameLen);
  1300.     }
  1301.     break;
  1302.  
  1303.     case MEMBEROFFSET:
  1304.     {
  1305.      RetVal = 0;
  1306.     }
  1307.     break;
  1308.  
  1309.     case MEMBERTYPE:
  1310.     {
  1311.      RetVal = typeno;
  1312.     }
  1313.     break;
  1314.  
  1315.    }
  1316.   }
  1317.   break;
  1318.  
  1319.   case T_CLSMEM:
  1320.   {
  1321.    TD_CLSMEM *pClsMem = (TD_CLSMEM *)pTrec;
  1322.    char       StaticName[256];
  1323.    char       PublicName[256];
  1324.  
  1325.    switch( Request )
  1326.    {
  1327.     case NAME:
  1328.     {
  1329.      RetVal = (ULONG)&(pClsMem->NameLen);
  1330.     }
  1331.     break;
  1332.  
  1333.     case MEMBEROFFSET:
  1334.     {
  1335.      if( pClsMem->TypeQual & CLSMEM_STATIC )
  1336.      {
  1337.       /***********************************************************************/
  1338.       /* - for static entries try:                                           */
  1339.       /*                                                                     */
  1340.       /*    - looking in symbols for static mangled name.                    */
  1341.       /*    - looking in publics for static unmangled name.                  */
  1342.       /*    - looking in symbols for static unmangled name.                  */
  1343.       /*                                                                     */
  1344.       /***********************************************************************/
  1345.       int len;
  1346.  
  1347.       len = pClsMem->NameLen + sizeof(pClsMem->NameLen);
  1348.  
  1349.       memset( StaticName, 0, sizeof(StaticName) );
  1350.       memcpy( StaticName, &(pClsMem->NameLen), len );
  1351.       RetVal = findsvar(mid, StaticName);
  1352.  
  1353.  
  1354.       if( RetVal == 0 )
  1355.       {
  1356.        char *cp;
  1357.  
  1358.        /**********************************************************************/
  1359.        /* - save the static name...we might need to search publics.          */
  1360.        /**********************************************************************/
  1361.        memset( PublicName, 0, sizeof(PublicName) );
  1362.        memcpy( PublicName, StaticName, len );
  1363.  
  1364.        cp  = ((char*)&(pClsMem->Name)) + pClsMem->NameLen;
  1365.        len = *(USHORT*)cp + sizeof(pClsMem->NameLen);
  1366.  
  1367.        memset(StaticName, 0, sizeof(StaticName) );
  1368.        memcpy(StaticName, cp, len );
  1369.        RetVal = findsvar(mid, StaticName);
  1370.       }
  1371.  
  1372.       if( RetVal == 0 )
  1373.       {
  1374.        DEBFILE *pdf;
  1375.  
  1376.        pdf=DBFindPdf(mid);
  1377.        if( pdf != NULL )
  1378.        {
  1379.         RetVal = DBPub(PublicName+2, pdf);
  1380.        }
  1381.       }
  1382.      }
  1383.      else
  1384.       RetVal = pClsMem->Offset;
  1385.     }
  1386.     break;
  1387.  
  1388.     case MEMBERTYPE:
  1389.     {
  1390.      RetVal = pClsMem->TypeIndex;
  1391.     }
  1392.     break;
  1393.  
  1394.    }
  1395.   }
  1396.   break;
  1397.  
  1398.   case T_BSECLS:
  1399.   {
  1400.    TD_BSECLS *pBseCls = (TD_BSECLS*)pTrec;
  1401.    TD_CLASS  *pClass;
  1402.  
  1403.    switch( Request )
  1404.    {
  1405.     case NAME:
  1406.     {
  1407.      typeno  = pBseCls->TypeIndex;
  1408.      pClass  = (TD_CLASS*)QtypeRec(mid, typeno);
  1409.      RetVal  = (ULONG)&(pClass->NameLen);
  1410.     }
  1411.     break;
  1412.  
  1413.     case MEMBEROFFSET:
  1414.     {
  1415.      RetVal = pBseCls->Offset;
  1416.     }
  1417.     break;
  1418.  
  1419.     case MEMBERTYPE:
  1420.     {
  1421.      RetVal = pBseCls->TypeIndex;
  1422.     }
  1423.     break;
  1424.    }
  1425.   }
  1426.   break;
  1427.  
  1428.   case T_CLSDEF:
  1429.   {
  1430.    TD_CLSDEF *pClsDef = (TD_CLSDEF*)pTrec;
  1431.  
  1432.    switch( Request )
  1433.    {
  1434.     case NAME:
  1435.     {
  1436.      typeno = pClsDef->TypeIndex;
  1437.      RetVal = (ULONG)QtypeName(mid, typeno);
  1438.     }
  1439.     break;
  1440.  
  1441.     case MEMBEROFFSET:
  1442.     {
  1443.      RetVal = 0;
  1444.     }
  1445.     break;
  1446.  
  1447.     case MEMBERTYPE:
  1448.     {
  1449.      RetVal = pClsDef->TypeIndex;
  1450.     }
  1451.     break;
  1452.    }
  1453.   }
  1454.   break;
  1455.  
  1456.   case T_FRIEND:
  1457.   {
  1458.    TD_FRIEND *pFriend;
  1459.  
  1460.    pFriend = (TD_FRIEND *)pTrec;
  1461.  
  1462.    switch( Request )
  1463.    {
  1464.     case NAME:
  1465.     {
  1466.      if( pFriend->TypeQual & FRIEND_CLASS )
  1467.      {
  1468.       /***********************************************************************/
  1469.       /* - should only come here if friend class.                            */
  1470.       /***********************************************************************/
  1471.       TD_CLASS  *pClass;
  1472.  
  1473.       typeno = pFriend->TypeIndex;
  1474.       pClass = (TD_CLASS*)QtypeRec(mid, typeno);
  1475.       RetVal = (ULONG)&(pClass->NameLen);
  1476.      }
  1477.      else
  1478.       RetVal = (ULONG)&(pFriend->NameLen);
  1479.     }
  1480.     break;
  1481.  
  1482.     case MEMBEROFFSET:
  1483.     {
  1484.      RetVal = 0;
  1485.     }
  1486.     break;
  1487.  
  1488.     case MEMBERTYPE:
  1489.     {
  1490.      RetVal = pFriend->TypeIndex;
  1491.     }
  1492.     break;
  1493.  
  1494.    }
  1495.   }
  1496.   break;
  1497.  }
  1498.  return(RetVal);
  1499. }
  1500.