]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/source-file.hh
* flower/include/std-string.hh:
[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 #include "std-vector.hh"
14 #include "lily-proto.hh"
15
16 #include <iostream>
17 using namespace std;
18
19 #include "protected-scm.hh"
20
21 /**
22    class for reading and mapping a file.
23
24    duplicates a lot of Data_file and Text_stream.
25    should look at including Data_file's functionality:
26    get_line (), get_word () here.
27 */
28
29 class Source_file
30 {
31 public:
32   Source_file (string fn);
33   Source_file (string, string);
34
35   virtual ~Source_file ();
36
37   char const *c_str () const;
38   virtual string quote_input (char const *pos_str0) const;
39   istream *get_istream ();
40   bool contains (char const *pos_str0) const;
41   int length () const;
42   virtual int get_line (char const *pos_str0) const;
43   string name_string () const;
44   string file_line_column_string (char const *str0) const;
45
46   // return start + n
47   char const *seek_str0 (int n);
48
49   int tell () const;
50   // return here + n bytes
51   char const *forward_str0 (int n);
52   char const *pos_str0 () { return pos_str0_; }
53   string get_string (int n);
54   void set_pos (char const *pos_str0);
55 public:
56   Slice line_slice (char const *pos_str0) const;
57   string line_string (char const *pos_str0) const;
58   void get_counts (char const *pos_str0, int *, int *, int *) 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;
68   string name_;
69
70 private:
71   vector<char*> newline_locations_;
72   istream *istream_;
73   char *contents_str0_;
74   vector<char> chs_;
75   int length_;
76   void load_stdin ();
77   void init_port ();
78
79   Protected_scm str_port_;
80 };
81
82 char *gulp_file (string fn, int *len);
83
84 #endif /* SOURCE_FILE_HH */
85