home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / mr2_230.zip / SAVEVCS.CMD < prev    next >
OS/2 REXX Batch file  |  1995-04-27  |  6KB  |  192 lines

  1. /*
  2.     MR/2 - SaveVCs.CMD
  3.  
  4.     Copyright (c) 1995, Nick Knight
  5.     All Rights Reserved.
  6.  
  7.     Author:     Nick Knight
  8.     Created:    01/06/95
  9.     Usage:        savevcs target.qwk
  10.     Purpose:    savevcs.cmd will pack MR/2-created NDX files back into
  11.                 the original QWK source packet (including MR/2 "merged"
  12.                 packets.)
  13.  
  14.     US Mail:    Nick Knight, 1823 David Ave.,  Parma, Ohio 44134
  15.     Fidonet:    1:157/2 or 1:/157/200
  16.     Internet:    nick.knight@pcohio.com
  17.     Compuserve: 76066,1240
  18.     BBS:        Private messages on Nerd's Nook, 356-1772 or 356-1872
  19.  
  20.     SaveVCs.CMD - MR/2 QWK Repacking Utility.
  21.  
  22.     This cmd file will repack the source QWK packet with NDX files
  23.     after the Virtual Conferences have been built.    If MR/2 can find
  24.     it, it is started up in a background session when virtual conference
  25.     building has been completed.
  26.  
  27.     For PKZip use, The -u says to update, the -k says to keep the
  28.     original ZIP file date. The -x claused exclude index files for
  29.     non-packet conferences. %1 is replaced with the original QWK packet
  30.     name.
  31.  
  32.     The date/time stamp is also preserved by this script.  It is first
  33.     saved in a string called datestamp, then this is passed to the MR/2
  34.     sfiledt.exe utility at the end of the script.
  35. */
  36.  
  37. echo off
  38.  
  39. /***********************************************************************/
  40. /*        A R C H I V E R     C O M M A N D     D E F I N I T I O N S       */
  41. /***********************************************************************/
  42. /*    To add support for a new unpacker, simply supply a new command
  43.     definition here.  The file name to unpack will be appended to
  44.     the end of the supplied command.  You can customize in more detail
  45.     by modifying the code directly, if need be.
  46. */
  47.  
  48. path = ''       /* path prefix, if needed for archivers, can be set here */
  49. UseInfoZip = 1    /* set this to 1 to use INFOZIP's ZIP.EXE instead of PKZIP's */
  50.  
  51. if (UseInfoZip > 0) then do
  52.     zip_leader =   'zip -jku "'
  53.     zip_trailer =  '" *.ndx -x Repl*.ndx InBasket.ndx'
  54. end
  55. else do
  56.     zip_leader =   'pkzip -u -k -xRepl*.ndx -xInBasket.ndx "'
  57.     zip_trailer =    '" *.ndx'
  58. end
  59.  
  60. arj_leader =       'arj u -e -s1 -xRepl*.ndx -xInBasket.ndx "'
  61. arj_trailer =       '" *.ndx'
  62.  
  63. lha_leader =       'lh a /i /m "'           /* For lh2 for OS/2 */
  64. lha_trailer =       '" *.ndx'
  65.  
  66. zoo_command =        'zoo u'
  67. lharc_command =     'lha u'
  68. arc_command =        'arc u'
  69.  
  70. /***********************************************************************/
  71. /*                       S A V E V C S . C M D                           */
  72. /***********************************************************************/
  73. /*
  74.     Returns -1 if it the file appears not to be a packed "archive".
  75.     Returns -2 if the file doesn't exist
  76.     Otherwise, the "archive_id" is returned (1 -> 6).
  77. */
  78.  
  79. parse arg filename
  80.  
  81. if (filename = "") then do
  82.     say ' '
  83.     say 'usage: savevcs bbs-pkt.qwk'
  84.     say ' '
  85.     pause
  86.     return -1
  87. end
  88.  
  89. /* trim off any quotations marks then filter in, it happens! ("filename") */
  90. if (substr(filename,1,1) = '"') then do
  91.     filename = substr(filename,2,length(filename)-2)
  92. end
  93.  
  94. Say ' '
  95. Say 'SaveVCs v1.00 - QWK Packet NDX Update Utility'
  96. Say 'Copyright (c) 1995, Nick Knight - All Rights Reserved.'
  97. Say ' '
  98. Say 'Repacking: '||filename
  99. Say ' '
  100.  
  101. if stream(filename,'c','query exists') = "" then do
  102.     say '** ERROR:  Named packet "'||filename||'" not found.'
  103. /*    pause */
  104.     return -2
  105. end
  106.  
  107. /*
  108.   Check for long file name - copy to 'shorter' 8.3 name for packer
  109. */
  110.  
  111. flongname = length(filename) - lastpos('\',filename) - 12
  112. if flongname <= 0 then do
  113.     flongname = length(filename) - pos('.',filename) - 3
  114. end
  115. if flongname > 0 then do
  116.     origname = filename
  117.     'copy "'filename'" MR2$TMP.QWK'
  118.     filename = 'MR2$TMP.QWK'
  119.     flongname = 1
  120. end
  121.  
  122. datestamp = stream(filename,'c','query datetime')
  123.  
  124. status = stream(filename,'c','open read')           /* read only */
  125. header = charin(filename,1,16)
  126.  
  127. /*    If it doesn't have at least 16 chars, it probably isn't real */
  128. if chars(filename) = 0 then do
  129.     status = stream(filename,'c','close')
  130.     say 'Packet "'||filename||'" appears to be too small to be valid'
  131. /*    pause */
  132.     return -1
  133. end
  134.  
  135. status = stream(filename,'c','close')       /* Close the file - Important! */
  136.  
  137. archiver_id = which_archiver(header)        /* call analyzer function, below */
  138.  
  139. select                                        /* execute the corresponding command */
  140.     when archiver_id = -1 then do
  141.         say "UNKNOWN ARCHIVE TYPE: " filename
  142.         return -1
  143.     end
  144.     when archiver_id = 1 then path || zip_leader||filename||zip_trailer
  145.     when archiver_id = 2 then path || arj_leader||filename||arj_trailer
  146.     when archiver_id = 3 then path || zoo_leader||filename||zoo_trailer
  147.     when archiver_id = 4 then path || lharc_leader||filename||lharc_trailer
  148.     when archiver_id = 5 then path || lha_leader||filename||lha_trailer
  149.     when archiver_id = 6 then path || arc_leader||filename||arc_trailer
  150.     otherwise
  151. end
  152.  
  153. if RC <> 0 then return RC
  154.  
  155. '..\\sfiledt' filename datestamp
  156.  
  157. if flongname > 0 then do
  158.     'copy MR2$TMP.QWK "'origname'"'
  159.     'del MR2$TMP.QWK'
  160. end
  161.  
  162. return archive_id                            /* return the ID type */
  163.  
  164.  
  165. /***********************************************************************/
  166. /*                   W H I C H     A R C H I V E R                       */
  167. /***********************************************************************/
  168. /*
  169.     Returns -1 if it can't tell, otherwise it returns the archiver id
  170.     that I've assigned to the ones I know about.  Others can be easily
  171.     added.    Some of this may not be correct (lha vs lharc), but I tested
  172.     as much of it as I could.  Looks OK.
  173. */
  174.  
  175. which_archiver:
  176.  
  177. parse arg header                /* header is the first 16 bytes of file */
  178.  
  179. select
  180.     when substr(header,1,2) = "PK" then id = 1              /* PKWare */
  181.     when substr(header,1,1) = '`' && substr(header,2,1) = '\xEA' then id = 2 /* ARJ */
  182.     when substr(header,1,3) = "ZOO" then id = 3             /* ZOO */
  183.     when substr(header,3,5) = "-lh0-" then id = 4           /* LHARC */
  184.     when substr(header,3,5) = "-lh1-" then id = 4           /* LHARC */
  185.     when substr(header,3,3) = "-lh" then id = 5             /* LHA */
  186.     when c2d(substr(header,1,1)) = 26 then id = 6            /* ARC */
  187.     otherwise
  188.         id = -1             /* Archiver unknown or not an archive */
  189. end
  190. return id
  191.  
  192.