]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/source-file.hh
* lily/my-lily-lexer.cc (set_encoding): New method.
[lilypond.git] / lily / include / source-file.hh
1 /*   
2   source-file.hh -- declare Source_file
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #ifndef SOURCE_FILE_HH
10 #define SOURCE_FILE_HH
11
12 #include <iostream>
13
14 #include "flower-proto.hh"
15 #include "string.hh"
16 #include "interval.hh"
17 #include "protected-scm.hh"
18 #include "parray.hh"
19
20 /**
21   class for reading and mapping a file. 
22
23   duplicates a lot of Data_file and Text_stream.
24   should look at including Data_file's functionality:
25   get_line (), get_word () here.
26 */
27
28 class Source_file
29 {
30 public:
31   Source_file (String fn);
32   Source_file (String, String );
33
34   virtual ~Source_file ();
35
36   char const* to_str0 () const;
37   virtual String error_string (char const* pos_str0 ) const;
38   std::istream * get_istream ();
39   bool contains (char const* pos_str0 ) const;
40   int length () const;
41   virtual int get_line (char const* pos_str0 ) const;
42   String name_string () const;
43   String file_line_column_string (char const* str0 ) const;
44
45   // return start + n
46   char const* seek_str0 (int n);
47
48   int tell () const;
49   // return here + n bytes
50   char const* forward_str0 (int n);
51   char const* pos_str0 () { return pos_str0_; }
52   String get_string (int n);
53   void set_pos (char const * pos_str0);
54 public:
55   Slice line_slice (char const* pos_str0) const;
56   String line_string (char const* pos_str0) const;
57   int get_column (char const* pos_str0) const;
58   int get_char (char const* pos_str0) const;
59
60   /*
61     JUNKME.
62
63     This thing doubles as a file-storage/file-iterator object.
64    */
65   char const* pos_str0_;
66
67   SCM get_port () const { return str_port_; }
68   String name_;
69
70 private:
71   Link_array<char> newline_locations_; 
72   std::istream* istream_;
73   char  * contents_str0_;
74   int length_;
75   void load_stdin ();
76   void init_port ();
77   
78   Protected_scm str_port_;
79 };
80
81 char *gulp_file (String fn, int *len);
82
83 #endif /* SOURCE_FILE_HH */
84