]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-smob.cc
0f928a67b763776ea024941b4b14db7a425b8ee9
[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--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "input.hh"
10 #include "source-file.hh"
11 #include "std-string.hh"
12
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 SCM
21 mark_smob (SCM s)
22 {
23   Input *sc = (Input *) SCM_CELL_WORD_1 (s);
24
25   if (Source_file *sf = sc->get_source_file ())
26     return sf->self_scm ();
27
28   return SCM_EOL;
29 }
30
31 static int
32 print_smob (SCM s, SCM port, scm_print_state *)
33 {
34   string str = "#<location " + unsmob_input (s)->location_string () + ">";
35   scm_puts (str.c_str (), port);
36   return 1;
37 }
38
39 static size_t
40 free_smob (SCM s)
41 {
42   delete unsmob_input (s);
43   return 0;
44 }
45
46 static SCM
47 equal_smob (SCM sa, SCM sb)
48 {
49   Input *a = (Input *) SCM_CELL_WORD_1 (sa);
50   Input *b = (Input *) SCM_CELL_WORD_1 (sb);
51   if (a->get_source_file () == b->get_source_file () &&
52       a->start () == b->start () &&
53       a->end () == b->end ())
54     return SCM_BOOL_T;
55   else
56     return SCM_BOOL_F;
57 }
58
59 static void
60 start_input_smobs ()
61 {
62   input_tag = scm_make_smob_type ("input", 0);
63   scm_set_smob_mark (input_tag, mark_smob);
64   scm_set_smob_free (input_tag, free_smob);
65   scm_set_smob_print (input_tag, print_smob);
66   scm_set_smob_equalp (input_tag, equal_smob);
67 }
68
69 SCM
70 make_input (Input ip)
71 {
72   Input *nip = new Input (ip);
73   SCM z;
74
75   SCM_NEWSMOB (z, input_tag, nip);
76   return z;
77 }
78
79 Input *
80 unsmob_input (SCM s)
81 {
82   if (SCM_IMP (s))
83     return 0;
84   if (SCM_CAR (s) == (SCM)input_tag) // ugh.
85     return (Input *) SCM_CDR (s);
86   else
87     return 0;
88 }
89
90 ADD_SCM_INIT_FUNC (input, start_input_smobs);
91