Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

htsearch.h

Go to the documentation of this file.
00001 /* 
00002  *      HT Editor
00003  *      htsearch.h
00004  *
00005  *      Copyright (C) 1999-2002 Stefan Weyergraf (stefan@weyergraf.de)
00006  *
00007  *      This program is free software; you can redistribute it and/or modify
00008  *      it under the terms of the GNU General Public License version 2 as
00009  *      published by the Free Software Foundation.
00010  *
00011  *      This program is distributed in the hope that it will be useful,
00012  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *      GNU General Public License for more details.
00015  *
00016  *      You should have received a copy of the GNU General Public License
00017  *      along with this program; if not, write to the Free Software
00018  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifndef __HTSEARCH_H__
00022 #define __HTSEARCH_H__
00023 
00024 #include "htatom.h"
00025 #include "htdialog.h"
00026 #include "htexcept.h"
00027 #include "htformat.h"
00028 #include "htobj.h"
00029 #include "htstring.h"
00030 #include "stream.h"
00031 
00032 #include <sys/types.h>
00033 extern "C" {
00034 #include "regex.h"
00035 }
00036 
00037 /*
00038  *      searching
00039  */
00040 
00041 // search classes
00042 #define SC_PHYSICAL                     0    // search in underlying binary data
00043 #define SC_VISUAL                       1    // search in displayed text
00044 
00045 // search types + flags
00046 #define ST_FXBIN                0               // search using fixed binary pattern
00047         #define SF_FXBIN_CASEINSENSITIVE                1
00048         #define SF_FXBIN_IDLE                           2
00049         
00050 #define ST_REGEX                1         // search using regular expression
00051         #define SF_REGEX_CASEINSENSITIVE                1
00052         #define SF_REGEX_IDLE                           2
00053 
00054 #define ST_EXPR         3         // search stops when expression evals to non-zero
00055 
00056 typedef ht_view* (*create_form_func)(bounds *b, HT_ATOM histid);
00057 typedef void (*create_desc_func)(char *buf, int buflen, ht_view *form);
00058 
00059 /*
00060  *      CLASS ht_fxbin_search_request
00061  */
00062  
00063 class ht_fxbin_search_request: public ht_search_request {
00064 public:
00065         UINT data_size;
00066         byte *data;
00067         
00068                         ht_fxbin_search_request(UINT search_class, UINT flags, UINT data_size, byte *data);
00069         virtual ~ht_fxbin_search_request();
00070 /* overwritten */
00071         virtual Object *duplicate();
00072 };
00073 
00074 /*
00075  *      CLASS ht_regex_search_request
00076  */
00077  
00078 class ht_regex_search_exception: public ht_exception {
00079 protected:
00080         char rxerr[128];
00081 public:
00082         int errorcode;
00083         regex_t *regex;
00084         
00085         ht_regex_search_exception(int e, regex_t *r);
00086         virtual const char *what();
00087 };
00088 
00089 class ht_regex_search_request: public ht_search_request {
00090 public:
00091         char *rx_str;
00092         regex_t rx;
00093 
00094                         ht_regex_search_request(UINT search_class, UINT flags, char *regex);
00095         virtual ~ht_regex_search_request();
00096 /* overwritten */
00097         virtual Object *duplicate();
00098 };
00099 
00100 /*
00101  *      CLASS ht_expr_search_request
00102  */
00103 
00104 class ht_expr_search_request: public ht_search_request {
00105 public:
00106         char *expr;
00107 
00108                         ht_expr_search_request(UINT search_class, UINT flags, char *Expr);
00109         virtual ~ht_expr_search_request();
00110 /* overwritten */
00111         virtual Object *duplicate();
00112 };
00113 
00114 /* binary search function */
00115 
00116 /*
00117  *      CLASS ht_hexascii_search_form
00118  */
00119  
00120 struct ht_hexascii_search_form_data {
00121         ht_strinputfield_data str;
00122         ht_hexinputfield_data hex;
00123         ht_strinputfield_data start;
00124         ht_strinputfield_data end;
00125         ht_checkboxes_data options;
00126 };
00127 
00128 class ht_hexascii_search_form: public ht_group {
00129 protected:
00130         ht_strinputfield *str;
00131         ht_strinputfield *range_start;
00132         ht_strinputfield *range_end;
00133         ht_checkboxes *option_boxes;
00134 public:
00135                         void init(bounds *b, int options, ht_list *history=0);
00136 };
00137 
00138 /*
00139  *      CLASS ht_evalstr_search_form
00140  */
00141 
00142 struct ht_evalstr_search_form_data {
00143         ht_strinputfield_data str;
00144         ht_strinputfield_data start;
00145         ht_strinputfield_data end;
00146         ht_checkboxes_data options;
00147 };
00148 
00149 class ht_evalstr_search_form: public ht_group {
00150 protected:
00151         ht_strinputfield *str;
00152         ht_strinputfield *range_start;
00153         ht_strinputfield *range_end;
00154         ht_checkboxes *option_boxes;
00155 public:
00156                         void    init(bounds *b, int options, ht_list *history=0);
00157 };
00158 
00159 /*
00160  *      CLASS ht_vregex_search_form
00161  */
00162 
00163 struct ht_vregex_search_form_data {
00164         ht_strinputfield_data str;
00165         ht_strinputfield_data start;
00166         ht_strinputfield_data end;
00167         ht_checkboxes_data options;
00168 };
00169 
00170 class ht_vregex_search_form: public ht_group {
00171 protected:
00172         ht_strinputfield *str;
00173         ht_strinputfield *range_start;
00174         ht_strinputfield *range_end;
00175         ht_checkboxes *option_boxes;
00176 public:
00177                         void    init(bounds *b, int options, ht_list *history=0);
00178 };
00179 
00180 /*
00181  *      CLASS ht_expr_search_form
00182  */
00183 
00184 struct ht_expr_search_form_data {
00185         ht_strinputfield_data str;
00186         ht_strinputfield_data start;
00187         ht_strinputfield_data end;
00188         ht_checkboxes_data options;
00189 };
00190 
00191 class ht_expr_search_form: public ht_group {
00192 protected:
00193         ht_strinputfield *str;
00194         ht_strinputfield *range_start;
00195         ht_strinputfield *range_end;
00196         ht_checkboxes *option_boxes;
00197 public:
00198                         void    init(bounds *b, int options, ht_list *history=0);
00199 };
00200 
00201 /*
00202  *      CLASS ht_replace_hexascii_search_form
00203  */
00204  
00205 struct ht_replace_hexascii_search_form_data {
00206         ht_strinputfield_data str;
00207         ht_hexinputfield_data hex;
00208 };
00209 
00210 class ht_replace_hexascii_search_form: public ht_group {
00211 protected:
00212         ht_strinputfield *str;
00213 public:
00214                         void init(bounds *b, int options, ht_list *history=0);
00215 };
00216 
00217 /*
00218  *      CLASS ht_search_dialog
00219  */
00220 
00221 struct ht_search_dialog_mode {
00222         int id;
00223         ht_view *view;
00224 };
00225 
00226 #define MAX_SEARCH_DIALOG_MODES 16
00227 
00228 class ht_search_dialog: public ht_dialog {
00229 protected:
00230         ht_listpopup *search_mode_popup;
00231 
00232         int smodeidx;
00233         int smodecount;
00234         ht_search_dialog_mode smodes[MAX_SEARCH_DIALOG_MODES];
00235 
00236         int find_search_mode(int id);
00237         void select_search_mode_bymodeidx();
00238 public:
00239         ht_xgroup *search_mode_xgroup;
00240         
00241                         void    init(bounds *b, const char *title);
00242         virtual void    done();
00243 /* overwritten */
00244         virtual void handlemsg(htmsg *msg);
00245 /* new */
00246                         void insert_search_mode(int id, char *desc, ht_view *v);
00247                         void select_search_mode(int id);
00248                         ht_view *get_search_modeform();
00249                         int get_search_modeid();
00250 };
00251 
00252 /*
00253  *      CLASS ht_replace_dialog
00254  */
00255 
00256 #define MAX_REPLACE_DIALOG_MODES 16
00257 
00258 class ht_replace_dialog: public ht_search_dialog {
00259 protected:
00260         ht_listpopup *replace_mode_popup;
00261 
00262         int rmodeidx;
00263         int rmodecount;
00264         ht_search_dialog_mode rmodes[MAX_REPLACE_DIALOG_MODES];
00265 
00266         int find_replace_mode(int id);
00267         void select_replace_mode_bymodeidx();
00268 public:
00269         ht_xgroup *replace_mode_xgroup;
00270         
00271                         void    init(bounds *b);
00272         virtual void    done();
00273 /* overwritten */
00274         virtual void handlemsg(htmsg *msg);
00275 /* new */
00276                         void insert_replace_mode(int id, char *desc, ht_view *v);
00277                         void select_replace_mode(int id);
00278                         ht_view *get_replace_modeform();
00279                         int get_replace_modeid();
00280 };
00281 
00282 
00283 /*
00284  *
00285  */
00286  
00287 #define SEARCHMODE_BIN          1
00288 #define SEARCHMODE_EVALSTR      2
00289 #define SEARCHMODE_VREGEX       4
00290 #define SEARCHMODE_EXPR         8
00291 
00292 ht_search_request *search_dialog(ht_format_viewer *format, UINT searchmodes, viewer_pos *start, viewer_pos *end);
00293 UINT replace_dialog(ht_format_viewer *format, UINT searchmodes, bool *cancelled);
00294 
00295 class ht_search_bin_context: public Object {
00296 public:
00297         ht_streamfile *file;
00298         bool file_end;
00299         UINT flags;
00300         
00301         FILEOFS ofs;
00302         UINT len;
00303 
00304         byte *pat;
00305         UINT patlen;
00306 
00307         FILEOFS o;
00308         UINT c;
00309         
00310         byte *buf;
00311         byte *bufptr;
00312 
00313         bool *return_success;
00314         FILEOFS *return_ofs;
00315         
00316         ~ht_search_bin_context();
00317 };
00318 
00319 // flags
00320 #define SFBIN_CASEINSENSITIVE   1
00321 
00322 Object* create_search_bin_context(ht_streamfile *file, FILEOFS ofs, UINT len, byte *pat, UINT patlen, UINT flags, UINT *return_ofs, bool *return_success);
00323 bool search_bin_process(Object *context, ht_text *progress_indicator);
00324 
00325 ht_view* create_form_hexascii(bounds *b, HT_ATOM histid);
00326 void create_desc_hexascii(char *buf, int buflen, ht_view *f);
00327 
00328 ht_search_result *linear_bin_search(ht_search_request *search, FILEOFS start, FILEOFS end, ht_streamfile *file, FILEOFS fofs, dword fsize);
00329 
00330 /*
00331  *
00332  */
00333 
00334 class ht_replace_bin_context: public Object {
00335 public:
00336         ht_streamfile *file;
00337 
00338         FILEOFS ofs;
00339         UINT len;
00340         
00341         UINT repllen;
00342         byte *repl;
00343 
00344         FILEOFS o;
00345         UINT z;
00346         byte *buf;
00347         
00348         UINT *return_repllen;
00349 
00350         ~ht_replace_bin_context();
00351 };
00352  
00353 Object* create_replace_bin_context(ht_streamfile *file, FILEOFS ofs, UINT len, byte *repl, UINT repllen, UINT *return_repllen);
00354 bool replace_bin_process(Object *context, ht_text *progress_indicator);
00355 
00356 #endif /* __HTSEARCH_H__ */

Generated on Fri May 7 21:15:37 2004 by doxygen 1.3.5