home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / exe2zip.zip / exe2zip.cmd next >
OS/2 REXX Batch file  |  2002-05-18  |  5KB  |  91 lines

  1. /* OS/2 REXX: get rid of ZIP SFX header (zip.EXE => zip.ZIP)      */
  2.  
  3. /* Normally ZIP option -J should strip any UNZIPSFX.EXE header,   */
  4. /* but sometimes ZIP cannot handle valid archives (i.e. ZIP -T    */
  5. /* reports an error, but an unzip-test resp. self test of the     */
  6. /* archive shows no error).  To get around this misbehaviour use  */
  7. /* ZIP -F -T (repairing spurious errors) before ZIP -J.           */
  8.  
  9. /* Not yet implemented:  use TMP directory for ZIP manipulation   */
  10. /* Not yet implemented:  use UNZIP -t before forcing ZIP -F -T    */
  11.  
  12.    signal on  novalue name TRAP  ;  signal on syntax name TRAP
  13.    signal on  failure name TRAP  ;  signal on halt   name TRAP
  14.  
  15.    NAME = strip( strip( strip( translate( arg( 1 ))), 'B', '"' ))
  16.    parse var NAME NAME '.' EXE   ;  ZIP = '"' || NAME || '.zip"'
  17.    if EXE <> 'EXE' then exit TRAP( 'bad argument' arg( 1 ))
  18.    OPT = '-T'                    ;  EXE = '"' || NAME || '.exe"'
  19.  
  20.    signal on  error   name TRAP  ;  address CMD '@COPY' EXE ZIP
  21.    signal off error              ;  address CMD '@ZIP'  OPT ZIP
  22.    signal on  error   name FAIL  ;  if rc = 3 then OPT = '-F -T'
  23.    if rc <> 0 then                  address CMD '@ZIP'  OPT ZIP
  24.    OPT = '-o -J'                 ;  address CMD '@ZIP'  OPT ZIP
  25.    signal on  error   name TRAP  ;  address CMD '@ERASE'    EXE
  26.    exit rc
  27.  
  28. FAIL:                            /* erase new ZIP, drop into TRAP */
  29.    signal on  error   name TRAP  ;  address CMD '@ERASE'    ZIP
  30.  
  31. TRAP:                            /* select REXX exception handler */
  32.    call trace 'O' ;  trace N           /* don't trace interactive */
  33.    parse source TRAP                   /* source on separate line */
  34.    TRAP = x2c( 0D ) || right( '+++', 10 ) TRAP || x2c( 0D0A )
  35.    TRAP = TRAP || right( '+++', 10 )   /* = standard trace prefix */
  36.    TRAP = TRAP condition( 'c' ) 'trap:' condition( 'd' )
  37.    select
  38.       when wordpos( condition( 'c' ), 'ERROR FAILURE' ) > 0 then do
  39.          if condition( 'd' ) > ''      /* need an additional line */
  40.             then TRAP = TRAP || x2c( 0D0A ) || right( '+++', 10 )
  41.          TRAP = TRAP '(RC' rc || ')'   /* any system error codes  */
  42.          if condition( 'c' ) = 'FAILURE' then rc = -3
  43.       end
  44.       when wordpos( condition( 'c' ), 'HALT SYNTAX'   ) > 0 then do
  45.          if condition( 'c' ) = 'HALT' then rc = 4
  46.          if condition( 'd' ) > '' & condition( 'd' ) <> rc then do
  47.             if condition( 'd' ) <> errortext( rc ) then do
  48.                TRAP = TRAP || x2c( 0D0A ) || right( '+++', 10 )
  49.                TRAP = TRAP errortext( rc )
  50.             end                        /* future condition( 'd' ) */
  51.          end                           /* may use errortext( rc ) */
  52.          else  TRAP = TRAP errortext( rc )
  53.          rc = -rc                      /* rc < 0: REXX error code */
  54.       end
  55.       when condition( 'c' ) = 'NOVALUE'  then rc = -2 /* dubious  */
  56.       when condition( 'c' ) = 'NOTREADY' then rc = -1 /* dubious  */
  57.       otherwise                        /* force non-zero whole rc */
  58.          if datatype( value( 'RC' ), 'W' ) = 0 then rc = 1
  59.          if condition() = '' then TRAP = TRAP arg( 1 )
  60.    end                                 /* direct: TRAP( message ) */
  61.  
  62.    TRAP = TRAP || x2c( 0D0A ) || format( sigl, 6 )
  63.    signal on syntax name TRAP.SIGL     /* throw syntax error 3... */
  64.    if 0 < sigl & sigl <= sourceline()  /* if no handle for source */
  65.       then TRAP = TRAP '*-*' strip( sourceline( sigl ))
  66.       else TRAP = TRAP '+++ (source line unavailable)'
  67. TRAP.SIGL:                             /* ...catch syntax error 3 */
  68.    if abbrev( right( TRAP, 2 + 6 ), x2c( 0D0A )) then do
  69.       TRAP = TRAP '+++ (source line unreadable)'   ;  rc = -rc
  70.    end
  71.    select
  72.       when 0 then do                   /* in pipes STDERR: output */
  73.          parse version TRAP.REXX . .   /* REXX/Personal: \dev\con */
  74.          signal on syntax name TRAP.FAIL
  75.          if TRAP.REXX = 'REXXSAA'      /* fails if no more handle */
  76.             then call lineout 'STDERR'  , TRAP
  77.             else call lineout '\dev\con', TRAP
  78.       end
  79.       when 0 then do                   /* OS/2 PM: RxMessageBox() */
  80.          signal on syntax name TRAP.FAIL
  81.          call RxMessageBox ,           /* fails if not in PMREXX  */
  82.             translate( TRAP, ' ', x2c( 0D )), , 'CANCEL', 'WARNING'
  83.       end                              /* replace any CR by blank */
  84.       otherwise   say TRAP ; trace ?L  /* interactive Label trace */
  85.    end
  86.  
  87.    if condition() = 'SIGNAL' then signal TRAP.EXIT
  88. TRAP.CALL:  return rc                  /* continue after CALL ON  */
  89. TRAP.FAIL:  say TRAP ;  rc = 0 - rc    /* force TRAP error output */
  90. TRAP.EXIT:  exit   rc                  /* exit for any SIGNAL ON  */
  91.