]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-scheme.cc
* ttftool/util.c (syserror): use errno for better error reporting.
[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 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "string.hh"
10 #include "input-smob.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, "ly:input-location?", 1, 0, 0,
15            (SCM x),
16            "Return #t if @var{x} is an 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, 0, (SCM sip, SCM msg),
22            "Print @var{msg} as a GNU compliant error message, pointing to the"
23            "location in @var{sip}.\n")
24 {
25   Input *ip = unsmob_input (sip);
26   SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location");
27   SCM_ASSERT_TYPE (scm_is_string (msg), msg, SCM_ARG2, __FUNCTION__, "string");
28
29   String m = ly_scm2string (msg);
30   ip->message (m);
31
32   return SCM_UNSPECIFIED;
33 }
34
35 LY_DEFINE (ly_input_file_line_column, "ly:input-file-line-char-column", 1, 0, 0, (SCM sip),
36            "Return input location in @var{sip} as (file-name line char column).")
37 {
38   Input *ip = unsmob_input (sip);
39   SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location");
40
41   int l, ch, col; 
42   ip->get_counts (&l, &ch, &col);
43   return scm_list_4 (scm_makfrom0str (ip->file_string ().to_str0 ()),
44                      scm_int2num (l),
45                      scm_int2num (ch),
46                      scm_int2num (col));
47 }
48
49 LY_DEFINE (ly_input_both_locations, "ly:input-both-locations", 1, 0, 0, (SCM sip),
50            "Return input location in @var{sip} as (file-name first-line first-column last-line last-column).")
51 {
52   Input *ip = unsmob_input (sip);
53   SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location");
54   return scm_list_5 (scm_makfrom0str (ip->file_string ().to_str0 ()),
55                      scm_int2num (ip->line_number ()),
56                      scm_int2num (ip->column_number ()),
57                      scm_int2num (ip->end_line_number ()),
58                      scm_int2num (ip->end_column_number ()));
59 }