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