home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games / INFESPGAMES.mdf / os2 / ribble / support / fpgline.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-10  |  1.4 KB  |  80 lines

  1. //
  2. // Copyright (c)1993, 1994 J.R.Shannon and D.J.Neades
  3. // All rights reserved.
  4. //
  5.  
  6. #include <CSupport.h>
  7. #include <CAssert.h>
  8. #include <string.h>
  9. #include <fcntl.h>
  10. #include <io.h>
  11.  
  12. char* CSExport
  13. fpreadline(int _fd)
  14. {
  15.   static char* line;
  16.   static int len = 0;
  17.  
  18.   if (len == 0)
  19.     {
  20.       len = 64;
  21.       line = new char[len];
  22.       CAssert(line);
  23.     }
  24.  
  25.   *line = '\0';
  26.  
  27.   int eof = 0;
  28.  
  29.   for (int got = 0; !eof;)
  30.     {
  31.       char ch;
  32.       if (read(_fd, &ch, sizeof(ch)) == sizeof(ch))
  33.         {
  34.           if (ch == '\n')
  35.             {
  36.               line[got] = '\0';
  37.               break;
  38.             }
  39.           line[got++] = ch;
  40.           if (got >= len)
  41.             {
  42.               len <<= 1;
  43.               char* ext = new char[len];
  44.               memcpy(ext, line, got);
  45.               delete [] line;
  46.               line = ext;
  47.             }
  48.         }
  49.       else
  50.         eof = 1;
  51.     }
  52.   return !got && eof ? 0 : line;
  53. }
  54.  
  55. char* CSExport
  56. fpgetline(int _fd)
  57. {
  58.   char* line;
  59.   while ((line = fpreadline(_fd)) != 0)
  60.     {
  61.       char* a = line;
  62.       char* b = line;
  63.       while ((*a = *b) != 0)
  64.         {
  65.           if (*b == '#')
  66.             {
  67.               *a = '\0';
  68.               break;
  69.             }
  70.           a++;
  71.           b++;
  72.         }
  73.       if (*line)
  74.         break;
  75.     }
  76.   return line;
  77. }
  78.  
  79.  
  80.