forked from tecknicaltom/HT-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtsearch.h
335 lines (277 loc) · 7.4 KB
/
htsearch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
* HT Editor
* htsearch.h
*
* Copyright (C) 1999-2002 Stefan Weyergraf
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __HTSEARCH_H__
#define __HTSEARCH_H__
#include "atom.h"
#include "htdialog.h"
#include "except.h"
#include "htformat.h"
#include "htobj.h"
#include "strtools.h"
#include "stream.h"
#include <sys/types.h>
extern "C" {
#include "regex.h"
}
/*
* searching
*/
// search types + flags
#define ST_FXBIN 0 // search using fixed binary pattern
#define SF_FXBIN_CASEINSENSITIVE 1
#define SF_FXBIN_IDLE 2
#define ST_REGEX 1 // search using regular expression
#define SF_REGEX_CASEINSENSITIVE 1
#define SF_REGEX_IDLE 2
#define ST_EXPR 3 // search stops when expression evals to non-zero
typedef ht_view* (*create_form_func)(Bounds *b, uint histid);
typedef void (*create_desc_func)(char *buf, int buflen, ht_view *form);
/*
* CLASS ht_fxbin_search_request
*/
class ht_fxbin_search_request: public ht_search_request {
public:
uint data_size;
byte *data;
ht_fxbin_search_request(uint search_class, uint flags, uint data_size, byte *data);
virtual ~ht_fxbin_search_request();
/* overwritten */
virtual ht_fxbin_search_request *clone() const;
};
/*
* CLASS ht_regex_search_request
*/
class ht_regex_search_exception: public Exception {
protected:
char rxerr[128];
public:
ht_regex_search_exception(int e, regex_t *r);
virtual String &reason(String &) const;
};
class ht_regex_search_request: public ht_search_request {
public:
char *rx_str;
regex_t rx;
ht_regex_search_request(uint search_class, uint flags, char *regex);
virtual ~ht_regex_search_request();
/* overwritten */
virtual ht_regex_search_request* clone() const;
};
/*
* CLASS ht_expr_search_request
*/
class ht_expr_search_request: public ht_search_request {
public:
char *expr;
ht_expr_search_request(uint search_class, uint flags, char *Expr);
virtual ~ht_expr_search_request();
/* overwritten */
virtual ht_expr_search_request *clone() const;
};
/* binary search function */
/*
* CLASS ht_hexascii_search_form
*/
struct ht_hexascii_search_form_data {
ht_strinputfield_data str;
// ht_hexinputfield_data hex; // is attached to |str|
ht_strinputfield_data start;
ht_strinputfield_data end;
ht_checkboxes_data options;
};
class ht_hexascii_search_form: public ht_group {
protected:
ht_strinputfield *str;
ht_strinputfield *range_start;
ht_strinputfield *range_end;
ht_checkboxes *option_boxes;
public:
void init(Bounds *b, int options, List *history=0);
};
/*
* CLASS ht_evalstr_search_form
*/
struct ht_evalstr_search_form_data {
ht_strinputfield_data str;
ht_strinputfield_data start;
ht_strinputfield_data end;
ht_checkboxes_data options;
};
class ht_evalstr_search_form: public ht_group {
protected:
ht_strinputfield *str;
ht_strinputfield *range_start;
ht_strinputfield *range_end;
ht_checkboxes *option_boxes;
public:
void init(Bounds *b, int options, List *history=0);
};
/*
* CLASS ht_vregex_search_form
*/
struct ht_vregex_search_form_data {
ht_strinputfield_data str;
ht_strinputfield_data start;
ht_strinputfield_data end;
ht_checkboxes_data options;
};
class ht_vregex_search_form: public ht_group {
protected:
ht_strinputfield *str;
ht_strinputfield *range_start;
ht_strinputfield *range_end;
ht_checkboxes *option_boxes;
public:
void init(Bounds *b, int options, List *history=0);
};
/*
* CLASS ht_expr_search_form
*/
struct ht_expr_search_form_data {
ht_strinputfield_data str;
ht_strinputfield_data start;
ht_strinputfield_data end;
ht_checkboxes_data options;
};
class ht_expr_search_form: public ht_group {
protected:
ht_strinputfield *str;
ht_strinputfield *range_start;
ht_strinputfield *range_end;
ht_checkboxes *option_boxes;
public:
void init(Bounds *b, int options, List *history=0);
};
/*
* CLASS ht_replace_hexascii_search_form
*/
struct ht_replace_hexascii_search_form_data {
ht_strinputfield_data str;
ht_hexinputfield_data hex;
};
class ht_replace_hexascii_search_form: public ht_group {
protected:
ht_strinputfield *str;
public:
void init(Bounds *b, int options, List *history=0);
};
/*
* CLASS ht_search_dialog
*/
struct ht_search_dialog_mode {
int id;
ht_view *view;
};
#define MAX_SEARCH_DIALOG_MODES 16
class ht_search_dialog: public ht_dialog {
protected:
ht_listpopup *search_mode_popup;
int smodeidx;
int smodecount;
ht_search_dialog_mode smodes[MAX_SEARCH_DIALOG_MODES];
int find_search_mode(int id);
void select_search_mode_bymodeidx();
public:
ht_xgroup *search_mode_xgroup;
void init(Bounds *b, const char *title);
virtual void done();
/* overwritten */
virtual void handlemsg(htmsg *msg);
/* new */
void insert_search_mode(int id, const char *desc, ht_view *v);
void select_search_mode(int id);
ht_view *get_search_modeform();
int get_search_modeid();
};
/*
* CLASS ht_replace_dialog
*/
#define MAX_REPLACE_DIALOG_MODES 16
class ht_replace_dialog: public ht_search_dialog {
protected:
ht_listpopup *replace_mode_popup;
int rmodeidx;
int rmodecount;
ht_search_dialog_mode rmodes[MAX_REPLACE_DIALOG_MODES];
int find_replace_mode(int id);
void select_replace_mode_bymodeidx();
public:
ht_xgroup *replace_mode_xgroup;
void init(Bounds *b);
virtual void done();
/* overwritten */
virtual void handlemsg(htmsg *msg);
/* new */
void insert_replace_mode(int id, const char *desc, ht_view *v);
void select_replace_mode(int id);
ht_view *get_replace_modeform();
int get_replace_modeid();
};
/*
*
*/
#define SEARCHMODE_BIN 1
#define SEARCHMODE_EVALSTR 2
#define SEARCHMODE_VREGEX 4
#define SEARCHMODE_EXPR 8
ht_search_request *search_dialog(ht_format_viewer *format, uint searchmodes, viewer_pos *start, viewer_pos *end);
uint replace_dialog(ht_format_viewer *format, uint searchmodes, bool *cancelled);
class ht_search_bin_context: public Object {
public:
File *file;
bool file_end;
uint flags;
FileOfs ofs;
FileOfs len;
byte *pat;
uint patlen;
FileOfs o;
uint c;
byte *buf;
byte *bufptr;
bool *return_success;
FileOfs *return_ofs;
~ht_search_bin_context();
};
// flags
#define SFBIN_CASEINSENSITIVE 1
Object* create_search_bin_context(File *file, FileOfs ofs, FileOfs len, byte *pat, uint patlen, uint flags, FileOfs *return_ofs, bool *return_success);
bool search_bin_process(Object *context, ht_text *progress_indicator);
ht_view* create_form_hexascii(Bounds *b, uint histid);
void create_desc_hexascii(char *buf, int buflen, ht_view *f);
/*
*
*/
class ht_replace_bin_context: public Object {
public:
File *file;
FileOfs ofs;
FileOfs len;
FileOfs repllen;
byte *repl;
FileOfs o;
FileOfs z;
byte *buf;
FileOfs *return_repllen;
~ht_replace_bin_context();
};
Object* create_replace_bin_context(File *file, FileOfs ofs, FileOfs len, byte *repl, FileOfs repllen, FileOfs *return_repllen);
bool replace_bin_process(Object *context, ht_text *progress_indicator);
#endif /* __HTSEARCH_H__ */