home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 09 / brief.lst < prev    next >
File List  |  1991-08-21  |  24KB  |  648 lines

  1. _A BRIEF MACRO PACKAGE FOR EDITING BINARY FILES_
  2. by James Rodriguez
  3.  
  4.  
  5. [LISTING ONE]
  6.  
  7. /¬ _ini⌠ _hex_edi⌠ _bin_oε _bin_ofµ _bin_mousσ write_buffe≥ */
  8.  
  9. #define HEX
  10.  
  11. #define SHOW_DELAY 50
  12. #define UP        -11
  13. #define DOWN       11
  14. #define LEFT       -1
  15. #define RIGHT       1
  16. #define PGUP      -21
  17. #define PGDN       21
  18. #define TOP        30
  19. #define BOTTOM    -31
  20. #define HOME      -40
  21. #define END       -41
  22.  
  23. extern   _package_buf,  delete_curr_buffer;
  24.  
  25. int  __hex_files, __bin_keyboard, __hex_window, __asc_window, __unix_files;
  26. _init ()
  27. {  __hex_files  = create_buffer ("HEXFILES", NULL, 1);  //Binary file database
  28.    __unix_files = create_buffer ("UNIXFILE", NULL, 1);  //Unix file database
  29.    register_macro (6, "_bin_edit");
  30.    keyboard_push ();                   // Create a new keyboard
  31.    set_mouse_action("_bin_mouse");     // Define the mouse handler
  32.    add_hex_keys();                     // Add key assignments
  33.    __bin_keyboard = inq_keyboard ();   // Store the keyboard identifier
  34.    keyboard_pop (1);                   // Reset the stack
  35. }
  36. // _hex_edit: associates a system buffer with a hex buffer and modifies
  37. //            the package information for .HEX files. Called by _bin_edit. 
  38. void _hex_edit (string file_name, int in_memory)
  39. {  int   __hex_buffer, __asc_buffer, tmp_buf, current_buffer;
  40.    string   buffer_name, file_ext, buffer_id, file_path;
  41.    global   __hex_buffer, __asc_buffer;
  42.  
  43.    if (get_parm (0, file_name))
  44.    { get_parm (1, in_memory);   //  Check any flag passed
  45.      if (index (file_name, "."))
  46.      { file_ext  = substr (file_name, 1 + rindex (file_name, "."));
  47.        file_name = substr (file_name, 1,  rindex (file_name, ".") - 1);
  48.      }
  49.      else  file_ext = "";
  50.      buffer_name = substr (file_name, rindex (file_name, "\\") + 1);
  51.      current_buffer = inq_buffer ();
  52.      if (inq_called () == "_bin_edit")
  53.        delete_buffer (current_buffer);
  54.      // Error check for bad buffer name                                     
  55.      tmp_buf = create_buffer (buffer_name + ".hex", file_name + ".hex", 0);
  56.      if (tmp_buf)
  57.      { set_buffer (__hex_files);
  58.        top_of_buffer ();
  59.        if (search_fwd (file_name + ",", 0, 0))
  60.          edit_file (file_name + ".hex");        // It's already in a buffer
  61.        else
  62.        { delete_buffer (tmp_buf);
  63.          sprintf (file_path, "bbe BH %s.%s %s.hex %s.asc>&nul", file_name,
  64.             file_ext, file_name, file_name);
  65.          // Do the hex files already exist?
  66.          if (!exist (file_name + ".hex") && !exist (file_name + ".asc"))
  67.          {  message ("Generating hex file");
  68.             dos (file_path);  // spawn standalone program to convert file
  69.          }
  70.          else
  71.             message ("Editing existing files.");
  72.          __hex_buffer = create_buffer (buffer_name + ".hex", file_name + 
  73.             ".hex", 0);
  74.          __asc_buffer = create_buffer (buffer_name + ("." + file_ext), 
  75.             file_name + ".asc", 1);
  76.          // Save info in the database for later.
  77.          sprintf (buffer_id, "oldb=%10d,newb=%10d,file=%s,ext=%s", 
  78.             __hex_buffer, __asc_buffer, file_name, file_ext);
  79.          set_buffer (__hex_files);
  80.          beginning_of_line ();
  81.          insert (buffer_id + "\n");
  82.          set_buffer (__hex_buffer);
  83.          top_of_buffer ();
  84.          drop_anchor ();
  85.          move_rel (0, 1);
  86.          // Access the package buffer and configure for the hex extension.
  87.          if (first_time ())
  88.          {  if (!_package_buf)   load_macro ("language");
  89.             set_buffer (_package_buf);
  90.             top_of_buffer ();
  91.             while (search_fwd ("<.hex", 1, 0))
  92.               delete_line ();
  93.             // Add the correct lines in packages to make this work.
  94.             insert (".hex_equivalents\n");
  95.             insert (".hex_new;\n");
  96.             insert (".hex_existing;\n");
  97.             insert (".hex_first;\n");
  98.             insert (".hex_on;_on,_bin_on\n"); // Enabled _bin_on
  99.             insert (".hex;=hex,,=hex\n");
  100.             top_of_buffer ();                                             
  101.          }
  102.          set_buffer (__hex_buffer);
  103.          if (! in_memory)
  104.             call_registered_macro (1);
  105.        }
  106.      }
  107.    }
  108. }
  109. // _bin_on:  edits the hex and ascii files in side by side windows by creating
  110. // and moving an edge. Insures correct local keyboard by setting it explicitly.
  111. // Looks in hex_files buffer for filename and extract buffer ids. Associate 
  112. // buffers with windows and return.
  113. string _bin_on ()
  114. {  int   i;
  115.    string   buf_to_find,  exten;
  116.    inq_names (buf_to_find, exten);
  117.    buf_to_find = substr (buf_to_find, 1, (rindex (buf_to_find, exten) - 
  118.                                                        strlen (exten)) + 1);
  119.    i = inq_buffer();
  120.    set_buffer (__hex_files);  // Edit the system buffer to find buffer id's.
  121.    top_of_buffer ();
  122.    if (search_fwd (buf_to_find + ",", 0, 0))  // Find the line with filename.
  123.    {                                          
  124.      keyboard_flush();                // Remove any pending keystrokes
  125.      use_local_keyboard (0);          // Detach the local keyboard
  126.      keyboard_push (__bin_keyboard);  // Activate the hex keyboard
  127.      set_mouse_action("_bin_mouse");  // Attach the mouse event handler
  128.      beginning_of_line ();
  129.      buf_to_find = trim (read ());    // Parse out the buffer ids
  130.      buf_to_find = ltrim (substr (buf_to_find, index (buf_to_find, "oldb=")
  131.                                                            + 5, 10));
  132.      __hex_buffer = atoi (buf_to_find, 1);
  133.      beginning_of_line ();
  134.      buf_to_find = read ();
  135.      buf_to_find = ltrim (substr (buf_to_find, index (buf_to_find, "newb=")
  136.                                                          + 5, 10));
  137.      __asc_buffer = atoi (buf_to_find, 1);
  138.      set_buffer (__hex_buffer);
  139.      // Unregister the registered macro so a recursive situation does not
  140.      // arise from the window manipulations.
  141.      unregister_macro (1, "_call_on_packages");
  142.      create_edge (3);
  143.      __hex_window = inq_window ();
  144.      move_edge (1, 12);
  145.      change_window (1);
  146.      __asc_window = inq_window ();
  147.      attach_buffer (__asc_buffer);  // Attach the system buffer to a window
  148.      if (!inq_marked ())
  149.           drop_anchor (2);
  150.      else
  151.           refresh ();                                                     
  152.      refresh ();
  153.      change_window (3);
  154.      register_macro (1, "_call_on_packages"); // Enable the language macro.
  155.      returns "_bin_off"; // Return the off event for the language package.
  156.      }
  157.    else
  158.    { set_buffer(i); // This is an error check to allow editing
  159.      returns "";    // of files with .hex extensions which are not
  160.    }                // under the binary package control.
  161. }
  162. // _bin_off --  deletes the created window and resets the keyboard.
  163. void _bin_off ()
  164. {  keyboard_flush();
  165.    keyboard_pop ();
  166.    keyboard_push ();
  167.    add_hex_keys();
  168.    __bin_keyboard = inq_keyboard ();
  169.    delete_edge (1);   // Delete the window
  170.    keyboard_pop (1);
  171.    set_mouse_action("_mouse_action"); // Reset the mouse handler
  172. }
  173. #define BUTTON_1_CLICK     10
  174. #define BUTTON_2_CLICK     11
  175. #define BUTTON_1_DBLCLK    13
  176. #define BUTTON_2_DBLCLK    14
  177. #define VERTICAL_SCROLL    17
  178. #define CLOSE_WINDOW       19
  179. #define SET_WINDOW         20
  180. #define STATUS_AREA        21
  181. #define SCROLLBAR__LINEUP   0
  182. #define SCROLLBAR__LINEDOWN 1
  183. #define SCROLLBAR__PAGEUP   2
  184. #define SCROLLBAR__PAGEDOWN 3
  185. #define SCROLLBAR__TOP      6
  186. #define SCROLLBAR__BOTTOM   7
  187. #define TITLE_BAR           1
  188.  
  189. void _bin_mouse(int action, int modifier, int line, int col)
  190. { if (inq_window() == __asc_window)
  191.        col = col*2; // Modify the column parameter if clicked in ascii window
  192.    switch (action)
  193.    {
  194.      case STATUS_AREA:   // Go to offset on status area click
  195.        execute_macro(inq_assignment("<Alt-g>"));
  196.      case SET_WINDOW:     // A different window was selected
  197.      {
  198.        if (col!=TITLE_BAR && line == __asc_window)  // Disregard mouse action
  199.        {                                            // on the border.
  200.          unregister_macro (1, "_call_on_packages");
  201.          set_window (__asc_window);
  202.        }
  203.      }
  204.      case BUTTON_2_CLICK:
  205.      case BUTTON_2_DBLCLK:
  206.      case BUTTON_1_CLICK:
  207.      case BUTTON_1_DBLCLK:                                           
  208.      { int lines,cols;
  209.        if (col % 2)    // Modify column parameter to event byte value
  210.          col++;
  211.        if (col > 50)   // If past formatted string length go to the end of
  212.          col = 50;     // the string.
  213.        unregister_macro (1, "_call_on_packages");
  214.        set_window (__hex_window);
  215.        inq_position(lines, cols);
  216.        raise_anchor ();
  217.        move_rel(0,-1);
  218.        save_position();
  219.        if (move_abs(line,col))
  220.        {
  221.          // If beyond the end of buffer ignore the action
  222.          if (! inq_position(lines,cols) && lines==line && cols == col)
  223.          {  restore_position(0);
  224.             move_rel(0,-1);
  225.             set_window (__asc_window);
  226.             raise_anchor ();
  227.             move_abs(line,col / 2);
  228.             drop_anchor (2);
  229.             refresh ();
  230.             set_window (__hex_window);
  231.          }
  232.          else
  233.             restore_position();
  234.        }
  235.        else
  236.           restore_position();
  237.        drop_anchor ();
  238.        move_rel (0, 1);
  239.        register_macro (1, "_call_on_packages");
  240.        refresh ();
  241.        switch (action)
  242.        {
  243.          case BUTTON_2_DBLCLK:  // Opens a line (feature not shown)
  244.          {  execute_macro(inq_assignment("<Ctrl-Enter>"));
  245.          }
  246.          case BUTTON_1_DBLCLK: // Double click modifies current byte.
  247.          {  string sread, character;
  248.             int hex_val;
  249.             raise_anchor ();
  250.             move_rel (0, -1);
  251.             sread = "Enter new value for ";
  252.             if (read (1) != "\n")
  253.               sread += read (2);
  254.             sread += ": ";
  255.             if (get_parm (NULL, character, sread, 2))
  256.             { hex_val = _bin_atoh (character);
  257.               sprintf (character, "%02x", hex_val); // Convert int to hex 
  258.               unregister_macro (1, "_call_on_packages");
  259.               set_window (__asc_window);
  260.               switch (hex_val) // Make sure the value is displayable.  
  261.               { case 13:
  262.                 case 9:
  263.                 case 0:
  264.                     sread = ".";
  265.                 default:
  266.                     sprintf (sread, "%c", hex_val);
  267.                 }
  268.               /* Insert the value in the hex and ascii buffers
  269.               ** rehighlight both windows and return. */
  270.               insert ("%s", sread);
  271.               raise_anchor ();
  272.               delete_char ();
  273.               move_rel (0, -1);
  274.               drop_anchor (2);
  275.               refresh ();
  276.               set_window (__hex_window);
  277.               insert ("%s", upper (character));
  278.               delete_char (2);
  279.               move_rel (0, -2);
  280.             }
  281.             drop_anchor ();
  282.             move_rel (0, 1);
  283.             refresh ();
  284.             register_macro (1, "_call_on_packages");
  285.             refresh ();
  286.          }
  287.        }
  288.      }
  289.      case VERTICAL_SCROLL:  // Vertical scroll bar events.
  290.      {
  291.        switch (line)
  292.        {
  293.          case SCROLLBAR__LINEUP:               // Click on up arrow
  294.             execute_macro(inq_assignment("<Left>"));
  295.          case SCROLLBAR__LINEDOWN:             // Click on down arrow
  296.             execute_macro(inq_assignment("<Right>"));
  297.          case SCROLLBAR__PAGEUP:               // Click above thumb button
  298.             execute_macro(inq_assignment("<PgUp>"));
  299.          case SCROLLBAR__PAGEDOWN:             // Click below thumb button
  300.             execute_macro(inq_assignment("<PgDn>"));
  301.          case SCROLLBAR__TOP:               // Double click on up arrow
  302.             execute_macro(inq_assignment("<Ctrl-PgUp>"));
  303.          case SCROLLBAR__BOTTOM:               // Double click on down arrow
  304.             execute_macro(inq_assignment("<Ctrl-PgDn>"));
  305.        }
  306.      }
  307.    }
  308. }
  309. // write_buffer:  A replacement for write_buffer. Checks file extension, cleans
  310. // up system buffers. Note: conversion back to binary is not done if buffer 
  311. // has not been modified.
  312. replacement int write_buffer ()
  313. {
  314.    int   buf_to_edit, buf_to_delete, file_is_controlled, file_was_modified;
  315.    string   file_name, ext, response, response2, old_buffer, write_command;
  316.    inq_names (file_name, ext);                                        
  317.    /* if write_buffer was not called from the keyboard and the extension
  318.    ** isn't .hex or .unx call write_buffer. */
  319.    if ("" == inq_called () && (ext == "hex" || ext == "unx"))
  320.      if (get_parm (0, response, "Convert file? ", 1, "Y"))
  321.        if (get_parm (1, response2, "Delete buffer? ", 1, "Y"))
  322.        { int   file_is_hex;
  323.          file_is_hex = 0;
  324.          buf_to_edit = inq_buffer (); // Store the current buffer id
  325.          raise_anchor ();         // Remove the highlight
  326.          if (inq_modified ())  // Only write and convert if changed
  327.          {
  328.             returns write_buffer ();  // Preserve the return value
  329.             file_was_modified = 1;
  330.          }
  331.          else
  332.             file_was_modified = 0; // if not changed don't reconvert
  333.          // Remove the extension.
  334.          if (index (file_name, "."))
  335.             file_name = substr (file_name, 1, rindex (file_name, ".") - 1);
  336.          // Make the system buffer database current
  337.          if (ext == "hex")
  338.          {
  339.             set_buffer (__hex_files);
  340.             file_is_hex = 1;
  341.          }
  342.          else
  343.             set_buffer (__unix_files); // Not used in this example
  344.          top_of_buffer ();
  345.          // Try to find filename record and extract original extension.
  346.          if (search_fwd (file_name + ",ext=", 0, 0))
  347.          {  beginning_of_line ();
  348.             ext = trim (read ());
  349.             file_is_controlled=1;
  350.             // Find the ascii buffer associated with the hex buffer
  351.             if (file_is_hex)
  352.             { int temp_buffer=inq_buffer();
  353.               ext = ltrim (substr (ext, index (ext, "newb=") + 5));
  354.               old_buffer = substr (ext, 1, 10);
  355.               // Retrieve the buffer id
  356.               buf_to_delete = atoi (old_buffer, 1);
  357.               set_buffer(buf_to_delete);
  358.               raise_anchor();
  359.               write_buffer();
  360.               drop_anchor(2);
  361.               set_buffer(temp_buffer);                                 
  362.               if (upper (response2) == "Y")
  363.                 delete_buffer (buf_to_delete);
  364.             }
  365.             ext = trim (substr (ext, rindex (ext, "=") + 1));
  366.             beginning_of_line ();
  367.             if (upper (response2) == "Y")
  368.               delete_line (); // Delete the record
  369.          }
  370.          // Reset the current buffer
  371.          set_buffer (buf_to_edit);
  372.          if (file_is_hex)
  373.             sprintf (write_command, "bbe HB %s.hex %s.%s>&nul", file_name, 
  374.               file_name, ext);
  375.          else
  376.             sprintf (write_command, "bbe DU %s.unx %s.%s>&nul", file_name, 
  377.               file_name, ext);
  378.          if (file_was_modified && upper (response) == "Y" && 
  379.             file_is_controlled)
  380.          {
  381.             message ("%s", write_command);
  382.             dos (write_command);        // Call DOS to execute the conversion
  383.             message ("Conversion complete");
  384.          }
  385.          // Delete the current buffer and the converted file(s).
  386.          if (upper (response2) == "Y")
  387.          {
  388.             if (1 != delete_curr_buffer())
  389.             {
  390.               file_is_controlled=-1;
  391.               delete_buffer(buf_to_edit);
  392.             }
  393.             if (file_is_hex)
  394.             {
  395.               sprintf (response, "%s.hex", file_name);
  396.               del (response);
  397.               sprintf (response, "%s.asc", file_name);
  398.             }
  399.             else
  400.               sprintf (response, "%s.unx", file_name);
  401.             del (response);
  402.             if (file_is_controlled == -1)  // No other buffers
  403.               exit("y");
  404.          }
  405.          else
  406.             if (file_is_hex && file_is_controlled)
  407.             {
  408.               move_rel (0, -1);
  409.               drop_anchor ();
  410.               move_rel (0, 1);
  411.             }
  412.          }
  413.        else ;
  414.      else ;
  415.    else // Call the primitive
  416.      return write_buffer ();
  417. }
  418.  
  419.  
  420. [LISTING TWO]
  421.  
  422. /* _bin_add _bin_atoh add_hex_keys _bin_edit _bin_delete */
  423.  
  424. // _bin_move -- this macro handles synchronized positioning.
  425. void _bin_move (int direction)
  426. {  int   col, line;
  427.    get_parm(0,direction);
  428.    raise_anchor ();
  429.    unregister_macro (1, "_call_on_packages");  // Remove the language control
  430.    set_window (__asc_window);
  431.    raise_anchor ();
  432.    inq_position (line, col);
  433.    switch (direction)
  434.    { case LEFT:
  435.      case RIGHT:
  436.      {
  437.        if ((col == 25 && direction == RIGHT) || (col==1 && direction==LEFT))
  438.        {  // Scrolling is needed
  439.          move_rel (direction,0);
  440.          col = (direction == LEFT ? 25 : 1);
  441.          move_abs (0,col);
  442.        }
  443.        else
  444.          move_rel (0,direction);
  445.      }
  446.      case UP:
  447.      case DOWN:
  448.        move_rel (direction % 10,0);
  449.      case PGUP:
  450.      case PGDN:
  451.      { inq_window_size(line);  // Get the number of lines in the window
  452.        move_rel ((direction % 20) * line,0);
  453.      }
  454.      case HOME:
  455.        move_abs(0,1); // Beginning of line
  456.      case END:
  457.        move_abs(0,25); // End of line
  458.      case TOP:
  459.          move_abs(1,1); // Top of buffer
  460.      case BOTTOM:
  461.      { end_of_buffer();
  462.        move_abs(0,25);  // End of buffer
  463.      }
  464.    }
  465.    while (inq_position (line,col))  // We might be in virtual space if
  466.      move_rel (-1, 0);           // so move up until we're not.
  467.    drop_anchor (2);
  468.    refresh ();
  469.    set_window (__hex_window);
  470.    move_abs(line,col * 2);   // Reposition in the hex buffer           
  471.    move_rel (0, -1);     // Highlight the current byte.
  472.    drop_anchor ();
  473.    move_rel (0, 1);
  474.    refresh ();
  475.    register_macro (1, "_call_on_packages");
  476. }
  477. // _bin_add: overwrites the byte in hex window. It is assigned to all of valid
  478. //  hex editing keys and uses push_back to get the original key.
  479. void _bin_add (string key_read)
  480. {  string   character,  sread;
  481.    int      hex_val, temp_hex;
  482.    // Get the parameter which is key pressed and push it back on keyboard
  483.    // buffer so that it displays in prompt as if it were typed there.
  484.    get_parm (0, key_read);
  485.    push_back (key_to_int (key_read));
  486.    raise_anchor ();
  487.    // Read the text from the buffer to display the old value at the prompt.
  488.    move_rel (0, -1);
  489.    sread = "Enter new value for ";
  490.    if (read (1) != "\n")
  491.      sread += read (2);
  492.    sread += ": ";
  493.    if (get_parm (1, character, sread, 2)) 
  494.    {                            // Limit the prompt response to two characters
  495.      hex_val = _bin_atoh(character);
  496.      sprintf (character, "%02x", hex_val); // Convert the int to hex.
  497.      unregister_macro (1, "_call_on_packages");  // Don't disturb the windows.
  498.      set_window (__asc_window);
  499.      switch (hex_val)  // Make sure the value typed is displayable
  500.      { case 13:
  501.        case 9:
  502.        case 0:
  503.          sread = ".";
  504.        default:
  505.          sprintf (sread, "%c", hex_val);
  506.      }
  507.      raise_anchor ();
  508.      delete_char ();  // Remove the old character and insert the new.
  509.      insert ("%s", sread);
  510.      move_rel(0,-1);
  511.      drop_anchor (2);
  512.      refresh ();
  513.      set_window (__hex_window);
  514.      delete_char (2); // Remove the old byte and insert the new.
  515.      insert ("%s", upper (character));
  516.      }
  517.    drop_anchor ();                                                     
  518.    move_rel (0, 1);
  519.    refresh ();
  520.    register_macro (1, "_call_on_packages"); // Reenable the language macro
  521.    refresh ();
  522.    execute_macro(inq_assignment("<Right>")); // Move to the next byte.
  523. }
  524. // _bin_delete: converts the current byte to XX which will be ignored when
  525. // reconverted. Parameter is for deleting a full line.
  526. void _bin_delete (~int line)
  527. {  get_parm(0,line);
  528.    unregister_macro (1, "_call_on_packages");
  529.    set_window (__asc_window);
  530.    raise_anchor ();
  531.    if (line)
  532.    { save_position();
  533.      move_abs(0,1);
  534.      drop_anchor(3);
  535.      translate("?",".",1,1,1,1);  // Change any character to a "."
  536.      raise_anchor ();
  537.      restore_position();
  538.    }
  539.    else
  540.    { delete_char ();
  541.      insert (".");
  542.      move_rel (0, -1);
  543.    }
  544.    drop_anchor (2);
  545.    refresh ();
  546.    set_window (__hex_window);
  547.    raise_anchor ();
  548.    if (line)
  549.    { save_position();
  550.      move_abs(0,1);
  551.      drop_anchor(3);
  552.      translate("?","X",1,1,1,1);  // Change any character to "X"
  553.      raise_anchor ();
  554.      restore_position();
  555.      move_rel (0, -1);
  556.    }
  557.    else
  558.    { move_rel (0, 1);
  559.      insert ("XX");
  560.      move_rel (0, -4);
  561.      delete_char (2);
  562.    }
  563.    drop_anchor ();
  564.    move_rel (0, 1);
  565.    register_macro (1, "_call_on_packages");
  566.    refresh ();
  567. }
  568. // _bin_atoh --  accepts a "hex" string and returns an integer.
  569. int _bin_atoh (string to_convert)
  570. {  string   str_rev;
  571.    int      converted, loop_count,  t_int;
  572.  
  573.    get_parm (0, to_convert);
  574.  
  575.    // Read a character from the end of the string and multiply
  576.    // it by the loop count which is multiplied by 16 on each iteration.
  577.    while (strlen (trim (to_convert)))
  578.    { str_rev = substr (to_convert, strlen (to_convert), 1);
  579.      t_int = index("123456789ABCDEF",upper(str_rev));
  580.      loop_count *= 16;
  581.      if (0 == loop_count)
  582.        loop_count = 1;
  583.      converted += t_int * loop_count;
  584.      to_convert = substr (to_convert, 1, strlen (to_convert) - 1);
  585.    }
  586.    return converted;
  587. }
  588. // add_hex_keys -- adds hex editing keys to the keyboard.
  589. add_hex_keys()
  590. {  string macro_name, key_name;
  591.    int loop;
  592.    for (loop=48; loop<58; loop++)   // Assign the numeric keys
  593.    {                              // to the keyboard
  594.      sprintf (key_name, "<%c>",loop);
  595.      sprintf (macro_name, "_bin_add \"%c\"",loop);
  596.      assign_to_key (key_name, macro_name);
  597.    }
  598.    for (loop=65;loop<71;loop++)  // Assign the a-f Hex keys
  599.    {                             // to the keyboard
  600.      sprintf (key_name, "<%c>",loop);
  601.      sprintf (macro_name, "_bin_add \"%c\"",loop);
  602.      assign_to_key (key_name, macro_name);
  603.      assign_to_key (lower(key_name), macro_name);
  604.    }
  605.    assign_to_key ("<Alt-n>", "edit_next_buffer");
  606.    assign_to_key ("<Alt-e>", "edit_file");
  607.    assign_to_key ("<Alt-w>", "write_buffer");
  608.    assign_to_key ("<Alt-x>", "exit");
  609.    sprintf (macro_name, "_bin_move %d", UP);
  610.    assign_to_key ("<Up>", macro_name);
  611.    sprintf (macro_name, "_bin_move %d", DOWN);
  612.    assign_to_key ("<Keypad-Enter>", macro_name);
  613.    assign_to_key ("<Down>", macro_name);
  614.    sprintf (macro_name, "_bin_move %d", LEFT);
  615.    assign_to_key ("<Left>", macro_name);
  616.    sprintf (macro_name, "_bin_move %d", RIGHT);
  617.    assign_to_key ("<Right>", macro_name);
  618.    sprintf (macro_name, "_bin_move %d", PGUP);
  619.    assign_to_key ("<PgUp>", macro_name);
  620.    sprintf (macro_name, "_bin_move %d", PGDN);
  621.    assign_to_key ("<PgDn>", macro_name);
  622.    sprintf (macro_name, "_bin_move %d", TOP);
  623.    assign_to_key ("<Ctrl-Pgup>", macro_name);
  624.    sprintf (macro_name, "_bin_move %d", BOTTOM);                       
  625.    assign_to_key ("<Ctrl-PgDn>", macro_name);
  626.    sprintf (macro_name, "_bin_move %d", HOME);
  627.    assign_to_key ("<Home>", macro_name);
  628.    sprintf (macro_name, "_bin_move %d", END);
  629.    assign_to_key ("<End>", macro_name);
  630. }
  631. // _bin_edit -- registered macro for trapping Null files message.
  632. void _bin_edit ()
  633. {  if (inq_message () == "Null characters in file fixed.")
  634.    { string   okay;
  635.      string   file;
  636.      inq_names (file);
  637.      // See if the conversion is requested.
  638.      if (get_parm (0, okay, "Okay to create HEX file to edit? ", 1, "Y"))
  639.        if (upper (okay) == "Y")
  640.          _hex_edit (file, 0); // Call _hex_edit to do conversion
  641.        else // Other wise let the user frustrate themselves.
  642.          message ("You asked for it.");
  643.    }
  644. }
  645. on_packages");  // Don't disturb the windows.
  646.      set_window (__asc_window);
  647.  
  648.