home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Current Shareware 1994 January
/
SHAR194.ISO
/
textutil
/
txt2bin.zip
/
TXT2BIN.DOC
next >
Wrap
Text File
|
1993-10-21
|
8KB
|
307 lines
TXT2BIN - Text-To-Binary Conversion Program
Version 1.13 (October 21, 1993)
Copyright 1992,1993 Bruce Lum
DISCLAIMER
----------
The TXT2BIN program is provided "AS-IS". You use this program
strictly at your own risk. No warranty of any kind exists. The
author is not responsible for any incidental or consequential
damages to your computer or the data stored on it as a result of
misuse or the inability to run the program. By running TXT2BIN,
you agree to this.
Trademarks
----------
LaserJet is a trademark of Hewlett-Packard Company.
Introduction
------------
TXT2BIN is a utility that helps you to create and maintain binary
files with the use of plain text files.
With TXT2BIN, you can avoid the use of hex editors and debuggers.
Hex editors tend to like working with hexadecimal characters.
Debuggers may allow a mixture of hexadecimal characters and text
strings; in the end, however, you are left with only the binary
image.
To use TXT2BIN, all you need is a text editor to describe the
contents of the binary file. From the text file, TXT2BIN creates
the binary file for you. If the binary file needs any changes,
just change the text file and run TXT2BIN again.
Your text file can even contain comments for documentation
purposes.
Below is the description of how to use TXT2BIN, from creating the
text file to actually running TXT2BIN to create the binary file.
Error messages are also described. The examples all refer to an
area where TXT2BIN may become useful: the sending of customized
commands to a printer.
The Text File
-------------
Each line in the text file can contain the following:
1. The hexadecimal representation of the bytes. Each byte
must consist of a pair of hexadecimal characters (0-9,
A-F, a-f). You may optionally insert spaces between
bytes.
Examples: 1B 26 6C 31 4F
1B 266C31 4F
2. A text string enclosed by double quotes.
Example: "%-12345X"
Escape sequences may also be part of a text string. See
the section later in this file called "Escape Sequences"
for more details.
3. A comment which starts with a semi-colon. The comment
can start anywhere on the line. Anything to the right of
the semi-colon is ignored.
Example: ; This is a comment that TXT2BIN will
; ignore
4. A combination of the above.
Example: 1B "%-12345X" ; Start of print job
1B "E" ; Reset printer
5. A blank line.
In this version, a single line is limited to the maximum of 254
characters.
The following example is part of a text file which contains the
instructions for initializing a Hewlett-Packard LaserJet IIP
printer:
;--------------------------------------
; Reset the printer
;--------------------------------------
1B "E"
;--------------------------------------
; Number of copies = 1
;--------------------------------------
1B "&l1X"
;--------------------------------------
; Paper source: MP Tray
;--------------------------------------
1B "&l1H"
Escape Sequences
----------------
The escape sequence allows certain hard-to-get characters (e.g.
control codes) to be represented. Usually, these characters
cannot easily be entered within a text editor.
An escape sequence is started with the backslash character (\)
and is followed by one or more octal, hexadecimal or ASCII
characters.
Here is the list of escape sequences that TXT2BIN currently
supports:
Sequence Value Char Description
\a 0x07 BEL Bell (Alert)
\b 0x08 BS Backspace
\f 0x0C FF Formfeed
\n 0x0A LF Newline
\r 0x0D CR Carriage return
\t 0x09 HT Horizontal tab
\v 0x0B VT Vertical tab
\' 0x27 ' Single quote (apostrophe)
\? 0x3F ? Question mark
\" 0x22 " Double quote
\\ 0x5C \ Backslash
\Onnn (any) 'nnn' is a string of up to 3
octal digits
\Xhh (any) 'hh' is a string of hex digits
\xhh (any) 'hh' is a string of hex digits
\nnn (any) 'nnn' is a string of up to 3
octal digits
Examples:
"\aFatal error!\r\n"
"The \"right\" way of using double-quotes"
"The ESC code is represented by \033"
"The ESC code is represented by \x1B"
"The ESC code is represented by \X1B"
"The ESC code is represented by \O033"
Converting the Text File to a Binary Image
------------------------------------------
The command to convert your text file has the following syntax:
TXT2BIN textfile binaryfile
where:
'textfile' - your text file with the hexadecimal bytes
and text strings;
'binaryfile' - the binary file to be created
Error Messages
--------------
During TXT2BIN's validation of the contents of the text file,
messages may appear as a result of an encountered error. These
messages will indicate the line and column numbers of where the
errors are located.
The error messages may be redirected to a file or to another
device other than the console screen.
Examples:
TXT2BIN filename.txt filename.bin >error.msg
TXT2BIN filename.txt filename.bin >NUL
TXT2BIN filename.txt filename.bin >LPT1
The following is the list of possible messages:
Incomplete hexadecimal character at column NNNNN
Only the first half of a hexadecimal character was
specified. Either the second half is missing, or an
invalid character was encountered.
Incomplete hexadecimal character at the end of this line
The end of the line was unexpectedly encountered before
the hexadecimal character was completed.
Invalid character at column NNNNN
A non-hexadecimal character was encountered. The valid
range of characters are:
- from 0 to 9 (inclusive);
- from A to F (inclusive);
- from a to f (inclusive).
Non-terminated string found
A text string did not end properly with a double-quote
(").
Numeric constant too big at column NNNNN
Within a text string, an octal value (\Onnn or \nnn) was
found to be more than 255 (or \O377 or \377).
Unable to open input file
The source text file could not be opened. Possible
causes are:
(1) the file name was misspelled;
(2) the file exists in another drive/directory.
Unable to open output file
The target binary file could not be opened. Possible
causes are:
(1) the file already exists, with its attribute set
as READ-ONLY;
(2) the file is the name of a directory or volume
label.
Distribution
------------
You may freely distribute this program, provided that the
following two files are distributed together:
TXT2BIN.DOC (The documentation file)
TXT2BIN.EXE (The program file)
Contributions
-------------
If you find TXT2BIN useful, please send $10.00 to the author at
the postal address below. Your support is greatly appreciated.
Correspondence
--------------
If you have any problems, questions, or any type of feedback,
electronic mail may be sent to the author (Bruce Lum) at the
following locations:
Compuserve: 72727,3104
Internet: 72727.3104@compuserve.com
If you are using the postal service, the address is:
P.O. Box 5098, Station A
Toronto, Ontario
CANADA M5W 1N4