/* OS/2 REXX: convert ZIP to self-extracting EXE (or vice versa) */ /* Prerequisites: unzipsfx.exe distributed with unzip???.exe, and */ /* zip.exe to adjust offsets. Put unzipsfx.exe in the DPATH or */ /* PATH, put zip.exe in the PATH. Some distributed versions of */ /* zip2exe.cmd didn't try to adjust the offset, or had UNIX line */ /* ends not supported by classic REXX. F.Ellermann, 2006 */ signal on novalue name TRAP ; signal on syntax name TRAP signal on failure name TRAP ; signal on halt name TRAP signal on notready name TRAP ; EXT = 'zip' call UTIL 'SysSearchPath' ; QUIET = '>/dev/nul' DST = 'un' || EXT || 'sfx.exe' SFX = SysSearchPath( 'PATH', DST ) if SFX = '' then SFX = SysSearchPath( 'DPATH', DST ) if SFX = '' then exit HELP( 'not found:' DST ) SRC = strip( strip( strip( arg( 1 )),, '"' )) if SRC = '' then exit HELP() DST = stream( SRC, 'C', 'QUERY EXISTS' ) if DST = '' then SRC = SRC || '.' || EXT DST = stream( SRC, 'C', 'QUERY EXISTS' ) if DST = '' then exit HELP( 'not found:' SRC ) SRC = DST if right( translate( SRC ), 4 ) = '.EXE' then do DST = '"' || left( SRC, length( SRC ) - 3 ) || EXT || '"' address CMD '@COPY "' || SRC || '"' DST QUIET if rc <> 0 then exit TRAP( 'not created:' DST ) else address CMD '@ZIP -q -T' DST QUIET '2>&1' if rc = 3 then address CMD '@ZIP -F -T' DST QUIET if rc = 0 then address CMD '@ZIP -o -J' DST QUIET if rc <> 0 then do say 'error' rc 'for zip -T' DST address CMD '@DEL' DST exit 1 end say 'archive' DST 'okay, deleting' SRC address CMD '@DEL "' || SRC || '"' exit rc end if right( translate( SRC ), 4 ) = . || translate( EXT ) then DST = left( SRC, length( SRC ) - 4 ) || '.exe' else DST = SRC || '.exe' SFX = '"' || SFX || '"+"' || SRC || '","' || DST || '"' address CMD '@COPY /b' SFX QUIET if rc <> 0 then exit TRAP( 'not created:' DST ) address CMD '@zip -A "' || DST || '"' QUIET address CMD '@"' || DST || '" -t' QUIET if rc <> 0 then do say 'self test error' rc 'for' DST '-t' address CMD '@DEL "' || DST || '"' exit 1 end else do say 'self test' DST '-t okay, deleting' SRC address CMD '@DEL "' || SRC || '"' exit rc end HELP: procedure expose EXT SFX /* output usage or error message */ if arg( 1 ) <> '' then say arg( 1 ) if SFX <> '' then do parse source . . SRC say 'usage:' SRC 'input.[' || EXT || '|exe]' say 'converts input.[' || EXT || '] to exe (or vice versa)' say 'using un' || EXT || 'sfx.exe and' EXT || '.exe' end return 1 /* see , (c) F. Ellermann */ UTIL: procedure /* load necessary RexxUtil entry */ if RxFuncQuery( arg( 1 )) then if RxFuncAdd( arg( 1 ), 'RexxUtil', arg( 1 )) then exit TRAP( "can't add RexxUtil" arg( 1 )) return 0 TRAP: /* select REXX exception handler */ call trace 'O' ; trace N /* don't trace interactive */ parse source TRAP /* source on separate line */ TRAP = x2c( 0D ) || right( '+++', 10 ) TRAP || x2c( 0D0A ) TRAP = TRAP || right( '+++', 10 ) /* = standard trace prefix */ TRAP = TRAP strip( condition( 'c' ) 'trap:' condition( 'd' )) select when wordpos( condition( 'c' ), 'ERROR FAILURE' ) > 0 then do if condition( 'd' ) > '' /* need an additional line */ then TRAP = TRAP || x2c( 0D0A ) || right( '+++', 10 ) TRAP = TRAP '(RC' rc || ')' /* any system error codes */ if condition( 'c' ) = 'FAILURE' then rc = -3 end when wordpos( condition( 'c' ), 'HALT SYNTAX' ) > 0 then do if condition( 'c' ) = 'HALT' then rc = 4 if condition( 'd' ) > '' & condition( 'd' ) <> rc then do if condition( 'd' ) <> errortext( rc ) then do TRAP = TRAP || x2c( 0D0A ) || right( '+++', 10 ) TRAP = TRAP errortext( rc ) end /* future condition( 'd' ) */ end /* may use errortext( rc ) */ else TRAP = TRAP errortext( rc ) rc = -rc /* rc < 0: REXX error code */ end when condition( 'c' ) = 'NOVALUE' then rc = -2 /* dubious */ when condition( 'c' ) = 'NOTREADY' then rc = -1 /* dubious */ otherwise /* force non-zero whole rc */ if datatype( value( 'RC' ), 'W' ) = 0 then rc = 1 if rc = 0 then rc = 1 if condition() = '' then TRAP = TRAP arg( 1 ) end /* direct: TRAP( message ) */ TRAP = TRAP || x2c( 0D0A ) || format( sigl, 6 ) signal on syntax name TRAP.SIGL /* throw syntax error 3... */ if 0 < sigl & sigl <= sourceline() /* if no handle for source */ then TRAP = TRAP '*-*' strip( sourceline( sigl )) else TRAP = TRAP '+++ (source line unavailable)' TRAP.SIGL: /* ...catch syntax error 3 */ if abbrev( right( TRAP, 2 + 6 ), x2c( 0D0A )) then do TRAP = TRAP '+++ (source line unreadable)' ; rc = -rc end select when 0 then do /* in pipes STDERR: output */ parse version TRAP.REXX . . /* REXX/Personal: \dev\con */ signal on syntax name TRAP.FAIL if TRAP.REXX = 'REXXSAA' /* fails if no more handle */ then call lineout 'STDERR' , TRAP else call lineout '\dev\con', TRAP end when 0 then do /* OS/2 PM: RxMessageBox() */ signal on syntax name TRAP.FAIL call RxMessageBox , /* fails if not in PMREXX */ translate( TRAP, ' ', x2c( 0D )), , 'CANCEL', 'WARNING' end /* replace any CR by blank */ otherwise say TRAP ; trace ?L /* interactive Label trace */ end if condition() = 'SIGNAL' then signal TRAP.EXIT TRAP.CALL: return rc /* continue after CALL ON */ TRAP.FAIL: say TRAP ; rc = 0 - rc /* force TRAP error output */ TRAP.EXIT: exit rc /* exit for any SIGNAL ON */