45 #include "../my_config.h"
58 #define ESCAPE_FIXED_SEQUENCE_NORMAL 0xAD
59 #define ESCAPE_FIXED_SEQUENCE_SPARSE_FILE 0xAE
61 #define MAX_BUFFER_SIZE 204800
63 #if SSIZE_MAX < MAX_BUFFER_SIZE
64 #undef MAX_BUFFER_SIZE
65 #define MAX_BUFFER_SIZE SSIZE_MAX
75 class escape :
public generic_file
104 escape(generic_file *below,
105 const std::set<sequence_type> & x_unjumpable);
106 escape(
const escape & ref) :
generic_file(ref) { copy_from(ref); };
107 const escape & operator = (
const escape & ref);
112 void add_mark_at_current_position(sequence_type t);
120 bool skip_to_next_mark(sequence_type t,
bool jump);
121 bool next_to_read_is_mark(sequence_type t);
122 bool next_to_read_is_which_mark(sequence_type & t);
124 void add_unjumpable_mark(sequence_type t) {
if(
is_terminated())
throw SRC_BUG; unjumpable.insert(t); };
125 void remove_unjumpable_mark(sequence_type t);
126 bool is_unjumpable_mark(sequence_type t)
const {
return unjumpable.find(t) != unjumpable.end(); };
127 void clear_all_unjumpable_marks() { unjumpable.clear(); };
134 bool skip(
const infinint & pos);
136 bool skip_relative(S_I x);
137 infinint get_position();
142 U_I inherited_read(
char *a, U_I size);
143 void inherited_write(
const char *a, U_I size);
144 void inherited_sync_write() { flush_write(); };
145 void inherited_terminate() { flush_or_clean(); };
147 void change_fixed_escape_sequence(
unsigned char value) { fixed_sequence[0] = value; };
148 bool has_escaped_data_since_last_skip()
const {
return escaped_data_count_since_last_skip > 0; };
155 static const U_I ESCAPE_SEQUENCE_LENGTH = 6;
156 static const U_I WRITE_BUFFER_SIZE = 2*ESCAPE_SEQUENCE_LENGTH;
157 static const U_I READ_BUFFER_SIZE = MAX_BUFFER_SIZE;
166 static const unsigned char usual_fixed_sequence[ESCAPE_SEQUENCE_LENGTH];
171 U_I write_buffer_size;
172 char write_buffer[WRITE_BUFFER_SIZE];
174 U_I read_buffer_size;
177 U_I escape_seq_offset_in_buffer;
178 char read_buffer[READ_BUFFER_SIZE];
179 std::set<sequence_type> unjumpable;
180 unsigned char fixed_sequence[ESCAPE_SEQUENCE_LENGTH];
181 infinint escaped_data_count_since_last_skip;
185 void set_fixed_sequence_for(sequence_type t) { fixed_sequence[ESCAPE_SEQUENCE_LENGTH - 1] = type2char(t); };
186 void check_below() {
if(x_below == NULL)
throw SRC_BUG; };
187 void clean_data() { read_buffer_size = already_read = escape_seq_offset_in_buffer = 0; };
189 void flush_or_clean()
203 void copy_from(
const escape & ref);
204 bool mini_read_buffer();
209 static char type2char(sequence_type x);
210 static sequence_type char2type(
char x);
218 static U_I trouve_amorce(
const char *a, U_I size,
const unsigned char escape_sequence[ESCAPE_SEQUENCE_LENGTH]);
228 static U_I remove_data_marks_and_stop_at_first_real_mark(
char *a, U_I size, U_I & delta,
const unsigned char escape_sequence[ESCAPE_SEQUENCE_LENGTH]);