⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slp_attr_y.c

📁 SLP协议在linux下的实现。此版本为1.2.1版。官方网站为www.openslp.org
💻 C
📖 第 1 页 / 共 3 页
字号:
yyreduce:  /* yyn is the number of a rule to reduce with.  */  yylen = yyr2[yyn];  /* If YYLEN is nonzero, implement the default value of the action:     `$$ = $1'.     Otherwise, the following line sets YYVAL to garbage.     This behavior is undocumented and Bison     users should not rely upon it.  Assigning to YYVAL     unconditionally makes the parser a bit smaller, and it avoids a     GCC warning that YYVAL may be used uninitialized.  */  yyval = yyvsp[1-yylen];  YY_REDUCE_PRINT (yyn);  switch (yyn)    {        case 2:#line 119 "slp_attr_y.y"    {    while ( !SLP_IS_HEAD(inProcessAttr.next) )    {        yyval._atl = inProcessAttr.next;       SLP_UNLINK(yyval._atl);       SLP_INSERT_BEFORE(yyval._atl, &attrHead);    }    /* all we really want to do here is link each attribute */    /* to the global list head. */}    break;  case 3:#line 130 "slp_attr_y.y"    {    /* both of these non-terminals are really lists */    /* ignore the first non-terminal */    while ( !SLP_IS_HEAD(inProcessAttr.next) )    {        yyval._atl = inProcessAttr.next;       SLP_UNLINK(yyval._atl);       SLP_INSERT_BEFORE(yyval._atl, &attrHead);    }}    break;  case 4:#line 142 "slp_attr_y.y"    {    yyval._atl =  SLPAllocAttr(yyvsp[0]._s, tag, NULL, 0);    if ( NULL != yyval._atl )    {       SLP_INSERT_BEFORE(yyval._atl, &inProcessAttr);    }}    break;  case 5:#line 150 "slp_attr_y.y"    {    yyval._atl =  SLPAllocAttr(yyvsp[-1]._s, tag, NULL, 0);    if (NULL != yyval._atl)    {       SLP_INSERT_BEFORE(yyval._atl, &inProcessAttr);    }}    break;  case 6:#line 158 "slp_attr_y.y"    {    yyval._atl = inProcessTag.next;    while (!SLP_IS_HEAD(yyval._atl))    {        yyval._atl->name = strdup(yyvsp[-3]._s); 	SLP_UNLINK(yyval._atl);	SLP_INSERT_BEFORE(yyval._atl, &inProcessAttr);	yyval._atl = inProcessTag.next;    }}    break;  case 7:#line 170 "slp_attr_y.y"    {    if(NULL != yyvsp[0]._atl)    {       SLP_INSERT(yyvsp[0]._atl, &inProcessTag);    }}    break;  case 8:#line 177 "slp_attr_y.y"    {    if (NULL != yyvsp[0]._atl)    {       SLP_INSERT_BEFORE(yyvsp[0]._atl, &inProcessTag);    }}    break;  case 9:#line 185 "slp_attr_y.y"    {    yyval._atl = SLPAllocAttr(NULL, boolean, &bt, sizeof(int));}    break;  case 10:#line 189 "slp_attr_y.y"    {    yyval._atl = SLPAllocAttr(NULL, boolean, &bf, sizeof(int));}    break;  case 11:#line 193 "slp_attr_y.y"    {     /* treat it as a string because it is already encoded */    yyval._atl = SLPAllocAttr(NULL, string, yyvsp[0]._s, strlen(yyvsp[0]._s) + 1);}    break;  case 12:#line 198 "slp_attr_y.y"    {        yyval._atl = SLPAllocAttr(NULL, string, yyvsp[0]._s, strlen(yyvsp[0]._s) + 1);}    break;  case 13:#line 202 "slp_attr_y.y"    {    yyval._atl = SLPAllocAttr(NULL, integer, &(yyvsp[0]._i), sizeof(int));}    break;    }/* Line 991 of yacc.c.  */#line 1185 "slp_attr_y.c"  yyvsp -= yylen;  yyssp -= yylen;  YY_STACK_PRINT (yyss, yyssp);  *++yyvsp = yyval;  /* Now `shift' the result of the reduction.  Determine what state     that goes to, based on the state we popped back to and the rule     number reduced by.  */  yyn = yyr1[yyn];  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)    yystate = yytable[yystate];  else    yystate = yydefgoto[yyn - YYNTOKENS];  goto yynewstate;/*------------------------------------.| yyerrlab -- here on detecting error |`------------------------------------*/yyerrlab:  /* If not already recovering from an error, report this error.  */  if (!yyerrstatus)    {      ++yynerrs;#if YYERROR_VERBOSE      yyn = yypact[yystate];      if (YYPACT_NINF < yyn && yyn < YYLAST)	{	  YYSIZE_T yysize = 0;	  int yytype = YYTRANSLATE (yychar);	  char *yymsg;	  int yyx, yycount;	  yycount = 0;	  /* Start YYX at -YYN if negative to avoid negative indexes in	     YYCHECK.  */	  for (yyx = yyn < 0 ? -yyn : 0;	       yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)	    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)	      yysize += yystrlen (yytname[yyx]) + 15, yycount++;	  yysize += yystrlen ("syntax error, unexpected ") + 1;	  yysize += yystrlen (yytname[yytype]);	  yymsg = (char *) YYSTACK_ALLOC (yysize);	  if (yymsg != 0)	    {	      char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");	      yyp = yystpcpy (yyp, yytname[yytype]);	      if (yycount < 5)		{		  yycount = 0;		  for (yyx = yyn < 0 ? -yyn : 0;		       yyx < (int) (sizeof (yytname) / sizeof (char *));		       yyx++)		    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)		      {			const char *yyq = ! yycount ? ", expecting " : " or ";			yyp = yystpcpy (yyp, yyq);			yyp = yystpcpy (yyp, yytname[yyx]);			yycount++;		      }		}	      yyerror (yymsg);	      YYSTACK_FREE (yymsg);	    }	  else	    yyerror ("syntax error; also virtual memory exhausted");	}      else#endif /* YYERROR_VERBOSE */	yyerror ("syntax error");    }  if (yyerrstatus == 3)    {      /* If just tried and failed to reuse lookahead token after an	 error, discard it.  */      /* Return failure if at end of input.  */      if (yychar == YYEOF)        {	  /* Pop the error token.  */          YYPOPSTACK;	  /* Pop the rest of the stack.  */	  while (yyss < yyssp)	    {	      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);	      yydestruct (yystos[*yyssp], yyvsp);	      YYPOPSTACK;	    }	  YYABORT;        }      YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);      yydestruct (yytoken, &yylval);      yychar = YYEMPTY;    }  /* Else will try to reuse lookahead token after shifting the error     token.  */  goto yyerrlab2;/*----------------------------------------------------.| yyerrlab1 -- error raised explicitly by an action.  |`----------------------------------------------------*/yyerrlab1:  /* Suppress GCC warning that yyerrlab1 is unused when no action     invokes YYERROR.  */#if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__) \    && !defined __cplusplus  __attribute__ ((__unused__))#endif  goto yyerrlab2;/*---------------------------------------------------------------.| yyerrlab2 -- pop states until the error token can be shifted.  |`---------------------------------------------------------------*/yyerrlab2:  yyerrstatus = 3;	/* Each real token shifted decrements this.  */  for (;;)    {      yyn = yypact[yystate];      if (yyn != YYPACT_NINF)	{	  yyn += YYTERROR;	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)	    {	      yyn = yytable[yyn];	      if (0 < yyn)		break;	    }	}      /* Pop the current state because it cannot handle the error token.  */      if (yyssp == yyss)	YYABORT;      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);      yydestruct (yystos[yystate], yyvsp);      yyvsp--;      yystate = *--yyssp;      YY_STACK_PRINT (yyss, yyssp);    }  if (yyn == YYFINAL)    YYACCEPT;  YYDPRINTF ((stderr, "Shifting error token, "));  *++yyvsp = yylval;  yystate = yyn;  goto yynewstate;/*-------------------------------------.| yyacceptlab -- YYACCEPT comes here.  |`-------------------------------------*/yyacceptlab:  yyresult = 0;  goto yyreturn;/*-----------------------------------.| yyabortlab -- YYABORT comes here.  |`-----------------------------------*/yyabortlab:  yyresult = 1;  goto yyreturn;#ifndef yyoverflow/*----------------------------------------------.| yyoverflowlab -- parser overflow comes here.  |`----------------------------------------------*/yyoverflowlab:  yyerror ("parser stack overflow");  yyresult = 2;  /* Fall through.  */#endifyyreturn:#ifndef yyoverflow  if (yyss != yyssa)    YYSTACK_FREE (yyss);#endif  return yyresult;}#line 207 "slp_attr_y.y"SLPAttrList *SLPAllocAttr(char *name, SLPTypes type, void *val, int len){    SLPAttrList *attr;    if ( NULL != (attr = (SLPAttrList *)calloc(1, sizeof(SLPAttrList))) )    {        if ( name != NULL )        {            if ( NULL == (attr->name = strdup(name)) )            {                free(attr);                return(NULL);            }        }        attr->type = type;        if ( type == head ) /* listhead */            return(attr);        if ( val != NULL )        {            switch ( type )            {                case string:                    if ( NULL != (attr->val.stringVal = strdup((unsigned char *)val)) )                        return(attr);                    break;                case integer:                    attr->val.intVal = *(unsigned int *)val;                    break;                case boolean:                    attr->val.boolVal = *(int *)val;                    break;                case opaque:                    #if 0                    if ( len > 0 )                    {                        int encLen;                        opq_EncodeOpaque(val, len, (char **)&(attr->val.opaqueVal), &encLen);                        if ( NULL != attr->val.opaqueVal )                        {                            /* first two bytes contain length of attribute */                           SLP_SETSHORT(((char *)attr->val.opaqueVal), encLen, 0 );                        }                    }                    #endif                    break;                default:                    break;            }        }    }    return(attr);}   SLPAttrList *SLPAllocAttrList(void){    SLPAttrList *temp;    if ( NULL != (temp = SLPAllocAttr(NULL, head, NULL, 0)) )    {        temp->next = temp->prev = temp;        temp->isHead = TRUE;      }    return(temp);}   /* attr MUST be unlinked from its list ! */void SLPFreeAttr(SLPAttrList *attr){    if ( attr->name != NULL )    {        free(attr->name);    }    if ( attr->type == string && attr->val.stringVal != NULL )    {        free(attr->val.stringVal);    }    else if ( attr->type == opaque && attr->val.opaqueVal != NULL )    {        free(attr->val.opaqueVal);    }        free(attr);}   void SLPFreeAttrList(SLPAttrList *list, int staticFlag){    SLPAttrList *temp;    while ( ! (SLP_IS_EMPTY(list)) )    {        temp = list->next;       SLP_UNLINK(temp);        SLPFreeAttr(temp);    }    if ( staticFlag == TRUE )    {        SLPFreeAttr(list);    }        return;}       void SLPInitInternalAttrList(void){    attrHead.next = attrHead.prev = &attrHead;    attrHead.isHead = TRUE;    inProcessAttr.next =  inProcessAttr.prev = &inProcessAttr;    inProcessAttr.isHead = TRUE;    inProcessTag.next =  inProcessTag.prev = &inProcessTag;    inProcessTag.isHead = TRUE;    return;}   SLPAttrList *_SLPDecodeAttrString(char *s){    unsigned int lexer = 0;    SLPAttrList *temp = NULL;   SLPInitInternalAttrList();    if ( s != NULL )    {        if ( NULL != (temp = SLPAllocAttrList()) )        {            if ((0 != (lexer = slp_attr_init_lexer(s))) &&  yyparse() )            {                SLPFreeAttrList(temp,0);                while ( !SLP_IS_HEAD(inProcessTag.next) )                {                    temp = inProcessTag.next;                   SLP_UNLINK(temp);                    SLPFreeAttr(temp);                }                while ( !SLP_IS_HEAD(inProcessAttr.next) )                {                    temp = inProcessAttr.next;                   SLP_UNLINK(temp);                    SLPFreeAttr(temp);                }                while ( !SLP_IS_HEAD(attrHead.next) )                {                    temp = attrHead.next;                   SLP_UNLINK(temp);                    SLPFreeAttr(temp);                }                slp_attr_close_lexer(lexer);                                return(NULL);            }            if ( !SLP_IS_EMPTY(&attrHead) )            {               SLP_LINK_HEAD(temp, &attrHead);            }            if ( lexer != 0 )            {                slp_attr_close_lexer(lexer);            }        }    }    return(temp);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -