* scm/beam.scm (check-slope-callbacks): check sign of slope.
[lilypond.git] / lily / input-smob.cc
blob798e61d51ac9c405b0f1a4463789801a9c2ddaa1
1 /*
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>
8 */
10 #include "input.hh"
11 #include "input-smob.hh"
12 #include "string.hh"
13 #include "ly-smobs.icc"
15 /* Dummy input location for use if real one is missing. */
16 Input dummy_input_global;
18 static long input_tag;
20 static
21 SCM mark_smob (SCM)
23 return SCM_EOL;
26 static int
27 print_smob (SCM s, SCM port, scm_print_state *)
29 String str = "#<location " + unsmob_input (s)->location_string () + ">";
30 scm_puts (str.to_str0 (), port);
31 return 1;
34 static size_t
35 free_smob (SCM s)
37 delete unsmob_input (s);
38 return 0;
42 static void
43 start_input_smobs ()
45 input_tag = scm_make_smob_type ("input", 0);
46 scm_set_smob_mark (input_tag, mark_smob);
47 scm_set_smob_free (input_tag, free_smob);
48 scm_set_smob_print (input_tag, print_smob);
49 scm_set_smob_equalp (input_tag, 0);
52 SCM
53 make_input (Input ip)
55 Input *nip = new Input (ip);
56 SCM z;
58 SCM_NEWSMOB (z, input_tag, nip);
59 return z;
62 Input *
63 unsmob_input (SCM s)
65 if (SCM_IMP (s))
66 return 0;
67 if (SCM_CAR (s) == (SCM)input_tag) // ugh.
68 return (Input*) SCM_CDR (s);
69 else
70 return 0;
73 /* We don't use IMPLEMENT_TYPE_P, since the smobification part is
74 implemented separately from the class. */
75 LY_DEFINE (ly_input, "ly:input-location?", 1, 0, 0,
76 (SCM x),
77 "Return #t if @var{x} is an input location.")
79 return unsmob_input (x) ? SCM_BOOL_T : SCM_BOOL_F;
82 LY_DEFINE (ly_input_message, "ly:input-message", 2, 0, 0, (SCM sip, SCM msg),
83 "Print @var{msg} as a GNU compliant error message, pointing to the"
84 "location in @var{sip}.\n")
86 Input *ip = unsmob_input (sip);
87 SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location");
88 SCM_ASSERT_TYPE (ly_c_string_p (msg), msg, SCM_ARG2, __FUNCTION__, "string");
90 String m = ly_scm2string (msg);
91 ip->message (m);
93 return SCM_UNSPECIFIED;
97 TODO: rename this function. ly:input-location? vs ly:input-location
99 LY_DEFINE (ly_input_location, "ly:input-location", 1, 0, 0, (SCM sip),
100 "Return input location in @var{sip} as (filename line column).")
102 Input *ip = unsmob_input (sip);
103 SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location");
104 return scm_list_3 (scm_makfrom0str (ip->file_string ().to_str0 ()),
105 scm_int2num (ip->line_number ()),
106 scm_int2num (ip->column_number ()));
109 ADD_SCM_INIT_FUNC (input, start_input_smobs);