]> git.donarmstrong.com Git - lilypond.git/blob - lily/binary-source-file.cc
Move marker for finished NEWS stuff. (forgot to merge this ealier)
[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 #if 0                           // FIXME
65   return *(U8 *)forward_str0 (1);
66 #endif
67   assert (false);
68   return 0;
69 }
70
71 U16
72 Binary_source_file::get_U16 ()
73 {
74   U16 b;
75
76   b = get_U8 () << 8;
77   b |= get_U8 ();
78
79   return b;
80 }
81
82 /*
83   naming is wrong. This is a UNIX-endian-32 (as opposed to xinu or ixun)
84 */
85
86 U32
87 Binary_source_file::get_U32 ()
88 {
89   U32 b;
90
91   b = get_U8 () << 24;
92   b |= get_U8 () << 16;
93   b |= get_U8 () << 8;
94   b |= get_U8 ();
95
96   return b;
97 }
98