#ifndef lint
/*static char yysccsid[] = "from: @(#)yaccpar	1.9 (Berkeley) 02/21/93";*/
static char yyrcsid[] = "$Id: skeleton.c,v 1.6 1995/09/07 17:34:04 jtc Exp $";
#endif
#define YYBYACC 1
#define YYMAJOR 1
#define YYMINOR 9
#define yyclearin (yychar=(-1))
#define yyerrok (yyerrflag=0)
#define YYRECOVERING (yyerrflag!=0)
#define YYPREFIX "yy"
#line 2 "newsrc.y"
#if !defined(lint) && !defined(SABER) && !defined(GCC_WALL)
static char XRNrcsid[] = "$Id: newsrc.y,v 1.14 1995/09/22 06:47:47 jik Exp $";
#endif

/*
 * xrn - an X-based NNTP news reader
 *
 * Copyright (c) 1988-1993, Ellen M. Sentovich and Rick L. Spickelmier.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of the University of California not
 * be used in advertising or publicity pertaining to distribution of 
 * the software without specific, written prior permission.  The University
 * of California makes no representations about the suitability of this
 * software for any purpose.  It is provided "as is" without express or
 * implied warranty.
 *
 * THE UNIVERSITY OF CALIFORNIA DISCLAIMS ALL WARRANTIES WITH REGARD TO 
 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 
 * FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR
 * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * newsrc.y - yacc parser for the newsrc file
 */

#include "copyright.h"
#include "config.h"
#include "utils.h"
#include <X11/Xos.h>
#include <X11/Intrinsic.h>
#include "avl.h"
#include "mesg.h"
#include "news.h"
#include "newsrcfile.h"
#include "mesg_strings.h"
#include "internals.h"

extern int yylineno;

int newsrc_mesg_name;

#line 53 "newsrc.y"
typedef union {
    int integer;
    char *string;
    char character;
    struct list *item;
} YYSTYPE;
#line 70 "y.tab.c"
#define NAME 257
#define SEPARATOR 258
#define NUMBER 259
#define EOL 260
#define DASH 261
#define COMMA 262
#define YYERRCODE 256
short yylhs[] = {                                        -1,
    0,    3,    3,    4,    4,    4,    1,    1,    2,    2,
};
short yylen[] = {                                         2,
    1,    1,    2,    4,    3,    2,    1,    3,    1,    3,
};
short yydefred[] = {                                      0,
    0,    0,    0,    0,    2,    6,    0,    3,    0,    5,
    0,    7,    0,    4,    0,   10,    8,
};
short yydgoto[] = {                                       3,
   11,   12,    4,    5,
};
short yysindex[] = {                                   -252,
 -251, -250,    0, -252,    0,    0, -253,    0, -249,    0,
 -260,    0, -248,    0, -246,    0,    0,
};
short yyrindex[] = {                                      0,
    0,    0,    0,   10,    0,    0,    0,    0, -259,    0,
    0,    0,    0,    0,    0,    0,    0,
};
short yygindex[] = {                                      0,
    0,   -1,    0,   11,
};
#define YYTABLESIZE 15
short yytable[] = {                                      14,
    9,   15,    9,    1,    2,    9,   10,    7,    6,    1,
   16,   13,    9,   17,    8,
};
short yycheck[] = {                                     260,
  260,  262,  262,  256,  257,  259,  260,  258,  260,    0,
  259,  261,  259,   15,    4,
};
#define YYFINAL 3
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 262
#if YYDEBUG
char *yyname[] = {
"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"NAME","SEPARATOR","NUMBER","EOL",
"DASH","COMMA",
};
char *yyrule[] = {
"$accept : goal",
"goal : newsrc_file",
"newsrc_file : newsrc_line",
"newsrc_file : newsrc_file newsrc_line",
"newsrc_line : NAME SEPARATOR artlist EOL",
"newsrc_line : NAME SEPARATOR EOL",
"newsrc_line : error EOL",
"artlist : articles",
"artlist : artlist COMMA articles",
"articles : NUMBER",
"articles : NUMBER DASH NUMBER",
};
#endif
#ifdef YYSTACKSIZE
#undef YYMAXDEPTH
#define YYMAXDEPTH YYSTACKSIZE
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 500
#define YYMAXDEPTH 500
#endif
#endif
int yydebug;
int yynerrs;
int yyerrflag;
int yychar;
short *yyssp;
YYSTYPE *yyvsp;
YYSTYPE yyval;
YYSTYPE yylval;
short yyss[YYSTACKSIZE];
YYSTYPE yyvs[YYSTACKSIZE];
#define yystacksize YYSTACKSIZE
#line 179 "newsrc.y"
#include "lex.yy.c"

#line 166 "y.tab.c"
#define YYABORT goto yyabort
#define YYREJECT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
#if defined(__STDC__)
yyparse(void)
#else
yyparse()
#endif
{
    register int yym, yyn, yystate;
#if YYDEBUG
    register char *yys;
    extern char *getenv();

    if (yys = getenv("YYDEBUG"))
    {
        yyn = *yys;
        if (yyn >= '0' && yyn <= '9')
            yydebug = yyn - '0';
    }
#endif

    yynerrs = 0;
    yyerrflag = 0;
    yychar = (-1);

    yyssp = yyss;
    yyvsp = yyvs;
    *yyssp = yystate = 0;

yyloop:
    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
    if (yychar < 0)
    {
        if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
        if (yydebug)
        {
            yys = 0;
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
            if (!yys) yys = "illegal-symbol";
            printf("%sdebug: state %d, reading %d (%s)\n",
                    YYPREFIX, yystate, yychar, yys);
        }
#endif
    }
    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
    {
#if YYDEBUG
        if (yydebug)
            printf("%sdebug: state %d, shifting to state %d\n",
                    YYPREFIX, yystate, yytable[yyn]);
#endif
        if (yyssp >= yyss + yystacksize - 1)
        {
            goto yyoverflow;
        }
        *++yyssp = yystate = yytable[yyn];
        *++yyvsp = yylval;
        yychar = (-1);
        if (yyerrflag > 0)  --yyerrflag;
        goto yyloop;
    }
    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
    {
        yyn = yytable[yyn];
        goto yyreduce;
    }
    if (yyerrflag) goto yyinrecovery;
    yyerror("syntax error");
#ifdef lint
    goto yyerrlab;
#endif
yyerrlab:
    ++yynerrs;
yyinrecovery:
    if (yyerrflag < 3)
    {
        yyerrflag = 3;
        for (;;)
        {
            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
            {
#if YYDEBUG
                if (yydebug)
                    printf("%sdebug: state %d, error recovery shifting\
 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
#endif
                if (yyssp >= yyss + yystacksize - 1)
                {
                    goto yyoverflow;
                }
                *++yyssp = yystate = yytable[yyn];
                *++yyvsp = yylval;
                goto yyloop;
            }
            else
            {
#if YYDEBUG
                if (yydebug)
                    printf("%sdebug: error recovery discarding state %d\n",
                            YYPREFIX, *yyssp);
#endif
                if (yyssp <= yyss) goto yyabort;
                --yyssp;
                --yyvsp;
            }
        }
    }
    else
    {
        if (yychar == 0) goto yyabort;
#if YYDEBUG
        if (yydebug)
        {
            yys = 0;
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
            if (!yys) yys = "illegal-symbol";
            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
                    YYPREFIX, yystate, yychar, yys);
        }
#endif
        yychar = (-1);
        goto yyloop;
    }
yyreduce:
#if YYDEBUG
    if (yydebug)
        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
                YYPREFIX, yystate, yyn, yyrule[yyn]);
#endif
    yym = yylen[yyn];
    yyval = yyvsp[1-yym];
    switch (yyn)
    {
case 4:
#line 80 "newsrc.y"
{
		    struct newsgroup *newsgroup;

		    if (! verifyGroup(yyvsp[-3].string, &newsgroup)) {
		      struct list *current, *next;

		      mesgPane(XRN_SERIOUS, newsrc_mesg_name,
			       BOGUS_NG_REMOVING_MSG, yyvsp[-3].string);

		      for (current = yyvsp[-1].item; current; current = next) {
			next = current->next;
			XtFree((char *) current);
		      }
		    } else {
			if (IS_NOENTRY(newsgroup) || IS_NEW(newsgroup)) {
			    CLEAR_NOENTRY(newsgroup);
			    CLEAR_NEW(newsgroup);
			    if (yyvsp[-2].character == ':')
				SET_SUB(newsgroup);
			    newsgroup->nglist = yyvsp[-1].item;
			    updateArticleArray(newsgroup);
			    newsgroup->newsrc = MaxGroupNumber;
			    Newsrc[MaxGroupNumber++] = newsgroup;
			} else {
			    mesgPane(XRN_SERIOUS, newsrc_mesg_name,
				     DUP_NEWSRC_ENTRY_MSG, yyvsp[-3].string);
			}
		    }
		    XtFree(yyvsp[-3].string);
	        }
break;
case 5:
#line 111 "newsrc.y"
{
		    struct newsgroup *newsgroup;

		    if (! verifyGroup(yyvsp[-2].string, &newsgroup))
		      mesgPane(XRN_SERIOUS, newsrc_mesg_name,
			       BOGUS_NG_REMOVING_MSG, yyvsp[-2].string);
		    else {
			if (IS_NOENTRY(newsgroup) || IS_NEW(newsgroup)) {
			    CLEAR_NOENTRY(newsgroup);
			    CLEAR_NEW(newsgroup);
			    if (yyvsp[-1].character == ':')
				SET_SUB(newsgroup);
			    newsgroup->nglist = NIL(struct list);
			    updateArticleArray(newsgroup);
			    newsgroup->newsrc = MaxGroupNumber;
			    Newsrc[MaxGroupNumber++] = newsgroup;
			} else {
			    mesgPane(XRN_SERIOUS, newsrc_mesg_name,
				     DUP_NEWSRC_ENTRY_MSG, yyvsp[-2].string);
			}
		    }
		    XtFree(yyvsp[-2].string);
	        }
break;
case 6:
#line 134 "newsrc.y"
{
		mesgPane(XRN_SERIOUS, newsrc_mesg_name, BAD_NEWSRC_LINE_MSG,
			 yylineno - 1);	/* yylineno stepped at EOL */
		yyerrok;
		yyclearin;
	    }
break;
case 7:
#line 143 "newsrc.y"
{
		    yyval.item = yyvsp[0].item;
		}
break;
case 8:
#line 147 "newsrc.y"
{
		    struct list *temp;

		    yyval.item = yyvsp[-2].item;
		    for (temp = yyval.item; temp != NIL(struct list); temp = temp->next) {
			if (temp->next == NIL(struct list)) {
			    temp->next = yyvsp[0].item;
			    break;
			}
		    }
		}
break;
case 9:
#line 161 "newsrc.y"
{
		    yyval.item = ALLOC(struct list);
		    yyval.item->type = SINGLE;
		    yyval.item->contents.single = (art_num) yyvsp[0].integer;
		    yyval.item->next = NIL(struct list);
		}
break;
case 10:
#line 168 "newsrc.y"
{
		    yyval.item = ALLOC(struct list);
		    yyval.item->type = RANGE;
		    yyval.item->contents.range.start = (art_num) yyvsp[-2].integer;
		    yyval.item->contents.range.end = (art_num) yyvsp[0].integer;
		    yyval.item->next = NIL(struct list);
		}
break;
#line 414 "y.tab.c"
    }
    yyssp -= yym;
    yystate = *yyssp;
    yyvsp -= yym;
    yym = yylhs[yyn];
    if (yystate == 0 && yym == 0)
    {
#if YYDEBUG
        if (yydebug)
            printf("%sdebug: after reduction, shifting from state 0 to\
 state %d\n", YYPREFIX, YYFINAL);
#endif
        yystate = YYFINAL;
        *++yyssp = YYFINAL;
        *++yyvsp = yyval;
        if (yychar < 0)
        {
            if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
            if (yydebug)
            {
                yys = 0;
                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
                if (!yys) yys = "illegal-symbol";
                printf("%sdebug: state %d, reading %d (%s)\n",
                        YYPREFIX, YYFINAL, yychar, yys);
            }
#endif
        }
        if (yychar == 0) goto yyaccept;
        goto yyloop;
    }
    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
        yystate = yytable[yyn];
    else
        yystate = yydgoto[yym];
#if YYDEBUG
    if (yydebug)
        printf("%sdebug: after reduction, shifting from state %d \
to state %d\n", YYPREFIX, *yyssp, yystate);
#endif
    if (yyssp >= yyss + yystacksize - 1)
    {
        goto yyoverflow;
    }
    *++yyssp = yystate;
    *++yyvsp = yyval;
    goto yyloop;
yyoverflow:
    yyerror("yacc stack overflow");
yyabort:
    return (1);
yyaccept:
    return (0);
}
