]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-scheme.cc
Merge branch 'master' of ssh+git://gpercival@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / lily / input-scheme.cc
1 /*
2   input-scheme.cc -- implement Input bindings.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "std-string.hh"
10 #include "input.hh"
11
12 /* We don't use IMPLEMENT_TYPE_P, since the smobification part is
13    implemented separately from the class.  */
14 LY_DEFINE (ly_input_location_p, "ly:input-location?", 1, 0, 0,
15            (SCM x),
16            "Is @var{x} an @code{input-location}?")
17 {
18   return unsmob_input (x) ? SCM_BOOL_T : SCM_BOOL_F;
19 }
20
21 LY_DEFINE (ly_input_message, "ly:input-message", 2, 0, 1, (SCM sip, SCM msg, SCM rest),
22            "Print @var{msg} as a GNU compliant error message, pointing to the "
23            "location in @var{sip}. @var{msg} is interpreted similar to @code{format}'s argument\n")
24 {
25   Input *ip = unsmob_input (sip);
26
27   LY_ASSERT_TYPE (unsmob_input, sip, 1);
28   LY_ASSERT_TYPE (scm_is_string, msg,2);
29
30   msg = scm_simple_format (SCM_BOOL_F, msg, rest);
31
32   string m = ly_scm2string (msg);
33   ip->message (m);
34
35   return SCM_UNSPECIFIED;
36 }
37
38
39 LY_DEFINE (ly_input_file_line_char_column,
40            "ly:input-file-line-char-column",
41            1, 0, 0, (SCM sip),
42            "Return input location in @var{sip} as (file-name line char column).")
43 {
44   LY_ASSERT_TYPE (unsmob_input, sip, 1);
45   Input *ip = unsmob_input (sip);
46
47   int l = 0;
48   int ch = 0;
49   int col = 0;
50   ip->get_counts (&l, &ch, &col);
51   return scm_list_4 (ly_string2scm (ip->file_string ()),
52                      scm_from_int (l),
53                      scm_from_int (ch),
54                      scm_from_int (col));
55 }
56
57 LY_DEFINE (ly_input_both_locations,
58            "ly:input-both-locations",
59            1, 0, 0, (SCM sip),
60            "Return input location in @var{sip} as "
61            "(file-name first-line first-column last-line last-column).")
62 {
63   
64   LY_ASSERT_TYPE (unsmob_input, sip, 1);
65   Input *ip = unsmob_input (sip);
66   
67   return scm_list_5 (ly_string2scm (ip->file_string ()),
68                      scm_from_int (ip->line_number ()),
69                      scm_from_int (ip->column_number ()),
70                      scm_from_int (ip->end_line_number ()),
71                      scm_from_int (ip->end_column_number ()));
72 }