]> git.donarmstrong.com Git - lilypond.git/blob - lily/binary-source-file.cc
* configure.in: Test for and accept lmodern if EC fonts not found.
[lilypond.git] / lily / binary-source-file.cc
1 /*
2   binary-source-file.cc -- implement Binary_source_file
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997--2004 Jan Nieuwenhuizen
7 */
8
9
10 #include "binary-source-file.hh"
11
12 #include <climits>              // INT_MAX
13
14 #include "string-convert.hh"
15
16 Binary_source_file::Binary_source_file (String& file_name_string)
17   : Source_file (file_name_string)
18 {
19 }
20
21 Binary_source_file::~Binary_source_file ()
22 {
23 }
24
25 String
26 Binary_source_file::error_string (char const* pos_str0) const
27 {
28   assert (this);
29   if (!contains (pos_str0))
30     return "";
31
32   char const* begin_str0 = pos_str0 - 8 >? to_str0 ();
33   char const* end_str0 = pos_str0 + 7 <? to_str0 () + length ();
34
35   String pre_string ((Byte const*)begin_str0, pos_str0 - begin_str0);
36   pre_string = String_convert::bin2hex (pre_string);
37   for (int i = 2; i < pre_string.length (); i += 3)
38     pre_string = pre_string.left_string (i) + " " + pre_string.cut_string (i, INT_MAX);
39   String post_string ((Byte const*)pos_str0, end_str0 - pos_str0);
40   post_string = String_convert::bin2hex (post_string);
41   for (int i = 2; i < post_string.length (); i += 3)
42     post_string = post_string.left_string (i) + " " + post_string.cut_string (i, INT_MAX);
43
44   String str = pre_string
45     + to_string ('\n')
46     + to_string (' ', pre_string.length () + 1) 
47     + post_string;
48   return str;
49 }
50
51 int
52 Binary_source_file::get_line (char const* pos_str0) const
53 {
54   if (!contains (pos_str0))
55     return 0;
56
57   return pos_str0 - to_str0 ();
58 }
59
60 U8
61 Binary_source_file::get_U8 ()
62 {
63   return * (U8*)forward_str0 (1);
64 }
65
66
67 U16
68 Binary_source_file::get_U16 ()
69 {
70   U16 b;
71
72   b = get_U8 () << 8;
73   b |= get_U8 ();
74
75   return b;
76 }
77
78 /*
79   naming is wrong. This is a UNIX-endian-32 (as opposed to xinu or ixun)
80  */
81
82 U32
83 Binary_source_file::get_U32 ()
84 {
85   U32 b;
86   
87   b = get_U8 () << 24;
88   b |= get_U8 () << 16;
89   b |= get_U8 () << 8;
90   b |= get_U8 ();
91
92   return b;
93 }
94
95