home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / PAGEFP.C < prev    next >
Text File  |  1996-03-12  |  9KB  |  178 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   pagefp.c                                                                */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*   Recreates an AFILE block for the specified module.                      */
  7. /*                                                                           */
  8. /* Static Functions:                                                         */
  9. /*                                                                           */
  10. /* External Functions:                                                       */
  11. /*                                                                           */
  12. /*                                                                           */
  13. /* History:                                                                  */
  14. /*                                                                           */
  15. /*   02/08/91 Creation of 32-bit SD86, from 16-bit version.                  */
  16. /*                                                                           */
  17. /*...16->32 port.                                                            */
  18. /*...                                                                        */
  19. /*... 02/08/91  100   made changes for 32-bit compilation.                   */
  20. /*... 06/02/91  111   fix warnings                                           */
  21. /*...                                                                        */
  22. /*...Release 1.00 (Pre-release 1)                                            */
  23. /*...                                                                        */
  24. /*... 08/22/91  234   Joe       PL/X gives "varname" is incorrect message    */
  25. /*...                           when entering a parameter name in the data   */
  26. /*...                           window.  This happens when the cursor is on  */
  27. /*...                           an internal procedure definition statement   */
  28. /*...                           and you use F2 to get into the data window   */
  29. /*...                           and then type the name.                      */
  30. /*...                                                                        */
  31. /*...Release 1.00 (Pre-release 108 12/05/91)                                 */
  32. /*...                                                                        */
  33. /*... 02/21/92  521   Srinivas  Port to C-Set/2.                             */
  34. /**Includes*******************************************************************/
  35.                                         /*                                   */
  36. #define INCL_16                         /* 16-bit API                     100*/
  37. #include "all.h"                        /* SD86 include files                */
  38.  
  39.  
  40. extern uint      VideoRows;
  41.  
  42. /*****************************************************************************/
  43. /*                                                                           */
  44. /* synopsis     pagefp( mid, lno );                                          */
  45. /*                                                                           */
  46. /*              uint  mid;              (* module ID *)                      */
  47. /*              uint  lno;              (* required line number *)           */
  48. /*                                                                           */
  49. /* description  Recreates an AFILE block for the specified module.           */
  50. /*                                                                           */
  51. /*****************************************************************************/
  52.  void
  53. pagefp(AFILE *fp,uint lno)
  54. {
  55.     uchar *srcbuf;
  56.     SEL srcsel, offsel;                 /* changed to SEL                 100*/
  57.     ushort srcseglen;                   /* 2-byte value                   100*/
  58.     ushort *offtab;                     /* 2-byte values                  100*/
  59.     uint    Nlines, retry;
  60.     int       OffsetTableBufSize;       /* size alloc'd for offtab.       234*/
  61.     uint FirstLineInSrcBuf;             /* First "real" line # in srcbuf. 234*/
  62.     uint LastLineInSrcBuf;              /* Last  "real" line # in srcbuf. 234*/
  63.  
  64.     /* Just return if the line # is zero, or the line is already */
  65.     /* in the buffer, or the source is complete in the buffer. */
  66.     if( (lno == 0)
  67.      || ((lno > fp->Nbias) && (lno <= (fp->Nbias + fp->Nlines)))
  68.      || !(fp->flags & AF_HUGE)
  69.       ) return;
  70.  
  71.     if( lno > LINESBEFORE )
  72.         FirstLineInSrcBuf = lno - LINESBEFORE;
  73.     else
  74.         FirstLineInSrcBuf = 1;
  75.  
  76.     /* Get the table of (line number, segment offset) pairs,     */
  77.     /* and allocate new segments for the source and line offsets */
  78.     srcsel = offsel = 0;                /* clear SEL variables            100*/
  79.     retry = 0;
  80.     if( !DosAllocSeg(0,(PSEL)&srcsel,0) &&
  81.         !DosAllocSeg(20*1024,(PSEL)&offsel,0)  ){
  82.  
  83.         Retry:
  84.             LoadSource( fp->filename+1, (uchar *)Sel2Flat(srcsel),/* changed macro 100 111*/
  85.                        (ushort *)Sel2Flat(offsel),       /* ushort ptr    100*/
  86.                 FirstLineInSrcBuf - 1, &srcseglen, &Nlines, NULL );
  87.  
  88.         if( Nlines ){
  89.             if( ((lno + VideoRows) > (FirstLineInSrcBuf + Nlines)) && !retry ){
  90.                 if( lno > VideoRows )
  91.                     FirstLineInSrcBuf = lno - VideoRows;
  92.                 else
  93.                     FirstLineInSrcBuf = 1;
  94.                 retry = 1;
  95.                 goto Retry;
  96.             }
  97.             DosReallocSeg(srcseglen, srcsel);
  98.  
  99.             if( fp->offtab )
  100.                 Tfree(( void * ) fp->offtab);                            /*521*/
  101.  
  102.    /**************************************************************************/
  103.    /* Allocate the offtab[] buffer to hold Nlines + 1 offsets. We add the 234*/
  104.    /* so that we can make the offset table indices line up with the       234*/
  105.    /* source line numbers.                                                234*/
  106.    /**************************************************************************/
  107.    OffsetTableBufSize = (Nlines+1)*sizeof(ushort);                      /*234*/
  108.    offtab = (ushort*) Talloc(OffsetTableBufSize);                   /*521 234*/
  109.    memcpy(offtab + 1, (uchar*)Sel2Flat(offsel), Nlines*sizeof(ushort) );/*234*/
  110.    fp->offtab = offtab;                                                 /*234*/
  111.  
  112.             fp->Nlines = Nlines;
  113.  
  114.             if( fp->source )
  115.                 DosFreeSeg( Flat2Sel(fp->source) );/* convert to sel      100*/
  116.             fp->source = srcbuf = (uchar *)Sel2Flat(srcsel);/* changed ptr macro   100 111 */
  117.  
  118.             fp->Nbias  = FirstLineInSrcBuf - 1;
  119.  
  120.             /* Flag all text lines for which a (line #, offset) pair exists  */
  121.             /*****************************************************************/
  122.             /* Scan the line number table looking for line numbers that      */
  123.             /* are within the range of lines loaded in the source buffer.    */
  124.             /* Flag these lines as ok to set a breakpoint on.                */
  125.             /*****************************************************************/
  126.             LastLineInSrcBuf = FirstLineInSrcBuf + Nlines - 1;
  127.  
  128.             MarkLineBrksOK( fp->pdf, fp->mid, fp->sfi, srcbuf, offtab,
  129.                             FirstLineInSrcBuf, LastLineInSrcBuf);
  130.             MarkLineBRKs( fp );
  131.     }   }
  132.     if( offsel )
  133.         DosFreeSeg(offsel);
  134.     if( !Nlines && srcsel )
  135.         DosFreeSeg(srcsel);
  136. }
  137.  
  138. void MarkLineBrksOK( DEBFILE *pdf,
  139.                      ULONG    mid,
  140.                      int      sfi,
  141.                      UCHAR   *srcbuf,
  142.                      USHORT  *offtab,
  143.                      UINT     FirstLineInSrcBuf,
  144.                      UINT     LastLineInSrcBuf)
  145. {
  146.  int     NumEntries;
  147.  int     lno;
  148.  CSECT  *pCsect;
  149.  MODULE *pModule;
  150.  LNOTAB *pLnoTabEntry;
  151.  
  152.  pModule = GetPtrToModule( mid, pdf );
  153.  if( pModule == NULL )
  154.   return;
  155.  
  156.  for(pCsect = pModule->pCsects; pCsect != NULL; pCsect=pCsect->next )
  157.  {
  158.   NumEntries   = pCsect->NumEntries;
  159.   pLnoTabEntry = pCsect->pLnoTab;
  160.  
  161.   if( (pLnoTabEntry != NULL) && ( NumEntries > 0 ) )
  162.   {
  163.    for( ; NumEntries; pLnoTabEntry++, NumEntries-- )
  164.    {
  165.     if( pLnoTabEntry->sfi == sfi )
  166.     {
  167.      lno = pLnoTabEntry->lno;
  168.      if( lno >= FirstLineInSrcBuf && lno <= LastLineInSrcBuf )
  169.      {
  170.       lno = lno - FirstLineInSrcBuf + 1;
  171.       *(srcbuf + offtab[lno] - 1) |= LINE_OK;
  172.      }
  173.     }
  174.    }
  175.   }
  176.  }
  177. }
  178.