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