diff --git a/os_tools/linux/config/network_interface_file.anubis b/os_tools/linux/config/network_interface_file.anubis index 125aa2d..69b0538 100644 --- a/os_tools/linux/config/network_interface_file.anubis +++ b/os_tools/linux/config/network_interface_file.anubis @@ -1,21 +1,16 @@ /* * Created by PyramIDE. - * User: Alexis + * User: Alexis & Totoro * Date: 03/09/2012 * Time: 16:05 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ - read system/logger.anubis read system/string.anubis read tools/basis.anubis -read tools/kero_loggers.anubis read tools/streams.anubis -read calexium_lib/net_services_protocols/logger_service.anubis - -read kero_constants.anubis delete_entry find_entry @@ -64,20 +59,20 @@ define String _to_String ( List(Network_Parameter) interface_entries, - String so_far + String so_far //this is so far of the section, not the general file )= if interface_entries is { [] then so_far, [h . t] then - _to_String(t, so_far + to_String(h)) + _to_String(t, so_far + "\t"+to_String(h)+"\n") }. public define String to_String ( List(Network_entry) network_entries, - String so_far + String so_far )= if network_entries is { @@ -86,10 +81,10 @@ public define String if h is { blank then to_String(t, so_far+"\n"), - comment(comment) then to_String(t, so_far + comment+"\n"), - section(net_type, params) then to_String(t, so_far+"auto "+net_type.name+"\n")+ + comment(comment) then to_String(t, so_far + comment), + section(net_type, params) then to_String(t, so_far+"auto "+net_type.name+"\n"+ to_String(net_type)+"\n"+ - _to_String( params, so_far) + _to_String( params, "")) } }. @@ -100,6 +95,7 @@ define Maybe(Network_Parameter) String name, String left_line )= + //println(" Extract value for name ["+name+"] in ["+left_line+"]"); if find_char(left_line, '#', 0) is { failure then success(conf_nv(name, left_line)), @@ -110,8 +106,13 @@ define Maybe(Network_Parameter) success(value) then if sub_string(left_line, idx+1, (length(left_line) - (idx+1))) is { - failure then success(conf_nv(name, value)), - success(comment) then success(conf_nvc(name, value, comment)) + failure then + //println("conf_nv found name="+name+" value="+value); + success(conf_nv(name, value)), + + success(comment) then + //println("conf_nvc found name="+name+" value="+value+" comment="+comment); + success(conf_nvc(name, value, comment)) } } }. @@ -125,6 +126,7 @@ define Maybe(Network_Parameter) { [] then failure, [ name . t] then + //println("Get network parameter for ["+name+"]"); if nth((Int)0, name) is { failure then failure, @@ -145,17 +147,19 @@ define Maybe(Network_type) if split_by_token(line, ' ') is { [ ] then failure, - [h . t] then - if h = "iface" then + [type . t] then + if type = "iface" then if t is { - [] then println("WARNING unamed iface section ["+name+"]");failure, + [] then + //println("WARNING unamed iface section ["+name+"]"); + failure, [h . t] then //check if auto name is equal to iface name if h = name then if get_network_parameter(t) is { - failure then failure, + failure then failure, success(net_param) then success(iface(name, net_param)) } else @@ -170,16 +174,30 @@ define List(Network_Parameter) Stream s, List(Network_Parameter) so_far )= - if read_line(s) is - { + if read_line(s) is + { failure then reverse(so_far), success(line) then - if get_network_parameter(split_by_token(line, ' ')) is - { - failure then reverse(so_far), - success(param) then parse_section_body(s,[param . so_far]) - } - }. + if nth((Int)0, line) is + { + failure then reverse(so_far), + success(c) then + if c = ' ' | c='\t' then + //it seem to be a a real section body entry we try it + //println("parse section line ["+trim(line)+"]"); + if get_network_parameter(split_by_token(trim(line), ' ')) is + { + failure then reverse(so_far), + success(param) then parse_section_body(s,[param . so_far]) + } + else + // itsn't part of section body, so we stop here and unput the line read + //and return the found Network_Parameter + //println("Not body part ["+trim(line)+"]"); + unput_line(s, line); + reverse(so_far) + } + }. define Network_entry parse_section @@ -194,17 +212,24 @@ define Network_entry if h = "auto" then if t is { - [] then println("WARNING unamed section ["+h+"]");blank, + [] then + //println("WARNING unamed section ["+h+"]"); + blank, [ name . t ] then + //println("auto found with name ["+name+"]"); //read the second line of the section where the type is located i.e. iface if read_line(s) is { failure then blank, success(type_line) then - if get_type(type_line, name) is + //println("get type line for "+name+"["+trim(type_line)+"]"); + if get_type(trim(type_line), name) is { - failure then blank, + failure then + //println("type not found for "+name); + blank, success(type_entry) then + //println("type found, parse for section"); section(type_entry, parse_section_body(s,[])) } } @@ -228,7 +253,7 @@ define Network_entry if c = '#' then comment(line) else - parse_section(s, line) + parse_section(s, trim(line)) }. define List(Network_entry) @@ -240,7 +265,9 @@ define List(Network_entry) if read_line(s) is { failure then reverse(so_far), - success(line) then println(line);read_interface_entries(s, [read_interface_entry(s, trim(line)) . so_far]) + success(line) then + //println("["+line+"]"); + read_interface_entries(s, [read_interface_entry(s, line) . so_far]) }. public define List(Network_entry) @@ -255,34 +282,34 @@ public define List(Network_entry) read_interface_entries(make_stream(f), []) }. -public define String - dump_interface_file - = - to_String(read_interface(etc_directory+"/network/interfaces"),""). - public define Maybe(One) write_interface ( - String interface_file + String file_name, + List(Network_entry) entries )= - if (Maybe(RWStream))file(etc_directory+"/network/interfaces_bis", new) is + if (Maybe(RWStream))file(file_name, new) is { failure then failure, - success(f) then success(forget(reliable_write(f, to_byte_array(dump_interface_file)))) + success(f) then success(forget(reliable_write(f, to_byte_array(to_String(entries, ""))))) }. - - + /** here tool for testing + * anbexec parse_interface + * will produce a dump of given_file into file named as original with ".dump" as an extension + */ + global define One - test_file - ( - List(String) args - )= - if write_interface(dump_interface_file) is - { - failure then unique, - success(_) then unique - } + parse_interface + ( + List(String) args + )= + if args is + { + [] then print("usage : parse_interface "), + [ file_name . t ] then + forget(write_interface(file_name+".dump",read_interface(file_name))) + } . -- libgit2 0.21.4