home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 09 / brief / binread.me < prev   
Text File  |  1991-06-07  |  9KB  |  184 lines

  1. *****************************************************************************
  2. The purpose of this set of macros is to deal with two annoying problems
  3. in Brief:
  4.  
  5.      1. Editing in a hex mode.
  6.      2. Editing "UNIX" files which use only a LF as an EOL terminator.
  7.  
  8. *****************************************************************************
  9.  
  10. The approach to solving the problem requires the execution of the BBE
  11. program.  This program was written to converts a binary file into hex/ascii
  12. files or a "Unix" file with no CR into a standard DOS file with CR/LF EOL
  13. sequence depending on the flag passed.  Since the program creates a hex and
  14. ascii file you will need at least three times the size of the original binary
  15. file in disk space.  Make sure the bbe.exe file is in your DOS path.
  16.  
  17. *****************************************************************************
  18. bbe.exe Usage:
  19.     bbe [BH|HB|UD|DU] file_to_convert outfile1 {outfile2}
  20.         Parameters:
  21.             BH - Binary to hex
  22.             HB - Hex to binary
  23.             UD - Unix to Dos
  24.             DU - Dos to Unix
  25.  
  26. *****************************************************************************
  27. The macros:
  28.  
  29. The binedit file contains two sets of macros one for hex editing and the other
  30. for UNIX file editing.  Load this macro through your BFLAG by adding:
  31.  
  32.    -mbinedit
  33.  
  34. I will describe the hex editing macro first since it is the most convoluted. 
  35. And then describe the unix editing macro.  Both of these macros are
  36. acitivated from the edit_file operation and should be transparent to the
  37. user.  Please see the limitations/caveats at the end of this file as well as
  38. the comments within the macro.
  39. *****************************************************************************
  40.  
  41. Editing Hex Files:
  42. This is accomplished by hooking into the language macro of brief by adding
  43. a package for .hex files.  A registered macro is used to trap the Null 
  44. characters fixed message and prompt for conversion.  If conversion is requested,
  45. the bbe program is called to create a .hex and .asc file from the binary file.
  46. The original buffer is then deleted after it's true filename has been stored
  47. in the system buffer.  The package buffer, which stores file extension specific
  48. information, is then modified to add the bin package without any specific
  49. BPACKAGE setting.  The macro then relies on the registered macros of brief
  50. to process the new package setting.  When the buffers are being created, the
  51. HEX buffer is given a .hex extension and the ASCII buffer is given the exten-
  52. sion of the original file.
  53.  
  54. When the .hex buffer is the current buffer the _bin_on macro will be called
  55. which creates two windows to display the .hex and .asc files in side by side
  56. windows.  A new keyboard is used which only assigns valid hex editing keys,
  57. movement keys and search keys.  The current byte is highlighted in the hex
  58. window to display the two characters as one entity and the file offset and
  59. corresponding ascii character are displayed on the message line.
  60.    
  61. Keyboard assignments:
  62. <Enter>  prompts for an ascii character to overwrite the current character 
  63.          with.  This will allow modification of text and do the hex conversion
  64.          for you updating both buffers.
  65. <Ctrl-Enter>  add a new line of bytes to the buffers
  66. <F10>    currently assigned to execute_macro.  Since you could rapidly shoot
  67.          yourself in the foot with this, I suggest you use it with extreme
  68.          caution.
  69. <Alt-n>  Edit_next_buffer, the same as Brief.  Changes buffers.
  70. <Alt-e>  Edit_file
  71. <Alt-d>  Delete a line of bytes
  72. <Alt-u>  Undo.  Since there is no undo stack for system buffers using this 
  73.          will not undo the changes to the ascii window.
  74. <Ctrl-u> Redo.  No redo on system buffers either.
  75. <Alt-w>  Write buffer and optionally delete the hex buffer.
  76. <up>     Highlight the byte above the cursor.
  77. <left>   Highlight the byte left of the cursor with scrolling.
  78. <right>  Highlight the byte to the right with scrolling.
  79. <down>   Highlight the byte below the cursor.
  80. <PgUp>   Highlight the byte on previous page.
  81. <PgDn>   Highlight the byte on the next page.
  82. <home>   Highlight the byte at the beginning of the line.
  83. <end>    Highlight the byte at the end of the line.
  84. <del>    Delete the current character.  Although the character is not 
  85.          physically deleted an XX byte is added which is ignored in the
  86.          conversion process.
  87. <Ctrl-Pgup>  Highlight the byte at the top of buffer.
  88. <Ctrl-PgDn>  Highlight the byte at the end of the buffer.
  89. <F5>     Perform a HEX search.
  90. <Alt-F5> Perform an ascii search.
  91. <Alt-x>  Exit brief.
  92. <Esc>    Show the corresponding ascii character for the highlighted byte.
  93.  
  94. Since there is no way in brief to trap a buffer being deleted, you are forced
  95. to write the buffer in order to delete the associated hex and ascii files
  96. and do the reverse conversion.  See the Limitations/Caveats for a more
  97. elaborate description of potential problems.   
  98.  
  99. There exists a macro for editing a non-binary file in hex format named
  100. edit_hex_file, you may at some point want to assign this macro to a key,
  101. if you have any free.
  102. *****************************************************************************
  103.  
  104. Editing UNIX files:  A Unix file is interpreted to be a file which has no "\n"
  105. on the first line of the file and has less than three lines in the file.  When
  106. these two conditions are met, the user is prompted for execution of the bbe
  107. program which replaces the LF with CR/LF and creates a buffer with extension
  108. .unx.  The macros acivate template editing for all of brief's supported
  109. languages with the default parameters described in the user's manual.  To
  110. modify the parameters, change the _unx_edit macro at the end of the BINEDIT file.
  111. *****************************************************************************
  112.  
  113. Limitations/Caveats 
  114.  
  115. Don't split the window with the mouse!!
  116.  
  117. When exiting Brief, the prompt for modified files will not call the converter.
  118. Always write your changes from the editor with Alt-w.
  119.  
  120. The restore macro does not interface with these macros.  Attempting to restore
  121. your session with controlled .hex and .unx files will merely edit/create the
  122. requested file.
  123.  
  124. These macros require the exclusive use of .hex and .unx file extensions.  You
  125. may have problems when editing files with these file extensions.  Especially
  126. with the write_buffer command.
  127.  
  128. These macros use the original path of the file specified and create a file
  129. with a different extension. Files with the same name and different extensions
  130. cannot be edited simultaneously.
  131.  
  132. When there is only one buffer and you exit Brief the macro may not delete
  133. the newly created files.  An error message will display whenever the conversion
  134. is done and the files/buffers cannot be deleted.  
  135.  
  136. When writing buffers, you will be prompted for reconversion and buffer
  137. deletion.  If you press ESC at any prompt the buffer will not be written.  If
  138. you would like to continue editing respond to the prompts with "N" "N".  This
  139. will write the buffer.  When you are through editing the buffer make sure you
  140. respond "Y" to the delete buffer prompt.  If you only have one buffer in
  141. memory the files will not be deleted.  
  142.  
  143. Be aware that deleting the hex file from the buf_list macro will not delete
  144. the buffer properly.
  145.  
  146. Files will not be reconverted if they have not been modified.
  147.  
  148. Don't do anything stupid!  Although F10 is assigned in the hex edit window,
  149. it is there for convenience as a last resort.  Avoid it like the plague.  
  150.  
  151. Characters cannot be inserted in the middle of the line in the hex edit
  152. window, they can only be changed.  Only full lines can be inserted. If you
  153. decide to add this capability, the bbe program will not convert any XX byte.
  154.  
  155. Undo/redo changes will not be reflected in the ascii buffer.  The stack is
  156. not maintained for system buffers.
  157.  
  158. If you don't care about editing binary files comment out the #define HEX.
  159. If you don't care about editing Unix files comment out the #define UNIX.
  160. Be sure to recompile afterward.
  161.  
  162. Don't recompile this macro while you are in Brief.  The system buffers will
  163. be recreated and all kinds of bizzare things will happen.
  164.  
  165. This is a macro which does things which Brief was not meant to do in the
  166. first place.  Although there is extensive error checking and as many
  167. different combinations as we could find were tested, you may have
  168. compatability problems with other macros which you have written.
  169.  
  170. The Unix editing macro enables template editing with the default parameters
  171. for all supported languages.  If you prefer smart or regular indenting, you
  172. will have to modify the _unx_edit macro.
  173.  
  174. This set of macros took a great deal of time and testing to make them function
  175. as intended.  They will take very little effort on your part to break them 
  176. beyond repair.  If you do not care for their implimentation.
  177.  
  178.  
  179. Good Luck,
  180.  
  181. Jim Rodriguez
  182. Tim Hanna
  183. 4/1/91
  184.