]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-smob.cc
* lily/text-item.cc (interpret_string): new file, select font with
[lilypond.git] / lily / input-smob.cc
1 /*   
2   input-smob.cc --  implement Input smob
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "input.hh"
11 #include "input-smob.hh"
12 #include "string.hh"
13 #include "ly-smobs.icc"
14
15 /* Dummy input location for use if real one is missing.  */
16 Input dummy_input_global;
17
18 static long input_tag;
19
20 static
21 SCM mark_smob (SCM)
22 {
23   return SCM_EOL;
24 }
25
26 static int
27 print_smob (SCM s, SCM port, scm_print_state *)
28 {
29   String str = "#<location " +  unsmob_input (s)->location_string () + ">";
30   scm_puts (str.to_str0 (), port);
31   return 1;
32 }
33
34 static size_t
35 free_smob (SCM s)
36 {
37   delete unsmob_input (s);
38   return 0;
39 }
40
41
42 static void
43 start_input_smobs ()
44 {
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);
50 }
51
52 SCM
53 make_input (Input ip)
54 {
55   Input *nip = new Input (ip);
56   SCM z;
57   
58   SCM_NEWSMOB (z, input_tag, nip);
59   return z;
60 }
61
62 Input *                                         
63 unsmob_input (SCM s)
64 {
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;                                   
71 }
72
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.")
78 {
79   return unsmob_input (x) ? SCM_BOOL_T : SCM_BOOL_F;
80 }
81
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")
85 {
86   Input *ip = unsmob_input (sip);
87   SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location");
88   SCM_ASSERT_TYPE (is_string (msg), msg, SCM_ARG2, __FUNCTION__, "string");
89
90   String m = ly_scm2string (msg);
91   ip->message (m);
92
93   return SCM_UNDEFINED;
94 }
95
96 LY_DEFINE (ly_input_location, "ly:input-location", 1, 0, 0, (SCM sip),
97           "Return input location in @var{sip} as (filename line column).")
98 {
99   Input *ip = unsmob_input (sip);
100   SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location");
101   return scm_list_3 (scm_makfrom0str (ip->file_string ().to_str0 ()),
102                      scm_int2num (ip->line_number ()),
103                      scm_int2num (ip->column_number ()));
104 }
105
106 ADD_SCM_INIT_FUNC (input, start_input_smobs);
107