'set novalue on' /* force KEXX and its way of SIGNAL ON NOVALUE */ /* Usage: [MACRO] HEXA [file] */ /* Or: KEDIT file (PROFile HEXA */ /* Example: HEXA kedit.exe => Kedit binary KEDIT.EXE */ /* HEXA => hex. view current file */ /* Purpose: (Ab)use KEDIT as hex. editor. HEXA is a quick */ /* hack of HEXE.KEX: HEXA does not try to change */ /* the screen width. */ /* Requires: Kedit 5.0 (KeditW should also work, test it) */ /* Optional: INITIAL.KML, COLOR.KEX, MONO.KEX, WINDOWS.KEX */ /* (Frank Ellermann, 2004) */ parse source . . NAME if profile() then exit EDIT( NAME ) ; call INIT if arg( 1 ) <> '' then do 'kedit' arg( 1 ) '(PROFile' NAME ; exit rc end 'extract /FEXT/FILEID' if alt.2() <> 0 then do 'emsg' FILEID.1 'changed' ; exit 12 end if FEXT.1 = 'BAK' then 'fext TMP' ; else 'fext BAK' if rc <> 0 then exit rc ; FILEID.0 = fileid.1() 'kedit "' || FILEID.1 || '" (PROFile' NAME if rc <> 0 then do /* trouble: reset old fileid */ NAME = rc ; 'fext' FEXT.2 ; exit NAME end 'kedit "' || FILEID.0 || '" (NEW' ; 'quit' 'kedit "' || FILEID.1 || '" (NEW' ; exit rc EDIT: procedure /* -------------------------------------------- */ if initial() then do /* initialize global settings */ 'hexdisp on' ; 'reprof on' ; 'shifts on' ; 'beep on' 'nomsg define initial.kml' ; 'nomsg macro' monitor.1() 'arbchar on' ; 'arrow off' ; 'backup temp' 'number on' ; 'wrap on' ; 'varblank on' call INIT /* save new favoured settings */ end 'editv get HEXE.0' do J = 1 to HEXE.0 /* restore any local settings */ 'editv get HEXE.' || J /* for file resp. view saved */ 'set' HEXE.J /* by procedure INIT before */ end /* -------------------------------------------- */ COL = 4 /* should be 8, 16, or 32, but VER accepts only */ /* 20 arg.s, so COL * 4 + 4 <= 20 is the limit. */ if pscreen.2() < 16 * 3 + COL then LEN = 8 /* 40 ? */ else if pscreen.2() < 24 * 3 + COL then LEN = 16 /* oops! */ else if pscreen.2() < 32 * 3 + COL then LEN = 24 /* 80 ? */ else LEN = 32 /* 132 ? */ if LEN * 3 + COL + 6 <= pscreen.2() then 'prefix nulls right' 'lrecl' LEN ; 'trunc' LEN ; 'zone 1' LEN 'eofin allow' ; 'eolin none' ; 'tabsin off' 'eofout none' ; 'eolout none' ; 'tabsout off' 'trailing on' ; 'recfm varying' 'hex on' ; 'screen 1' ; 'autoscroll off' /* RECFM FIXED would add blanks to last record upto LRECL, for */ /* patching binaries this is no good idea. Use HEXE only for */ /* viewing (and maybe replacing a few bytes). CAVEAT: Do not */ /* insert or delete bytes or "lines" (= records = LEN bytes). */ SPACE = 2 * LEN ; R = '' ; S = R ; V = R do J = 1 to LEN by LEN % COL /* process record, COL parts */ K = LEN % COL + J - 1 do I = J - 1 to K - 1 /* process a part of record: */ R = R d2x( I // 16 ) /* build text for RESERVED */ S = S || d2x( I // 16 ) end R = R '' /* build text for the VERIFY */ V = V 'H' || J K SPACE SPACE end /* Hex. col.s J to K, + space */ 'reserved' msgline.2() attr.11() R || S 'verify' V 1 LEN SPACE '*' ; return rc INIT: procedure /* -------------------------------------------- */ 'nomsg query attr' ; HEXE.1 = lastmsg.1() 'nomsg query arbchar' ; HEXE.2 = lastmsg.1() 'nomsg query arrow' ; HEXE.3 = lastmsg.1() 'nomsg query backup' ; HEXE.4 = lastmsg.1() 'nomsg query number' ; HEXE.5 = lastmsg.1() 'nomsg query varblank' ; HEXE.6 = lastmsg.1() 'nomsg query wrap' ; HEXE.7 = lastmsg.1() HEXE.0 = 7 do N = 0 to HEXE.0 ; 'editv put HEXE.' || N ; end return