* lexer-gcc-3.1.sh: Remove.
[lilypond/patrick.git] / lily / input-smob.cc
blob7f66bcd3d3ec13ba84e79d96d75da05a5b314ac6
1 /*
2 input-smob.cc -- implement Input smob
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "input.hh"
10 #include "source-file.hh"
11 #include "std-string.hh"
13 #include "ly-smobs.icc"
15 /* Dummy input location for use if real one is missing. */
16 Input dummy_input_global;
18 static long input_tag;
20 static
21 SCM mark_smob (SCM s)
23 Input *sc = (Input *) SCM_CELL_WORD_1 (s);
25 if (Source_file *sf = sc->get_source_file ())
26 return sf->self_scm ();
28 return SCM_EOL;
31 static int
32 print_smob (SCM s, SCM port, scm_print_state *)
34 string str = "#<location " + unsmob_input (s)->location_string () + ">";
35 scm_puts (str.c_str (), port);
36 return 1;
39 static size_t
40 free_smob (SCM s)
42 delete unsmob_input (s);
43 return 0;
46 static void
47 start_input_smobs ()
49 input_tag = scm_make_smob_type ("input", 0);
50 scm_set_smob_mark (input_tag, mark_smob);
51 scm_set_smob_free (input_tag, free_smob);
52 scm_set_smob_print (input_tag, print_smob);
53 scm_set_smob_equalp (input_tag, 0);
56 SCM
57 make_input (Input ip)
59 Input *nip = new Input (ip);
60 SCM z;
62 SCM_NEWSMOB (z, input_tag, nip);
63 return z;
66 Input *
67 unsmob_input (SCM s)
69 if (SCM_IMP (s))
70 return 0;
71 if (SCM_CAR (s) == (SCM)input_tag) // ugh.
72 return (Input *) SCM_CDR (s);
73 else
74 return 0;
77 ADD_SCM_INIT_FUNC (input, start_input_smobs);