/****** axuucp/rn-list *******************************************************
*
*   NAME
*	rn-list - List available AXsh Newsgroups
*
*   SYNOPSIS
*	rx rn-list.rexx [trailer]
*
*   DESCRIPTION
*	This script scans the AXsh:usr/spool/news hierarchy and reports all
*	existing Newsgroups.  It can be used to create the NewsGroups file
*	automatically.  The optional trailer will be printed behind the
*	name of each group, seperated by a space.
*
*   EXAMPLE
*	Create the NewsGroups file with an expire time of 60 days for each
*	group:
*
*	% rx rn-list.rexx 60 > AXsh:usr/spool/news/NewsGroups
*
*   AUTHOR
*	Tobias Ferber <tf@ganymed.hall.sub.org>
*
******************************************************************************
*
*/

axnews = axconfig("news")
tempfile = "t:rn-list." || pragma('Id')

/**/

cwd = pragma('D',axnews)
address command 'list all dirs lformat "%p%n" >' tempfile
address command 'sort from' tempfile 'to' tempfile
call pragma('D',cwd)

call open('fp',tempfile)
g=readln('fp')

do until eof('fp')
  s= readln('fp')
  if ~abbrev(s,g) then say translate(g,'.','/') arg(1)
  g=s
  end

call close('fp')
address command 'delete quiet' tempfile
exit


/*@<axconfig>*/

/* get an AXsh configuration value */

axconfig: procedure
  tempfile = "T:axconfig." || pragma('Id')
  rc_index  = "AXsh:rexx/rc.index"
  var_val=""; var_file=""; var_defval="";

  parse upper arg var_name
  if left(var_name,1) ~= '%' then var_name = '%'var_name
  if right(var_name,1) ~= ':' then var_name = var_name':'

  if open('idx',rc_index,'Read') then do
    do until (eof('idx') | (var_file~=''))
      str= translate(readln('idx'),' ',d2c(9))
      if words(str) > 0 then do
        parse var str vname ' ' fname '"' defval '"'
        if upper(vname) = var_name then do
          var_file= strip(fname,'B',' 'd2c(9))
          var_defval= defval
          end
        end
      end
    call close('idx')
    end
  else say 'Could not read "'rc_index'"'

  if words(var_file) > 0 then do
    if open('rc',var_file,'Read') then do
      do until (eof('rc') | (var_val~=''))
        str= translate(readln('rc'),' ',d2c(9))
        if upper(word(str,1)) = var_name then var_val = strip(readln('rc'),'B',' 'd2c(9))
        end
      call close('rc')
      end
    else say 'Could not examine "'var_file'" for' var_name
    end
  else do
    if words(var_defval) > 0 then var_val= var_defval
    else say 'No such config variable:' var_name
    end

  return var_val

