home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_DEV08B.LHA / gerlib / libg++ / gperf / src / read-line.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  1.8 KB  |  69 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. #ifndef read_line_h
  28. #define read_line_h 1
  29.  
  30. #include <stdio.h>
  31. #include "trace.h"
  32.  
  33. class Read_Line
  34. {
  35. private:
  36.   char *readln_aux (int chunks);
  37.   FILE *fp;                       /* FILE pointer to the input stream. */
  38.   const int CHUNK_SIZE;               /* Size of each chunk. */
  39.  
  40. public:
  41.         Read_Line (FILE *stream = stdin, int size = BUFSIZ): 
  42.           fp (stream), CHUNK_SIZE (size) {;}
  43.   char *get_line (void);
  44. };
  45.  
  46. #ifdef __OPTIMIZE__
  47. inline char *
  48. Read_Line::get_line (void) 
  49. {
  50.   T (Trace t ("Read_Line::get_line");)
  51.   int c;
  52.  
  53.   if ((c = getc (fp)) == '#')
  54.     {
  55.       while (getc (fp) != '\n')
  56.         ;
  57.  
  58.       return get_line ();
  59.     }
  60.   else
  61.     {
  62.       ungetc (c, stdin);
  63.       return readln_aux (0);
  64.     }
  65. }
  66. #endif
  67.  
  68. #endif
  69.