]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/source-file.hh
3c21e1df6eb49a600c0cd2f8ad26398b0a74f61d
[lilypond.git] / lily / include / source-file.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2014 Jan Nieuwenhuizen <janneke@gnu.org>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef SOURCE_FILE_HH
21 #define SOURCE_FILE_HH
22
23 #include "std-vector.hh"
24 #include "lily-proto.hh"
25 #include "smobs.hh"
26
27 #include <iostream>
28 using namespace std;
29
30 /**
31    class for reading and mapping a file.
32
33    duplicates a lot of Data_file and Text_stream.
34    should look at including Data_file's functionality:
35    get_line (), get_word () here.
36 */
37
38 class Source_file : public Smob<Source_file>
39 {
40 public:
41   int print_smob (SCM, scm_print_state *);
42   SCM mark_smob ();
43   static const char type_p_name_[];
44   virtual ~Source_file ();
45 private:
46   vector<char const *> newline_locations_;
47   istream *istream_;
48   vector<char> characters_;
49   SCM str_port_;
50
51   void load_stdin ();
52   void init_port ();
53   void init ();
54
55 public:
56   Source_file (const string &fn);
57   Source_file (const string&, const string&);
58
59   char const *c_str () const;
60   virtual string quote_input (char const *pos_str0) const;
61   istream *get_istream ();
62   bool contains (char const *pos_str0) const;
63   int length () const;
64   virtual int get_line (char const *pos_str0) const;
65   void set_line (char const *pos_str0, int i);
66   string name_string () const;
67   string file_line_column_string (char const *str0) const;
68
69   Slice line_slice (char const *pos_str0) const;
70   string line_string (char const *pos_str0) const;
71   void get_counts (char const *pos_str0, int *, int *, int *, int *) const;
72
73   SCM get_port () const;
74   string name_;
75
76 protected:
77   int line_offset_;
78 };
79
80 vector<char> gulp_file (const string &fn, int desired);
81
82 #endif /* SOURCE_FILE_HH */