2 input-smob.cc -- implement Input smob
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "input-smob.hh"
14 #include "ly-smobs.icc"
16 /* Dummy input location for use if real one is missing. */
17 Input dummy_input_global;
19 static long input_tag;
28 print_smob (SCM s, SCM port, scm_print_state *)
30 String str = "#<location " + unsmob_input (s)->location_string () + ">";
31 scm_puts (str.to_str0 (), port);
38 delete unsmob_input (s);
46 input_tag = scm_make_smob_type ("input", 0);
47 scm_set_smob_mark (input_tag, mark_smob);
48 scm_set_smob_free (input_tag, free_smob);
49 scm_set_smob_print (input_tag, print_smob);
50 scm_set_smob_equalp (input_tag, 0);
56 Input *nip = new Input (ip);
59 SCM_NEWSMOB (z, input_tag, nip);
68 if (SCM_CAR (s) == (SCM)input_tag) // ugh.
69 return (Input*) SCM_CDR (s);
74 /* We don't use IMPLEMENT_TYPE_P, since the smobification part is
75 implemented separately from the class. */
76 LY_DEFINE (ly_input, "ly:input-location?", 1, 0, 0,
78 "Return #t if @var{x} is an input location.")
80 return unsmob_input (x) ? SCM_BOOL_T : SCM_BOOL_F;
83 LY_DEFINE (ly_input_message, "ly:input-message", 2, 0, 0, (SCM sip, SCM msg),
84 "Print @var{msg} as a GNU compliant error message, pointing to the"
85 "location in @var{sip}.\n")
87 Input *ip = unsmob_input (sip);
88 SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location");
89 SCM_ASSERT_TYPE (scm_is_string (msg), msg, SCM_ARG2, __FUNCTION__, "string");
91 String m = ly_scm2string (msg);
94 return SCM_UNSPECIFIED;
98 TODO: rename this function. ly:input-location? vs ly:input-location
100 LY_DEFINE (ly_input_location, "ly:input-location", 1, 0, 0, (SCM sip),
101 "Return input location in @var{sip} as (file-name line column).")
103 Input *ip = unsmob_input (sip);
104 SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location");
105 return scm_list_3 (scm_makfrom0str (ip->file_string ().to_str0 ()),
106 scm_int2num (ip->line_number ()),
107 scm_int2num (ip->column_number ()));
110 ADD_SCM_INIT_FUNC (input, start_input_smobs);