home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / mr2_230.zip / MQWK.CMD < prev    next >
OS/2 REXX Batch file  |  1996-02-01  |  7KB  |  336 lines

  1. /*
  2.     MR/2 - MQWK.CMD
  3.  
  4.     Copyright (c) 1994, Nick Knight
  5.     All Rights Reserved.
  6.  
  7.     Author:     Nick Knight
  8.     Created:    12/28/93
  9.     Usage:        mqwk target.qwk packet1.qwk packet2.qwk [packet3.qwk ...]
  10.     Purpose:    mqwk.cmd will merge two or more QWK packets into a single
  11.                 packet.
  12.  
  13.     US Mail:    Nick Knight, 1823 David Ave.,  Parma, Ohio 44134
  14.     Fidonet:    1:157/2 or 1:/157/200
  15.     Internet:    nick.knight@pcohio.com
  16.     Compuserve: 76066,1240
  17.     BBS:        Private messages on Nerd's Nook, 356-1772 or 356-1872
  18. */
  19.  
  20. /*****    COMMANDS FOR USING PKZIP AND PKUNZIP (DEFAULT) *********/
  21. pkunzip = 'pkunzip -n'
  22. pkzip = 'start /min /b /c pkzip -x*.ndx -xmr2*.*'
  23. pkziptrailer = '>mqwk.log'
  24.  
  25. /*****     ALTERNATIVE COMMANDS FOR USING INFOZIP *********/
  26. /*
  27. pkunzip = 'unzip -n'
  28. pkzip = 'zip -j'
  29. pkziptrailer = '-x *.ndx mr2*.* >mqwk.log'
  30. */
  31.  
  32. dirname = 'TMP$$'
  33.  
  34. /***********************************************************************/
  35. /*                        M E R G E     Q W K                               */
  36. /***********************************************************************/
  37. echo off
  38.  
  39. rest = ''
  40. next = ''
  41.  
  42. parse arg target source1 source2 rest
  43.  
  44. if ((source2 = "") | (source1 = "") | (target = "")) then do
  45.     say ' '
  46.     say 'usage: mqwk makenew.qwk source1.qwk source2.qwk [source3.qwk ...]'
  47.     say ' '
  48.     return -1
  49. end
  50.  
  51. Say ' '
  52. Say 'MQwk v1.01 - QWK Packet merge utility'
  53. Say 'Copyright (c) 1994, Nick Knight - All Rights Reserved.'
  54. Say ' '
  55.  
  56. if stream(target,'c','query exists') <> "" then do
  57.     say '** WARNING:  Target file exists.'
  58. end
  59.  
  60. control = 'Control.dat'
  61. ctrl_tmp1 = 'c1$$$tmp.dat'
  62. ctrl_tmp2 = 'c2$$$tmp.dat'
  63.  
  64. msg = 'Messages.dat'
  65. wip = 'Messages.wip'
  66. s1 = stream(source1,'c','query exists')
  67. s2 = stream(source2,'c','query exists')
  68.  
  69. if s1 == "" then do
  70.     say '** WARNING:  Source file' source1 'does not exists.'
  71.     return 1
  72. end
  73.  
  74. if s2 == "" then do
  75.     say '** WARNING:  Source file' source2 'does not exists.'
  76.     return 2
  77. end
  78.  
  79. 'mkdir' dirname '2>nul'
  80. 'for %%i in ('||dirname||'\*.*) do del %%i 2>nul'
  81.  
  82. 'cd' dirname
  83.  
  84. say 'Unpacking' s1 '...'
  85. pkunzip s1
  86. 'del *.ndx 2>nul'
  87. 'ren' msg wip
  88. 'ren' Control ctrl_tmp1
  89.  
  90. do while s2 <> ""
  91.  
  92.     say 'Unpacking' s2 '...'
  93.     pkunzip s2
  94.     'del *.ndx 2>nul'
  95.     'ren' Control ctrl_tmp2
  96.  
  97.     say 'Merging message bases ...'
  98.  
  99.     status = stream(wip,'c','open')
  100.  
  101.     /* a block of nulls is often (always?) appended at the end. */
  102.     /* read back a block at a time until a valid block is found. */
  103.     /* leave "next" write position just past last valid block. */
  104.  
  105.     testback = 129
  106.     status = stream(wip,'c','seek <'testback)
  107.     block = charin(wip,,128)
  108.     do while (c2d(substr(block,2,1)) = 0 | c2d(substr(block,2,1)) = 255)
  109.         testback = testback + 128
  110.         status = stream(wip,'c','seek <'testback)
  111.         block = charin(wip,,128)
  112.     end
  113.  
  114.     status = stream(msg,'c','open read')
  115.     status = stream(msg,'c','seek 128')
  116.  
  117.     do while (chars(msg) > 0)
  118.         block = charin(msg,,128)
  119.         ctr = charout(wip,block)
  120.         if ctr <> 0 then do
  121.             call beep 262,200
  122.             say ' '
  123.             say '** Warning: Write error, probably disk full.'
  124.             say 'Packet merge cannot be completed'
  125.             say ' '
  126.             exit -1
  127.         end
  128.     end
  129.  
  130.     status = stream(wip,'c','close')
  131.     status = stream(msg,'c','close')
  132.  
  133.     'del' msg
  134.     erc = MControl(control, ctrl_tmp1, ctrl_tmp2)
  135.     'del' ctrl_tmp1
  136.     'del' ctrl_tmp2
  137.     'ren' control ctrl_tmp1
  138.  
  139.     status = next_file(rest)
  140.  
  141. end
  142.  
  143. 'ren' ctrl_tmp1 Control
  144. 'ren' wip msg
  145.  
  146. 'cd ..'
  147. if target <> "~" then do
  148.     pkzip target dirname||'\*.*' pkziptrailer
  149. /*    'for %%i in ('||dirname||'\*.*) do del %%i >nul' */
  150. /*    'rmdir' dirname */
  151. end
  152.  
  153. return 0
  154.  
  155. /******************************/
  156. /* Procedure next_file          */
  157. /******************************/
  158. next_file:
  159. parse arg s1 rest2
  160. rest = rest2
  161. 'cd ..'
  162. s2 = ""
  163. if s1 <> "" then do
  164.     s2 = stream(s1,'c','query exists')
  165.     say ' '
  166. end
  167. 'cd' dirname
  168. return 0
  169.  
  170. MControl:  PROCEDURE EXPOSE ctrl_tmp1 ctrl_tmp2 control
  171. /***********************************************************************/
  172. /*                          M E R G E    C O N F I G                       */
  173. /***********************************************************************/
  174. echo off
  175.  
  176. target = ARG(1)
  177. src1 = ARG(2)
  178. src2 = ARG(3)
  179.  
  180. cs1 = ''
  181. cs2 = ''
  182. ctmp = 'o1$$tmp.dat'
  183. cwip = 'ctl$$tmp.dat'
  184. iline = ''
  185. line1 = ''
  186. line2 = ''
  187. nbr_conferences_1 = 0
  188. nbr_conferences_2 = 0
  189. c1 = 0
  190. c2 = 0
  191.  
  192. say 'Merging Control.dat files ...'
  193.  
  194. if stream(target,'c','query exists') <> "" then do
  195.     say '** WARNING:  Target file exists.'
  196. end
  197.  
  198. cs1 = stream(ctmp,'c','query exists')
  199. if cs1 <> "" then do
  200.     'del' cs1 '>nul'
  201. end
  202.  
  203. cs1 = stream(cwip,'c','query exists')
  204. if cs1 <> "" then do
  205.     'del' cs1 '>nul'
  206. end
  207.  
  208. cs1 = stream(src1,'c','query exists')
  209. cs2 = stream(src2,'c','query exists')
  210.  
  211. if cs1 == "" then do
  212.     say '** WARNING:  Source file' src1 'does not exists.'
  213.     return 1
  214. end
  215.  
  216. if cs2 == "" then do
  217.     say '** WARNING:  Source file' src2 'does not exists.'
  218.     return 2
  219. end
  220.  
  221. status = stream(cwip,'c','open write')
  222.  
  223. status = stream(cs1,'c','open read')
  224. status = stream(cs2,'c','open read')
  225. status = stream(ctmp,'c','open write')
  226.  
  227. say 'Creating control header ...'
  228.  
  229. ctr = 10
  230. do while ctr > 0
  231.     iline = linein(cs1)
  232.     erc = lineout(cwip,iline)
  233.     ctr = ctr - 1
  234. end
  235.  
  236. iline = linein(cs1)
  237. nbr_conferences_1 = iline;
  238.  
  239. ctr = 11
  240. do while ctr > 0
  241.     iline = linein(cs2)
  242.     ctr = ctr - 1
  243. end
  244.  
  245. nbr_conferences_2 = iline
  246. prev_conference = -1
  247. totctr = 0
  248. line1 = linein(cs1)
  249. c1 = line1
  250. line2 = linein(cs2)
  251. c2 = line2
  252.  
  253. say 'Merging conferences ...'
  254.  
  255. do while 1
  256.     if c1 > c2 then do
  257.         erc = lineout(ctmp,line2)
  258.         totctr = totctr + 1;
  259.         line2 = linein(cs2)
  260.         erc = lineout(ctmp,line2)
  261.         line2 = linein(cs2)
  262.         c2 = line2
  263.         nbr_conferences_2 = nbr_conferences_2 - 1
  264.     end
  265.     else if c1 < c2 then do
  266.         erc = lineout(ctmp,line1)
  267.         totctr = totctr + 1;
  268.         line1 = linein(cs1)
  269.         erc = lineout(ctmp,line1)
  270.         line1 = linein(cs1)
  271.         c1 = line1
  272.         nbr_conferences_1 = nbr_conferences_1 - 1
  273.     end
  274.     else do
  275.         erc = lineout(ctmp,line2)
  276.         totctr = totctr + 1;
  277.         line2 = linein(cs2)
  278.         erc = lineout(ctmp,line2)
  279.         line2 = linein(cs2)
  280.         c2 = line2
  281.         nbr_conferences_2 = nbr_conferences_2 - 1
  282.  
  283.         line1 = linein(cs1)
  284.         line1 = linein(cs1)
  285.         c1 = line1
  286.         nbr_conferences_1 = nbr_conferences_1 - 1
  287.     end
  288.     if nbr_conferences_1 < 1 then do
  289.         if nbr_conferences_2 < 1 then do
  290.             leave
  291.         end
  292.         c1 = 30000
  293.     end
  294.     if nbr_conferences_2 < 1 then do
  295.         c2 = 30000
  296.     end
  297. end
  298.  
  299. say 'Appending control trailer ...'
  300.  
  301. erc = lineout(ctmp,line1)
  302.  
  303. do while lines(cs1) > 0
  304.     line1 = linein(cs1)
  305.     erc = lineout(ctmp,line1)
  306. end
  307.  
  308. status = stream(cs1,'c','close')
  309. status = stream(cs2,'c','close')
  310.  
  311. say 'Combining header, conferences and trailer ...'
  312.  
  313. iline = totctr
  314. erc = lineout(cwip,iline)
  315.  
  316. status = stream(ctmp,'c','close')
  317. status = stream(ctmp,'c','open read')
  318.  
  319. do while lines(ctmp) > 0
  320.     iline = linein(ctmp)
  321.     erc = lineout(cwip,iline)
  322. end
  323.  
  324. status = stream(cwip,'c','close')
  325. status = stream(ctmp,'c','close')
  326.  
  327. 'copy' cwip target '> nul'
  328. 'del' ctmp '>nul'
  329. 'del' cwip '>nul'
  330.  
  331. Say 'Control file "'||target||'" has been created.'
  332.  
  333. return 0
  334.  
  335.  
  336.