home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples1.exe / smc / infile.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.2 KB  |  138 lines

  1. /*****************************************************************************/
  2. #ifndef _INFILE_H_
  3. #define _INFILE_H_
  4. /*****************************************************************************/
  5.  
  6. struct infileState;
  7.  
  8. class  infile
  9. {
  10. public:
  11.  
  12.     bool            inputStreamInit(Compiler        comp,
  13.                                     const char    * filename,
  14.                                     bool            textMode);
  15.  
  16.     void            inputStreamInit(Compiler        comp,
  17.                                     QueuedFile      buff,
  18.                                     const char    * text);
  19.  
  20.     void            inputStreamDone();
  21.  
  22.     const   char *  inputSrcFileName()
  23.     {
  24.         return  inputFileName;
  25.     }
  26.  
  27.     void            inputSetFileName(const char *fname)
  28.     {
  29.         inputFileName = fname;
  30.     }
  31.  
  32. private:
  33.  
  34.     unsigned        inputStreamMore();
  35.  
  36.     Compiler        inputComp;
  37.  
  38.     const   char *  inputSrcText;
  39.     QueuedFile      inputSrcBuff;
  40.  
  41.     bool            inputFileText;
  42.     const char *    inputFileName;
  43.     bool            inputFileOver;
  44.  
  45.     size_t          inputBuffSize;
  46.     const BYTE *    inputBuffAddr;
  47. public:
  48.     const BYTE *    inputBuffNext;
  49. private:
  50.     const BYTE *    inputBuffLast;
  51.  
  52.     unsigned        inputFilePos;
  53.  
  54.     HANDLE          inputFile;
  55.  
  56. public:
  57.  
  58.     unsigned        inputStreamRdU1();
  59.     void            inputStreamUnU1();
  60.  
  61.     /* The following keep track of text lines */
  62.  
  63. private:
  64.  
  65.     unsigned        inputStreamLineNo;
  66.     const BYTE    * inputStreamLineBeg;
  67.  
  68. public:
  69.  
  70.     unsigned        inputStreamNxtLine()
  71.     {
  72.         inputStreamLineBeg = inputBuffNext - 1;
  73.  
  74.         return  ++inputStreamLineNo;
  75.     }
  76.  
  77.     unsigned        inputStreamNxtLine(const BYTE *pos)
  78.     {
  79.         inputStreamLineBeg = pos - 1;
  80.  
  81.         return  ++inputStreamLineNo;
  82.     }
  83.  
  84.     unsigned        inputStreamCurCol()
  85.     {
  86.         return  inputBuffNext - inputStreamLineBeg;
  87.     }
  88. };
  89.  
  90. /*****************************************************************************
  91.  *
  92.  *  The following captures the state of the input file so that input from it
  93.  *  can be suspended and restarted later.
  94.  */
  95.  
  96. struct infileState
  97. {
  98.     size_t          inpsvBuffSize;
  99.     const BYTE *    inpsvBuffAddr;
  100.     const BYTE *    inpsvBuffNext;
  101.     const BYTE *    inpsvBuffLast;
  102.  
  103.     const char *    inpsvFileName;
  104.  
  105.     bool            inpsvFileOver;
  106.     unsigned        inpsvFilePos;
  107.  
  108.     unsigned        inpsvStreamLineNo;
  109.     const BYTE *    inpsvStreamLineBeg;
  110. };
  111.  
  112. /*****************************************************************************/
  113.  
  114. inline
  115. unsigned            infile::inputStreamRdU1()
  116. {
  117. #if 0
  118.     return  (inputBuffNext >= inputBuffLast) ? inputStreamMore()
  119.                                              : *inputBuffNext++;
  120. #else
  121.     assert  (inputBuffNext <  inputBuffLast);
  122.     return  *inputBuffNext++;
  123. #endif
  124. }
  125.  
  126. inline
  127. void                infile::inputStreamUnU1()
  128. {
  129.     assert(inputBuffNext > inputBuffAddr);
  130.  
  131.     if  (!inputFileOver)
  132.         inputBuffNext--;
  133. }
  134.  
  135. /*****************************************************************************/
  136. #endif
  137. /*****************************************************************************/
  138.