home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / zipbrexx.zip / zipbrand.cmd < prev    next >
OS/2 REXX Batch file  |  1994-11-17  |  10KB  |  195 lines

  1. /* -----------------------------   Rexx   -------------------------------- */
  2. /*                                                                         */
  3. /* ZIPBRAND.CMD -- BRAND THE ZIP FILES WITH BBS SPECIFIC COMMENT v1.0      */
  4. /*                                                                         */
  5. /* This REXX exec will brand all zip files in a path with a user supplied  */
  6. /* comment.  It also changes the date on the file to the 'true' date, this */
  7. /* is newest date of any file contained in the archive.                    */
  8. /*                                                                         */
  9. /*  Syntax: zipbrand /P{filespec} /C{filespec} /L{filespec} /V /Q          */
  10. /*                                                                         */
  11. /*      OPTION   DESCRIPTION                 DEFAULT                       */
  12. /*        /P     Starting path filespec      ./                            */
  13. /*        /C     Comment file filespec       ./zipbrand.cmt                */
  14. /*        /L     Log file filespec           stdout                        */
  15. /*        /V     Verbose logging             Errors only                   */
  16. /*        /Q     Quiet                       Write stdout, stderr          */
  17. /*                                                                         */
  18. /*               Tested with: Zip 2.0.1 (Sept 19th 1993)                   */
  19. /*                No other archive program was tested!                     */
  20. /*                                                                         */
  21. /*  KNOWN PROBLEMS AND BUGS:                                               */
  22. /*  1) None, perfection is so seldom seen (-:                              */
  23. /*                                                                         */
  24. /*  HISTORY                                                                */
  25. /*  94/11/17 - Released version 1.0 into public domain.                    */
  26. /*                                                                         */
  27. /* ----- DISCLAIMER ---- DISCLAIMER ---- DISCLAIMER ---- DISCLAIMER ------ */
  28. /* Engage! BBS and Jona Computer Associates offers this code to the public */
  29. /* domain with no written or expressed warranties.  You may use this code  */
  30. /* for any reason.  You are authorized to alter this code, but we ask that */
  31. /* if you distribute the altered code, that this original code be packaged */
  32. /* with the altered code.                                                  */
  33. /* ----- DISCLAIMER ---- DISCLAIMER ---- DISCLAIMER ---- DISCLAIMER ------ */
  34. /*                                                                         */
  35. /*      (C) Copyright Engage! BBS and Jona Computer Associates 1994.       */
  36. /*                           All rights reserved.                          */
  37. /*                                                                         */
  38. /*            Author: Joel R. Derider   Date Written: 11/01/94             */
  39. /* ----------------------------------------------------------------------- */
  40.  
  41. spawnbbs: arg arg.1 arg.2 arg.3 arg.4 arg.5 .;arg arg.0; arg.0 = words(arg.0)
  42.  
  43.    call init_program
  44.    call modify_zip_files
  45.    call end_program
  46.    exit 0
  47.  
  48. /* ----------------------------------------------------------------------- */
  49. /* initialize the program                                                  */
  50. /* ----------------------------------------------------------------------- */
  51. init_program: ;
  52.    ask         =  0
  53.    rdebug      =  0
  54.    verbose     =  0
  55.    zipparms    = '-o -z'
  56.    quiet       =  0
  57.    timestamp   =  date('S')'.'substr(time('L'),1,length(time('L'))-4)
  58.  
  59.    call Verify_input_parameters
  60.    call Set_necessary_defaults
  61.    call Set_log_redirection
  62.  
  63.    return
  64. /* ----------------------------------------------------------------------- */
  65. /* verify the input parameters.  Will exit from here if input is bad       */
  66. /* ----------------------------------------------------------------------- */
  67. verify_input_parameters: ;
  68.    do ctr = 1 to arg.0 by 1
  69.       select
  70.          when substr(arg.ctr,1,2) = '/P' then do
  71.               spath   = substr(arg.ctr,3)
  72.               '@cd 'spath
  73.               if rc > 0 then show_syntax(P)
  74.                                               end
  75.          when substr(arg.ctr,1,2) = '/C' then do
  76.               cpath   = substr(arg.ctr,3)
  77.               if stream(cpath,'C','query exists') = "" then show_syntax(C)
  78.                                               end
  79.          when substr(arg.ctr,1,2) = '/L' then do
  80.               lpath   = substr(arg.ctr,3)
  81.               if stream(lpath,'C','query exists') = "" then do
  82.                  rc = lineout(lpath,timestamp' ===== CREATED LOG FILE==============================')
  83.                  if rc <> 0 then show_syntax(L)
  84.                                                             end
  85.                                               end
  86.          when substr(arg.ctr,1,2) = '/V' then verbose = 1
  87.          when substr(arg.ctr,1,2) = '/Q' then quiet   = 1
  88.          otherwise show_syntax(arg.ctr,1,length(arg.ctr))
  89.       end
  90.    end
  91.  
  92.    return
  93. /* ----------------------------------------------------------------------- */
  94. /* Set the necessary defaults (if the command line doesn't override)       */
  95. /* ----------------------------------------------------------------------- */
  96. set_necessary_defaults: ;
  97.    if spath = 'SPATH' then spath = './'
  98.    if cpath = 'CPATH' then cpath = './zipbrand.cmt'
  99.    if stream(cpath,'C','query exists') = "" then show_syntax(C)
  100.  
  101.    return
  102. /* ----------------------------------------------------------------------- */
  103. /* set the log redirection variable based on command line input            */
  104. /* ----------------------------------------------------------------------- */
  105. set_log_redirection: ;
  106.    if lpath = 'LPATH' then do
  107.       lpath2 = ''
  108.       select
  109.          when  verbose &  quiet then lpath = ' > nul'
  110.          when  verbose & ¬quiet then lpath = ''
  111.          when ¬verbose &  quiet then lpath = ' > nul'
  112.          when ¬verbose & ¬quiet then lpath = ' 1> nul'
  113.          otherwise say 'how did I get here?'
  114.       end
  115.                            end
  116.    else do
  117.       lpath2 = lpath
  118.       select
  119.          when  verbose &  quiet then lpath = ' > nul '
  120.          when  verbose & ¬quiet then lpath = ' >> 'lpath
  121.          when ¬verbose &  quiet then lpath = ' > nul '
  122.          when ¬verbose & ¬quiet then lpath = ' 1> nul 2>> 'lpath
  123.          otherwise say 'how did I get here?'
  124.       end
  125.         end
  126.    return
  127. /* ----------------------------------------------------------------------- */
  128. /* show the syntax of this utility then exit                               */
  129. /* ----------------------------------------------------------------------- */
  130. show_syntax: ; arg badopt
  131.    say ''; say ''
  132.    if badopt = '/?' | badopt = '?' | badopt = 'help' | badopt = '/help' | ,
  133.       badopt = 'h'  | badopt = '/h' then
  134.       nop
  135.    else  say 'Syntax error has occured!  Please correct syntax and try again'
  136.       say ''
  137.    select
  138.       when badopt = 'C' then say 'Error - Comment  filespec not found'
  139.       when badopt = 'P' then say 'Error - Starting filespec not found'
  140.       when badopt = 'L' then say 'Error - Logging  filespec not found'
  141.       otherwise nop
  142.    end
  143.    say 'Syntax: zipbrand /P{filespec} /C{filespec} /L{filespec} /V /Q      '
  144.    say '                                                                   '
  145.    say '  OPTION   DESCRIPTION                 DEFAULT                     '
  146.    say '    /P     Starting path filespec      ./                          '
  147.    say '    /C     Comment file filespec       ./zipbrand.cmt              '
  148.    say '    /L     Log file filespec           stdout                      '
  149.    say '    /V     Verbose logging             Errors only                 '
  150.    say '    /Q     Quiet                       Write stdout, stderr        '
  151.    say '    /?     Display this help           N/A                         '
  152.    say '                                                                   '
  153.    say '  EXAMPLE: To brand all files in the directory tree d:\max\file\dos'
  154.    say '           Using comments in file d:\zipbrand.cmt                  '
  155.    say '           Logging errors to file d:\logs\zipbrand.log             '
  156.    say '                                                                   '
  157.    say '  zipbrand /Pd:\max\file\dos /Cd:\zipbrand\zipbrand.cmt /Ld:\logs\zipbrand.log'
  158.    SAY '                                                                   '
  159.    exit 8
  160. /* ----------------------------------------------------------------------- */
  161. /* modify all zip files in the directory tree                              */
  162. /* ----------------------------------------------------------------------- */
  163. modify_zip_files: ;
  164.  
  165.    rc = sysfiletree(spath'\*.zip',zipfiles,'fs')
  166.  
  167.    rc = lineout(lpath2,'')
  168.    rc = lineout(lpath2,timestamp' ===== BEGIN =======================================')
  169.    rc = lineout(lpath2,'                     Options in effect')
  170.    rc = lineout(lpath2,'                        Start  ='spath)
  171.    rc = lineout(lpath2,'                        Comment='cpath)
  172.    rc = lineout(lpath2,'                        Log    ='lpath)
  173.    rc = lineout(lpath2,'                        Verbose='verbose)
  174.    rc = lineout(lpath2,'                        Quiet  ='quiet)
  175.    rc = lineout(lpath2,'                     Processing 'zipfiles.0' .zip files')
  176.    if lpath2 <> '' then rc = stream(lpath2,'c','close')
  177.  
  178.    do ctr = 1 to zipfiles.0 by 1
  179.       zipfile = strip(substr(zipfiles.ctr,38),'b')
  180.       archbit = substr(zipfiles.ctr,31,1)
  181.       '@type 'cpath' | zip 'zipparms zipfile lpath
  182.       if archbit = '-' then '@attrib -A 'zipfile' > nul'
  183.    end
  184.  
  185.    return
  186. /* ----------------------------------------------------------------------- */
  187. /* end the program                                                         */
  188. /* ----------------------------------------------------------------------- */
  189. end_program: ;
  190.    endtimestamp = date('S')'.'substr(time('L'),1,length(time('L'))-4)
  191.  
  192.    rc = lineout(lpath2,timestamp' ===== END ============================ 'endtimestamp)
  193.  
  194.    return
  195.