]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-smob.cc
*** empty log message ***
[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--2003 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 static long input_tag;
16
17 static
18 SCM mark_smob (SCM)
19 {
20   return SCM_EOL;
21 }
22
23 static int
24 print_smob (SCM s, SCM port, scm_print_state *)
25 {
26   String str = "#<location " +  unsmob_input (s)->location_string () + ">";
27   scm_puts (str.to_str0 (), port);
28   return 1;
29 }
30
31 static size_t
32 free_smob (SCM s)
33 {
34   delete unsmob_input (s);
35   return 0;
36 }
37
38 /*
39   We don't use IMPLEMENT_TYPE_P, since the smobification part is
40   implemented separately from the class.
41  */
42 LY_DEFINE(ly_input, "ly:input-location?", 1, 0, 0,
43           (SCM x),
44           "Return whether @var{x} is an input location")
45 {
46   return unsmob_input (x) ? SCM_BOOL_T : SCM_BOOL_F ;
47 }
48
49 LY_DEFINE(ly_input_message,  "ly:input-message", 2, 0, 0, (SCM sip, SCM msg),
50           "Print @var{msg} as a GNU compliant error message, pointing to the\n"
51           "location in @var{sip}.\n"
52           )
53 {
54   Input *ip  = unsmob_input(sip);
55   
56   SCM_ASSERT_TYPE(ip, sip, SCM_ARG1, __FUNCTION__, "input location");
57   SCM_ASSERT_TYPE(gh_string_p (msg), msg, SCM_ARG2, __FUNCTION__, "string");
58
59   String m = ly_scm2string (msg);
60
61   ip->message (m);
62   return SCM_UNDEFINED;
63 }
64
65
66 static void
67 start_input_smobs ()
68 {
69   input_tag = scm_make_smob_type ("input", 0);
70   scm_set_smob_mark (input_tag, mark_smob);
71   scm_set_smob_free (input_tag, free_smob);
72   scm_set_smob_print (input_tag, print_smob);
73   scm_set_smob_equalp (input_tag, 0);
74 }
75
76 SCM
77 make_input (Input ip)
78 {
79   Input * nip =  new Input (ip);
80   SCM z;
81   
82   SCM_NEWSMOB (z, input_tag, nip);
83   return z;
84 }
85
86 Input *                                         
87 unsmob_input (SCM s)
88 {
89   if (SCM_IMP (s))
90     return 0;
91   if (SCM_CAR (s) == (SCM)input_tag) // ugh.
92     return (Input*) SCM_CDR (s);
93   else                                          
94     return 0;                                   
95 }
96
97
98 ADD_SCM_INIT_FUNC (input, start_input_smobs);
99
100
101 Input dummy_input_global;
102