]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-smob.cc
* configure.in: Test for and accept lmodern if EC fonts not found.
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "input-smob.hh"
11
12 #include "string.hh"
13
14 #include "ly-smobs.icc"
15
16 /* Dummy input location for use if real one is missing.  */
17 Input dummy_input_global;
18
19 static long input_tag;
20
21 static
22 SCM mark_smob (SCM)
23 {
24   return SCM_EOL;
25 }
26
27 static int
28 print_smob (SCM s, SCM port, scm_print_state *)
29 {
30   String str = "#<location " +  unsmob_input (s)->location_string () + ">";
31   scm_puts (str.to_str0 (), port);
32   return 1;
33 }
34
35 static size_t
36 free_smob (SCM s)
37 {
38   delete unsmob_input (s);
39   return 0;
40 }
41
42
43 static void
44 start_input_smobs ()
45 {
46   input_tag = scm_make_smob_type ("input", 0);
47   scm_set_smob_mark (input_tag, mark_smob);
48   scm_set_smob_free (input_tag, free_smob);
49   scm_set_smob_print (input_tag, print_smob);
50   scm_set_smob_equalp (input_tag, 0);
51 }
52
53 SCM
54 make_input (Input ip)
55 {
56   Input *nip = new Input (ip);
57   SCM z;
58   
59   SCM_NEWSMOB (z, input_tag, nip);
60   return z;
61 }
62
63 Input *                                         
64 unsmob_input (SCM s)
65 {
66   if (SCM_IMP (s))
67     return 0;
68   if (SCM_CAR (s) == (SCM)input_tag) // ugh.
69     return (Input*) SCM_CDR (s);
70   else                                          
71     return 0;                                   
72 }
73
74 /* We don't use IMPLEMENT_TYPE_P, since the smobification part is
75    implemented separately from the class.  */
76 LY_DEFINE (ly_input, "ly:input-location?", 1, 0, 0,
77            (SCM x),
78            "Return #t if @var{x} is an input location.")
79 {
80   return unsmob_input (x) ? SCM_BOOL_T : SCM_BOOL_F;
81 }
82
83 LY_DEFINE (ly_input_message, "ly:input-message", 2, 0, 0, (SCM sip, SCM msg),
84           "Print @var{msg} as a GNU compliant error message, pointing to the"
85            "location in @var{sip}.\n")
86 {
87   Input *ip = unsmob_input (sip);
88   SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location");
89   SCM_ASSERT_TYPE (scm_is_string (msg), msg, SCM_ARG2, __FUNCTION__, "string");
90
91   String m = ly_scm2string (msg);
92   ip->message (m);
93
94   return SCM_UNSPECIFIED;
95 }
96
97 /*
98   TODO: rename this function. ly:input-location? vs ly:input-location
99  */
100 LY_DEFINE (ly_input_location, "ly:input-location", 1, 0, 0, (SCM sip),
101           "Return input location in @var{sip} as (file-name line column).")
102 {
103   Input *ip = unsmob_input (sip);
104   SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location");
105   return scm_list_3 (scm_makfrom0str (ip->file_string ().to_str0 ()),
106                      scm_int2num (ip->line_number ()),
107                      scm_int2num (ip->column_number ()));
108 }
109
110 ADD_SCM_INIT_FUNC (input, start_input_smobs);
111