]> git.donarmstrong.com Git - lilypond.git/blob - src/binary-source-file.cc
release: 0.0.36
[lilypond.git] / src / binary-source-file.cc
1 //
2 // binary-source-file.cc
3 //
4
5 #include <limits.h>             // INT_MAX
6 #include <assert.h>
7
8 #include "proto.hh"
9 #include "plist.hh"
10 #include "string.hh"
11 #include "debug.hh"
12 #include "sourcefile.hh"
13 #include "binary-source-file.hh"
14
15 Binary_source_file::Binary_source_file( String& filename_str )
16         : Source_file( filename_str )
17 {
18 }
19
20 Binary_source_file::~Binary_source_file()
21 {
22 }
23
24 String
25 Binary_source_file::error_str( char const* pos_ch_c_l )
26 {
27     assert( this );
28     if ( !in_b( pos_ch_c_l ) )
29         return "";
30
31     char const* begin_ch_c_l = pos_ch_c_l - 8 >? ch_c_l();
32     char const* end_ch_c_l = pos_ch_c_l + 7 <? ch_c_l() + length_off();
33
34     String pre_str( (Byte const*)begin_ch_c_l, pos_ch_c_l - begin_ch_c_l );
35     pre_str = StringConversion::bin2hex_str( pre_str );
36     for ( int i = 2; i < pre_str.length_i(); i += 3 )
37         pre_str = pre_str.left( i ) + " " + pre_str.mid( i + 1, INT_MAX );
38     String post_str( (Byte const*)pos_ch_c_l, end_ch_c_l - pos_ch_c_l );
39     post_str = StringConversion::bin2hex_str( post_str );
40     for ( int i = 2; i < post_str.length_i(); i += 3 )
41         post_str = post_str.left( i ) + " " + post_str.mid( i + 1, INT_MAX );
42
43     String str = pre_str
44         + String( '\n' )
45         + String( ' ', pre_str.length_i() + 1 ) 
46         + post_str;
47     return str;
48 }
49
50 int
51 Binary_source_file::line_i( char const* pos_ch_c_l )
52 {
53     if ( !in_b( pos_ch_c_l ) )
54         return 0;
55
56     return pos_ch_c_l - ch_c_l();
57 }
58