home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ZIPENG10.ZIP / ZIPVIEW.CMD < prev   
OS/2 REXX Batch file  |  1993-03-21  |  13KB  |  409 lines

  1. /* The Zip Engine -- A shareware graphical approach to file zipping/unzipping */
  2. /* Copyright 1992-93 Kari Jackson and Bart Toulouse */
  3. /* View-Text-Files-Within-a-.ZIP Subroutine, and a couple others */
  4. parse arg ARGS
  5. if (lastpos('/',ARGS)<25)&(ARGS<>'Date2')&(ARGS<>'List')&(left(ARGS,5)<>'About')&(left(ARGS,4)<>'Sure') then do
  6.    say 'Sorry, this is not a standalone program.  It should be'
  7.    say 'used only as a subroutine of the Zip Engine program.'
  8.    signal End
  9. end
  10. if ARGS = 'Date2' then do
  11.    drop ARGS
  12.    call Date2
  13.    return RESULT
  14. end
  15. if left(ARGS,4) = 'Sure' then do
  16.    parse var ARGS . PAR2.q OPTIONS
  17.    drop ARGS
  18.    call Sure
  19.    return RESULT
  20. end
  21. if ARGS = 'List' then do
  22.    drop ARGS
  23.    call ListFile
  24.    return RESULT
  25. end
  26. if left(ARGS,5) = 'About' then do
  27.    parse var ARGS . TEXT '/' BG '/' FG
  28.    drop ARGS
  29.    call About
  30.    return
  31. end
  32. parse var ARGS TEXT '/' EXECUTABLE '/' OPTIONS '/' SOURCE '/' DIRNAME '/' EXT '/' BG '/' FG
  33. drop ARGS
  34. if right(DIRNAME,1) = '\' then DIRNAME2 = systempfilename(DIRNAME'ZIP?????')
  35. else DIRNAME2 = systempfilename(DIRNAME'\ZIP?????')
  36. rc = sysmkdir(DIRNAME2)
  37. if rc<>0 then do
  38.    MSG.0 = 3
  39.    call linein TEXT,1
  40.    do 138
  41.       call linein TEXT
  42.    end
  43.    do y = 1 to 3
  44.       MSG.y = linein(TEXT)
  45.    end
  46.    call vmsgbox "Oops!", MSG, 1
  47.    return
  48. end
  49. drop rc
  50. POS.left = 10 ; POS.right = 90 ; POS.top = 25 ; POS.bottom = 10
  51. WINDOW = vopenwindow('(Zip Engine) Working.....', BG, POS)
  52. call vsetfont WINDOW, 'SYSTEM', 10
  53. call vforecolor WINDOW, FG
  54. drop POS.
  55. call vsay WINDOW, 200, 700, 'Please wait..........'
  56. call vsay WINDOW, 50, 500, 'We are unzipping the' SOURCE
  57. call vsay WINDOW, 50, 300, 'file into a temporary directory named'
  58. call vsay WINDOW, 50, 100, DIRNAME2"."
  59. if right(DIRNAME,1)='\' then TEMPAFILE = systempfilename(DIRNAME'1?????.'EXT)
  60. else TEMPAFILE = systempfilename(DIRNAME'\1?????.'EXT)
  61. call lineout TEMPAFILE,'@ECHO OFF'
  62. if RESULT = 1 then do
  63.    call sysrmdir DIRNAME2
  64.    call vclosewindow WINDOW
  65.    return 'error'
  66. end
  67. call lineout TEMPAFILE,EXECUTABLE OPTIONS SOURCE DIRNAME2
  68. call lineout TEMPAFILE,"ATTRIB -R" TEMPAFILE
  69. call lineout TEMPAFILE,"REM If Zip Engine isn't running at this moment, delete this file."
  70. call lineout TEMPAFILE
  71. 'ATTRIB +R' TEMPAFILE
  72. if wordpos('-s',OPTIONS)>0 then 'start /win /b /c' TEMPAFILE
  73. else 'start /b /c' TEMPAFILE
  74. do until rc = 0
  75.    rc = sysfiledelete(TEMPAFILE)
  76.    if rc<>0 then call syssleep 1
  77. end
  78. drop TEMPAFILE
  79. DIRNAME2 = DIRNAME2'\'
  80. call DiskFiles
  81. if (DISKFILES<>'')&(DISKFILES<>'DISKFILES') then do
  82.    POS.left = 2 ; POS.right = 98 ; POS.top = 25 ; POS.bottom = 10
  83.    call vclearwindow WINDOW
  84.    call vresize WINDOW, POS
  85.    drop POS.
  86.    do until DISKFILES = 'DISKFILES'
  87.       call ViewDiskFiles
  88.       call DiskFiles
  89.    end
  90. end
  91. else if EXIST<>'yes' then do
  92.    MSG.0 = 3
  93.    MSG.1 = 'A strange occurrence......no files came out of'
  94.    MSG.2 = 'this .ZIP file for some reason.  Returning'
  95.    MSG.3 = 'you to the main menu now.'
  96.    call vmsgbox 'Sorry!', MSG, 1
  97. end
  98. call vclosewindow WINDOW
  99. do x = 1 to VAR.0
  100.    call sysfiledelete VAR.x
  101. end
  102. call sysrmdir left(DIRNAME2,length(DIRNAME2)-1)
  103. return
  104. ViewDiskFiles:
  105.    drop BUTTON2
  106.    do b = 1 while DISKFILES<>''
  107.       select
  108.          when left(DISKFILES,1) = '"' then do
  109.             parse var DISKFILES . '"' NAME.b '"' DISKFILES
  110.             NAME.b = '"'||NAME.b||'"'
  111.          end
  112.          when left(DISKFILES,1) = "'" then do
  113.             parse var DISKFILES . "'" NAME.b "'" DISKFILES
  114.             NAME.b = "'"||NAME.b||"'"
  115.          end
  116.          otherwise parse var DISKFILES NAME.b DISKFILES
  117.       end
  118.       DISKFILES = strip(DISKFILES)
  119.       NAME.0 = b
  120.    end
  121.    if symbol('NAME.0') = 'VAR' then do b = 1 to NAME.0 while BUTTON2<>'CANCEL'
  122.       VIEWER = NAME.b
  123.       if translate(right(VIEWER,4)) = '.INF' then do
  124.          FIN.0 = 5
  125.          FIN.1 = "You've chosen" VIEWER'.'
  126.          FIN.2 = 'If' SOURCE
  127.          FIN.3 = "contains an OS/2 program, its .INF file is probably"
  128.          FIN.4 = 'meant to be read with the VIEW command.  Click on YES'
  129.          FIN.5 = 'for VIEW or NO for plain text.'
  130.          BUTINF = vmsgbox(".INF File", FIN, 6)
  131.          if BUTINF = 'YES' then do
  132.             'VIEW.EXE' VIEWER
  133.             OUT.0 = 8
  134.             call linein TEXT,1
  135.             do 142
  136.                call linein TEXT
  137.             end
  138.             do y = 1 to 8
  139.                OUT.y = linein(TEXT)
  140.             end
  141.             call vmsgbox "WAIT!  Warning:", OUT, 1
  142.          end
  143.          else call ViewThis
  144.          drop FIN. BUTINF OUT.
  145.       end
  146.       else call ViewThis
  147.    end
  148.    drop VIEWER NAME.
  149. return
  150. ViewThis:
  151.    call vclearwindow WINDOW
  152.    call vsay WINDOW, 200, 700, 'Please wait..............Retrieving text from the file.'
  153.    call vsay WINDOW, 5, 500, 'Only the first 80 characters of each line (which is all there is in'
  154.    call vsay WINDOW, 5, 300, 'most text files), and only the first 630 lines of the file, will be'
  155.    call vsay WINDOW, 5, 100, "displayed."
  156.    drop MSG.
  157.    THATNUM = 1
  158.    do while (lines(VIEWER))&(THATNUM<631)
  159.       MSG.THATNUM = left(linein(VIEWER),80)
  160.       THATNUM = THATNUM+1
  161.    end
  162.    if lines(VIEWER) then MSG.THATNUM = '                       <<<Those were the first 630 lines of your file>>>'
  163.    else do
  164.       MSG.THATNUM = ' '
  165.       THATNUM = THATNUM+1
  166.       MSG.THATNUM = '                                       <<<End of File>>>'
  167.    end
  168.    call lineout VIEWER
  169.    MSG.0 = THATNUM
  170.    BUTTON2 = vlistbox("View the" VIEWER "file:", MSG, 100, 10, 3)
  171.    call vclearwindow WINDOW
  172.    drop MSG. THATNUM
  173. return
  174. DiskFiles:
  175.    DISKFILES = ''
  176.    drop VAR. NUMBER MSG. BUTTON
  177.    call sysfiletree DIRNAME2'*.*', 'VAR', 'OF'
  178.    SubDiskFiles:
  179.    if BUTTON = 'CANCEL' then return
  180.    if NUMBER = 'NUMBER' then NUMBER = 0
  181.    do a = NUMBER+1 to NUMBER+10
  182.       if VAR.a = 'VAR.'a then VAR.a = ' '
  183.    end
  184.    if value('VAR.'NUMBER+1) = ' ' then return
  185.    EXIST = 'yes'
  186.    MSG.0 = 10
  187.    NEWNUM = NUMBER
  188.    do y = 1 to 10
  189.       NEWNUM = NEWNUM+1
  190.       MSG.y = value('VAR.'NEWNUM)'                  '
  191.    end
  192.    NUMBER = NUMBER+10
  193.    DATA = 'files'NUMBER'.0'
  194.    interpret DATA "= 0"
  195.    drop DATA NEWNUM
  196.    BUTTON = vcheckbox("Choose the files to view:", MSG, value('files'||NUMBER), 3)
  197.    if BUTTON = 'OK' then do e = 1 to value('files'||NUMBER'.0')
  198.       DISKFILES = strip(DISKFILES value('files'||NUMBER'.'e))
  199.    end
  200.    call SubDiskFiles
  201.    if DISKFILES = '' then drop DISKFILES
  202.    DATA = 'files'||NUMBER'.'
  203.    drop MSG. value(DATA) DATA
  204. return
  205. Date2:
  206.    PAR.i = ''
  207.    T1.0 = 2
  208.    T1.1 = 'On or after MMDDYY: (-t)      '
  209.    T1.2 = 'Before MMDDYY: (-T)      '
  210.    T2.0 = 2
  211.    T2.1 = ''
  212.    T2.2 = ''
  213.    do until (OK1 = 'ok')&(OK2 = 'ok')
  214.       DATEBUT = vmultbox('Enter the Date(s) in MMDDYY format:', T1, 6, 0, T2, 3)
  215.       if DATEBUT = 'CANCEL' then do
  216.          OK1 = 'ok' ; OK2 = 'ok'
  217.       end
  218.       if T2.1 = '' then OK1 = 'ok' ; if T2.2 = '' then OK2 = 'ok'
  219.       if (length(T2.1) = 6)&(datatype(T2.1,'W') = 1) then OK1 = 'ok'
  220.       if (length(T2.2) = 6)&(datatype(T2.2,'W') = 1) then OK2 = 'ok'
  221.    end
  222.    select
  223.       when (T2.1 = '')&(T2.2 = '')&(DATEBUT = 'OK') then PAR.i = '-t'
  224.       when (T2.1<>'')&(T2.2<>'') then PAR.i = '-t'T2.1 '-T'T2.2
  225.       when T2.1 = '' then PAR.i = '-T'T2.2
  226.       when T2.1<>'' then PAR.i = '-t'T2.1
  227.       otherwise nop
  228.    end
  229. return PAR.i
  230. ListFile:
  231.    LST.0 = 2
  232.    LST.1 = 'Specify the complete drive:\path\filename.ext   '
  233.    LST.2 = 'of the list file you want to create.'
  234.    LST.VSTRING = ''
  235.    do until RESULT<>'NO WAY'
  236.       BUTLIST = vinputbox("List File:", LST, 40, 3)
  237.       drop SLASH FILEN RESULT
  238.       if LST.VSTRING<>'' then do
  239.          SLASH = lastpos('\',LST.VSTRING)
  240.          if SLASH>1 then do
  241.             DIRN = left(LST.VSTRING,SLASH-1)
  242.             FILEN = substr(LST.VSTRING,SLASH+1)
  243.             call Validate DIRN
  244.          end
  245.       end
  246.       else if BUTLIST='OK' then RESULT='NO WAY'
  247.    end
  248.    if RESULT<>'RESULT' then do
  249.       if right(RESULT,1) = '\' then LST.VSTRING = RESULT''FILEN
  250.       else LST.VSTRING = RESULT'\'FILEN
  251.    end
  252.    if (SLASH = 0)&(substr(LST.VSTRING,2,1)<>':') then LST.VSTRING = directory()'\'LST.VSTRING
  253.    else if SLASH = 0 then do
  254.       CURDIR = directory()
  255.       call directory left(LST.VSTRING,2)
  256.       THAT = directory()
  257.       call directory(CURDIR)
  258.       if right(THAT,1)<>'\' then LST.VSTRING = THAT'\'substr(LST.VSTRING,3)
  259.       else LST.VSTRING = THAT''substr(LST.VSTRING,3)
  260.    end
  261.    if LST.VSTRING<>'' then PAR2.q = '-@'LST.VSTRING
  262.    else PAR2.q = ''
  263. return PAR2.q
  264. Validate:
  265.    procedure
  266.    arg VALID
  267.    if (VALID = '')|(VALID = '\') then return VALID
  268.    if (VALID = '.')|(VALID = '.\') then return directory()
  269.    if (VALID = '..')|(VALID = '..\') then do
  270.       SLASH = lastpos('\',directory())
  271.       VALID = left(directory(),SLASH-1)
  272.       if substr(VALID,2) = ':' then VALID = VALID'\'
  273.       return VALID
  274.    end
  275.    VALIDLEN = length(VALID)
  276.    if (substr(VALID,2) = ':')&(datatype(left(VALID,1),'M') = 1) then return VALID
  277.    if (substr(VALID,2) = ':\')&(datatype(left(VALID,1),'M') = 1) then return VALID
  278.    if right(VALID,1) = '\' then VALID = left(VALID,VALIDLEN-1)
  279.    call sysfiletree VALID, 'TEST'
  280.    if TEST.0 = 1 then return VALID
  281.    MSG.0 = 3
  282.    MSG.1 = 'Please specify a directory name that exists.'
  283.    MSG.2 = VALID
  284.    MSG.3 = 'does not exist.'
  285.    call vmsgbox 'Sorry!', MSG, 1
  286. return 'NO WAY'
  287. About:
  288.    MSG.0 = 8
  289.    call linein TEXT,1
  290.    do 241
  291.       call linein TEXT
  292.    end
  293.    do y = 1 to 8
  294.       if y = 6 then MSG.6 = ''
  295.       else MSG.y = linein(TEXT)
  296.    end
  297.    ABOUT = vmsgbox("About.....", MSG, 3)
  298.    drop MSG.
  299.    if ABOUT = 'CANCEL' then return
  300.    rc = stream('ZIPENG.DOC', 'c', 'query exists')
  301.    if rc<>'' then DOCFILE = rc
  302.    else do
  303.       rc = syssearchpath('PATH','ZIPENG.DOC')
  304.       if rc<>'' then DOCFILE = rc
  305.    end
  306.    if DOCFILE<>'DOCFILE' then do
  307.       POS.left = 35 ; POS.right = 65 ; POS.top = 50 ; POS.bottom = 35
  308.       WINDOW = vopenwindow('Zip Engine', BG, POS)
  309.       call vsetfont WINDOW, 'SYSTEM', 10
  310.       call vforecolor WINDOW, FG
  311.       call vsay WINDOW, 150, 500, 'Working.....'
  312.       call vsay WINDOW, 150, 300, 'Please wait.....'
  313.       do THATNUM = 1 while lines(DOCFILE) = 1
  314.          MSG.THATNUM = left(linein(DOCFILE),75)
  315.       end
  316.       call lineout DOCFILE
  317.       MSG.THATNUM = ' '
  318.       MSG.0 = THATNUM-1
  319.       call vlistbox "View the ZIPENG.DOC file:", MSG, 90, 10, 1
  320.       call vclosewindow WINDOW
  321.    end
  322.    else do
  323.       MSG.0 = 3
  324.       call linein TEXT
  325.       do y = 1 to 3
  326.          MSG.y = linein(TEXT)
  327.       end
  328.       call vmsgbox "Sorry!", MSG, 1
  329.    end
  330. return
  331. Sure:
  332.    if PAR2.q = '-c' then do
  333.       ITEM = 'screen'
  334.       THAT = '-p'
  335.    end
  336.    if PAR2.q = '-p' then do
  337.       ITEM = 'printer'
  338.       THAT = '-c'
  339.    end
  340.    MSG.0 = 8
  341.    MSG.1 = "You can't extract to" ITEM "and to disk at the same time.  Plus,"
  342.    MSG.2 = "if you're extracting any non-text files, your" ITEM "is going"
  343.    MSG.3 = "to go nuts!  Furthermore, you can't use the" THAT", -$, -@, -d,"
  344.    MSG.4 = "-J, -o, -f, or -n switches with the" PAR2.q "switch.  So....are"
  345.    MSG.5 = "you sure you want to use the" PAR2.q "switch now?  (If you say"
  346.    MSG.6 = "yes, we'll get rid of all those illegal switches for you.)  Do"
  347.    MSG.7 = "you really want to extract to" ITEM "instead of to disk?  Click"
  348.    MSG.8 = "on NO to drop the" PAR2.q "switch."
  349.    BUTTON = vmsgbox("Really?", MSG, 6)
  350.    if BUTTON = 'NO' then return ' /'OPTIONS
  351.    COUNT = words(OPTIONS)
  352.    do g = 1 to COUNT
  353.       TRIAL = left(word(OPTIONS,g),2)
  354.       select
  355.          when (ITEM = 'printer')&(TRIAL = '-c') then do
  356.             OPTIONS = delword(OPTIONS,g,1)
  357.             g = g-1
  358.          end
  359.          when TRIAL = '-$' then do
  360.             OPTIONS = delword(OPTIONS,g,1)
  361.             g = g-1
  362.          end
  363.          when TRIAL = '-@' then do
  364.             select
  365.                when pos('"',word(OPTIONS,g))>0 then do
  366.                   OPTIONS = delword(OPTIONS,g,1)
  367.                   do while pos('"',word(OPTIONS,g)) = 0
  368.                      OPTIONS = delword(OPTIONS,g,1)
  369.                   end
  370.                   OPTIONS = delword(OPTIONS,g,1)
  371.                end
  372.                when pos("'",word(OPTIONS,g))>0 then do
  373.                   OPTIONS = delword(OPTIONS,g,1)
  374.                   do while pos("'",word(OPTIONS,g)) = 0
  375.                      OPTIONS = delword(OPTIONS,g,1)
  376.                   end
  377.                   OPTIONS = delword(OPTIONS,g,1)
  378.                end
  379.                otherwise OPTIONS = delword(OPTIONS,g,1)
  380.             end
  381.             g = g-1
  382.          end
  383.          when TRIAL = '-d' then do
  384.             OPTIONS = delword(OPTIONS,g,1)
  385.             g = g-1
  386.          end
  387.          when TRIAL = '-J' then do
  388.             OPTIONS = delword(OPTIONS,g,1)
  389.             g = g-1
  390.          end
  391.          when TRIAL = '-o' then do
  392.             OPTIONS = delword(OPTIONS,g,1)
  393.             g = g-1
  394.          end
  395.          when TRIAL = '-f' then do
  396.             OPTIONS = delword(OPTIONS,g,1)
  397.             g = g-1
  398.          end
  399.          when TRIAL = '-n' then do
  400.             OPTIONS = delword(OPTIONS,g,1)
  401.             g = g-1
  402.          end
  403.          otherwise nop
  404.       end
  405.    end
  406. return PAR2.q'/'OPTIONS
  407. End:
  408. exit
  409.