]> git.donarmstrong.com Git - lilypond.git/blob - lily/binary-source-file.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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--2006 Jan Nieuwenhuizen
7 */
8
9 #include <climits>              // INT_MAX
10 using namespace std;
11
12 #include "binary-source-file.hh"
13 #include "string-convert.hh"
14
15 Binary_source_file::Binary_source_file (string &file_name_string)
16   : Source_file (file_name_string)
17 {
18 }
19
20 Binary_source_file::~Binary_source_file ()
21 {
22 }
23
24 string
25 Binary_source_file::quote_input (char const *pos_str0) const
26 {
27   assert (this);
28   if (!contains (pos_str0))
29     return "";
30
31   char const *begin_str0 = max (pos_str0 - 8, c_str ());
32   char const *end_str0 = min (pos_str0 + 7, c_str () + length ());
33
34   string pre_string (begin_str0, pos_str0 - begin_str0);
35   pre_string = String_convert::bin2hex (pre_string);
36   for (ssize i = 2; i < pre_string.length (); i += 3)
37     pre_string = pre_string.substr (0, i)
38       + " " + pre_string.substr (i, NPOS);
39   string post_string (pos_str0, end_str0 - pos_str0);
40   post_string = String_convert::bin2hex (post_string);
41   for (ssize i = 2; i < post_string.length (); i += 3)
42     post_string = post_string.substr (0, i)
43       + " " + post_string.substr (i, NPOS);
44
45   string str = pre_string
46     + to_string ('\n')
47     + to_string (' ', pre_string.length () + 1)
48     + post_string;
49   return str;
50 }
51
52 int
53 Binary_source_file::get_line (char const *pos_str0) const
54 {
55   if (!contains (pos_str0))
56     return 0;
57
58   return pos_str0 - c_str ();
59 }
60
61 U8
62 Binary_source_file::get_U8 ()
63 {
64   return *(U8 *)forward_str0 (1);
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