home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gperf.lzh / GPERF / READ-LIN.H < prev    next >
C/C++ Source or Header  |  1993-07-30  |  2KB  |  66 lines

  1. /* This may look like C code, but it is really -*- C++ -*- */
  2.  
  3. /* Reads arbitrarily long string from input file, returning it as a dynamic buffer. 
  4.  
  5.    Copyright (C) 1989 Free Software Foundation, Inc.
  6.    written by Douglas C. Schmidt (schmidt@ics.uci.edu)
  7.  
  8. This file is part of GNU GPERF.
  9.  
  10. GNU GPERF is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 1, or (at your option)
  13. any later version.
  14.  
  15. GNU GPERF is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. GNU General Public License for more details.
  19.  
  20. You should have received a copy of the GNU General Public License
  21. along with GNU GPERF; see the file COPYING.  If not, write to
  22. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  23.  
  24. /* Returns a pointer to an arbitrary length string.  Returns NULL on error or EOF
  25.    The storage for the string is dynamically allocated by new. */
  26.  
  27. #pragma once
  28. #include <stdio.h>
  29. #include "trace.h"
  30.  
  31. class Read_Line
  32. {
  33. private:
  34.   char *readln_aux (int chunks);
  35.   FILE *fp;                       /* FILE pointer to the input stream. */
  36.   const int CHUNK_SIZE;               /* Size of each chunk. */
  37.  
  38. public:
  39.         Read_Line (FILE *stream = stdin, int size = BUFSIZ): 
  40.           fp (stream), CHUNK_SIZE (size) {;}
  41.   char *get_line (void);
  42. };
  43.  
  44. #ifdef __OPTIMIZE__
  45. inline char *
  46. Read_Line::get_line (void) 
  47. {
  48.   T (Trace t ("Read_Line::get_line");)
  49.   int c;
  50.  
  51.   if ((c = getc (fp)) == '#')
  52.     {
  53.       while (getc (fp) != '\n')
  54.         ;
  55.  
  56.       return get_line ();
  57.     }
  58.   else
  59.     {
  60.       ungetc (c, stdin);
  61.       return readln_aux (0);
  62.     }
  63. }
  64. #endif
  65.  
  66.