egv@aicchi.UUCP (Vann) (08/24/86)
REM *******************************************************
REM **
REM ** Hex Dump V1.0 15 August 1986
REM **
REM ** Purpose: Dump the contents (in hex) of any file...
REM **
REM ** Input: Name of file to be dumped...
REM **
REM ** Process: Read in single bytes convert to hex...
REM ** print offset in hex too... Print all bytes in
ASCII
REM ** if possible, otherwise convert to period (.).
REM **
REM ** Output: file is displayed at 52 lines per page with date
REM ** and time stamps... Pages are numbered as
well...
REM ** ImageWriter II is assumed...
REM **
REM ** Author: Eric Geoffrey Vann
REM ** Analysts International Corp.
REM ** 650 Woodfield Drive, Suite #300
REM ** Schaumburg, IL 60195
REM **
REM ** (312) 882-4673
REM **
REM *******************************************************
REM *******************************************************
REM ** Variables Declared... All are defined to be integers...
REM *******************************************************
start:
DEFINT a-z
PageWidth=96
NumPages = 0
NumLines = 0
CharWidth = 44
PageDepth = 52
ByteOffset# = 0
WindowTop=50
WindowLeft=100
WindowRight=350
WindowBottom=300
ErrOccured = 0
ErrMessage$="Error:- Error Detected"
Dir2Prnt$ = "LPT1:DIRECT"
Dir2File$ = "HexDump.lst"
PageDate$=DATE$
PageTime$=TIME$
FF$=CHR$(12)
LF$=CHR$(10)
ESC$=CHR$(27)
ApplNm$="HEX DUMP V1.0"
Blank100$="
"
EofMessage$ = "End-of-file enountered..."
REM *******************************************************
REM ** Turn Dialog Event Manager On and goto BEGIN
REM *******************************************************
ON ERROR GOTO ErrRoutine
MOUSE OFF
MENU ON
DIALOG ON
GOTO Begin
REM *******************************************************
REM ** Come here when printer output is desired...
REM *******************************************************
OutputFile:
GOSUB InitStr
ErrMessage$="Error:- Bad Path Name"
which$= FILES$(1,"TEialogEvent=DIALOG(0)
IF DialogEvent <> 1 THEN GOTO Branch1
EventType=DIALOG(1)
IF EventType=1 THEN GOTO Abort
Branch1:
CALL TEXTFACE(0):CALL MOVETO(20,80):PRINT"Writing File...";Device$:CALL
TEXTFACE(0):CALL MOVETO(20,100):PRINT "Bytes written:- ";STR$(ByteOffset#)
char$ = INPUT$(1,#1)
IF LEN(HEX$(ASC(char$))) < 2 THEN GOSUB PadHexString ELSE GOSUB
HexString
HexLen = HexLen + 2
IF ((HexLen MOD 4) = 0) THEN GOSUB InsertBlank
IF ASC(char$) < 32 OR ASC(char$) > 126 THEN GOSUB NonPrintable ELSE
GOSUB Printable
AscLen = AscLen + 1
IF HexLen = CharWidth THEN GOSUB CloseHex:GOSUB InitStr
IF NumLines = PageDepth THEN GOSUB PrtHeader
WEND
REM *******************************************************
REM ** Print EOF message and close both files...
REM *******************************************************
Abort:
GOSUB CloseHex
PRINT#2, EofMessage$;FF$
CLOSE #1
CLOSE #2
RETURN
REM *******************************************************
REM ** Display Menu choices for user...
REM *******************************************************
DisplayMenu:
WINDOW 1,"Hex Dump V1.0",(WindowLeft,WindowTop)-(WindowRight,WindowBottom),2
RepaintMenu:
WINDOW OUTPUT 1
CLS
CALL TEXTFONT(0) : CALL TEXTSIZE(12)
CALL MOVETO (80,20) : CALL TEXTMODE(0):CALL TEXTFACE(4)
PRINT"Hex Dump V1.0" :CALL TEXTFACE(0)
CALL MOVETO(20,50):PRINT"Click in one of the boxes below:"
IF ErrOccured =0 THEN CALL MOVETO(20,100):CALL TEXTFACE(72):PRINT"Quit";
:CALL TEXTFACE(0) :PRINT" - returns TO Finder"
IF ErrOccured = 0 THEN CALL MOVETO(20,120) :CALL
TEXTFACE(72):PRINT"File";:CALL TEXTFACE(0):PRINT" - OUTPUT to File" ELSE CALL
MOVETO(20,140) :CALL TEXTFACE(72):PRINT"Resume";:CALL TEXTFACE(0):PRINT" - ERROR
occured"
IF ErrOccured = 0 THEN CALL MOVETO(20,140):CALL TEXTFACE(72):PRINT"Print";
:CALL TEXTFACE(0): PRINT" - OUTPUT to Printer"
IF ErrOccured = 0 THEN BUTTON 1,1,"Quit",(25,220)-(80,240),1 ELSE BUTTON
CLOSE 1
IF ErrOccured = 0 THEN BUTTON 2, 1,"File",(100,220)-(150,240),1 ELSE BUTTON
2, 1,"Resume",(100,220)-(150,240),1
IF ErrOccured = 0 THEN BUTTON 3,1,"Print",(175,220)-(225,240),1 ELSE BUTTON
CLOSE 3
RETURN
REM *******************************************************
REM ** Empty Dialog queue
REM *******************************************************
FlushDialogQueue:
WHILE DIALOG(0)<>0
WEND
RETURN
REM *******************************************************
REM ** Inserts blanks between columns of four hex bytes...
REM *******************************************************
InsertBlank:
HexString$ = HexString$ + " "
RETURN
REM *******************************************************
REM ** Build and pad hex strings with leading zeroes...
REM *******************************************************
PadHexString:
HexString$ = HexString$ + "0"+ HEX$(ASC(char$))
RETURN
REM *******************************************************
REM ** Build hex strings which don't need padding with leading zeroes...
REM *******************************************************
HexString:
HexString$ = HexString$ + HEX$(ASC(char$))
RETURN
REM *******************************************************
REM ** Insert ASCII for non-printable characters in ascii strings...
REM *******************************************************
NonPrintable:
AscString$ = AscString$ + "."
RETURN
REM *******************************************************
REM ** Insert printable characters in ascii strings...
REM *******************************************************
Printable:
AscString$ = AscString$ + char$
RETURN
REM *******************************************************
REM ** print line of hex and ascii data terminated with "]"...
REM *******************************************************
CloseHex:
IF LEN(HexString$) < 66 THEN HexString$ =
HexString$+LEFT$(Blank100$,66-LEN(HexString$))
IF LEN(AscString$) < 23 THEN AscString$ =
AscString$+LEFT$(Blank100$,23-LEN(AscString$))
PRINT #2, HexString$ + " " + AscString$ + "]"
RETURN
REM *******************************************************
REM ** Print page header and its information...
REM *******************************************************
PrtHeader:
NumLines=0:NumPages=NumPages+1
IF NumPages <> 1 THEN PRINT#2,FF$
Header$=ApplNm$+LEFT$(Blank100$,PageWidth-(LEN(ApplNm$)+LEN(which$)+LEN("File:
")) )+"File: "+which$
PRINT#2,Header$
Header$="Page #"+STR$(NumPages)+LEFT$(Blank100$,PageWidth-(LEN("Page
#")+LEN(STR$(NumPages))+LEN(PageDate$)+LEN(PageTime$)+LEN(" ")) )+PageDate$+"
"+PageTime$
PRINT#2,Header$
PRINT#2,LF$;LF$;LF$
RETURN
REM *******************************************************
REM ** Initialize strings to be used to build line of printout...
REM *******************************************************
InitStr:
NumLines = NumLines + 1
ByteOffset# = ByteOffset# + AscLen
HexString$ = LEFT$(Blank100$, 8-LEN(HEX$(ByteOffset#)))+HEX$(ByteOffset#)+":
"
AscString$ = "["
HexLen = 0
AscLen = 0
RETURN
REM *******************************************************
REM ** Establish New Menus...
REM CALL TEXTSIZE(12)
CALL MOVETO (160,20) : CALL TEXTMODE(0):CALL TEXTFACE(4)
PRINT"Help Screen" :CALL TEXTFACE(0)
CALL MOVETO(20,50):PRINT"Click in box below to continue:"
CALL MOVETO(40,90):CALL TEXTFACE(72):PRINT"PRINT - ";
CALL TEXTFACE(0):CALL MOVETO(110,90):PRINT "ImageWriter II...Reasonably
fast..."
CALL MOVETO(40,110):CALL TEXTFACE(72):PRINT"FILE - "
CALL TEXTFACE(0):CALL MOVETO(110,110):PRINT "file NAME Hex Dump.lst..."
CALL TEXTFACE(0):CALL MOVETO(110,130):PRINT"This takes forever...Very
slow..."
CALL MOVETO(40,150):CALL TEXTFACE(72):PRINT"QUIT - ";
CALL TEXTFACE(0):CALL MOVETO(110,150):PRINT"Returns you TO the Finder..."
BUTTON 1,1,"Resume",(175,220)-(240,240),1
Loop5:
DialogEvent=DIALOG(0)
IF DialogEvent <> 1 THEN GOTO Loop5
EventType=DIALOG(1)
IF EventType<>1 THEN GOTO Loop5
WINDOW CLOSE 2
MENU
GOSUB DisplayMenu
RETURN
REM *******************************************************
REM ** Here begins main loop...
REM *******************************************************
Begin:
GOSUB FlushDialogQueue
GOSUB DisplayMenu
GOSUB SetUpMenus
MainEventLoop:
DialogEvent=DIALOG(0)
IF DialogEvent <>1 THEN GOTO HandleMenu
EventType=DIALOG(1)
IF EventType=1 THEN GOTO Leave
IF EventType=2 THEN Device$=Dir2File$ :GOSUB OutputFile :GOSUB RepaintMenu
IF EventType=3 THEN Device$=Dir2Prnt$ :GOSUB OutputFile :GOSUB RepaintMenu
REM IF EventType=3 THEN PageDepth=5:Device$=Dir2Scrn$:GOSUB OutputFile:GOTO
start
HandleMenu:
MenuNumber=MENU(0)
IF MenuNumber <> 1 THEN GOTO MainEventLoop
MenuItem=MENU(1)
IF MenuItem = 1 THEN GOSUB DspHelpScrn
GOTO MainEventLoop
REM *******************************************************
REM ** Send user back to Finder...
REM *******************************************************
Leave:
MENU RESET
SYSTEM
END
ErrRoutine:
ErrOccured = 1
GOSUB RepaintMenu
Loop2:
CALL TEXTFACE(65):CALL MOVETO(20,100):PRINT ErrMessage$
CALL TEXTFACE(72):CALL MOVETO(20,100):PRINT ErrMessage$
DialogEvent=DIALOG(0)
IF DialogEvent <> 1 THEN GOTO Loop2
EventType=DIALOG(1)
IF EventType=2 THEN ErrOccured = 0: GOSUB RepaintMenu:RESUME MainEventLoop
GOTO Loop2
*** REPLACE THIS LINE WITH YOUR MESSAGE ***
--
Eric Geoffrey Vann
Analysts International (Chicago Branch)
(312) 882-4673
..!ihnp4!aicchi!egv