home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winui / shell / fparser / vs_asc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-25  |  4.4 KB  |  224 lines

  1. #include "vsp_asc.h"
  2. #include "vsctop.h"
  3. #include "vs_asc.pro"
  4.  
  5. #define EOF (-1)
  6.  
  7. /************************** ROUTINES *****************************************/
  8.  
  9. /******************************************************************************
  10. *                ASC_INIT                      *
  11. *    Initialize the data union data structure                   *
  12. ******************************************************************************/
  13. VW_ENTRYSC  SHORT  VW_ENTRYMOD    VwStreamOpenFunc (fp, FileId, FileName, FilterInfo, hProc)
  14. SOFILE    fp;
  15. SHORT    FileId;
  16. BYTE VWPTR    *FileName;
  17. SOFILTERINFO    VWPTR    *FilterInfo;
  18. HPROC    hProc;
  19. {
  20.     char    chread[10];
  21.     SHORT    ch;
  22.     SHORT    chCount;
  23.     SHORT    done;
  24.     SHORT    locText;
  25.  
  26.     if ( FilterInfo != NULL )
  27.     {
  28.         FilterInfo->wFilterCharSet = SO_PC;
  29.         strcpy ( FilterInfo->szFilterName, VwStreamIdName[0].FileDescription );
  30.     }
  31.  
  32.     Proc.AscSave.SeekSpot = 0L;
  33.     Proc.AscSave.lastchar = 0;
  34.     Proc.bFileIsText = FALSE;
  35.  
  36.     Proc.hFile = _lopen ( (LPCSTR) FileName, OF_READ | OF_SHARE_DENY_WRITE );
  37.     if (Proc.hFile == HFILE_ERROR)
  38.         return -1;
  39.  
  40.     _llseek (Proc.hFile, 0L, 0);
  41.  
  42.     chCount    = 0;
  43.     done        = FALSE;
  44.     locText    = TRUE;
  45.  
  46.     do {
  47.         if (chCount >= 512)
  48.             break;
  49.  
  50.         if (0==_lread (Proc.hFile, chread, 1) )
  51.             ch=EOF;
  52.         else
  53.             ch=chread[0];
  54.  
  55.         chCount ++;
  56.         switch (ch)
  57.             {
  58.             case EOF:
  59.                 done=TRUE;
  60.                 break;
  61.  
  62.             case 0x0d:        // CR
  63.             case 0x08:        // Backspace
  64.             case 0x0a:        // NL
  65.             case 0x09:        // TAB
  66.             case 0x0c:        // NEW PAGE
  67.             case 0x1a:       // ASCII EOF
  68.             case 0x00:        // NULL
  69.             case 0xc6:        // 850 - a tilde
  70.             case 0xc7:         // 850 - A tilde
  71.                 break;
  72.  
  73.             default:
  74.                 if ( (ch>=0x20) && (ch<=0x7F) )
  75.                     break;
  76.                 if ( ch >= 0x80 && ch <= 0xA5 )
  77.                     break;
  78.                 if ( ch >= 0xD0 && ch <= 0xD8 )
  79.                     break;
  80.                 if ( ch >= 0xE0 && ch <= 0xEF )
  81.                     break;
  82.                 if ( ch >= 0xB5 && ch <= 0xB7 )
  83.                     break;
  84.                 locText = FALSE;
  85.                 done = TRUE;
  86.             }
  87.  
  88.         }while (done == FALSE);
  89.  
  90.     if (locText)
  91.         Proc.bFileIsText = TRUE;
  92.  
  93.     _llseek (Proc.hFile, 0L, 0);
  94.  
  95.     return ( 0 );
  96. }
  97.  
  98. VW_ENTRYSC VOID VW_ENTRYMOD VwStreamCloseFunc(SOFILE hFile, HPROC hProc)
  99. {
  100.     _lclose ( Proc.hFile );
  101. }
  102.  
  103. VW_ENTRYSC SHORT VW_ENTRYMOD VwStreamSeekFunc(hFile,hProc)
  104. SOFILE    hFile;
  105. HPROC    hProc;
  106. {
  107.     return((SHORT)_llseek(Proc.hFile,Proc.VwStreamSaveName.SeekSpot,0));
  108. }
  109.  
  110. VW_ENTRYSC SHORT VW_ENTRYMOD VwStreamTellFunc(hFile,hProc)
  111. SOFILE    hFile;
  112. HPROC    hProc;
  113. {
  114.     Proc.VwStreamSaveName.SeekSpot = _llseek(Proc.hFile,0L, 1);
  115.     return(0);
  116. }
  117.  
  118. /******************************************************************************
  119. *                ASC_SECTION_FUNC                  *
  120. ******************************************************************************/
  121. VW_ENTRYSC  SHORT  VW_ENTRYMOD    VwStreamSectionFunc (fp, hProc)
  122. SOFILE    fp;
  123. HPROC    hProc;
  124. {
  125.     SOPutSectionType ( SO_PARAGRAPHS, hProc );
  126.     return(0);
  127. }
  128.  
  129. VW_ENTRYSC  SHORT  VW_ENTRYMOD    VwStreamReadFunc (fp, hProc)
  130. SOFILE    fp;
  131. HPROC    hProc;
  132. {
  133.     SHORT    ch;
  134.     char  chread[10];
  135.     SHORT    chCount;
  136.     SHORT    chTabs;
  137.     SHORT    type, done;
  138.  
  139.     type = SO_PARABREAK;
  140.  
  141.     do {
  142.         chCount    = 0;
  143.         chTabs    = 0;
  144.         done        = FALSE;
  145.  
  146.         do {
  147.             if (0==_lread (Proc.hFile, chread, 1) )
  148.                 ch=EOF;
  149.             else
  150.                 ch=chread[0];
  151.  
  152.             if ((ch >= 0x20) && (ch <= 0x7e))
  153.                 {
  154.                 chCount++;
  155.                 SOPutChar ( ch, hProc );
  156.                 }
  157.             else if (ch == 0x09)
  158.                 {
  159.                 chCount++;
  160.                 chTabs++;
  161.                 SOPutSpecialCharX ( SO_CHTAB, SO_COUNT, hProc );
  162.                 }
  163.             else if (ch == 0x0c)
  164.                 {
  165.                 chCount++;
  166.                 SOPutSpecialCharX ( SO_CHHPAGE, SO_COUNT, hProc );
  167.                 }
  168.             else if (ch == EOF)
  169.                 {
  170.                 type = SO_EOFBREAK;
  171.                 done = TRUE;
  172.                 }
  173.             else if (ch == 0x0a)
  174.                 {
  175.                 if (Proc.AscSave.lastchar != 0x0d)
  176.                     {
  177.                     done = TRUE;
  178.                     }
  179.                 else
  180.                     {
  181.                     ch = 0x00;
  182.                     }
  183.                 }
  184.             else if (ch == 0x0d)
  185.                 {
  186.                 if (Proc.AscSave.lastchar != 0x0a)
  187.                     {
  188.                     done = TRUE;
  189.                     }
  190.                 else
  191.                     {
  192.                     ch = 0x00;
  193.                     }
  194.                 }
  195.             else if (Proc.bFileIsText)
  196.                 {
  197.                 // Put out logical extended TEXT characters ...
  198.                 if ( ( ch >= 0x80 && ch <= 0xA5 ) ||
  199.                       ( ch >= 0xD0 && ch <= 0xD8 ) ||
  200.                       ( ch >= 0xB5 && ch <= 0xB7 ) ||
  201.                       ( ch == 0xC6) ||
  202.                       ( ch == 0xC7) ||
  203.                       ( ch >= 0xE0 && ch <= 0xEF ) )
  204.  
  205.                     {
  206.                     chCount++;
  207.                     SOPutChar ( ch, hProc );
  208.                     }
  209.                 }
  210.  
  211.             if (chCount > 2048 || chTabs > 10)
  212.                 done = TRUE;
  213.  
  214.             Proc.AscSave.lastchar = ch;
  215.  
  216.             } while ( !done );
  217.  
  218.         } while ( SOPutBreak (type, (LONG) NULL, hProc) != SO_STOP );
  219.  
  220.     return ( 0 );
  221.  
  222. }  /** end of file **/
  223.  
  224.