home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / SHOWD2.C < prev    next >
Text File  |  1994-02-16  |  27KB  |  394 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   showd2.c                                                                */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*  data display routines.                                                   */
  8. /*                                                                           */
  9. /*                                                                           */
  10. /* History:                                                                  */
  11. /*                                                                           */
  12. /*   02/08/91 Creation of 32-bit SD86, from 16-bit version.                  */
  13. /*                                                                           */
  14. /*...16->32 port.                                                            */
  15. /*...                                                                        */
  16. /*... 02/08/91  100   Philip    port to 32 bit.                              */
  17. /*... 02/08/91  101   Joe       port to 32 bit.                              */
  18. /*... 02/08/91  102   Pratima   port to 32 bit.                              */
  19. /*... 02/08/91  103   Dave      port to 32 bit.                              */
  20. /*... 02/08/91  104                                                          */
  21. /*... 02/08/91  105   Christina port to 32 bit.                              */
  22. /*... 02/08/91  106   Srinivas  port to 32 bit.                              */
  23. /*... 02/08/91  107   Dave      port to 32 bit.                              */
  24. /*... 02/08/91  108   Dave      port to 32 bit.                              */
  25. /*... 02/08/91  109                                                          */
  26. /*... 02/08/91  110   Srinivas  port to 32 bit.                              */
  27. /*... 02/08/91  111   Christina port to 32 bit.                              */
  28. /*... 02/08/91  112   Joe       port to 32 bit.                              */
  29. /*... 02/08/91  113                                                          */
  30. /*... 02/08/91  114                                                          */
  31. /*... 02/08/91  115   Srinivas  port to 32 bit.                              */
  32. /*... 02/08/91  116   Joe       port to 32 bit.                              */
  33. /*                                                                           */
  34. /*...Release 1.00 (Pre-release 1)                                            */
  35. /*...                                                                        */
  36. /*... 08/06/91  221   srinivas  Users app being started in back ground       */
  37. /*... 08/14/91  215   Christina   also adding support HLL format             */
  38. /*...                                                                        */
  39. /*...Release 1.00 (Pre-release 108 12/05/91)                                 */
  40. /*...                                                                        */
  41. /*... 02/12/92  521   Srinivas  Port to C-Set/2.                             */
  42. /*... 02/13/92  529   Srinivas  Truncate big member names of structures in   */
  43. /*...                           data window.                                 */
  44. /*...Release 1.02 (10/22/92)                                                 */
  45. /*...                                                                        */
  46. /*... 03/03/93  813   Joe       Revised types handling for HL03.             */
  47. /*... 12/20/93  912   Joe       Integer divide by zero trap on 0 len arrays. */
  48. /*... 02/16/94  915   Joe       Fix for not editing UCHAR and CHAR arrays.   */
  49. /**Includes*******************************************************************/
  50.  
  51. #include "all.h"                        /* SD86 include files                */
  52.  
  53. /**Defines *******************************************************************/
  54.  
  55. #define TAB1 15                         /* first tab pos for data display    */
  56. #define TAB2 27                         /* second tab pos for data display   */
  57.  
  58. /**External declararions******************************************************/
  59.  
  60. extern uint       ExprAddr;             /* Address value of expr          101*/
  61.                                         /* ( Set by ParseExpr )              */
  62.  
  63. /*****************************************************************************/
  64. /* ShowStruct()                                                              */
  65. /*                                                                           */
  66. /* Description:                                                              */
  67. /*   Show a data structure.                                                  */
  68. /*                                                                           */
  69. /* Parameters:                                                               */
  70. /*   dfp       input - pointer to dfile node.                                */
  71. /*   row       input - where to start the display.                           */
  72. /*   rows      input - rows available for display.                           */
  73. /*   skip      input - # of logical records to skip.                         */
  74. /*                                                                           */
  75. /* Return:                                                                   */
  76. /*   TRUE                                                                    */
  77. /*   FALSE                                                                   */
  78. /*                                                                           */
  79. /*****************************************************************************/
  80. uint                                    /*                                521*/
  81. ShowStruct(DFILE *dfp,uint row,uint rows,uint skip)
  82.                                         /* -> dfile node containing stucture.*/
  83.                                         /* screen row.                       */
  84.                                         /* rows available for display.       */
  85.                                         /* # of logical data recs to skip.   */
  86. {                                       /*                                   */
  87.  uint   item;                           /*                                   */
  88.  uint   rr;                             /*                                   */
  89.  uint   n;                              /*                                   */
  90.  TD_STRUCT   *tp;                       /*                                813*/
  91.  TD_TYPELIST *typelist;                 /*                                813*/
  92.  Trec  *namelist;                       /*                                   */
  93.  uint   Nitems;                         /*                                   */
  94.  uint   mid;                            /*                                   */
  95.  uint   sfx;                            /*                                   */
  96.  uchar *cp;                             /*                                   */
  97.  uint   baseaddr;                       /*                                112*/
  98.  uchar  buffer[2*DATALINESPAN];         /*                                   */
  99.  uint   memberoffs;                     /* offset of member within structure.*/
  100.  uint   membertype;                     /* type of the structure member.     */
  101.  USHORT MaxLen;                         /* length of max structure name813529*/
  102.                                         /*                                   */
  103.  mid = dfp->mid;                        /*                                   */
  104.  sfx = dfp->sfx;                        /*                                   */
  105.  baseaddr = dfp->baseaddr;              /*                                   */
  106.  
  107. /*****************************************************************************/
  108. /* The first thing we want to do is get a pointer to the base type record.   */
  109. /* If the showtype is <= 512, indicating a primitive type, then we will      */
  110. /* get a back a NULL.                                                        */
  111. /*****************************************************************************/
  112.  tp = (TD_STRUCT*)QbasetypeRec(mid, dfp->showtype); /*                    813*/
  113.  if(!tp ||                              /* cutting through the typedefs.     */
  114.     tp->RecType != T_STRUCT             /*                                   */
  115.    )                                    /* cutting through the typedefs.     */
  116.   return(FALSE);
  117.  
  118. /*****************************************************************************/
  119. /* Now, we are going to get the number of structure members and quit if we   */
  120. /* were told to skip more than the number of structure members.              */
  121. /*****************************************************************************/
  122.  Nitems = tp->NumMembers;               /*                                813*/
  123.  if( Nitems <= skip )
  124.   return(FALSE);
  125.  
  126. /*****************************************************************************/
  127. /* Now, get pointers to the type list and the name list.                     */
  128. /*****************************************************************************/
  129.  typelist = (TD_TYPELIST*)QtypeRec(mid, tp->TypeListIndex);             /*813*/
  130.  namelist = QtypeRec(mid, tp->NameListIndex);                           /*813*/
  131.                                         /*                                   */
  132.  if( skip )                             /*                                   */
  133.      dfp = NULL;                        /*                                   */
  134.                                         /*                                   */
  135.  for( rr=0, item=skip+1;                /*                                813*/
  136.       (rr < rows) &&                    /*                                   */
  137.       (item <= Nitems);                 /*                                   */
  138.       ++rr, ++item                      /*                                   */
  139.     )                                   /*                                   */
  140.  {                                      /*                                   */
  141.   cp = (UCHAR *)QNameList(namelist,NAME,item-1);   /* find a member name. 813*/
  142.  
  143.   if(!cp)                               /* if there is no name then go home. */
  144.     break;                              /*                                   */
  145.                                         /*                                   */
  146.   InitDataBuffer( buffer,               /* initialize the data buffer, i.e.  */
  147.                   DATALINESPAN,         /* clear it, put expression name in  */
  148.                   dfp                   /* it, put attributes in it, and  .  */
  149.                 );                      /* and terminate it with \0.         */
  150.   dfp = NULL;                           /* kill dfp so we won't write the    */
  151.                                         /* expression name again.            */
  152.   MaxLen = *(USHORT*)cp;                /* length of structure name    813529*/
  153.   MaxLen =                              /* limit the length of the name   529*/
  154.   (MaxLen < (TAB2-2)) ? MaxLen : (TAB2-2);  /* till TAB2 position         529*/
  155.   n = sprintf( buffer + STGCOL+1,       /* put the member name in the buffer.*/
  156.               "%.*s: ",                 /*                                521*/
  157.               MaxLen,                   /*                                529*/
  158.               cp+sizeof(USHORT)         /*                                813*/
  159.             );                          /*                                   */
  160.                                         /*                                   */
  161.                                         /* compute the offset of this member */
  162.                                         /* within the data structure.        */
  163.   memberoffs = QNameList(namelist,MEMBEROFFSET,item-1);                 /*813*/
  164.  
  165.                                         /* find the type of this member.     */
  166.   membertype = typelist->TypeIndex[item-1];                          /*813112*/
  167.                                         /*                                   */
  168.                                         /*                                   */
  169.   *(buffer + STGCOL+1 + n) = ' ';       /* remove null inserted by buffmt    */
  170.                                         /*                                   */
  171.   if ( n <= TAB1 )  n = TAB1;           /* move to a tab position based      */
  172.   else  n = TAB2;                       /* on length of member name          */
  173.                                         /*                                   */
  174.                                         /*                                   */
  175.                                         /* now format this item in the buffer*/
  176.   FormatDataItem( buffer + STGCOL+1 + n,/*  starting position for the data.  */
  177.                   baseaddr + memberoffs,/*  address of the member to format. */
  178.                   mid,                  /*  mid containing the data.         */
  179.                   membertype,           /*  type of the member.              */
  180.                   sfx                   /*  stack frame index if there is one*/
  181.                 );                      /*                                   */
  182.                                         /*                                   */
  183.   buffer[ DATALINESPAN-1 ] = 0;         /* terminate the data buffer...again.*/
  184.   putrc( row + rr, 0, buffer );         /* now display the data line.        */
  185.  }                                      /*                                   */
  186.                                         /*                                   */
  187.  if( rr < rows )                        /* now clear the remaining rows.     */
  188.    ClrScr( row + rr,                    /*                                   */
  189.            row + rows - 1,              /*                                   */
  190.            vaStgExp                     /*                                   */
  191.          );                             /*                                   */
  192.  return( TRUE );                        /*                                   */
  193. }                                       /*                                   */
  194.  
  195. uint                                    /*                                521*/
  196. ZapStruct(DFILE *dfp,uint row,uint skip )
  197. {
  198.     TD_STRUCT *tp;                                                      /*813*/
  199.  
  200.     TD_TYPELIST *typelist;                                              /*813*/
  201.  
  202.     Trec *namelist;
  203.     uint itemtype, mid = dfp->mid, sfx = dfp->sfx;
  204.     uchar *cp, *baseaddr = (uchar*) ExprAddr;
  205.  
  206.     if( (tp = (TD_STRUCT*)QbasetypeRec(mid, dfp->showtype))
  207.      && (tp->RecType == T_STRUCT)
  208.      && (tp->NumMembers) > skip                                         /*813*/
  209.      && (typelist = (TD_TYPELIST*)QtypeRec(mid,tp->TypeListIndex))      /*813*/
  210.      && (namelist = QtypeRec(mid, tp->NameListIndex))                   /*813*/
  211.      && (cp = (UCHAR*)QNameList(namelist,NAME,skip))                    /*813*/
  212.      && (itemtype = typelist->TypeIndex[skip] )                         /*813*/
  213.      )
  214.     {
  215.      return( (* PickKeyer( mid, itemtype))
  216.             (mid, itemtype, sfx, row, *cp + 2,
  217.             baseaddr + QNameList(namelist,MEMBEROFFSET,skip)  ) );   /*813215*/
  218.     }
  219.     return( FALSE );
  220. }
  221.  
  222. /*****************************************************************************/
  223. /* ShowArray()                                                            112*/
  224. /*                                                                        112*/
  225. /* Description:                                                           112*/
  226. /*   Show a array.                                                        112*/
  227. /*                                                                        112*/
  228. /* Parameters:                                                            112*/
  229. /*   dfp       input - pointer to dfile node.                             112*/
  230. /*   row       input - where to start the display.                        112*/
  231. /*   rows      input - rows available for display.                        112*/
  232. /*   skip      input - # of logical records to skip.                      112*/
  233. /*                                                                        112*/
  234. /* Return:                                                                112*/
  235. /*   TRUE                                                                 112*/
  236. /*   FALSE                                                                112*/
  237. /*                                                                        112*/
  238. /*****************************************************************************/
  239. uint                                    /*                                521*/
  240. ShowArray( DFILE *dfp, uint row, uint rows, uint skip )                 /*112*/
  241. {                                                                       /**12*/
  242.  TD_ARRAY  *tp;                         /*                                813*/
  243.  uint   item;                           /* array item to display.         112*/
  244.  uint   rr;                             /*                                112*/
  245.  uint   n;                              /* gp integer.                    112*/
  246.  uint   Nitems;                         /* number of array items.         112*/
  247.  uint   atomtype;                       /* type of array items.           112*/
  248.  uint   atomsize;                       /* size of an array item.         112*/
  249.  uint   mid;                            /* module id for the array var.   112*/
  250.  uint   sfx;                            /* stack frame index if auto.     112*/
  251.  uint   baseaddr;                       /* user addr where array starts.  112*/
  252.  uchar  buffer[2*DATALINESPAN];         /* display buffer for array item. 112*/
  253.  uchar *cp;                             /* gp char ptr.                   112*/
  254.  uint   addr;                           /* gp address.                    112*/
  255.                                                                         /*112*/
  256.  mid = dfp->mid;                                                        /*112*/
  257.  sfx = dfp->sfx;                                                        /*112*/
  258.  baseaddr = dfp->baseaddr;                                              /*112*/
  259.                                                                         /*112*/
  260.  /****************************************************************************/
  261.  /* - get a ptr to the defining type record in $$type seg.                112*/
  262.  /* - get the atomic type of the array elements.                          112*/
  263.  /* - get the size of the atomic type.                                    112*/
  264.  /* - get the number of array items.                                      112*/
  265.  /* - handle any errors in the above steps by simply returning false.     112*/
  266.  /*                                                                       112*/
  267.  /****************************************************************************/
  268.  tp = (TD_ARRAY*)QbasetypeRec(mid, dfp->showtype);                   /*813112*/
  269.  if( ( tp == NULL ) || ( tp->RecType != T_ARRAY ) )                  /*813112*/
  270.   return( FALSE );                                                      /*112*/
  271.                                                                         /*112*/
  272.  atomtype = tp->ElemType;                                            /*813112*/
  273.  atomtype = HandleUserDefs(mid,atomtype);                               /*813*/
  274.                                                                         /*512*/
  275.  if( atomtype == 0 )                                                    /*112*/
  276.   return( FALSE );                                                      /*112*/
  277.                                                                         /*112*/
  278.  atomsize = QtypeSize(mid, atomtype);                                   /*112*/
  279.  if( atomsize == 0 )                                                    /*112*/
  280.   return( FALSE );                                                      /*112*/
  281.                                                                         /*112*/
  282.  Nitems = tp->ByteSize/atomsize;                                     /*813112*/
  283.  if( Nitems == 0 )                                                      /*912*/
  284.    Nitems = 1;                                                          /*912*/
  285.  if( Nitems <= skip )                                                   /*112*/
  286.   return( FALSE );                                                      /*112*/
  287.                                                                         /*112*/
  288.  /************************************************************************112*/
  289.  /* simply show character array bytes as a string.                        112*/
  290.  /************************************************************************112*/
  291.  if( atomtype == TYPE_CHAR || atomtype == TYPE_UCHAR )                  /*112*/
  292.  {                                                                      /*112*/
  293.   ShowHexBytes(dfp, row, rows, skip);                                   /*112*/
  294.   return( TRUE );                                                       /*112*/
  295.  }                                                                      /*112*/
  296.                                                                         /*112*/
  297.  /************************************************************************112*/
  298.  /* -we only want to associate the array name with the first element of   112*/
  299.  /*  the array. We set dfp == null after the first element, or before the 112*/
  300.  /*  first element if we have scrolled the array name off the screen.     112*/
  301.  /* -format each element.                                                 112*/
  302.  /* -display in int and hex format.                                       112*/
  303.  /* -truncate long lines.                                                 112*/
  304.  /*                                                                       112*/
  305.  /************************************************************************112*/
  306.  if( skip )                                                             /*112*/
  307.   dfp = NULL;                                                           /*112*/
  308.                                                                         /*112*/
  309.  for( rr=0, item=skip+1; (rr < rows) && (item <= Nitems); ++rr, ++item) /*112*/
  310.  {                                                                      /*112*/
  311.   InitDataBuffer( buffer, DATALINESPAN, dfp );                          /*112*/
  312.   dfp = NULL;                                                           /*112*/
  313.   n = sprintf( buffer + STGCOL+1, "[%02u] ", item-1 );                  /*521*/
  314.                                                                         /*112*/
  315.   *(buffer + STGCOL+1 + n) = ' ';                                       /*112*/
  316.                                                                         /*112*/
  317.   if ( n <= TAB1 )  n = TAB1;                                           /*112*/
  318.   else  n = TAB2;                                                       /*112*/
  319.                                                                         /*112*/
  320.                                                                         /*112*/
  321.   cp   = buffer + STGCOL + 1 + n;                                       /*112*/
  322.   addr = baseaddr+atomsize*(item-1);                                    /*112*/
  323.   FormatDataItem( cp , addr, mid, atomtype, sfx);                       /*112*/
  324.   buffer[ DATALINESPAN-1 ] = 0;                                         /*112*/
  325.   putrc( row + rr, 0, buffer );                                         /*112*/
  326.  }                                                                      /*112*/
  327.  if( rr < rows )                                                        /*112*/
  328.   ClrScr( row + rr, row + rows - 1, vaStgExp );                         /*112*/
  329.  return( TRUE );                                                        /*112*/
  330. }                                       /* end ShowArray().             /*112*/
  331.  
  332. uint                                    /*                                521*/
  333. ZapArray(DFILE *dfp,uint row,uint skip)
  334. {
  335.     TD_ARRAY *tp;                                                       /*813*/
  336.     uint  col;                          /* was register.                  112*/
  337.     uint Nitems, atomsize, mid = dfp->mid, sfx = dfp->sfx;
  338.     uint   atomtype;                                                    /*101*/
  339.     uchar  buffer[10], *baseaddr = (uchar*) ExprAddr;
  340.  
  341.     if( (tp = (TD_ARRAY*)QbasetypeRec(mid, dfp->showtype))
  342.      && (tp->RecType == T_ARRAY)
  343.      && (atomtype = tp->ElemType)                                       /*813*/
  344.      && (atomsize = QtypeSize(mid, atomtype))
  345.      && (Nitems   = tp->ByteSize / atomsize) > skip                     /*813*/
  346.      ){
  347.         /*****************************************************************915*/
  348.         /* At this point, tp could be pointing to a T_TYPEDEF record      915*/
  349.         /* that defines a primitive type. This is the case with UCHAR     915*/
  350.         /* and CHAR typedefs. So, we have to get the "true" atomtype.     915*/
  351.         /*****************************************************************915*/
  352.         atomtype = HandleUserDefs(mid,atomtype);                        /*915*/
  353.  
  354.         if( atomtype == TYPE_CHAR || atomtype == TYPE_UCHAR ){
  355.             if( Nitems <= (uint)16*skip )
  356.                 return( FALSE );
  357.             return( ZapHexBytes(dfp, row, skip) );
  358.         }
  359.         col = sprintf( buffer, "[%02u] ", skip );                       /*521*/
  360.         return( (* PickKeyer( mid, atomtype))
  361.             (mid, atomtype, sfx, row, col, baseaddr + atomsize * skip) );
  362.     }
  363.     return( FALSE );
  364. }
  365.  
  366.  
  367. /* Note: The order of "keyers" MUST match the TGROUP type */
  368.  
  369.  
  370. static UINTFUNC keyers[] =
  371. {
  372.  NULL,                                  /* TG_UNKNOWN                        */
  373.  (UINTFUNC)KeyScalar,                   /* TG_SCALAR                         */
  374.  (UINTFUNC)KeyPointer,                  /* TG_POINTER                        */
  375.  NULL,                                  /* TG_STRUCT                         */
  376.  NULL,                                  /* TG_ARRAY                          */
  377.  NULL,                                  /* TG_ENUM                           */
  378.  NULL                                   /* TG_BITFLD                         */
  379. };
  380.  
  381.  UINTFUNC
  382. PickKeyer( uint mid, uint tno )         /*                                101*/
  383. {
  384.     UINTFUNC f;
  385.  
  386.     return( (f = keyers[QtypeGroup(mid,tno)]) ? f : (UINTFUNC)FalseKeyer );
  387. }
  388.  
  389.  uint
  390. FalseKeyer( )
  391. {
  392.     return( FALSE );
  393. }
  394.