🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nn
4 messages
4 total messages Started by Mark Nagel Fri, 28 Feb 1992 17:39
unable to subscribe to empty newsgroup
#2526
Author: Mark Nagel
Date: Fri, 28 Feb 1992 17:39
16 lines
1362 bytes
I installed dynafeed which prevents news from being sent here if no
one subscribes to a particular group, then that group is not sent by
our feed.  Works great.  Only problem is that to request a group
that is not currently sent, you must first subscribe to that group.
Nn will not allow you to subscribe to a group unless there are
articles present in it.  Is there any way to force entry into a
group so you can subscribe to it even if the group is empty?  I have
no problem with editing my .newsrc, but I'm trying to make this
painless for our users.  I suppose a simple edit script would work
well enough, but it would be nice if it could be done from within nn.

Mark
-- 
Mark Nagel
  Network Administrator                 UUCP: {uupsi,ucivax}!cigna!nagel
  CIGNA FIRST                           INET: nagel@cigna.com
easy subscribe to newsgroups
#2537
Author: Rudi van Houten
Date: Tue, 03 Mar 1992 09:31
1550 lines
50751 bytes
In <1992Feb28.173945.1397@Cigna.COM> nagel@Cigna.COM (Mark Nagel) writes:

>I installed dynafeed which prevents news from being sent here if no
>one subscribes to a particular group, then that group is not sent by
>our feed.  Works great.  Only problem is that to request a group
>that is not currently sent, you must first subscribe to that group.
>Nn will not allow you to subscribe to a group unless there are
>articles present in it.  Is there any way to force entry into a
>group so you can subscribe to it even if the group is empty?  I have
>no problem with editing my .newsrc, but I'm trying to make this
>painless for our users.  I suppose a simple edit script would work
>well enough, but it would be nice if it could be done from within nn.

>Mark
>-- 
>Mark Nagel
>  Network Administrator                 UUCP: {uupsi,ucivax}!cigna!nagel
>  CIGNA FIRST                           INET: nagel@cigna.com

Some time ago I wrote a program to make subscription to newsgroups
somewhat easier. It was appreciated by some people and perhaps this
difficult is also handled by it. I called the gadget nnsub since I
had the way nn presents its information in mind, but it really has
not anything to do with nn. I too hope that the program becomes
superfluous when nn includes a subscription menu. But that is not
yet so, and development on nn seems to have stopped. I ought to
post it to alt.sources or comp.sources, but I first have to check
the conventions to do so.

Well, here it comes. Have fun with it.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  README nnsub.1 Makefile avl.h patchlevel.h version.h
#   Findsub.c avl.c nnsub.c strsave.c
# Wrapped by acbhour@accucx on Tue Mar  3 10:13:16 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1438 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X
X **********    nnsub Release 1.0 PL3  Jan 1992 ***************
X
XThis program nnsub is intended to make it easy to subscribe to newsgroups
Xif only a part of the name is known. If you don't know if the esperanto-group
Xis named "sci.lang.esperanto" or "soc.culture.esperanto" you can simply
Xtype in "nnsub esperanto".
X
XIf running without NNTP (or on the nntp server) the program needs the
Xfiles /usr/lib/news/active and /usr/lib/news/newsgroups. The exact location
Xof these files can be changed via the #define-symbols ACTIVE and NEWSGROUPS.
XThe first draft version of the program was written and tested on a old micro
Xwith CPM-80 with local copies of the files "active" and "newsgroups". The
Xlater version which I first posted in "news.software.nn" was finished on a
XConvex C210 with OS-8.1 (BSD-4.2/4.3). I expect it can easily adapted to
Xother machines.
X
XIf running on an nntp-client the symbol NNTP must be defined as the name
Xof the nntp-server. This version was developped, and works fine on a Sun
XSparcstation and a SUN 3/50.
XThis version undoubtly needs more pruning to adapt it to other systems.
X
XFor an extensive listing of the define-symbols and their meaning see
Xthe comment in nnsub.c and the Makefile.
X
XSuccess
X
XI have compiled and run the program without problems on:
XConvex C220 with ConvexOS-9.1 (a UNIX BSD variant)
XSUN 3/50 and SUN Sparc with SunOS 4.1
XPhilips P9070 (a Motorola 68030 with ATT Unix SysV R3)
XHP 9000-832S
END_OF_FILE
if test 1438 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'nnsub.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'nnsub.1'\"
else
echo shar: Extracting \"'nnsub.1'\" \(2372 characters\)
sed "s/^X//" >'nnsub.1' <<'END_OF_FILE'
X.TH NNSUB l
X.UC 4
X.SH NAME
Xnnsub \- subscribe to newsgroups
X.SH SYNOPSIS
X.B nnsub
X[ \-v[0,1] ]  [ group ] ...
X.SH DESCRIPTION
X.B nnsub
Xsubscribes to the supplied groups by updating your .newsrc file.
X.LP
XThe groupnames can be entered either as program arguments or on
Xthe standard input (one groupname per line).
X.LP
XIf running with terminal control and verbosity 1 (see options)
X.B nnsub
Xtries to find all newsgoup names which partially match the supplied
Xname if an exact match is not found. It then prints the count of
Xfound matches and gives you the option to subscribe to all, to none or
Xto select groups via a menu in the same way as described below.
X.LP
XIf a questionmark (\?) is given as groupname
X.B nnsub
Xwill start to present all (1000+) newsgroups in menu's of one screen.
XOne group per line preceeded by a letter resembling the selection menu
Xfrom
X.B nn.
XAt each menu you are asked to enter a command closed by a NEWLINE.
XNewgroups can be selected for subscription by including their preceding
X(lower case) letter in the command. The presenting of the menu's can
Xbe quitted by including a capital Q (for Quit) in the commandline. Also
Xrecognized are B (=Bye), E (=End), R (=Resume) or X (=eXit). An empty
Xcommandline will result in the prsenting of the next menu (or in quiting
Xthe presenting of the menu's).
X.LP
XIf running without terminal control or verbosity 0 partial name matching
Xis only performed if the supplied name starts and\/or ends with a dot (.).
XAll found matches will be subscribed to. A questionmark (\?) as groupname
Xwill be ignored.
X.SH OPTIONS
X.PP
XThere is one option -v for verbosity with a value 0 or 1.
X.TP
X.B \-v0
XNo interaction is possible, fuzzy matching only if the name
Xstarts and\/or ends with a dot. No report is written, the program's
Xexitvalue shows the number of requested but not subscribed (BOGUS)
Xnewsgroups.
XDefault if running without terminal control.
X.TP
X.B \-v1
XThe program tries to find newsgroups with partial name matching and
Xenables you to confirm subscriptions if partial matches are found.
XA report of subscriptions is written.
XDefault if running with a terminal.
X.SH FILES
X.DT
X.\"ta 0 20
X~/.newsrc	The record of read articles
X.DT
X.SH "SEE ALSO"
Xnn(1), nncheck(1), nngoback(1), nngrab(1), nngrep(1), nnpost(1), nntidy(1)
X.SH AUTHOR
XRudi van Houten, Academisch Computer Centrum Utrecht
X.br
XE-mail: Rudi@cc.ruu.nl
END_OF_FILE
if test 2372 -ne `wc -c <'nnsub.1'`; then
    echo shar: \"'nnsub.1'\" unpacked with wrong size!
fi
# end of 'nnsub.1'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(1509 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X#
X# create program nnsub
X#
X# define the smbol DEFS in accordance to your system
X#
X# define the symbol DEST as the directory in everybody's searchpath
X# where the program should reside
X#
X# install the file nnsub.1 manually in the directory for local
X# manpages (By us this is /usr/local/man/man1)
X
X# this I use on convex
XDEFS= -pcc
X# this should be used on SysV boxes, also HP/UX
X#DEFS= -DSYSV
X# possible DEFS are:
X#	ACTIVE		pathname of file containing active newsgroups
X#	DEFRC		pathname of default .newsrc (see nn INSTALL)
X#	ERR_EXIT	value for error exit
X#	NCOLS		number of colums on a terminal screen (80)
X#	NEWSGROUPS	pathname of file with short descriptions
X#	NEWSRC		file .newsrc
X#	NLINES		number of lines in a screen menu (22)
X#	NNTP		hostname of nntp server
X#	OLDRC		filename to save old .newsrc
X#	PORT		port number for nntp, see file /etc/services
X#	SYSV		compile and run on System V UNIX
X#	TEMPRC		temporary template to write new .newsrc
X#	TIMEOUT		timeout value while waiting for server reply
X#	iShwfac		interval for writing a dot if debugging
X#	iSlen		length of string buffer
X#	iMeuGrpart	max space to be used to write groupname in menu
X
XSUBS= avl.o Findsub.o strsave.o
XDEST=/usr/local/bin
XCC=   cc
XCFLAGS= -O $(DEFS)
XLDFLAGS=
X
X.c.o:
X	$(CC) $(CFLAGS) -c $*.c
X
Xnnsub:	nnsub.o $(SUBS)
X	$(CC) -o nnsub nnsub.o $(SUBS)
X
Xinstall: nnsub
X	mv nnsub $(DEST)
X	strip $(DEST)/nnsub
X	chmod 551 $(DEST)/nnsub
X
Xclean:
X	rm -f nnsub core *.o a.out
X
Xnnsub.o:	patchlevel.h version.h avl.h nnsub.c
Xavl.o:		avl.h avl.c
END_OF_FILE
if test 1509 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'avl.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'avl.h'\"
else
echo shar: Extracting \"'avl.h'\" \(1950 characters\)
sed "s/^X//" >'avl.h' <<'END_OF_FILE'
X/*
X    routines for handling AVL tree
X
X    Copyright
X	Rudi van Houten, Academic Computer Centre Utrecht
X			 Budapestlaan 6  3584 CD  Utrecht  Netherlands
X    Author : Rudi van Houten
X
X    The field content is here defined as a character pointer
X    but all references to it are made outside these routines
X    e.g. the parameter function CNTCMP so the calling program
X    is free to use a different definition. In the comments
X    this pointertype is called CONTENT.
X    The routine CNTCMP is called with two parameters of the
X    type CONTENT, and yields an integer value:
X        < 0    if 1st par < 2nd par
X        = 0    if 1st par = 2nd par
X        > 0    if 1st par > 2nd par
X    e.g. the routine strcmp.
X*/
X#include <stdio.h>
Xextern char * strsave();
X
Xtypedef struct avl_node
X            { char * content;                 /* pointer to data */
X              short  balance;                 /* balance the tree */
X              struct avl_node *left, *right;  /* tree pointers */
X            } AVL_NODE;
X
Xtypedef AVL_NODE * P_AVL_NODE;
X
Xextern int insert_avl();
X    /* parameterplan: (value,tree,CNTCMP,rtnval)
X                      CONTENT value, *rtnval;
X                      P_AVL_NODE *tree;
X                      int (*CNTCMP)();
X        the variable rtnval yields a reference to the
X        datastructure in the found AVL_NODE, it will
X        be equal to value if a new node is created.
X    */
X
Xextern int insavlnode();
X    /* parameterplan: (node,p,CNTCMP)
X                      P_AVL_NODE node, *p;
X                      int (*CNTCMP)();
X    */
Xextern P_AVL_NODE find_avlnode();
X    /* parameterplan: (value,tree,CNTCMP)
X                      CONTENT value;
X                      P_AVL_NODE tree;
X                      int (*CNTCMP)();
X    */
Xextern int unravel_avl();
X    /* parameterplan: (tree,action,delflag)
X                      P_AVL_NODE *tree;
X                      int (*action)();
X                      int delflag;
X    */
END_OF_FILE
if test 1950 -ne `wc -c <'avl.h'`; then
    echo shar: \"'avl.h'\" unpacked with wrong size!
fi
# end of 'avl.h'
fi
if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'patchlevel.h'\"
else
echo shar: Extracting \"'patchlevel.h'\" \(821 characters\)
sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
X#define PATCHLEVEL 3
X/*
X    patch history:
X
X    7/2/91	original version with bugs preventing running as
X		nntp client on Sun-3/50.
X    13/2/91	patch #1
X		-correct an error in uncontrolled use of 'tolower'
X		which solved the problem running as nntp client on
X		a SUN-3/50.
X		-Also truncate long lines in menu to prevent screen
X		overflow caused by wrapped lines (controlled by symbol
X		TRUNCATE).
X		-Add debug value iVleavetmp.
X    20/2/91	patch #2
X		-Alan P. Barrett <barrett@dalsy.ee.und.ac.za> reworked
X		and contributed the code in Printcharter to fit lines
X		on the screen, not rudely truncate them.
X		-Present the many found groups after fuzzy match via
X		submenu's, don't ask one by one.
X    6/1/92	patch #3
X		create a Makefile and include conditional compilation
X		to disinguish betwen BSD and Systm V (-DSYSV)
X*/
END_OF_FILE
if test 821 -ne `wc -c <'patchlevel.h'`; then
    echo shar: \"'patchlevel.h'\" unpacked with wrong size!
fi
# end of 'patchlevel.h'
fi
if test -f 'version.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'version.h'\"
else
echo shar: Extracting \"'version.h'\" \(34 characters\)
sed "s/^X//" >'version.h' <<'END_OF_FILE'
X#define VERSION 1
X#define SUBNR 0
END_OF_FILE
if test 34 -ne `wc -c <'version.h'`; then
    echo shar: \"'version.h'\" unpacked with wrong size!
fi
# end of 'version.h'
fi
if test -f 'Findsub.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Findsub.c'\"
else
echo shar: Extracting \"'Findsub.c'\" \(617 characters\)
sed "s/^X//" >'Findsub.c' <<'END_OF_FILE'
X#include <stdio.h>
X#include <string.h>
X#ifdef SYSV
X#define index strchr
X#endif
X
Xchar * Findsub(sC,sF)
Xchar *sC, *sF;
X/*
X    return the start of substring sF in string sC
X    or NULL if sC doesn't contain sF
X
X    Copyright
X	Rudi van Houten, Academic Computer Centre Utrecht
X			 Budapestlaan 6  3584 CD  Utrecht  Netherlands
X*/
X{
X    int iFlen;
X    register char *pcC;
X    iFlen= strlen(sF);
X    if ((pcC= index(sC,sF[0])) == NULL) return(NULL);
X    while (strlen(pcC) >= iFlen)
X	if (strncmp(pcC,sF,iFlen) == 0) return(pcC);
X	else
X	if ((pcC= index(++pcC,sF[0])) == NULL) return(NULL);
X    return(NULL);
X} /* Findsub */
END_OF_FILE
if test 617 -ne `wc -c <'Findsub.c'`; then
    echo shar: \"'Findsub.c'\" unpacked with wrong size!
fi
# end of 'Findsub.c'
fi
if test -f 'avl.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'avl.c'\"
else
echo shar: Extracting \"'avl.c'\" \(4340 characters\)
sed "s/^X//" >'avl.c' <<'END_OF_FILE'
X#include <stdio.h>
X
X/*
X    Copyright
X	Rudi van Houten, Academic Computer Centre Utrecht
X			 Budapestlaan 6  3584 CD  Utrecht  Netherlands
X    Author : Rudi van Houten
X
X    Purpose:
X    C routines for handling AVL tree 
X    use the includefiel avl.h in the programs
X
X    The field content is here defined as a character pointer
X    but all references to it are made outside these routines
X    e.g. the parameter function CNTCMP so the calling program
X    is free to use a different definition.
X    The routine CNTCMP is called with two parameters of the
X    type content, and yields an integer value:
X        < 0    if 1st par < 2nd par
X        = 0    if 1st par = 2nd par
X        > 0    if 1st par > 2nd par
X    e.g. the routine strcmp.
X--end_doc-
X*/
X
Xtypedef char * CONTENT;
Xtypedef struct avl_node
X            { CONTENT content;
X              short  balance;                 /* balance the tree */
X              struct avl_node *left, *right;  /* tree pointers */
X            } AVL_NODE;
X
Xtypedef AVL_NODE * P_AVL_NODE;
X
XP_AVL_NODE rotate1(p)
XP_AVL_NODE *p;
X{
X    P_AVL_NODE q;
X    if ((*p)->balance > 0)
X    {
X        q= (*p)->right;
X        (*p)->right= q->left;
X        q->left= *p;
X    }
X    else /* if ((*p)->balance > 0) */
X    {
X        q= (*p)->left;
X        (*p)->left= q->right;
X        q->right= *p;
X    } /* if ((*p)->balance > 0) */
X    (*p)->balance= 0; q->balance= 0;
X    *p= q;
X    return(*p);
X} /* rotate1 */
X
XAVL_NODE * rotate2(p)
XP_AVL_NODE *p;
X{
X    P_AVL_NODE q, l, r;
X    if ( (*p)->balance > 0)
X    {
X        l= *p; r= (*p)->right; q= r->left;
X    }
X    else /* if ( (*p)->balance >  0) */
X    {
X        r= *p; l= (*p)->left; q= l->right;
X    } /* if ( (*p)->balance > 0 ) */
X    l->balance= r->balance= 0;
X    if (q->balance < 0)
X        r->balance= 1;
X    else
X    if (q->balance > 0)
X        l->balance= -1;
X
X    q->balance= 0;
X    l->right= q->left;
X    r->left= q->right;
X    q->left= l; q->right= r; *p= q;
X    return(*p);
X} /* rotate2 */
X
XAVL_NODE * rotate(p)
XP_AVL_NODE *p;
X{
X    if ( (*p)->balance > 0 )
X        if ( (*p)->right->balance > 0)
X            rotate1(p);
X        else
X            rotate2(p);
X    else
X        if ( (*p)->left->balance < 0 )
X            rotate1(p);
X        else
X            rotate2(p);
X    return(*p);
X} /* rotate */
X
Xint insert_avl(value,p,CNTCMP,rtnval)
XCONTENT value, *rtnval;
XP_AVL_NODE *p;
Xint (*CNTCMP)();
X{
X    short k;
X
X    if (*p == NULL)
X    {
X        *p= (P_AVL_NODE)malloc(sizeof(AVL_NODE));
X        (*p)->content= value;
X        (*p)->balance= 0;
X        (*p)->left= NULL; (*p)->right= NULL;
X        *rtnval= value;
X        return(1);
X    }
X    else /* if (*p == NULL) */
X    if (k= (*CNTCMP)(value,(*p)->content))
X    {
X        if (k < 0)
X            k= -insert_avl(value,&((*p)->left),CNTCMP,rtnval);
X        else
X            k= insert_avl(value,&((*p)->right),CNTCMP,rtnval);
X        if (k)
X        {
X            (*p)->balance += k;
X            if (abs((*p)->balance) > 1) rotate(p);
X            if ((*p)->balance) return(1);
X        }
X    }
X    else *rtnval= (*p)->content;
X    return(0);
X} /* insert_avl */
X
Xint insavlnode(node,p,CNTCMP)
XP_AVL_NODE node, *p;
Xint (*CNTCMP)();
X{
X    short k;
X
X    if (*p == NULL) *p= node;
X    else
X    if (k= (*CNTCMP)(node->content,(*p)->content))
X    {
X        if (k < 0)
X            k= -insavlnode(node,&((*p)->left),CNTCMP);
X        else
X            k= insavlnode(node,&((*p)->right),CNTCMP);
X        (*p)->balance += k;
X        if (abs((*p)->balance) > 1) rotate(p);
X
X        if ((*p)->balance)
X            return(abs(k));
X        else
X            return(0);
X    }
X    else return(0);
X} /* insavlnode */
X
XP_AVL_NODE find_avlnode(value,tree,CNTCMP)
XCONTENT value;
XP_AVL_NODE tree;
Xint (*CNTCMP)(); /* must be the same routine as used by insavlnode */
X{
X    int k;
X    while (1)
X    {
X        if (tree == NULL) return(NULL);
X        if (k= (*CNTCMP)(value,tree->content))
X            if (k < 0) tree= tree->left; else tree= tree->right;
X        else return(tree);
X    }
X} /* find_avlnode */
X
Xint unravel_avl(tree,action,delflag)
XP_AVL_NODE *tree;
Xint (*action)();
Xint delflag;
X{
X    if (*tree == NULL) return(0);
X    unravel_avl(&(*tree)->left,action,delflag);
X    (*action)((*tree)->content);
X    unravel_avl(&(*tree)->right,action,delflag);
X    if (delflag) { free(*tree); *tree= NULL; }
X    return(1);
X} /* unravel_avl */
END_OF_FILE
if test 4340 -ne `wc -c <'avl.c'`; then
    echo shar: \"'avl.c'\" unpacked with wrong size!
fi
# end of 'avl.c'
fi
if test -f 'nnsub.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'nnsub.c'\"
else
echo shar: Extracting \"'nnsub.c'\" \(28237 characters\)
sed "s/^X//" >'nnsub.c' <<'END_OF_FILE'
X/*
X    nnsub [-v] [newsgroups....]
X
X	exit status ERR_EXIT indicates a failure
X
X	option -v for verbosity
X	-v0	don't show output, no questions.
X		exit status shows number of newsgroups requested but
X		not subscribed (bogus).
X		Default if running without terminal control.
X	-v1	if interactive the program can ask questions and
X		a report of subscriptions is written.
X		Default if running with a terminal.
X
X	groups to subscribe to can be supplied as program arguments
X	or on input. Partial groupnames can be given by starting or
X	ending the name with a dot, and the program will try to find
X	the groupname (as in the nn init file). If running without
X	terminal control or with verbosity 0 all the matches found
X	on such a partial name will be subscribed to.
X        With a terminal and verbosity unequal 0 all names are handled
X	as partial names and the options are to subscribe to all, or
X	to none or list the found matches and ask confirmation to
X	subscribe. Farther a questionmark (?) as groupname will result
X	in menu's with NLINES groupnames and choices can be made by entering
X        a string of the indicating letters (or only a NEWLINE if nothing
X        is selected). The capital R will resume the option of entering
X        (partial) newsgroup names, a Q will quit that phase entirily and
X        complete the program by updating the newsrc file.
X        
X	For testing purposes there are some higher verbosity levels
X        (if symbol DEBUG is defined).
X	-v2	report some file read or file search actions.
X	-v3	also the progress while reading or searching is made visible
X        -v4	yet more output about internal databases (debugging)
X	-v5	as -v4, but don't delete temporary files
X	These higher verbosity-levels also causes the .newsrc file to be
X	update in directory ~/tmp en not the home directory itself.
X
X	Define symbols:
X	ACTIVE		pathname of file containing active newsgroups
X	DEFRC		pathname of default .newsrc (see nn INSTALL)
X	ERR_EXIT	value for error exit
X	NCOLS		number of colums on a terminal screen (80)
X	NEWSGROUPS	pathname of file with short descriptions
X	NEWSRC		file .newsrc
X	NLINES		number of lines in a screen menu (22)
X	NNTP		hostname of nntp server
X	OLDRC		filename to save old .newsrc
X	PORT		port number for nntp, see file /etc/services
X	SYSV		compile and run on System V UNIX
X	TEMPRC		temporary template to write new .newsrc
X	TIMEOUT		timeout value while waiting for server reply
X	iShwfac		interval for writing a dot if debugging
X	iSlen		length of string buffer
X	iMeuGrpart	max space to be used to write groupname in menu
X
X	For NNTP-servers where the files "active" and "newsgroups"
X	are kept local, mostly in "/usr/lib/news" the symbols ACTIVE
X	and NEWSGROUPS must be set to the pathnames of these files
X	and the symbol NNTP must *NOT* be defined, PORT is not used.
X	For NNTP-clients the symbol NNTP must be set to the name of
X	the NNTP-server (as in the file nntp-server in nn's "cofig.h")
X	and the symbol PORT must be correct, ACTIVE and NEWSGROUPS are
X	not used.
X
X	Strategy:
X	1.Build an avl-tree (balanced binary tree) from all the
X	  newsgroups listed in the active file (nntp-clients can obtain
X	  these data via nntp with the command 'list active').
X	2.If Verbosity > 0 store with each newsgroup the byte address
X	  of the corresponding entry in the newsgroups file (nntp-clients
X	  must first build this file with the nntp command 'list newsgroups').
X	3.Then build a second avl-tree with pointers to the requested
X	  newsgroups.
X	4.Write a new .newsrc combining the data with the second avl-tree.
X
X
X	Copyright: Rudi van Houten <Rudi@cc.ruu.nl>
X		   Acadmisch Computer Centrum Utrecht
X		   Budapestlaan 6  3584 CD  Utrecht
X*/
X
X				/* filename definitions */
X
X#ifndef ACTIVE
X#define ACTIVE "/usr/lib/news/active"	/* file "active" (non NNTP) */
X#endif
X#ifndef NEWSGROUPS
X#define NEWSGROUPS "/usr/lib/news/newsgroups" /* idem "newsgroups" */
X#endif
X
X#ifndef DEFRC
X#define DEFRC  "/usr/spool/news/.nn/db/.defaultnewsrc"
X#endif
X
X#ifndef NEWSRC
X#define NEWSRC ".newsrc"
X#endif
X#ifndef OLDRC
X#define OLDRC  ".newsrc.old"
X#endif
X#ifndef TEMPRC
X#define TEMPRC "tmprcXXXXXX"
X#endif
X#ifndef PORT
X#define PORT 119			/* port for NNTP "/etc/services" */
X#endif
X
X				/* some constants */
X#ifndef iSlen
X#define iSlen 256
X#endif
X#ifndef NLINES
X#define NLINES 22
X#endif
X#ifndef NCOLS
X#define NCOLS 80
X#endif
X#ifndef iMenuGrpart
X#define iMenuGrpart 20		/* max. space for newsgroupname in menu */
X#endif
X
X#ifndef TIMEOUT
X#define TIMEOUT 15
X#endif
X#define ERR_EXIT 9999
X
X				/* and more constants and includes */
X
X#define iVreport 1
X#ifdef DEBUG
X#define iVactions 2
X#define iVprogress 3
X#define iVdebug 4
X#define iVleavetmp 5
X#define iShwfac 100
X#endif
X
X#define iVerbdef iVreport
X
X#ifdef NNTP
X#define CHARTERS "/tmp/ngrpXXXXXX"
X#else
X#define CHARTERS NEWSGROUPS
X#endif
X
X#include <stdio.h>
X#include <string.h>
X#include <ctype.h>
X#include "avl.h"
X#include "version.h"
X#include "patchlevel.h"
X#ifdef NNTP
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netinet/in.h>
X#include <netdb.h>
X#endif
X#ifdef DEBUG
X#include <sys/file.h>
X#endif
X#ifdef SYSV
X#define index strchr
X#define bcopy(a,b,c) memcpy(b,a,c)
X#include <unistd.h>
X#endif
X
Xtypedef struct
X    {
X        char *sName;
X        long iTitle_pos;
X    } s_Group;
Xtypedef s_Group * ps_Group;
X
Xtypedef struct s_grlink
X    {
X        s_Group * pGroup;
X        struct s_grlink * pNext;
X    } s_Grlink;
X
Xstatic P_AVL_NODE paGr_tree= NULL, paGr_requests= NULL;
Xstatic s_Grlink *pGr_list= NULL, *pGr_endlist= NULL;
Xstatic short iVerbosity, bIntractive;
Xstatic FILE *fGroups, *fCharters, *fNewgroups;
Xstatic char *sNewgrplfn, *sCharterlfn;
X#ifdef NNTP
Xstatic int sock, sock_wr;
Xstruct sockaddr_in sNntpServer;
Xstruct hostent *psNntpHost, *gethostbyname();
X#endif
X
Xstatic char * sRequest;
Xstatic short bStart_is_free, bEnd_is_free; /* needed for fuzzy compare */
X
Xextern char * Findsub();
Xextern char * mktemp();
Xextern char * getenv();
Xextern char * malloc();
X
Xint Grpcmp(g1,g2)
Xs_Group *g1, *g2;
X{
X    return (strcmp(g1->sName,g2->sName));
X} /* Grpcmp */
X
XPrintcharter(pGr,iOffset)
Xs_Group *pGr;
Xint iOffset;
X{
X    char sLine[iSlen], sNewsgroup[iSlen], sDescription[iSlen];
X    int iNglen, iDesclen;      /* length of groupname and description */
X    int iNgwidth, iDescwidth;  /* space to use for printing */
X    int iAvailable;            /* available space on screnline */
X
X    iAvailable= NCOLS - iOffset;
X    if (pGr->iTitle_pos < 0) { puts(pGr->sName); return; }
X    if (fseek(fCharters,pGr->iTitle_pos,0) < 0)
X        { perror(sCharterlfn); exit(ERR_EXIT); }
X    fgets(sLine,iSlen,fCharters);
X    sscanf(sLine,"%[^ \t]%*[ \t]%[^\n]",sNewsgroup,sDescription);
X    iNglen= strlen(sNewsgroup); iDesclen= strlen(sDescription);
X    if (iNglen + 1 + iDesclen > iAvailable)
X    { /* have to truncate dscription */
X	iNgwidth= iNglen + 1; /* one blank after group name */
X	iDescwidth= iAvailable - iNgwidth;   /* rest of line */
X    }
X    else
X    if (iNglen < iMenuGrpart)
X    {
X	if (iDesclen + iMenuGrpart <= iAvailable)
X	{ /* use "iMenuGrpart" columns for groupname */
X	    iNgwidth= iMenuGrpart;
X	    iDescwidth= iDesclen;
X	}
X	else
X	{ /* use less space for groupname
X	     and right-justify description */
X	    iNgwidth= iAvailable - iDesclen;
X	    iDescwidth= iDesclen;
X	}
X    }
X    else /* if (iNglen < iMenuGrpart) */
X    {
X	if (iNglen + 5 + iDesclen <= iAvailable)
X	{ /* leave 5 spaces between name and description */
X	    iNgwidth= iNglen + 5;
X	    iDescwidth= iDesclen;
X	}
X	else
X	{ /* leave less blanks after groupname and right-justify description */
X	    iNgwidth= iAvailable - iDesclen;
X	    iDescwidth= iDesclen;
X	}
X    }
X    printf("%-*s%.*s\n",iNgwidth,sNewsgroup,iDescwidth,sDescription);
X
X} /* Printcharter */
X
Xint Add_list_element(pGr)
Xs_Group *pGr;
X{
X    register s_Grlink *pLocal;
X    pLocal= (s_Grlink*)malloc(sizeof(s_Grlink));
X    pLocal->pGroup= pGr;
X    pLocal->pNext= NULL;
X    if (pGr_list == NULL)
X        pGr_list= pGr_endlist= pLocal;
X    else
X        pGr_endlist= pGr_endlist->pNext= pLocal;
X#   ifdef DEBUG
X    if (iVerbosity > iVdebug) putchar('.');
X#   endif
X    return 0;
X} /* Add_list_element */
X
Xint Fuzzycheck(pGr)
Xs_Group *pGr;
X/*
X    if a fuzzy compare of the string sRequest matches the
X    name of the supplied group that group is added in the
X    one-way-linked list for later consideration
X*/
X{
X    register short bFound;
X    register char *pcC;
X    if (bStart_is_free)
X        { if ((pcC= Findsub(pGr->sName,sRequest)) == NULL) return(0); }
X    else pcC= pGr->sName;
X    if (!bEnd_is_free) bFound= strcmp(sRequest,pcC) == 0;
X    else bFound= strncmp(sRequest,pcC,strlen(sRequest)) == 0;
X    if (bFound) Add_list_element(pGr);
X    return(bFound);
X} /* int Fuzzycheck(pGr) */
X
Xint Checkrequest(sName)
Xchar * sName;
X{
X    register P_AVL_NODE pNode;
X    register s_Grlink *pLink;
X    s_Group s_Glocal, *pGr_dum;
X    char cC;
X    int iCount;
X    for (iCount=0;iCount<strlen(sName);iCount++)
X        if (isupper(sName[iCount])) sName[iCount]= tolower(sName[iCount]);
X    bStart_is_free= sName[0] == '.';
X    bEnd_is_free= (cC= sName[strlen(sName)-1]) == '.';
X    s_Glocal.sName= sName;
X    if (!bStart_is_free && !bEnd_is_free)
X    {
X        if (find_avlnode(&s_Glocal,paGr_requests,Grpcmp)) return(0);
X        if (pNode= find_avlnode(&s_Glocal,paGr_tree,Grpcmp))
X        {
X            insert_avl(pNode->content,&paGr_requests,Grpcmp,&pGr_dum);
X#           ifdef DEBUG
X            if (iVerbosity > iVprogress)
X                printf("..Added in request tree: %s\n",sName);
X#           endif
X            return(1);
X        }
X        else /* if (pNode= find_avlnode(&s_Glocal,paGr_tree,Grpcmp)) */
X        if (iVerbosity && bIntractive)
X            bStart_is_free= bEnd_is_free= 1;
X        else /* if (iVerbosity && bIntractive) */
X        {
X            if (iVerbosity) printf("BOGUS newsgroup \"%s\"\n",sName);
X            return(0);
X        } /* if (iVerbosity && bIntractive) */
X        /* if (pNode= find_avlnode(&s_Glocal,paGr_tree,Grpcmp)) */
X    } /* if (!bStart_is_free && !bEnd_is_free) */
X    sRequest= sName;
X    unravel_avl(&paGr_tree,Fuzzycheck,0);
X    if (pGr_list == NULL)
X    {
X        if (iVerbosity) printf("\"%s\": no matching newsgroups found\n",sName);
X        return(0);
X    }
X    iCount= 0; /* and now count the found groups */
X    for (pGr_endlist= pGr_list;
X         pGr_endlist != NULL;
X         pGr_endlist= pGr_endlist->pNext) iCount++;
X    if (iVerbosity)
X    {
X#       ifdef DEBUG
X	if (iVerbosity >= iVdebug) putchar('\n');
X#       endif
X        if (bIntractive)
X            if (iCount == 1)
X            {
X		putchar('\n');
X                Printcharter(pGr_list->pGroup,1);
X                fputs("  OK? (y) ",stdout);
X                cC= getchar();
X		if (cC != '\n') while (getchar() != '\n'); else cC= 'y';
X                if (cC != 'y' && cC != 'Y') { free(pGr_list); pGr_list= NULL; }
X            }
X            else /* if iCount == 1) */
X            {
X                printf("Partial name \"%s\": %d matching newsgroups found\n"
X                      ,sName,iCount);
X                fputs("Subscribe to: a)ll, c)onfirmation, n)one? ",stdout);
X                cC= getchar(); if (cC != '\n') while (getchar() != '\n');
X                switch (cC)
X                {
X                default:
X                    break; /* default answer is 'a' */
X                case 'n':
X                case 'N':
X                    pGr_endlist= pGr_list; pGr_list= NULL;
X                    while (pGr_endlist)
X                    {
X                        pLink= pGr_endlist; pGr_endlist= pLink->pNext;
X                        free(pLink);
X                    }
X                    return(0);
X                case 'c':
X                case 'C':
X                    return(Menusubscribe());
X                } /* switch(cC) */
X            } /* if (iCount == 1) */
X        /* if (bIntractive) */
X    } /* if (iVerbosity) */
X    if (pGr_list == NULL) return(0);
X    iCount= 0; pGr_endlist= pGr_list; pGr_list= NULL;
X    while (pGr_endlist != NULL)
X    {
X        if (find_avlnode(pGr_endlist->pGroup,paGr_requests,Grpcmp) == NULL)
X        {
X            insert_avl(pGr_endlist->pGroup,&paGr_requests,Grpcmp,&pGr_dum);
X#           ifdef DEBUG
X            if (iVerbosity > iVprogress)
X                printf("..Added in request tree: %s\n"
X                      ,pGr_endlist->pGroup->sName);
X#           endif
X            iCount++;
X        }
X        pLink= pGr_endlist; pGr_endlist= pLink->pNext;
X        free(pLink);
X    } /* while (pGr_endlist != NULL) */
X    return(iCount);
X} /* int Checkrequest(sName) */
X
Xint Menusubscribe()
X/*
X    returnvalue: number of subscribed groups
X*/
X{
X    ps_Group sgMline[NLINES], pGr_dum;
X    char sLine[iSlen], cTop;
X    register s_Grlink * pLink;
X    register int i;
X    short bStop;
X    int iReturnvalue;
X
X    if (pGr_list == NULL)    /* first unravel the tree */
X#   ifdef DEBUG
X    {
X        if (iVerbosity >= iVdebug) puts("Unravel tree to one-way linked list");
X#       endif
X        unravel_avl(&paGr_tree,Add_list_element,0);
X#       ifdef DEBUG
X        if (iVerbosity >= iVdebug) puts("\n=Done ===========");
X    }
X#   endif
X    pGr_endlist= pGr_list; pGr_list= NULL;
X    i= iReturnvalue= 0; bStop= 0;
X    while (pGr_endlist != NULL && bStop == 0)
X    {
X	if (i == 0) puts("\n\n\n");
X        pLink= pGr_endlist; printf("%c: ",i+'a');
X	Printcharter(sgMline[i]= pLink->pGroup,4);
X        pGr_endlist= pLink->pNext; free(pLink);
X        if (i++, pGr_endlist == NULL || i == NLINES)
X        {
X            cTop= (char)((int)'a' + i - 1);
X            printf("\n>> Select with [a..%c], or Quit:",cTop);
X            if (gets(sLine) == NULL) bStop= 1;
X            else
X            for (i= 0; sLine[i] != '\0'; i++)
X                if (index("QREBSX",sLine[i])) bStop= 1;
X                else
X                if (sLine[i] >= 'a' && sLine[i] <= cTop)
X		{
X                    insert_avl(sgMline[(int)sLine[i] - (int)'a']
X                              ,&paGr_requests,Grpcmp,&pGr_dum);
X                    if (pGr_dum == sgMline[(int)sLine[i] - (int)'a'])
X                    {
X                        iReturnvalue++;
X#                       ifdef DEBUG
X                        if (iVerbosity >= iVdebug)
X		        {
X			    puts("Added to request tree:");
X                            Printcharter(pGr_dum,1);
X                        }
X#                       endif
X                    }
X		}
X                /* ignore garbage */
X            /* for (i= 0; sLine[i] != '\0'; i++) */
X            i= 0;
X         } /* if (pGr_endlist == NULL || ++i > NLINES) */
X    } /* while (pGr_endlist != NULL && bStop == 0) */
X#   ifdef DEBUG
X    if (iVerbosity >= iVdebug && pGr_endlist != NULL)
X        puts("Clean up the one-way linked list");
X#   endif
X    while (pGr_endlist != NULL)
X    {
X        pLink= pGr_endlist; pGr_endlist= pLink->pNext;
X        free(pLink);
X#       ifdef DEBUG
X        if (iVerbosity >= iVdebug)
X	{
X	    putchar('.');
X            if (pGr_endlist == NULL) puts("\n>> Cleaning done\n");
X	}
X#       endif
X    } /* while (pGr_endlist != NULL) */
X    return(iReturnvalue);
X} /* int Menusubscribe() */
X
Xint Addsubscription(pGr)
Xs_Group *pGr;
X{
X    if (islower(pGr->sName[0]))
X    {
X        fprintf(fNewgroups,"%s:\n",pGr->sName);
X        if (iVerbosity) { puts("New subscription:"); Printcharter(pGr,1); }
X    }
X    return(0);
X} /* Addsubscription */
X
X#ifdef NNTP
Xstatic FILE *fNntpOut;
X
Xstatic Nntpcommand(sCommand)
Xchar *sCommand;
X/*
X     send a command to the nntp server ad check the reply
X     in case of error give an exit, timeout exits on alarm.
X*/
X{
X    char sLine[iSlen];
X    int iReply;
X#   ifdef DEBUG
X    if (iVerbosity >= iVactions) printf("NNTP: %s\n",sCommand);
X#   endif
X    fprintf(fNntpOut,"%s\r\n",sCommand);
X    if (fflush(fNntpOut) == EOF)
X	{ perror(sCommand); exit(ERR_EXIT); }
X    alarm(TIMEOUT);
X    if (fgets(sLine,iSlen,fGroups) == NULL)
X	{ fprintf(stderr,"NULL response on %s\n",sCommand); exit(ERR_EXIT); }
X    alarm(0);
X    if (sscanf(sLine,"%d",&iReply) != 1)
X    {
X	fprintf(stderr,"Illegal response on %s:\n%s",sCommand,sLine);
X        exit(ERR_EXIT);
X    }
X    if (iReply < 200 || iReply >= 400)
X    {
X	fprintf(stderr,"Error response on %s\n%s",sCommand,sLine);
X	exit(ERR_EXIT);
X    }
X#   ifdef DEBUG
X    if (iVerbosity >= iVactions) fputs(sLine,stdout);
X#   endif
X} /* Nntpcommand */
X#endif
X
X
Xmain(argc,argv,envp)
Xint argc;
Xchar *argv[], *envp[];
X{
Xchar sLine[iSlen];
Xregister char *pcC;
Xregister s_Group *pG1;
Xs_Group *pG2;
Xregister P_AVL_NODE p_AVL;
Xint i, j, k, iGr, iGrfault;
X
Xif (bIntractive= isatty(0)) iVerbosity= iVerbdef; else iVerbosity= 0;
X
XiGr= 0; /* counter for groupname arguments */
Xif (argc > 1)
Xfor (i=1; i<argc; i++)
X    if (argv[i][0] == '-')
X        switch(argv[i][1])
X        {
X        default:
X            fprintf(stderr,"Unknown option \"%s\" ignored\n",argv[i]);
X            break;
X        case 'V':
X        case 'v':
X            if (argv[i][2] == '\0') iVerbosity= iVerbdef;
X            else iVerbosity= atoi(&argv[i][2]);
X            break;
X        } /* switch(argv[i][1]) */
X    else /* if (argv[i][0] == '-') */
X        iGr++; /* increment supplied groupname counter */
X/* for (i=1; i<argc; i++) */
X
Xif (iVerbosity)
X    printf("\nNetnews subscribe\nRelease %d.%d PL%d (Rudi van Houten 1991)\n\n"
X	  ,VERSION,SUBNR,PATCHLEVEL);
X
X#ifdef NNTP
X	/* create socket */
Xif ((sock= socket(AF_INET,SOCK_STREAM,0)) < 0)
X    { perror("-- opening stream socket"); exit(ERR_EXIT); }
X
X	/* fill socket structure .....*/
XsNntpServer.sin_family= AF_INET;
Xif ((psNntpHost= gethostbyname(NNTP)) == 0)
X{
X#define cMessage "While trying to connect to "
X    char *sMessage;
X    sMessage= malloc(strlen(NNTP)+strlen(cMessage));
X    strcpy(sMessage,cMessage); strcat(sMessage,NNTP);
X    perror(sMessage);
X    exit(ERR_EXIT);
X}
Xbcopy(psNntpHost->h_addr,&sNntpServer.sin_addr,psNntpHost->h_length);
XsNntpServer.sin_port= htons(PORT);
X
X	/*........and connect */
Xif (iVerbosity) printf("Connecting to nntp server %s\n",NNTP);
Xif (connect(sock,&sNntpServer,sizeof(sNntpServer)) < 0)
X    { perror("connecting stream socket"); exit(ERR_EXIT); }
Xif ((fGroups= fdopen(sock,"r")) == NULL)
X    { perror("assign socket to FILE fGroups"); exit(ERR_EXIT); }
Xalarm(TIMEOUT);
Xif (fgets(sLine,iSlen,fGroups) == NULL)
X    { fputs("No reply from server\n",stderr); exit(ERR_EXIT); }
Xalarm(0);
Xif (strncmp(sLine,"200 ",4)) { fputs(sLine,stderr); exit(ERR_EXIT); }
X#ifdef DEBUG
Xif (iVerbosity >= iVactions) puts(sLine);
X#endif
Xsock_wr= dup(sock);
Xif ((fNntpOut= fdopen(sock_wr,"w")) == NULL)
X    { perror("assign outputfile to socket"); exit(ERR_EXIT); }
XNntpcommand("LIST ACTIVE");
X#else
Xif ((fGroups= fopen(ACTIVE,"r")) == NULL) { perror(ACTIVE); exit(ERR_EXIT); }
X#ifdef DEBUG
Xif (iVerbosity >= iVactions)
X    printf("Reading active newsgroups from \"%s\"\n",ACTIVE);
X#endif
X#endif
X
Xi= 0; pG1= NULL;
X#ifdef NNTP
X#ifdef DEBUG
Xif (iVerbosity >= iVdebug) puts("Get active groups from server");
X#endif
Xwhile (alarm(TIMEOUT),fgets(sLine,iSlen,fGroups) != NULL)
X#else
Xwhile (fgets(sLine,iSlen,fGroups) != NULL)
X#endif
X{
X#   ifdef NNTP
X    alarm(0);
X#   endif
X    k= strlen(sLine);
X    for (j=0; j<k; j++)
X        if (index(" \t\r\n",sLine[j])) { sLine[j]= '\0'; break; }
X        else if (isupper(sLine[j])) sLine[j]= tolower(sLine[j]);
X    if (strcmp(sLine,".") == 0) break;
X    if (pG1 == NULL) pG1= (s_Group*)malloc(sizeof(s_Group));
X    pG1->sName= strsave(sLine); pG1->iTitle_pos= -1;
X    insert_avl(pG1,&paGr_tree,Grpcmp,&pG2);
X    if (pG1 == pG2)
X    {
X        i++;
X#       ifdef DEBUG
X        if (iVerbosity >= iVprogress)
X            { if (i % iShwfac == 0) putchar('.'); }
X#       endif
X        pG1= NULL;
X    }
X} /* while (...fgets(sLine,iSlen,fGroups) != NULL) */
Xif (iVerbosity) printf("\n %d active groups found\n",i);
X#ifndef NNTP
Xfclose(fGroups);
XsCharterlfn= CHARTERS;
X#else
XsCharterlfn= strsave(CHARTERS);
XsCharterlfn= mktemp(sCharterlfn);
Xif ((fCharters= fopen(sCharterlfn,"w")) == NULL)
X    { perror(sCharterlfn); exit(ERR_EXIT); }
XNntpcommand("LIST NEWSGROUPS");
X#ifdef DEBUG
Xif (iVerbosity >= iVactions)
X{
X    puts(sLine);
X    printf("Copying nntp <LIST NEWSGROUPS> to \"%s\"\n",sCharterlfn);
X}
X#endif
Xfor (j=0;;j++)
X{
X#   ifdef NNTP
X    alarm(TIMEOUT);
X#   endif
X    if (fgets(sLine,iSlen,fGroups) == NULL) break;
X#   ifdef NNTP
X    alarm(0);
X#   endif
X    i= strlen(sLine) - 1;
X    while (index(" \t\r\n",sLine[i])) sLine[i--]= '\0';
X    if (strcmp(sLine,".") == 0) break;
X    fputs(sLine,fCharters); putc('\n',fCharters);
X#   ifdef DEBUG
X    if (iVerbosity >= iVprogress) if (j % iShwfac == 0) putchar('.');
X#   endif
X}
X#ifdef DEBUG
Xif (iVerbosity >= iVprogress) putchar('\n');
X#endif
Xfclose(fCharters);
XNntpcommand("QUIT");
Xif (iVerbosity) printf("Connection with %s closed\n",NNTP);
Xfclose(fGroups); fclose(fNntpOut);
X#endif
X
X/* now read newsgroups with Charter/Title per group */
X
Xif ((fCharters= fopen(sCharterlfn,"r")) == NULL)
X{
X    if (iVerbosity)
X        printf("File %s not found, no descriptions can be given\n"
X              ,sCharterlfn);
X}
Xelse /* if ((fCharters= fopen(sCharterlfn,"r")) == NULL) */
X{
X#   ifdef DEBUG
X    if (iVerbosity >= iVactions)
X        printf("Reading short descriptions from \"%s\"\n",sCharterlfn);
X#   endif
X    if (pG1 == NULL) pG1= (s_Group*)malloc(sizeof(s_Group));
X    pG1->iTitle_pos= 0; i= 0;
X    while (fgets(sLine,iSlen,fCharters) != NULL)
X    {
X        pG1->sName= pcC= &sLine[0];
X	while (isgraph(*pcC)) 
X	    { if (isupper(*pcC)) *pcC= tolower(*pcC); pcC++; };
X        *pcC++= '\0';
X	if (sLine[0] != '\0')
X            if ((p_AVL= find_avlnode(pG1,paGr_tree,Grpcmp)) != NULL)
X                ((s_Group*)(p_AVL->content))->iTitle_pos= pG1->iTitle_pos;
X#       ifdef DEBUG
X            else
X            if (iVerbosity > iVprogress)
X                printf("\nNot \"active\" group: %s\n\t%s",sLine,pcC);
X#       endif
X        pG1->iTitle_pos= ftell(fCharters);
X#       ifdef DEBUG
X        if (iVerbosity >= iVprogress)
X            if (++i % iShwfac == 0) putchar('.');
X#       endif
X    } /* while (fgets(sLine,iSlen,fCharters) != NULL) */
X    /* don't close file, read random when titles must be printed */
X#   ifdef DEBUG
X    if (iVerbosity >= iVprogress) putchar('\n');
X#   endif
X} /* if ((fCharter= fopen(sCharterlfn,"r")) == NULL) */
X
Xif (iGr) /* requests are supplied as program arguments */
X{
X#   ifdef DEBUG
X    if (iVerbosity >= iVdebug) puts("Process arguments");
X#   endif
X    iGrfault= iGr;
X    for (i=1;i<argc;i++)
X    {
X        if (argv[i][0] != '-')
X            if (strcmp(argv[i],"?") == 0)
X            {
X                if (bIntractive && iVerbosity)
X                    if (Menusubscribe()) iGrfault--;
X            }
X            else
X            if (strcmp(argv[i],"."))
X                if (Checkrequest(argv[i])) iGrfault--;
X    }
X}
X
Xif (iGr == 0) /* no groupnames supplied as arguments, read from stdin */
X{
X    if (bIntractive && iVerbosity) puts("\nEnter newsgroups to subscribe to:");
X    for (;;)
X    {
X        if (bIntractive && iVerbosity) fputs(" ?  ",stdout);
X        if (gets(sLine) == NULL) break;
X	if (sLine[0] == '\0') break;
X	if (strcmp(sLine,"Q") == 0) break;
X        if (strcmp(sLine,".") == 0) break;
X        if (strcmp(sLine,"?") == 0)
X        {
X            if (bIntractive && iVerbosity) if (Menusubscribe()) break;
X        }
X        else
X        if (Checkrequest(sLine) == 0) iGr++;
X    }
X}
X
Xif (paGr_requests == NULL)
X{
X    if (iVerbosity) puts("No legal subscribe requests");
X#   ifdef NNTP
X#   ifdef DEBUG
X    if (iVerbosity == iVdebug) printf("unlink temporary %s\n",sCharterlfn);
X    if (iVerbosity < iVleavetmp)
X#   endif
X    unlink(sCharterlfn);
X#   ifdef DEBUG
X    else printf("Temporary newsgroup descriptions on %s\n",sCharterlfn);
X#   endif
X#   endif
X    exit(0);
X}
X
X/*
X    And now go looking into .newsrc
X*/
X
Xif (chdir(getenv("HOME"))) { perror("dir to $HOME"); exit(ERR_EXIT); }
X#ifdef DEBUG
Xif (iVerbosity > iVreport)
X{
X    if (access("tmp",F_OK))
X	if (mkdir("tmp",0750)) { perror("mkdir tmp"); exit(ERR_EXIT); }
X    if (chdir("tmp")) { perror("dir to ~/tmp"); exit(ERR_EXIT); }
X}
Xif (iVerbosity >= iVdebug) printf(" cwd = %s\n",getcwd(sLine,iSlen));
X#endif
XsNewgrplfn= strsave(TEMPRC);
XsNewgrplfn= mktemp(sNewgrplfn);
X
Xif ((fNewgroups= fopen(sNewgrplfn,"w")) == NULL)
X    { perror("NEW newsrc"); exit(ERR_EXIT); }
X#ifdef DEBUG
Xif (iVerbosity >= iVactions) printf("Opened file %s for writing\n"
X                                   ,sNewgrplfn);
X#endif
X
Xif ((fGroups= fopen(NEWSRC,"r")) == NULL)
X{
X    FILE *fDefnewsrc;
X    if ((fDefnewsrc= fopen(DEFRC,"r")) != NULL)
X    { /* add groups on .defaultnewsrc */
X        s_Group sGr_local, *pGr_dum;
X	register char *pCc;
X	register P_AVL_NODE pNode;
X#       ifdef DEBUG
X	if (iVerbosity >= iVactions)
X	    printf("Read default groups from %s\n",DEFRC);
X#       endif
X	sGr_local.sName= sLine; /* and hold it during the loop */
X	while (fgets(sLine,iSlen,fDefnewsrc) != NULL)
X	    if (strlen(sLine))
X		if (pCc= index(sLine,':'))
X	        {
X		    *pCc= '\0';
X		    if (find_avlnode(&sGr_local,paGr_requests,Grpcmp) == NULL)
X			if (pNode= find_avlnode(&sGr_local,paGr_tree,Grpcmp))
X			{
X                            insert_avl(pNode->content,&paGr_requests
X					,Grpcmp,&pGr_dum);
X#                           ifdef DEBUG
X		            if (iVerbosity >= iVdebug)
X			        printf("Default group %s added\n",sLine);
X#                           endif
X			}
X                }
X	fclose(fDefnewsrc);
X    }
X#   ifdef DEBUG
X    else
X    if (iVerbosity >= iVactions)
X	printf("Default newsrc (%s) non-existant or not readable\n",DEFRC);
X#   endif
X}
Xelse /* if ((fGroups= fopen(NEWSRC,"r")) == NULL) */
X{
X    s_Group sG_local;
X    register char cC;
X#   ifdef DEBUG
X    if (iVerbosity >= iVactions) printf("Opened file %s for reading\n",NEWSRC);
X#   endif
X    sG_local.sName= sLine; /* and hold it so during read of .newsrc */
X    for (;;)
X    {
X        if (fgets(sLine,iSlen,fGroups) == NULL)
X        {
X#           ifdef DEBUG
X            if (iVerbosity >= iVprogress) putchar('\n');
X            if (iVerbosity >= iVdebug)
X                printf("End of %s reached\n",NEWSRC);
X#           endif
X            break;
X        }
X
X            /* search for '!' or ':' or 'white space' */
X        pcC= sLine; while(index("!: \t\n",*pcC) == NULL) pcC++;
X        cC= *pcC; *pcC= '\0';
X        if (p_AVL= find_avlnode(&sG_local,paGr_requests,Grpcmp))
X        {
X#           ifdef DEBUG
X	    if (iVerbosity >= iVprogress) putchar('\n');
X#           endif
X            if (iVerbosity)
X                switch(cC)
X                {
X                default:
X                    puts("Strange line in \".newsrc\", run \"nntidy\"");
X                    *pcC= cC; puts(sLine); exit(ERR_EXIT);
X                case ':':
X                    puts("Already subscribed:");
X                    Printcharter(p_AVL->content,1);
X                    break;
X                case '!':
X                    puts("Renew cancelled subscription");
X                    Printcharter(p_AVL->content,1);
X                    break;
X                } /* switch(cC) */
X            /* if (iVerbosity) */
X            *pcC= ':';
X	    pcC= ((s_Group*)(p_AVL->content))->sName;
X            *pcC= toupper(*pcC); /* mark as already processed */
X        }
X        else /* if (p_AVL= find_avlnode(&sG_local,paGr_requests,Grpcmp)) */
X	{
X            *pcC= cC;
X#           ifdef DEBUG
X	    if (iVerbosity >= iVprogress) putchar('.');
X#           endif
X	} /* if (p_AVL= find_avlnode(&sG_local,paGr_requests,Grpcmp)) */
X        fputs(sLine,fNewgroups);
X    } /* for (;;) */
X    fclose(fGroups);
X} /* if ((fGroups= fopen(NEWSRC,"r")) == NULL) */
X
Xunravel_avl(&paGr_requests,Addsubscription,0);
Xfclose(fNewgroups);
Xif (fCharters != NULL) fclose(fCharters);
X#ifdef DEBUG
Xif (iVerbosity >= iVdebug) printf("\nunlink %s\n",OLDRC);
X#endif
Xunlink(OLDRC);
X#ifdef DEBUG
Xif (iVerbosity >= iVdebug) printf("rename %s to %s\n",NEWSRC,OLDRC);
X#endif
Xrename(NEWSRC,OLDRC);
X#ifdef DEBUG
Xif (iVerbosity >= iVdebug) printf("rename %s to %s\n",sNewgrplfn,NEWSRC);
X#endif
Xrename(sNewgrplfn,NEWSRC);
X#ifdef NNTP
X#ifdef DEBUG
Xif (iVerbosity == iVdebug) printf("unlink temporary %s\n",sCharterlfn);
Xif (iVerbosity < iVleavetmp)
X#endif
X    unlink(sCharterlfn);
X#ifdef DEBUG
Xelse printf("Temporary newsgroup descriptions on %s\n",sCharterlfn);
X#endif
X#endif
X
Xif (iVerbosity == 0) exit(iGrfault);
Xexit(0);
X
X} /* main */
END_OF_FILE
if test 28237 -ne `wc -c <'nnsub.c'`; then
    echo shar: \"'nnsub.c'\" unpacked with wrong size!
fi
# end of 'nnsub.c'
fi
if test -f 'strsave.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'strsave.c'\"
else
echo shar: Extracting \"'strsave.c'\" \(145 characters\)
sed "s/^X//" >'strsave.c' <<'END_OF_FILE'
Xextern char *malloc();
X
Xchar *strsave(s)
Xchar *s;
X{
Xchar *result;
Xresult= malloc(strlen(s)+1);
Xstrcpy(result,s);
Xreturn(result);
X} /* strsave */
END_OF_FILE
if test 145 -ne `wc -c <'strsave.c'`; then
    echo shar: \"'strsave.c'\" unpacked with wrong size!
fi
# end of 'strsave.c'
fi
echo shar: End of shell archive.
exit 0
-- 
Rudi van Houten	<rudi@cc.ruu.nl>
Academisch Computer Centrum Utrecht / Besturings Systemen
Budapestlaan 8  -  3584 CD  -  Utrecht  -  Netherlands
:-) Experience is the harvest of many mistakes.
Re: unable to subscribe to empty newsgroup
#2568
Author: Bill Irwin
Date: Wed, 11 Mar 1992 07:55
22 lines
1886 bytes
nagel@Cigna.COM (Mark Nagel) writes:

: I installed dynafeed which prevents news from being sent here if no
: one subscribes to a particular group, then that group is not sent by
: our feed.  Works great.  Only problem is that to request a group
: that is not currently sent, you must first subscribe to that group.
: Nn will not allow you to subscribe to a group unless there are
: articles present in it.  Is there any way to force entry into a
: group so you can subscribe to it even if the group is empty?  I have
: no problem with editing my .newsrc, but I'm trying to make this
: painless for our users.  I suppose a simple edit script would work
: well enough, but it would be nice if it could be done from within nn.

What about posting an article to the group with local
distribution and waiting a bit for it to get into the system,
then subscribe to the group.  The delay between posting and
subscribing is not good, but workable.
-- 
Bill Irwin    -       The Westrheim Group     -    Vancouver, BC, Canada
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uunet!twg!bill            (604) 431-9600 (voice) |     Your Computer  
bill@twg.bc.ca            (604) 430-4329 (fax)   |    Systems Partner
Re: unable to subscribe to empty newsgroup
#2590
Author: Pierre Uszynski
Date: Mon, 16 Mar 1992 22:24
37 lines
2222 bytes
In <1992Feb28.173945.1397@Cigna.COM> nagel@Cigna.COM (Mark Nagel) writes:

>I installed dynafeed which prevents news from being sent here if no
>one subscribes to a particular group, then that group is not sent by
>our feed.  Works great.  Only problem is that to request a group
>that is not currently sent, you must first subscribe to that group.
>Nn will not allow you to subscribe to a group unless there are
>articles present in it.  Is there any way to force entry into a
..

We are trying to install such a system here too. Here is a trick that
is working for us (if i remember well...):

-We dynamically control news flow by listing all wanted news groups
or hierarchies in our sys file (we use nntp). To do that we had to fix
a line buffer size in the source but that's easy enough (the sys entry
is now in the 15000 character range :-)

-nn does not allow g-ing to an empty group, so we post, with local
distribution one article that tells the user "this group will start
getting articles when you subscribe to it". the local distribution
is not actually "local" but our site-area name ("prpa"). It seems
postnews handles this post correctly even though the group is not
listed in the sys file.

-The "message" post has to be repeated appropriately to survive
expiration.

I think i remember right. I'll check and report any mistakes in the
above. The details will depend quite a bit on your local setup anyway.

Pierre.

-- 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
         Pierre Uszynski, Philips Research Palo Alto, CA
              415-354-0328, pierre@PRPA.Philips.COM
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads