/src/tools/configuration/liberty_etc.e
Specman e | 265 lines | 224 code | 26 blank | 15 comment | 12 complexity | 3886285ae456f4e886f238b7495f0fce MD5 | raw file
1-- This file is part of Liberty Eiffel. 2-- 3-- Liberty Eiffel is free software: you can redistribute it and/or modify 4-- it under the terms of the GNU General Public License as published by 5-- the Free Software Foundation, version 3 of the License. 6-- 7-- Liberty Eiffel is distributed in the hope that it will be useful, 8-- but WITHOUT ANY WARRANTY; without even the implied warranty of 9-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10-- GNU General Public License for more details. 11-- 12-- You should have received a copy of the GNU General Public License 13-- along with Liberty Eiffel. If not, see <http://www.gnu.org/licenses/>. 14-- 15expanded class LIBERTY_ETC 16 17insert 18 LIBERTY_ERROR_LEVELS 19 LOGGING 20 21create {ANY} 22 make 23 24feature {ANY} 25 configure_for (a_program_cluster: ABSTRACT_STRING; a_visitor: like visitor) is 26 require 27 not is_configured 28 a_visitor /= Void 29 local 30 done: BOOLEAN; i: INTEGER 31 rc_file: STRING 32 do 33 visitor_memory.set_item(a_visitor) 34 from 35 i := roots.lower 36 until 37 done or else i > roots.upper 38 loop 39 rc_file := once "" 40 rc_file.copy(roots.item(i)) 41 env.substitute(rc_file) 42 dir.compute_file_path_with(rc_file, master_name) 43 if not dir.last_entry.is_empty then 44 rc_file.copy(dir.last_entry) 45 if files.file_exists(rc_file) and then files.is_file(rc_file) then 46 done := set_configuration_from(rc_file) 47 end 48 end 49 i := i + 1 50 end 51 configure_program_cluster(a_program_cluster) 52 visitor.check_validity 53 ensure 54 is_configured 55 visitor = a_visitor 56 end 57 58 log_clusters is 59 do 60 clusters.do_all(agent show_cluster) 61 end 62 63 is_configured: BOOLEAN is 64 do 65 Result := visitor /= Void 66 end 67 68 clusters: MAP[LIBERTY_ETC_CLUSTER, FIXED_STRING] is 69 require 70 is_configured 71 do 72 Result := visitor.clusters 73 ensure 74 Result /= Void 75 end 76 77feature {LIBERTY_ETC_VISITOR} 78 configure_cluster_rc (a_cluster_rc: ABSTRACT_STRING) is 79 local 80 conf: STRING; evaled: BOOLEAN 81 do 82 parser_file.connect_to(a_cluster_rc) 83 if parser_file.is_connected then 84 conf := once "" 85 conf.clear_count 86 from 87 parser_file.read_line 88 until 89 parser_file.end_of_input 90 loop 91 conf.append(parser_file.last_string) 92 conf.extend('%N') 93 parser_file.read_line 94 end 95 conf.append(parser_file.last_string) 96 parser_file.disconnect 97 parser_buffer.initialize_with(conf) 98 99 grammar.reset 100 evaled := parser.eval(parser_buffer, grammar.table, once "Cluster_Definition") 101 if not evaled then 102 errors.add_position(errors.syntax_position(conf.upper, conf, a_cluster_rc.intern)) 103 errors.set(level_fatal_error, "Incomplete cluster definition text") 104 errors.emit 105 check 106 dead: False 107 end 108 end 109 if parser.error /= Void then 110 errors.emit_syntax_error(parser.error, conf, a_cluster_rc.intern) 111 die_with_code(1) 112 else 113 grammar.root_node.accept(visitor) 114 end 115 end 116 end 117 118 visitor: LIBERTY_ETC_VISITOR is 119 do 120 Result := visitor_memory.item 121 end 122 123feature {} 124 visitor_memory: REFERENCE[LIBERTY_ETC_VISITOR] is 125 once 126 create Result 127 end 128 129 show_cluster (a_cluster: LIBERTY_ETC_CLUSTER) is 130 do 131 if log.is_trace then 132 log.trace.put_line(a_cluster.out) 133 end 134 end 135 136 set_configuration_from (file: STRING): BOOLEAN is 137 -- True if the configuration file was successfully read 138 local 139 conf: STRING; evaled: BOOLEAN 140 do 141 parser_file.connect_to(file) 142 if parser_file.is_connected then 143 conf := once "" 144 conf.clear_count 145 from 146 parser_file.read_line 147 until 148 parser_file.end_of_input 149 loop 150 conf.append(parser_file.last_string) 151 conf.extend('%N') 152 parser_file.read_line 153 end 154 conf.append(parser_file.last_string) 155 parser_file.disconnect 156 parser_buffer.initialize_with(conf) 157 158 grammar.reset 159 evaled := parser.eval(parser_buffer, grammar.table, once "Master") 160 if not evaled then 161 errors.add_position(errors.syntax_position(conf.upper, conf, file.intern)) 162 errors.set(level_fatal_error, "Incomplete master definition text") 163 errors.emit 164 check 165 dead: False 166 end 167 end 168 if parser.error /= Void then 169 errors.emit_syntax_error(parser.error, conf, file.intern) 170 die_with_code(1) 171 else 172 grammar.root_node.accept(visitor) 173 Result := True 174 end 175 end 176 end 177 178 configure_program_cluster (a_program_cluster: ABSTRACT_STRING) is 179 do 180 dir.compute_short_name_of(a_program_cluster) 181 inspect 182 dir.last_entry 183 when "cluster.rc" then 184 configure_cluster_rc(a_program_cluster) 185 when "loadpath.se" then 186 configure_program_loadpath(a_program_cluster) 187 else 188 std_error.put_line("Unknown program cluster format: " + a_program_cluster + " (" + dir.last_entry + ")") 189 breakpoint 190 die_with_code(1) 191 end 192 end 193 194 configure_program_loadpath (a_program_loadpath: ABSTRACT_STRING) is 195 local 196 conf: STRING; evaled: BOOLEAN 197 do 198 conf := once "" 199 conf.copy(once "cluster PROGRAM_LOADPATH version %"0%" locations %"") 200 conf.append(a_program_loadpath) 201 conf.append(once "%" end") 202 parser_buffer.initialize_with(conf) 203 204 grammar.reset 205 evaled := parser.eval(parser_buffer, grammar.table, once "Cluster_Definition") 206 if not evaled then 207 errors.add_position(errors.syntax_position(conf.upper, conf, "Generated cluster definition".intern)) 208 errors.set(level_system_error, "Incomplete generated cluster definition text!!") 209 errors.emit 210 check 211 dead: False 212 end 213 end 214 if parser.error /= Void then 215 errors.emit_syntax_error(parser.error, conf, "Generated cluster definition".intern) 216 die_with_code(1) 217 else 218 grammar.root_node.accept(visitor) 219 end 220 end 221 222 master_name: STRING is 223 do 224 Result := once "" 225 Result.make_from_string(visitor.tool_name) 226 Result.append(once ".rc") 227 end 228 229feature {} 230 make is 231 do 232 roots := {FAST_ARRAY[STRING] << "${HOME}/.liberty", "/etc/liberty" >> } 233 end 234 235 grammar: LIBERTY_ETC_GRAMMAR is 236 once 237 create Result.make(create {LIBERTY_ETC_FACTORY}.make) 238 end 239 240 roots: TRAVERSABLE[STRING] 241 242 parser_file: TEXT_FILE_READ is 243 once 244 create Result.make 245 end 246 247 parser_buffer: MINI_PARSER_BUFFER is 248 once 249 create Result 250 end 251 252 parser: DESCENDING_PARSER is 253 once 254 create Result.make 255 end 256 257 errors: LIBERTY_ERRORS 258 env: LIBERTY_ENVIRONMENT 259 dir: BASIC_DIRECTORY 260 files: FILE_TOOLS 261 262invariant 263 not roots.is_empty 264 265end -- class LIBERTY_ETC