home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / LDSOURCE.C < prev    next >
Text File  |  1994-05-28  |  5KB  |  102 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   ldsource.c                                                              */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*   load source                                                             */
  7. /*                                                                           */
  8. /* Static Functions:                                                         */
  9. /*                                                                           */
  10. /* External Functions:                                                       */
  11. /*                                                                           */
  12. /*                                                                           */
  13. /* History:                                                                  */
  14. /*                                                                           */
  15. /*...16->32 port.                                                            */
  16. /*...                                                                        */
  17. /*... 02/08/91  100   Philip    port to 32 bit.                              */
  18. /*... 02/08/91  101   Joe       port to 32 bit.                              */
  19. /*... 02/08/91  111   Christina port to 32 bit.                              */
  20. /*...                                                                        */
  21. /*...Release 1.00 (After pre-release 1.08)                                   */
  22. /*...                                                                        */
  23. /*... 02/12/92  521   Joe       Port to C-Set/2.                             */
  24. /*...                                                                        */
  25. /**Includes*******************************************************************/
  26.  
  27. #define INCL_16                         /* 16-bit API                     100*/
  28. #include "all.h"                        /* SD86 include files                */
  29.  
  30. extern  ushort FRlength;                /*                                101*/
  31.  
  32. /* name         LoadSource -- Loads (part of) a source file.
  33.  *
  34.  * synopsis     LoadSource( filename, srcbuf, offbuf, skiplines,
  35.  *                  srclenptr, Nlinesptr, Tlinesptr );
  36.  *
  37.  *              uchar *filename;        Name of source file.
  38.  *              uchar *srcbuf;          Buffer for lines of source file.
  39.  *              uint  *offbuf;          Buffer for line offsets into srcbuf.
  40.  *              uint  skiplines;        # of lines to skip at start of file.
  41.  *              uint  *srclenptr;       Returns # bytes used from srcbuf.
  42.  *              uint  *Nlinesptr;       Returns # lines in srcbuf and offbuf.
  43.  *              uint  *Tlinesptr;       Returns # lines in file (optional).
  44.  *
  45.  * description  The specified file is opened, read into storage, and an array
  46.  *              of line offsets is constructed.  If the file can not be found
  47.  *              or read, or a source buffer can not be allocated, then an AFILE
  48.  *              block without source is returned.
  49.  *
  50.  * assumptions  1.  Each line of the file ends with 0x0D and 0x0A.
  51.  *              2.  0x1A immediately follows the last line of the file.
  52.  *              3.  The srcbuf starts at segment offset zero, and is 64K.
  53.  */
  54.  
  55. #define IOBUFLEN 0xFFF8
  56. #define LIMIT (ushort)(0-MAXCOLS-1)     /* This is only a 2-byte constant 100*/
  57.  
  58.  void
  59. LoadSource(uchar *filename,uchar *srcbuf,ushort *offbuf,uint skiplines,
  60.            ushort *srclenptr,uint *Nlinesptr,uint *Tlinesptr )
  61. {
  62.     SEL      selector = 0;              /*  initialized.                  521*/
  63.     uchar *buffer, *lp;
  64.     uint Nlines=0, Tlines=0;            /* was register.                  112*/
  65.  
  66.     if( !DosAllocSeg((USHORT)IOBUFLEN, (PSEL)&selector, 0) ){  /* 111 */
  67.         if( !FRopen(filename, buffer = (UCHAR *)Sel2Flat(selector),(USHORT)IOBUFLEN) )
  68.         {                                                           /*100 111*/
  69.             lp = FRread(buffer);
  70.             while( lp )
  71.             {
  72.              if( ++Nlines > skiplines )
  73.              {
  74.                  *srcbuf++ = 0;
  75.                  *offbuf++ = LoFlat(srcbuf); /* offsets are 2-bytes    100*/
  76.                  srcbuf += Encode(lp, srcbuf,
  77.                      ((FRlength > MAXCOLS) ? MAXCOLS : FRlength) );
  78.                  if( LoFlat(srcbuf) > LIMIT )
  79.                  {                             /* 2-byte limit         100*/
  80.                   if( Tlinesptr )
  81.                    for( Tlines = Nlines ; FRread(buffer) ; ++Tlines )
  82.                     {;}
  83.                   break;
  84.                  }
  85.              }
  86.              lp = FRread(buffer);
  87.             }
  88.             FRclose(buffer);
  89.             *srcbuf++ = 0;
  90.             if( Nlines >= skiplines )
  91.                 Nlines -= skiplines;
  92.             else
  93.                 Nlines = 0;
  94.         }
  95.         DosFreeSeg(selector);
  96.     }
  97.     *srclenptr = LoFlat(srcbuf);        /* length is 2-byte value         100*/
  98.     *Nlinesptr = Nlines;
  99.     if( Tlinesptr )
  100.         *Tlinesptr = (Tlines ? Tlines : (Nlines + skiplines));
  101. }
  102.