]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-scheme.cc
Doc-fr: updates input.itely
[lilypond.git] / lily / input-scheme.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
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 #include "std-string.hh"
21 #include "input.hh"
22
23 /* We don't use IMPLEMENT_TYPE_P, since the smobification part is
24    implemented separately from the class.  */
25 LY_DEFINE (ly_input_location_p, "ly:input-location?", 1, 0, 0,
26            (SCM x),
27            "Is @var{x} an @code{input-location}?")
28 {
29   return unsmob_input (x) ? SCM_BOOL_T : SCM_BOOL_F;
30 }
31
32 LY_DEFINE (ly_input_message, "ly:input-message", 2, 0, 1, (SCM sip, SCM msg, SCM rest),
33            "Print @var{msg} as a GNU compliant error message, pointing"
34            " to the location in @var{sip}.  @var{msg} is interpreted"
35            " similar to @code{format}'s argument, using @var{rest}.")
36 {
37   Input *ip = unsmob_input (sip);
38
39   LY_ASSERT_TYPE (unsmob_input, sip, 1);
40   LY_ASSERT_TYPE (scm_is_string, msg, 2);
41
42   msg = scm_simple_format (SCM_BOOL_F, msg, rest);
43
44   string m = ly_scm2string (msg);
45   ip->message (m);
46
47   return SCM_UNSPECIFIED;
48 }
49
50 LY_DEFINE (ly_input_file_line_char_column,
51            "ly:input-file-line-char-column",
52            1, 0, 0, (SCM sip),
53            "Return input location in @var{sip} as"
54            " @code{(file-name line char column)}.")
55 {
56   LY_ASSERT_TYPE (unsmob_input, sip, 1);
57   Input *ip = unsmob_input (sip);
58
59   int l, ch, col, offset = 0;
60   ip->get_counts (&l, &ch, &col, &offset);
61   return scm_list_4 (ly_string2scm (ip->file_string ()),
62                      scm_from_int (l),
63                      scm_from_int (ch),
64                      scm_from_int (col));
65 }
66
67 LY_DEFINE (ly_input_both_locations,
68            "ly:input-both-locations",
69            1, 0, 0, (SCM sip),
70            "Return input location in @var{sip} as"
71            " @code{(file-name first-line first-column last-line last-column)}.")
72 {
73
74   LY_ASSERT_TYPE (unsmob_input, sip, 1);
75   Input *ip = unsmob_input (sip);
76
77   return scm_list_5 (ly_string2scm (ip->file_string ()),
78                      scm_from_int (ip->line_number ()),
79                      scm_from_int (ip->column_number ()),
80                      scm_from_int (ip->end_line_number ()),
81                      scm_from_int (ip->end_column_number ()));
82 }