home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / utilities / editors / ced-programs / formatnewsheader.ced next >
Text File  |  1994-06-23  |  3KB  |  115 lines

  1. /*
  2.  * FormatNewsHeader.ced
  3.  *
  4.  * Find the next header of a news article (starting with
  5.  * "Article:") and format it in a nice way, stripping all
  6.  * unnecessary lines like "Path", "Nntp-Posting-Host:" etc.
  7.  *
  8.  * Example:
  9.  *
  10.  *   Subject: Re: Byte's Amiga 4000 review...
  11.  *
  12.  *   From: andy@cbmvax.commodore.com (Andy Finkel)
  13.  *   Organization: Flying Cat, Inc.
  14.  *   Date: 11 Jan 93 15:29:12 GMT
  15.  *
  16.  *   Newsgroups: comp.sys.amiga.advocacy
  17.  *   Article: 5376 of comp.sys.amiga.advocacy
  18.  *   Message-ID: <38461@cbmvax.commodore.com>
  19.  *
  20.  * Known Problem:
  21.  *
  22.  *     Cannot handle keywords with more than one line of text.
  23.  *
  24.  * Author: Stefan Winterstein (winter@cs.uni-sb.de)
  25.  * Status: Public Domain
  26.  *
  27.  */
  28.  
  29.  
  30. LF  = '0A'X
  31. options results        /* Allow CygnusEd to pass status variables */
  32.  
  33. address 'rexx_ced'    /* Tell ARexx to talk to CygnusEd */
  34.  
  35. signal on error
  36. signal on syntax
  37.  
  38. status 69
  39. if (result ~= -1) then 'mark block'    /* turns block marking off */
  40.  
  41. /*
  42.  * Find the beginning of the next header.
  43.  */
  44. 'search for' 'rticle:' FALSE FALSE TRUE FALSE
  45. if ~result then do
  46.     okay1 "Could not find 'Article:'"
  47.     exit
  48. end
  49. 'beg of line'
  50. 'mark location' 3
  51.  
  52. /*
  53.  * Now read in line by line until no ':' can be found. This is
  54.  * considered the end of the header.
  55.  * Each line is stored in 'header.keyword', where 'keyword' is
  56.  * the word before the colon.
  57.  */
  58. do until (dppos == 0)
  59.     status 55
  60.         line = result    /* current line of text */
  61.     dppos = index(line, ':')
  62.  
  63.     if (dppos ~= 0) then do
  64.         keyword = left(line, dppos-1)
  65.         /* Avoid syntax problems with '-' in 'Message-ID' */
  66.                 keyword = translate(keyword, '_', '-')
  67.  
  68.         interpret header.keyword "= line"
  69.  
  70.             'down'
  71.     end
  72. end
  73.  
  74. /*
  75.  * Cut the header.
  76.  */
  77. 'mark block'
  78. 'jump to mark' 3
  79. 'cut block'
  80.  
  81. /*
  82.  * Now insert the lines we want (if they exist).
  83.  */
  84. if header.subject ~= 'HEADER.SUBJECT' then
  85.     'text' header.subject
  86. if header.summary ~= 'HEADER.SUMMARY' then
  87.     'text' header.summary
  88. if header.keywords ~= 'HEADER.KEYWORDS' then
  89.     'text' header.keywords
  90. 'text' LF
  91. if header.from ~= 'HEADER.FROM' then
  92.     'text' header.from
  93. if header.organization ~= 'HEADER.ORGANIZATION' then
  94.     'text' header.organization
  95. if header.date ~= 'HEADER.DATE' then
  96.     'text' header.date
  97. 'text' LF
  98. if header.newsgroups ~= 'HEADER.NEWSGROUPS' then
  99.     'text' header.newsgroups
  100. if header.article ~= 'HEADER.ARTICLE' then
  101.     'text' header.article
  102. if header.message_id ~= 'HEADER.MESSAGE_ID' then
  103.     'text' header.message_id
  104. 'text' LF
  105.  
  106. /*
  107.  * Bye.
  108.  */
  109. exit
  110.  
  111. error:
  112.     okay1 "Error in line" sigl LF||"Error code" rc
  113. syntax:
  114.     okay1 "Syntax Error in line" sigl LF||"Error code" rc
  115.