]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-scheme.cc
Web-ja: update introduction
[lilypond.git] / lily / input-scheme.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2015 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 LY_DEFINE (ly_input_warning, "ly:input-warning", 2, 0, 1, (SCM sip, SCM msg, SCM rest),
24            "Print @var{msg} as a GNU compliant warning message, pointing"
25            " to the location in @var{sip}.  @var{msg} is interpreted"
26            " similar to @code{format}'s argument, using @var{rest}.")
27 {
28   Input *ip = unsmob<Input> (sip);
29
30   LY_ASSERT_SMOB (Input, sip, 1);
31   LY_ASSERT_TYPE (scm_is_string, msg, 2);
32
33   msg = scm_simple_format (SCM_BOOL_F, msg, rest);
34
35   string m = ly_scm2string (msg);
36   ip->warning (m);
37
38   return SCM_UNSPECIFIED;
39 }
40
41 LY_DEFINE (ly_input_message, "ly:input-message", 2, 0, 1, (SCM sip, SCM msg, SCM rest),
42            "Print @var{msg} as a GNU compliant error message, pointing"
43            " to the location in @var{sip}.  @var{msg} is interpreted"
44            " similar to @code{format}'s argument, using @var{rest}.")
45 {
46   Input *ip = unsmob<Input> (sip);
47
48   LY_ASSERT_SMOB (Input, sip, 1);
49   LY_ASSERT_TYPE (scm_is_string, msg, 2);
50
51   msg = scm_simple_format (SCM_BOOL_F, msg, rest);
52
53   string m = ly_scm2string (msg);
54   ip->message (m);
55
56   return SCM_UNSPECIFIED;
57 }
58
59 LY_DEFINE (ly_input_file_line_char_column,
60            "ly:input-file-line-char-column",
61            1, 0, 0, (SCM sip),
62            "Return input location in @var{sip} as"
63            " @code{(file-name line char column)}.")
64 {
65   LY_ASSERT_SMOB (Input, sip, 1);
66   Input *ip = unsmob<Input> (sip);
67
68   int l, ch, col, offset = 0;
69   ip->get_counts (&l, &ch, &col, &offset);
70   return scm_list_4 (ly_string2scm (ip->file_string ()),
71                      scm_from_int (l),
72                      scm_from_int (ch),
73                      scm_from_int (col));
74 }
75
76 LY_DEFINE (ly_input_both_locations,
77            "ly:input-both-locations",
78            1, 0, 0, (SCM sip),
79            "Return input location in @var{sip} as"
80            " @code{(file-name first-line first-column last-line last-column)}.")
81 {
82
83   LY_ASSERT_SMOB (Input, sip, 1);
84   Input *ip = unsmob<Input> (sip);
85
86   return scm_list_5 (ly_string2scm (ip->file_string ()),
87                      scm_from_int (ip->line_number ()),
88                      scm_from_int (ip->column_number ()),
89                      scm_from_int (ip->end_line_number ()),
90                      scm_from_int (ip->end_column_number ()));
91 }