]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-smob.cc
af9180a744f58a534028bc775de1b0d08c0c0a43
[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--2002 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_str () + ">";
27   scm_puts (str.ch_C (), 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 SCM
43 ly_input_p (SCM x)
44 {
45   return unsmob_input (x) ? SCM_BOOL_T : SCM_BOOL_F ;
46 }
47
48 SCM
49 ly_input_message (SCM sip, SCM msg)
50 {
51   Input *ip  = unsmob_input(sip);
52   
53   SCM_ASSERT_TYPE(ip, sip, SCM_ARG1, __FUNCTION__, "input location");
54   SCM_ASSERT_TYPE(gh_string_p(msg), msg, SCM_ARG2, __FUNCTION__, "string");
55
56   String m = ly_scm2string (msg);
57
58   ip->message (m);
59   return SCM_UNDEFINED;
60 }
61
62
63 static void
64 start_input_smobs ()
65 {
66   input_tag = scm_make_smob_type ("input", 0);
67   scm_set_smob_mark (input_tag, mark_smob);
68   scm_set_smob_free (input_tag, free_smob);
69   scm_set_smob_print (input_tag, print_smob);
70   scm_set_smob_equalp (input_tag, 0);
71
72   
73   scm_c_define_gsubr ("ly-input-location?", 1, 0, 0,
74                       (Scheme_function_unknown)ly_input_p);
75   scm_c_define_gsubr ("ly-input-message", 2, 0, 0,
76                       (Scheme_function_unknown)ly_input_message);
77 }
78
79 SCM
80 make_input (Input ip)
81 {
82   Input * nip =  new Input (ip);
83   SCM z;
84   
85   SCM_NEWCELL (z);
86   SCM_SETCAR (z, (SCM)input_tag);
87   SCM_SETCDR (z, (SCM)nip);
88                                 // fixme: done_malloc
89   return z;
90 }
91
92 Input *                                         
93 unsmob_input (SCM s)
94 {
95   if (SCM_IMP (s))
96     return 0;
97   if (SCM_CAR (s) == (SCM)input_tag) // ugh.
98     return (Input*) SCM_CDR (s);
99   else                                          
100     return 0;                                   
101 }
102
103
104 ADD_SCM_INIT_FUNC (input, start_input_smobs);
105
106
107 Input dummy_input_global;
108