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