2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "std-string.hh"
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,
27 "Is @var{x} an @code{input-location}?")
29 return unsmob_input (x
) ? SCM_BOOL_T
: SCM_BOOL_F
;
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}.")
37 Input
*ip
= unsmob_input (sip
);
39 LY_ASSERT_TYPE (unsmob_input
, sip
, 1);
40 LY_ASSERT_TYPE (scm_is_string
, msg
,2);
42 msg
= scm_simple_format (SCM_BOOL_F
, msg
, rest
);
44 string m
= ly_scm2string (msg
);
47 return SCM_UNSPECIFIED
;
51 LY_DEFINE (ly_input_file_line_char_column
,
52 "ly:input-file-line-char-column",
54 "Return input location in @var{sip} as"
55 " @code{(file-name line char column)}.")
57 LY_ASSERT_TYPE (unsmob_input
, sip
, 1);
58 Input
*ip
= unsmob_input (sip
);
60 int l
, ch
, col
, offset
= 0;
61 ip
->get_counts (&l
, &ch
, &col
, &offset
);
62 return scm_list_4 (ly_string2scm (ip
->file_string ()),
68 LY_DEFINE (ly_input_both_locations
,
69 "ly:input-both-locations",
71 "Return input location in @var{sip} as"
72 " @code{(file-name first-line first-column last-line last-column)}.")
75 LY_ASSERT_TYPE (unsmob_input
, sip
, 1);
76 Input
*ip
= unsmob_input (sip
);
78 return scm_list_5 (ly_string2scm (ip
->file_string ()),
79 scm_from_int (ip
->line_number ()),
80 scm_from_int (ip
->column_number ()),
81 scm_from_int (ip
->end_line_number ()),
82 scm_from_int (ip
->end_column_number ()));