home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / qwk2text.zip / QWK2TEXT.CMD < prev    next >
OS/2 REXX Batch file  |  1995-02-03  |  3KB  |  95 lines

  1. /* 
  2.       Author:     Dennis Peterson, Sysop, OS/2 Northwest BBS
  3.       FidoNet:    1:343/179
  4.       Internet:   dpeterso@os2nw.ces.wa.com
  5.       Date:       Feb. 3, 1995
  6.       Version:    3.5
  7.       Warranty:   Guaranteed to occupy space on your disk
  8.  
  9.       History:
  10.          3.1 - first release
  11.          3.5 - added abilty to return only messages that contain a pattern
  12.                provided on command line.
  13.              - added defaults for commandline args
  14.  
  15.       Purpose:
  16.       This utility reads QWK-format messages.dat files as found in a QKW
  17.       download and converts the messages to ASCII text. If a pattern is
  18.       included it will extract only messages that contain that pattern. The
  19.       pattern match is case sensitive.
  20.  
  21.       Usage:
  22.       1) Unpack a .QWK message packet
  23.       2) Look for a file called messages.dat. It's there.
  24.       3) Run this REXX program. Use the > character to redirect the output
  25.          to a file. That's it! The file will be coverted to a text file.
  26.  
  27.          qwk2text [messages.dat] [pattern] (defaults: messages.dat ---)      
  28.  
  29.       If no args are provided messages.dat is assumed and all messages
  30.       will be extracted using --- for pattern.
  31. */
  32.  
  33.  
  34. /* Initialize REXX */
  35. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  36. call SysLoadFuncs
  37.  
  38. /* define constants */
  39. CR    = '0d'x
  40. QWKLF = 'e3'x
  41.  
  42.  
  43. parse arg messages_file pattern debris
  44.  
  45. /* messages.dat is the message file normally found in QWK packets */
  46. if messages_file = "" then
  47.    messages_file = 'messages.dat'
  48.  
  49. /* --- is standard QWK end of message string and is found in all messages */
  50. if pattern = "" then
  51.    pattern = '---'
  52.  
  53. rc = SysFileTree(messages_file, 'file', 'F')
  54. if file.0 = 0 then do
  55.    say 'Error: 'messages_file' not found'
  56.    exit
  57. end
  58.  
  59. /* Read and ignore QWK packet message header - may use it in next version */
  60.  
  61. Header_block = charin(messages_file,1,128)
  62.  
  63. /* Start message translation loop */
  64.  
  65. Do while Chars(messages_file) > 0
  66.  
  67. /* Get the message header block, extract message #, date, time, to:, from:, 
  68.    subject:, discard rest */
  69.  
  70.    message_block = charin(messages_file,,128)
  71.  
  72. /* Each message is made up of 128 byte records. The number of records in a
  73.    particular message is found at offset:length 117:6 in the message header
  74.    block. This number includes the message header block so 1 is subtracted. */
  75.  
  76.    num_recs = strip(substr(message_block,117,6) - 1,'B')
  77.    message_body = charin(messages_file,,num_recs * 128)
  78.  
  79. /* convert QWK end-of-line to CR (sans LF) and say result  */
  80.    result = translate(message_body, CR, QWKLF)
  81.  
  82.    if POS(pattern, result) > 0 then do
  83.       say '*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*'
  84.       say 'Message: 'strip(substr(message_block,2,7),'B')
  85.       say 'Date:    'substr(message_block,9,8)'    Time:    'substr(message_block,17,5)
  86.       say 'From:    'strip(substr(message_block,47,25),'B')
  87.       say 'To:      'strip(substr(message_block,22,25),'B')
  88.       say 'Subject: 'strip(substr(message_block,72,25),'B')
  89.       say '--------------------------------------------------------------------'
  90.       say
  91.       say result
  92.    end
  93. end
  94. exit
  95.