]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-smob.cc
release: 1.3.131
[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--2001 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
32 scm_sizet free_smob (SCM s)
33 {
34   delete unsmob_input (s);
35   return 0;
36 }
37
38 SCM
39 ly_input_p (SCM x)
40 {
41   return unsmob_input (x) ? SCM_BOOL_T : SCM_BOOL_F ;
42 }
43
44 static
45 void start_input_smobs()
46 {
47   input_tag
48     = scm_make_smob_type_mfpe ("input", 0,
49                                mark_smob, free_smob,
50                                print_smob, 0);
51   scm_make_gsubr ("ly-input-location?", 1, 0, 0, (Scheme_function_unknown)ly_input_p);
52  
53 }
54
55 SCM
56 make_input (Input ip)
57 {
58   Input * nip =  new Input (ip);
59   SCM z;
60   
61   SCM_NEWCELL(z);
62   SCM_SETCAR (z, (SCM)input_tag);
63   SCM_SETCDR (z, (SCM)nip);
64                                 // fixme: done_malloc
65   return z;
66 }
67
68 Input *                                         
69 unsmob_input (SCM s)
70 {
71   if (SCM_IMP (s))
72     return 0;
73   if ((long)SCM_CAR(s) == input_tag) // ugh.
74     return (Input*) SCM_CDR(s);
75   else                                          
76     return 0;                                   
77 }
78
79
80 ADD_SCM_INIT_FUNC(input, start_input_smobs);
81
82
83 Input dummy_input_global;
84