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

📄 btsrv-parser.c

📁 affix是一个Open Source的蓝牙协议栈
💻 C
📖 第 1 页 / 共 3 页
字号:
      if (yyn == 0 || yyn == YYTABLE_NINF)	goto yyerrlab;      yyn = -yyn;      goto yyreduce;    }  if (yyn == YYFINAL)    YYACCEPT;  /* Shift the lookahead token.  */  YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));  /* Discard the token being shifted unless it is eof.  */  if (yychar != YYEOF)    yychar = YYEMPTY;  *++yyvsp = yylval;  /* Count tokens shifted since error; after three, turn off error     status.  */  if (yyerrstatus)    yyerrstatus--;  yystate = yyn;  goto yynewstate;/*-----------------------------------------------------------.| yydefault -- do the default action for the current state.  |`-----------------------------------------------------------*/yydefault:  yyn = yydefact[yystate];  if (yyn == 0)    goto yyerrlab;  goto yyreduce;/*-----------------------------.| yyreduce -- Do a reduction.  |`-----------------------------*/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 6:#line 105 "btsrv-parser.y"    { yyval.num = 1; }    break;  case 7:#line 105 "btsrv-parser.y"    { yyval.num = 0; }    break;  case 8:#line 106 "btsrv-parser.y"    { yyval.str = NULL; }    break;  case 10:#line 108 "btsrv-parser.y"    { waitsemi = 1; }    break;  case 17:#line 122 "btsrv-parser.y"    { managepin = yyvsp[0].num; }    break;  case 18:#line 123 "btsrv-parser.y"    { managekey = yyvsp[0].num; }    break;  case 19:#line 124 "btsrv-parser.y"    { startsvc = yyvsp[0].num; }    break;  case 20:#line 125 "btsrv-parser.y"    { initdev = yyvsp[0].num; }    break;  case 21:#line 130 "btsrv-parser.y"    {				char	*name = yyvsp[0].str;				if (name == NULL) {					DBPRT("found common device\n");					if (devnum)						devices[devnum] = devices[0];					dev = &devices[0];					dev->name[0] = '*';				} else {					DBPRT("found device: %s", name);					/* get device num */					dev = &devices[devnum];					strcpy(dev->name, name);				}			}    break;  case 22:#line 147 "btsrv-parser.y"    { devnum++; }    break;  case 25:#line 157 "btsrv-parser.y"    {				dev->btname = strdup(yyvsp[0].str);			}    break;  case 26:#line 161 "btsrv-parser.y"    {				str2cod(yyvsp[0].str, &dev->cod);				DBPRT("cod: %#.6x", dev->cod);			}    break;  case 27:#line 166 "btsrv-parser.y"    {				str2mask(role_map, yyvsp[0].str, &dev->role);				;			}    break;  case 28:#line 171 "btsrv-parser.y"    {				str2mask(sec_mode_map, yyvsp[0].str, &dev->security);				DBPRT("sec_mode: %#x", dev->security);			}    break;  case 29:#line 176 "btsrv-parser.y"    {				str2mask(scan_map, yyvsp[0].str, &dev->scan);				DBPRT("scan_mode: %#x", dev->scan);			}    break;  case 30:#line 182 "btsrv-parser.y"    {				str2mask(pkt_type_map, yyvsp[0].str, &dev->pkt_type);				DBPRT("pkt_type: %#x", dev->pkt_type);			}    break;  case 31:#line 194 "btsrv-parser.y"    { 				int	i;				svc = &services[svcnum];				DBPRT("found service: [%s]", yyvsp[0].str);				for (i = 0; profiles[i].name; i++) {					if (strcasecmp(profiles[i].name, yyvsp[0].str) == 0)						break;				}				if (profiles[i].name == NULL) {					BTERROR("Invalid profile name %s in config file %s line %d",						yyvsp[0].str, config_file, yylineno);					return -1;				}				svc->profile = &profiles[i];			}    break;  case 32:#line 211 "btsrv-parser.y"    { svcnum++; }    break;  case 35:#line 220 "btsrv-parser.y"    { 				DBPRT("found profile: %s", yyvsp[0].str); 			}    break;  case 36:#line 224 "btsrv-parser.y"    { 				struct affix_tupla	flags[] = {						{SRV_FLAG_SOCKET, "socket"},						{SRV_FLAG_RFCOMM_TTY|SRV_FLAG_SOCKET, "tty"},						{SRV_FLAG_STD, "std"},						{0, 0}						};				DBPRT("found flag list: [%s]", yyvsp[0].str);				if (!str2mask(flags, yyvsp[0].str, &svc->flags)) {					BTERROR("Invalid flags at line %d", yylineno);					return -1;				}			}    break;  case 37:#line 239 "btsrv-parser.y"    { 				strcpy(svc->cmd, yyvsp[0].str);				DBPRT("found exec: %s", svc->cmd);			}    break;  case 38:#line 244 "btsrv-parser.y"    {				svc->name = strdup(yyvsp[0].str);				DBPRT("Found name: %s\n", svc->name);			}    break;  case 39:#line 249 "btsrv-parser.y"    {				svc->prov = strdup(yyvsp[0].str);			}    break;  case 40:#line 253 "btsrv-parser.y"    {				svc->desc = strdup(yyvsp[0].str);			}    break;  case 41:#line 257 "btsrv-parser.y"    {				str2cod_svc(yyvsp[0].str, &svc->cod);				DBPRT("cod: %#.6x", svc->cod);			}    break;  case 42:#line 262 "btsrv-parser.y"    {				str2sec_level(yyvsp[0].str, &svc->security);			}    break;  case 43:#line 266 "btsrv-parser.y"    {				svc->port = yyvsp[0].num;			}    break;  case 44:#line 271 "btsrv-parser.y"    {				DBPRT("Found active: %d\n", yyvsp[0].num);				svc->active = yyvsp[0].num;			}    break;    }/* Line 999 of yacc.c.  */#line 1384 "y.tab.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 yyerrlab1;/*----------------------------------------------------.| yyerrlab1 -- error raised explicitly by an action.  |`----------------------------------------------------*/yyerrlab1:  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 280 "btsrv-parser.y"void yyerror(char *s){	BTERROR("reading config file: %s at line %d", s, yylineno);}void myyyerror(char *format, ...){	int	n;	char	str[255];	va_list	ap;	va_start(ap, format);	n = vsnprintf(str, sizeof(str), format, ap);	va_end(ap);	yyerror(str);}	int btsrv_read_config(char *file, int *service_num, int *device_num){	int			err;	extern FILE		*yyin;		config_file = file;	yyin = fopen(config_file, "r");	if (!yyin) {		BTERROR("Unable to open config file %s", config_file);                return -1;	}	svcnum = 0;	devnum = 0;	err = yyparse();	/* parse config file */	*service_num = svcnum;	*device_num = devnum;	fclose(yyin);	yyin = NULL;	return err;}int btsrv_read_config_buf(char *config, int *service_num, int *device_num){	int			err;	extern FILE		*yyin;		config_file = "<STDIN>";	yyin = tmpfile();	if (!yyin) {		BTERROR("Unable to creat config file\n");                return -1;	}	err = fputs(config, yyin);	if (err < 0) {		BTERROR("fputs() error\n");		fclose(yyin);		yyin = NULL;	}	fseek(yyin, 0, SEEK_SET);	svcnum = 0;	devnum = 0;	err = yyparse();	/* parse config file */	*service_num = svcnum;	*device_num = devnum;	fclose(yyin);	yyin = NULL;	return err;}

⌨️ 快捷键说明

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