📄 parse.c
字号:
#include "parse.h"#include <string.h>int parse_conf(char *IP,char *NetMask,char *Gateway,int *Port,int *Current_factor_PhaseA,int *Voltage_factor_PhaseA,int *Current_factor_PhaseB,int *Voltage_factor_PhaseB,int *Current_factor_PhaseC,int *Voltage_factor_PhaseC){ char *config_file="power.conf"; struct token t[10]; int cur_token=0,line; enum STRING{NONE,SIP,SNETMASK,SGETWAY,SPORT,SCURRENTFACTORPHASEA,SVOLTAGEFACTORPHASEA,SCURRENTFACTORPHASEB,SVOLTAGEFACTORPHASEB,SCURRENTFACTORPHASEC,SVOLTAGEFACTORPHASEC}; enum STRING type_string=NONE; if(IP==NULL || NetMask==NULL || Gateway==NULL || Port==NULL || Current_factor_PhaseA==NULL || Voltage_factor_PhaseA==NULL|| Current_factor_PhaseB==NULL || Voltage_factor_PhaseB==NULL|| Current_factor_PhaseC==NULL || Voltage_factor_PhaseC==NULL) return -1; if(start_conf_read(config_file)<0){ printf("cannot open power.conf file\n"); return -1; } while(get_next_token(&t[cur_token],&line)>0){ switch(t[cur_token].type){ case TOKEN_NUM: if(type_string==SPORT){ *Port=t[cur_token].v.num; }else if(type_string==SCURRENTFACTORPHASEA){ *Current_factor_PhaseA=t[cur_token].v.num; }else if(type_string==SVOLTAGEFACTORPHASEA){ *Voltage_factor_PhaseA=t[cur_token].v.num; }else if(type_string==SCURRENTFACTORPHASEB){ *Current_factor_PhaseB=t[cur_token].v.num; }else if(type_string==SVOLTAGEFACTORPHASEB){ *Voltage_factor_PhaseB=t[cur_token].v.num; }else if(type_string==SCURRENTFACTORPHASEC){ *Current_factor_PhaseC=t[cur_token].v.num; }else if(type_string==SVOLTAGEFACTORPHASEC){ *Voltage_factor_PhaseC=t[cur_token].v.num; } type_string=NONE; break; case TOKEN_STR: if(!strcmp(t[cur_token].v.str,"IP")){ type_string=SIP; }else if(!strcmp(t[cur_token].v.str,"NetMask")){ type_string=SNETMASK; }else if(!strcmp(t[cur_token].v.str,"Gateway")){ type_string=SGETWAY; }else if(!strcmp(t[cur_token].v.str,"Port")){ type_string=SPORT; }else if(!strcmp(t[cur_token].v.str,"Current_Factor_PhaseA")){ type_string=SCURRENTFACTORPHASEA; }else if(!strcmp(t[cur_token].v.str,"Voltage_Factor_PhaseA")){ type_string=SVOLTAGEFACTORPHASEA; }else if(!strcmp(t[cur_token].v.str,"Current_Factor_PhaseB")){ type_string=SCURRENTFACTORPHASEB; }else if(!strcmp(t[cur_token].v.str,"Voltage_Factor_PhaseB")){ type_string=SVOLTAGEFACTORPHASEB; }else if(!strcmp(t[cur_token].v.str,"Current_Factor_PhaseC")){ type_string=SCURRENTFACTORPHASEC; }else if(!strcmp(t[cur_token].v.str,"Voltage_Factor_PhaseC")){ type_string=SVOLTAGEFACTORPHASEC; }else if(type_string==SIP){ strcpy(IP,t[cur_token].v.str); type_string=NONE; }else if(type_string==SNETMASK){ strcpy(NetMask,t[cur_token].v.str); type_string=NONE; }else if(type_string==SGETWAY){ strcpy(Gateway,t[cur_token].v.str); type_string=NONE; } break; case ';': break; default: break; } } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -