diff --git a/tools/ggDeco/ggDeco.ml b/tools/ggDeco/ggDeco.ml index 0e2caad2afb8ede5e024b689a462ec0b621c7579..893988da671d7a2ab29885db4e3fd8eaf8306384 100644 --- a/tools/ggDeco/ggDeco.ml +++ b/tools/ggDeco/ggDeco.ml @@ -29,7 +29,7 @@ let rec apply_pattern : (files_spec_t list -> int -> string) = let deco : (Topology.t -> files_spec_t list -> Topology.t) = fun g fl -> - List.iter (fun (i,j,file) -> Printf.eprintf "deco pattern = %i-%i:%s\n%!" i j file) fl; + List.iter (fun (i,j,file) -> Printf.eprintf "deco pattern: %i-%i:%s\n%!" i j file) fl; let newNodes = List.mapi (fun i n -> @@ -49,12 +49,12 @@ let to_dot_string : (t -> string -> string) = let attrs = (try [("diameter", Register.get_graph_attribute "diameter")] with _ ->[]) @ - [("min_deg", Register.get_graph_attribute "min_deg"); - ("mean_deg", Register.get_graph_attribute "mean_deg"); - ("max_deg", Register.get_graph_attribute "max_deg"); + [("min_deg", Register.get_graph_attribute "min_deg"); + ("mean_deg", Register.get_graph_attribute "mean_deg"); + ("max_deg", Register.get_graph_attribute "max_deg"); ("is_connected", Register.get_graph_attribute "is_connected"); - ("is_cyclic", Register.get_graph_attribute "is_cyclic"); - ("is_tree", Register.get_graph_attribute "is_tree"); + ("is_cyclic", Register.get_graph_attribute "is_cyclic"); + ("is_tree", Register.get_graph_attribute "is_tree"); ("links_number", Register.get_graph_attribute "links_number") ] in diff --git a/tools/ggDeco/ggDeco_Arg.ml b/tools/ggDeco/ggDeco_Arg.ml index 9c261c72256b49031753b054990f07698a7ecc39..aea4c600f2873b955ba77ffaaf5c23e535be8dbb 100644 --- a/tools/ggDeco/ggDeco_Arg.ml +++ b/tools/ggDeco/ggDeco_Arg.ml @@ -132,95 +132,86 @@ let (add_other : t -> string -> unit) = let current = ref 0;; -let parse_file_spec : (string list -> files_spec_t list) = - fun s -> - List.map - (fun file -> - try ( - Scanf.sscanf file "%[-0-9]:%s" - (fun range file -> - if range = "" then - raise (Invalid_file_spec - (file, "The first and last node's indexes are \ - missing")) - else - Scanf.sscanf range "%d%s" - (fun a s -> - if (a < 0) then - raise (Invalid_file_spec - (file,"The first node's index have to be positive or null")) else - if (s = "") then (a,a,file) else - if (s = "-") then (a,-1,file) else - Scanf.sscanf s "-%d" (fun b -> - if (b < a) then - raise - (Invalid_file_spec - (file, - "The last node's index have to be higher than the first node's index")) - else - (a,b,file) - ) - ) - ) - ) - with - | Scanf.Scan_failure _ -> - raise ( - Invalid_file_spec ( - file, - "The boundaries (first and last node's indexes) should be integers, but an non-numerical character has been found")) - ) s - -let rec pop l = (* last ? *) - match l with - | [] -> assert false - | [a] -> ([],a) - | b::tl -> - let (l,a) = pop tl in - (b::l,a) - +let parse_file_spec : (string -> files_spec_t) = + fun patt -> + try + Scanf.sscanf patt "%[-0-9]:%s" + (fun range file -> + if range = "" then + raise ( + Invalid_file_spec (patt, "The first and last node's indexes are missing")) + else + Scanf.sscanf range "%d%s" + (fun a s -> + if (a < 0) then + raise (Invalid_file_spec + (patt,"The first node's index have to be positive or null")) + else + if (s = "") then (a,a,file) else + if (s = "-") then (a,-1,file) else + Scanf.sscanf s "-%d" + (fun b -> + if (b < a) then + raise + (Invalid_file_spec + (patt, + "The last node's index have to be higher than the first node's index")) + else + (a,b,file) + ) + ) + ) + with + | Scanf.Scan_failure _ -> + raise ( + Invalid_file_spec ( + patt, + "The boundaries (first and last node's indexes) should be integers, but an non-numerical character has been found")) + let parse argv = ( - let save_current = !current in - let args = make_args () in - mkoptab argv args; - try ( - Arg.parse_argv ~current:current argv args._args (add_other args) - (usage_msg argv.(0)); - current := save_current; - - (* Same as List.rev, but also check if there's no option - (starting by '-') in these arguments *) - let others = - List.fold_left - (fun l o -> if String.get o 0 = '-' then unexpected o else o::l) - [] args._others - in - (match others with - | [] | [_] -> - (Printf.fprintf stderr "Error : you need 2 arguments to use %s\n" (argv.(0)); - flush stderr; - print_usage (argv.(0))) - | l -> ( - let (a,b) = pop l in - let a = try ( - parse_file_spec a - ) with Invalid_file_spec (fs,s) -> ( - Printf.fprintf stderr - "Error while parsing the file specification \"%s\" :\n" fs; - Printf.fprintf stderr "%s\n"s; - flush stderr; print_usage (argv.(0)) - ) in - args.files_spec <- a; exist_file b; args.dot_file <- b + let save_current = !current in + let args = make_args () in + mkoptab argv args; + try ( + Arg.parse_argv ~current:current argv args._args (add_other args) + (usage_msg argv.(0)); + current := save_current; + + (* Same as List.rev, but also check if there's no option + (starting by '-') in these arguments *) + let others = + List.fold_left + (fun l o -> if String.get o 0 = '-' then unexpected o else o::l) + [] args._others + in + (match others with + | [deco_patt;ifile] -> ( + let deco_patt_list = Str.split (Str.regexp "[ \t]+") deco_patt in + let fl = try List.map parse_file_spec (List.rev deco_patt_list) + with Invalid_file_spec (fs,s) -> ( + Printf.fprintf stderr + "Error while parsing the file specification \"%s\" :\n" fs; + Printf.fprintf stderr "%s\n"s; + flush stderr; print_usage (argv.(0)) + ) + in + args.files_spec <- fl; + exist_file ifile; + args.dot_file <- ifile ) - ); - args - ) - with - | Arg.Bad msg -> ( + | _ -> + (Printf.fprintf stderr "Error: you need 2 arguments to use %s\n" (argv.(0)); + flush stderr; + print_usage (argv.(0))) + ); + args + ) + with + | Arg.Bad msg -> ( Printf.fprintf stderr "*** Error when calling '%s': %s\n%s\n" (argv.(0)) (first_line msg) (usage_msg argv.(0)); exit 2 ) - | Arg.Help _ -> ( + | Arg.Help _ -> ( help args argv.(0) ) - ) +)