lilypond-1.5.10
[lilypond.git] / lily / input-smob.cc
blobbd7061a3d08405ad0c43e5988ad77a1eaaa204ee
1 /*
2 input-smob.cc -- implement Input smob
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "input.hh"
11 #include "input-smob.hh"
12 #include "string.hh"
13 #include "ly-smobs.icc"
15 static long input_tag;
17 static
18 SCM mark_smob (SCM)
20 return SCM_EOL;
23 static int
24 print_smob (SCM s, SCM port, scm_print_state *)
26 String str = "#<location " + unsmob_input (s)->location_str () + ">";
27 scm_puts (str.ch_C (), port);
28 return 1;
31 static size_t
32 free_smob (SCM s)
34 delete unsmob_input (s);
35 return 0;
38 SCM
39 ly_input_p (SCM x)
41 return unsmob_input (x) ? SCM_BOOL_T : SCM_BOOL_F ;
44 static
45 void start_input_smobs ()
47 input_tag = scm_make_smob_type ("input", 0);
48 scm_set_smob_mark (input_tag, mark_smob);
49 scm_set_smob_free (input_tag, free_smob);
50 scm_set_smob_print (input_tag, print_smob);
51 scm_set_smob_equalp (input_tag, 0);
53 scm_c_define_gsubr ("ly-input-location?", 1, 0, 0,
54 (Scheme_function_unknown)ly_input_p);
57 SCM
58 make_input (Input ip)
60 Input * nip = new Input (ip);
61 SCM z;
63 SCM_NEWCELL (z);
64 SCM_SETCAR (z, (SCM)input_tag);
65 SCM_SETCDR (z, (SCM)nip);
66 // fixme: done_malloc
67 return z;
70 Input *
71 unsmob_input (SCM s)
73 if (SCM_IMP (s))
74 return 0;
75 if (SCM_CAR (s) == (SCM)input_tag) // ugh.
76 return (Input*) SCM_CDR (s);
77 else
78 return 0;
82 ADD_SCM_INIT_FUNC (input, start_input_smobs);
85 Input dummy_input_global;