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

htleimg.cc

Go to the documentation of this file.
00001 /*
00002  *      HT Editor
00003  *      htleimg.cc
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 #include "log.h"
00022 #include "htnewexe.h"
00023 #include "htpal.h"
00024 #include "htleimg.h"
00025 #include "htsearch.h"
00026 #include "htstring.h"
00027 #include "formats.h"
00028 #include "tools.h"
00029 
00030 #include "lestruct.h"
00031 
00032 #include "htanaly.h"
00033 #include "le_analy.h"
00034 
00035 static ht_view *htleimage_init(bounds *b, ht_streamfile *file, ht_format_group *group)
00036 {
00037         ht_le_shared_data *le_shared=(ht_le_shared_data *)group->get_shared_data();
00038 
00039         ht_streamfile *myfile = le_shared->reloc_file;
00040 
00041         LOG("%s: LE: loading image (starting analyser)...", file->get_filename());
00042         LEAnalyser *p = new LEAnalyser();
00043         p->init(le_shared, myfile);
00044 
00045         bounds c = *b;
00046         ht_group *g = new ht_group();
00047         g->init(&c, VO_RESIZE, DESC_LE_IMAGE"-g");
00048         AnalyInfoline *head;
00049 
00050         c.y += 2;
00051         c.h -= 2;
00052         ht_le_aviewer *v = new ht_le_aviewer();
00053         v->init(&c, DESC_LE_IMAGE, VC_EDIT | VC_GOTO | VC_SEARCH, myfile, group, p, le_shared);
00054         v->search_caps = SEARCHMODE_VREGEX;
00055 
00056         c.y -= 2;
00057         c.h = 2;
00058         head = new AnalyInfoline();
00059         head->init(&c, v, ANALY_STATUS_DEFAULT);
00060 
00061         v->attachInfoline(head);
00062 
00063 /* search for lowest/highest */
00064         LEAddress l=(LEAddress)-1, h=0;
00065         LE_OBJECT *s = le_shared->objmap.header;
00066         for (UINT i=0; i<le_shared->objmap.count; i++) {
00067                 LEAddress base = LE_MAKE_ADDR(le_shared, i, 0);
00068                 UINT evsize = MAX(LE_get_seg_vsize(le_shared, i), LE_get_seg_psize(le_shared, i));
00069                 if (base < l) l = base;
00070                 if ((base + evsize > h) && (evsize)) h = base + evsize - 1;
00071                 s++;
00072         }
00073 
00074         Address *low = p->createAddressFlat32(l);
00075         Address *high = p->createAddressFlat32(h);
00076         ht_analy_sub *analy = new ht_analy_sub();
00077         analy->init(myfile, v, p, low, high);
00078         v->analy_sub = analy;
00079         v->insertsub(analy);
00080         delete high;
00081         delete low;
00082 
00083         v->sendmsg(msg_complete_init, 0);
00084 
00085         g->insert(head);
00086         g->insert(v);
00087 
00088         g->setpalette(palkey_generic_window_default);
00089 
00090         le_shared->v_image = v;
00091         return g;
00092 }
00093 
00094 format_viewer_if htleimage_if = {
00095         htleimage_init,
00096         0
00097 };
00098 
00099 /*
00100  *      CLASS ht_le_aviewer
00101  */
00102 
00103 void ht_le_aviewer::init(bounds *b, char *desc, int caps, ht_streamfile *File, ht_format_group *format_group, Analyser *Analy, ht_le_shared_data *LE_shared)
00104 {
00105         ht_aviewer::init(b, desc, caps, File, format_group, Analy);
00106         le_shared = LE_shared;
00107         file = File;
00108 }
00109 
00110 char *ht_le_aviewer::func(UINT i, bool execute)
00111 {
00112         switch (i) {
00113                 case 3: {
00114                         bool e = false;
00115                         file->cntl(FCNTL_GET_RELOC, &e);
00116                         if (execute) {
00117                                 file->cntl(FCNTL_SET_RELOC, !e);
00118                                 analy_sub->output->invalidateCache();
00119                                 dirtyview();
00120                         }
00121                         return e ? (char*)"unrelocate" : (char*)"relocate";
00122                 }
00123         }
00124         return ht_aviewer::func(i, execute);
00125 }
00126 
00127 bool ht_le_aviewer::offset_to_pos(FILEOFS ofs, viewer_pos *p)
00128 {
00129         if (!analy) return false;
00130         Address *a = ((LEAnalyser*)analy)->realFileofsToAddress(ofs);
00131         bool res = convertAddressToViewerPos(a, p);
00132         delete a;
00133         return res;
00134 }
00135 
00136 bool ht_le_aviewer::pos_to_offset(viewer_pos p, FILEOFS *ofs)
00137 {
00138         if (analy) {
00139                 Address *addr;
00140                 if (!convertViewerPosToAddress(p, &addr)) return false;
00141                 FILEOFS o=((LEAnalyser*)analy)->addressToRealFileofs(addr);
00142                 delete addr;
00143                 if (o!=INVALID_FILE_OFS) {
00144                         *ofs=o;
00145                         return true;
00146                 }
00147         }
00148         return false;
00149 }
00150 
00151 bool ht_le_aviewer::get_current_real_offset(FILEOFS *ofs)
00152 {
00153         FILEOFS o;
00154         if (!get_current_offset(&o)) return false;
00155         UINT m;
00156         if (!le_shared->linear_file->map_ofs(o, ofs, &m)) return false;
00157         return true;
00158 }
00159 
00160 void ht_le_aviewer::setAnalyser(Analyser *a)
00161 {
00162         ((LEAnalyser*)a)->le_shared = le_shared;
00163         ((LEAnalyser*)a)->file = file;
00164         analy = a;
00165         analy_sub->setAnalyser(a);
00166 }

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