Fixed newline characters throughout the code
[com/gs-lite.git] / src / ftacmp / nic_def.cc
1 /* ------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3    Licensed under the Apache License, Version 2.0 (the "License");
4    you may not use this file except in compliance with the License.
5    You may obtain a copy of the License at
6
7      http://www.apache.org/licenses/LICENSE-2.0
8
9    Unless required by applicable law or agreed to in writing, software
10    distributed under the License is distributed on an "AS IS" BASIS,
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12    See the License for the specific language governing permissions and
13    limitations under the License.
14  ------------------------------------------- */
15 #include<stdio.h>
16 #include<stdlib.h>
17
18 #include"nic_def.h"
19
20 extern int NicParserparse(void);
21 extern FILE *NicParserin;
22 extern int NicParserdebug;
23
24
25 nic_property *nicp;
26 std::vector<std::string> nic_attr_vec;
27 std::vector<std::string> nic_val_vec;
28 std::string nic_a, nic_v;
29
30 using namespace std;
31
32 nic_property *load_nic_property(std::string dir, std::string name){
33
34         string fname;
35         if(dir != "")
36                 fname = dir + "/nic_property_"+name+".def";
37         else
38                 fname = "nic_property_"+name+".def";
39
40         FILE *nicf = fopen(fname.c_str(),"r");
41         if(! nicf){
42                 fprintf(stderr,"ERROR, can't open nic property file %s\n",fname.c_str());
43                 return NULL;
44         }
45
46 NicParserdebug = 0;
47         nicp = new nic_property();
48         NicParser_setfileinput(nicf);
49         if(NicParserparse()){
50                 fprintf(stderr,"could not parse nic property file %s\n",fname.c_str());
51                 return NULL;
52         }
53         
54         return nicp;
55 }
56
57 bool nic_property::legal_type(string t){
58 int i;
59         for(i=0;i<typea.size();++i){
60                 if(t==typea[i])
61                         return true;
62         }
63         return false;
64 }
65
66
67 bool nic_property::legal_unary_op(string t){
68 int i;
69         for(i=0;i<opua.size();++i){
70                 if(t==opua[i])
71                         return true;
72         }
73         return false;
74 }
75
76
77
78 bool nic_property::legal_binary_op(string t){
79 int i;
80         for(i=0;i<opba.size();++i){
81                 if(t==opba[i])
82                         return true;
83         }
84         return false;
85 }
86
87
88 bool nic_property::illegal_field(string t){
89 int i;
90         for(i=0;i<fieldsa.size();++i){
91                 if(t==fieldsa[i])
92                         return true;
93         }
94         return false;
95 }
96
97
98
99 bool nic_property::option_exists(string t){
100 int i;
101         for(i=0;i<opta.size();++i){
102                 if(t==opta[i])
103                         return true;
104         }
105         return false;
106 }
107
108
109 string nic_property::option_value(string t){
110 int i;
111         for(i=0;i<opta.size();++i){
112                 if(t==opta[i])
113                         return optv[i];
114         }
115         return "";
116 }
117
118
119
120
121
122
123
124
125
126
127
128