Author Topic: Hex Data to usefull information  (Read 5522 times)

sjeeva

  • Junior Community Member
  • Posts: 4
  • Hero Points: 0
Hex Data to usefull information
« on: November 17, 2006, 10:47:29 PM »
Often time I deal with hex data files like below, which mapped to some meaning full information.

[01-30-1991 22:22:10][108740] -  ----- Tag 0 -----
[01-30-1991 22:22:10][108740] -  tag                 0x008E0011
[01-30-1991 22:22:10][108740] -  tag                 0x008E0021
[01-30-1991 22:22:10][108740] -  tag                 0x008E001C

Is there way I could map the hex value to the use information and show them when I hover the mouse over it like a function help?
TIA!
Jeeva

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: Hex Data to usefull information
« Reply #1 on: November 21, 2006, 02:29:30 PM »
I've used this macro before to display a tooltip message display the base on the current word at the cursor position.  The tooltip is dismissed by any key or mouse event once it is displayed.  I used on a key binding rather than trying to implement it through the mouse handler.  To use as a hover over, it would required modifiying the global _mouse_move() (macros/mouse.e) handler.  It could be done, there would be additional work to implement it using just the mouse.
Just bind all_your_base to a key to use.
Code: [Select]
#include 'slick.sh'
#pragma option(strict,on)

static boolean ishexnum(_str num)
{
   boolean out = false;
   int start = length(num);
   int i = start;
   for (i = start; i > 0; --i) {
      if (out) {
         return false;
      }
      _str ch = lowcase(substr(num,i,1));
      if (! (isdigit(ch) || ch == 'a' || ch == 'b' || ch == 'c' || ch == 'd' || ch == 'e' || ch == 'f')) {
         out = true;
      }
      if (ch == 'x' || ch == 'X') {
         if (i == 1 || (substr(num, i-1, 1) == 0 && i - 1 == 1)) {
            return true;
         }
      }
   }
   return true;
}

_command void all_your_base() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
   int old_col = p_col;
   int start_col = 0;
   _str word = cur_word(start_col);
   if (word == "") {
      message("No word at cursor");
      return;
   }

   int number;
   if (isnumber(word)) {
      number = (int)word;
   } else if (ishexnum(word)) {
      number = (int)hex2dec(word);
   } else {
      message("Not a number");
      return;
   }

   _str msg = number :+ " : " :+
              dec2hex(number) :+ " : " :+
              dec2hex(number, 8) :+ " : " :+
              dec2hex(number, 2);
   p_col = start_col;
   int x = p_cursor_x;
   int y = p_cursor_y + p_font_height;
   _map_xy(p_window_id, 0, x, y);
   _bbhelp('M', p_window_id, x, y, msg);
   p_col = old_col;
   for(;;) {
      typeless event = get_event();
      if (event != "") {
         break;
      }
   }
   _bbhelp('C');
}


You could alternatively just use the message() instead of _bbhelp() function to display the text on the status line rather than using a tooltip message. 

Tested in 11.0.2 version.