home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / packer / lharc / sources / lhio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  1.4 KB  |  65 lines

  1. /*----------------------------------------------------------------------*/
  2. /*        File I/O module for LHarc UNIX                */
  3. /*                                    */
  4. /*        Copyright(C) MCMLXXXIX  Yooichi.Tagawa            */
  5. /*                                    */
  6. /*  V0.00  Original                1989.06.25  Y.Tagawa    */
  7. /*  V0.03  Release #3  Beta Version        1989.07.02  Y.Tagawa    */
  8. /*----------------------------------------------------------------------*/
  9.  
  10. extern int        text_mode;
  11.  
  12. extern unsigned int    crc_table[0x100];
  13. extern unsigned int    crc_value;
  14. extern int        crc_getc_cashe;
  15. extern FILE        *crc_infile, *crc_outfile;
  16. extern long        crc_size;
  17.  
  18.  
  19. #define CRC_CHAR(c)                        \
  20. { register unsigned int ctmp = crc_value ^ c;             \
  21.     crc_value = (ctmp >> 8) ^ crc_table [ ctmp & 0xff ]; }
  22.  
  23.  
  24.  
  25. #if defined (__GNUC__)
  26. /*#define inlnie*/
  27.  
  28. /* DECODING */
  29. /* '0D0A' -> '0A' conversion and strip '1A' when text_mode */
  30. static inline putc_crc (int c)
  31. {
  32.   CRC_CHAR (c);
  33.   if (!text_mode || (c != 0x0d && c != 0x1a))
  34.     {
  35.       putc (c, crc_outfile);
  36.     }
  37. }
  38.  
  39. /* ENCODING */
  40. /* '0A' -> '0D0A' conversion when text_mode */
  41. static inline int getc_crc ()
  42. {
  43.   int    c;
  44.  
  45.   if (crc_getc_cashe != EOF)
  46.     {
  47.       c = crc_getc_cashe;
  48.       crc_getc_cashe = EOF;
  49.       CRC_CHAR (c);
  50.       crc_size++;
  51.     }
  52.   else if ((c = getc (crc_infile)) != EOF)
  53.     {
  54.       if (text_mode && c == 0x0a)
  55.     {
  56.       crc_getc_cashe = c;
  57.       c = 0x0d;
  58.     }
  59.       CRC_CHAR (c);
  60.       crc_size++;
  61.     }
  62.   return c;
  63. }
  64. #endif
  65.