]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/source-file.hh
*** empty log message ***
[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--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #ifndef SOURCE_FILE_HH
10 #define SOURCE_FILE_HH
11
12 #include "std-string.hh"
13
14 #include <iostream>
15 using namespace std;
16
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 (std::string fn);
32   Source_file (std::string, std::string);
33
34   virtual ~Source_file ();
35
36   char const *c_str () const;
37   virtual std::string quote_input (char const *pos_str0) const;
38   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   std::string name_string () const;
43   std::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   std::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   std::string line_string (char const *pos_str0) const;
57   void get_counts (char const *pos_str0, int *, int *, int *) const;
58
59   /*
60     JUNKME.
61
62     This thing doubles as a file-storage/file-iterator object.
63   */
64   char const *pos_str0_;
65
66   SCM get_port () const;
67   std::string name_;
68
69 private:
70   Link_array<char> newline_locations_;
71   istream *istream_;
72   char *contents_str0_;
73   int length_;
74   void load_stdin ();
75   void init_port ();
76
77   Protected_scm str_port_;
78 };
79
80 char *gulp_file (std::string fn, int *len);
81
82 #endif /* SOURCE_FILE_HH */
83