2 input-smob.cc -- implement Input smob
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "input-smob.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
;
27 print_smob (SCM s
, SCM port
, scm_print_state
*)
29 String str
= "#<location " + unsmob_input (s
)->location_string () + ">";
30 scm_puts (str
.to_str0 (), port
);
37 delete unsmob_input (s
);
45 input_tag
= scm_make_smob_type ("input", 0);
46 scm_set_smob_mark (input_tag
, mark_smob
);
47 scm_set_smob_free (input_tag
, free_smob
);
48 scm_set_smob_print (input_tag
, print_smob
);
49 scm_set_smob_equalp (input_tag
, 0);
55 Input
*nip
= new Input (ip
);
58 SCM_NEWSMOB (z
, input_tag
, nip
);
67 if (SCM_CAR (s
) == (SCM
)input_tag
) // ugh.
68 return (Input
*) SCM_CDR (s
);
73 /* We don't use IMPLEMENT_TYPE_P, since the smobification part is
74 implemented separately from the class. */
75 LY_DEFINE (ly_input
, "ly:input-location?", 1, 0, 0,
77 "Return #t if @var{x} is an input location.")
79 return unsmob_input (x
) ? SCM_BOOL_T
: SCM_BOOL_F
;
82 LY_DEFINE (ly_input_message
, "ly:input-message", 2, 0, 0, (SCM sip
, SCM msg
),
83 "Print @var{msg} as a GNU compliant error message, pointing to the"
84 "location in @var{sip}.\n")
86 Input
*ip
= unsmob_input (sip
);
87 SCM_ASSERT_TYPE (ip
, sip
, SCM_ARG1
, __FUNCTION__
, "input location");
88 SCM_ASSERT_TYPE (ly_c_string_p (msg
), msg
, SCM_ARG2
, __FUNCTION__
, "string");
90 String m
= ly_scm2string (msg
);
93 return SCM_UNSPECIFIED
;
97 TODO: rename this function. ly:input-location? vs ly:input-location
99 LY_DEFINE (ly_input_location
, "ly:input-location", 1, 0, 0, (SCM sip
),
100 "Return input location in @var{sip} as (filename line column).")
102 Input
*ip
= unsmob_input (sip
);
103 SCM_ASSERT_TYPE (ip
, sip
, SCM_ARG1
, __FUNCTION__
, "input location");
104 return scm_list_3 (scm_makfrom0str (ip
->file_string ().to_str0 ()),
105 scm_int2num (ip
->line_number ()),
106 scm_int2num (ip
->column_number ()));
109 ADD_SCM_INIT_FUNC (input
, start_input_smobs
);