Commit 8bd26094 authored by Robert Ricci's avatar Robert Ricci

Instead of skipping headers in a .sub file, read them in and give them

to the caller.
parent da811203
......@@ -58,7 +58,7 @@ let do_nothing () : unit =
raise (Failure "do_nothing called")
;;
let graph = match !graphfile with
let (graph,_) = match !graphfile with
Some(x) -> Graph.read_subgraph_file x
(* | None -> raise (Failure "No graph file given");; *)
| None -> Graph.read_subgraph_file "-"
......
......@@ -153,16 +153,20 @@ let read_graph_file (filename : string) : ('a,'b) t =
make_graph_from_edges edges
;;
let rec eat_shit channel =
let rec parse_header channel : (string * int) list =
let line = input_line channel in
let firsttwo = Str.first_chars line 2 in
if firsttwo = "%%" then () else eat_shit channel
if firsttwo = "%%" then [] else
let parts = Str.split (Str.regexp " +") line in
match parts with
key :: value :: [] -> (key,int_of_string value) :: parse_header channel
| _ -> raise (Failure "Bad header line")
;;
(* Read in one of Jon's graph files *)
let read_subgraph_file (filename : string) : ('a,'b) t =
let read_subgraph_file (filename : string) : (('a,'b) t * (string * int) list) =
let channel = if filename = "-" then stdin else open_in filename in
eat_shit channel;
let headers = parse_header channel in
let rec get_nodes () : int list list =
try
let line = input_line channel in
......@@ -253,7 +257,7 @@ let read_subgraph_file (filename : string) : ('a,'b) t =
in node.incident_edges <- node.incident_edges + 1) yss);
set_edge_count xs in
set_edge_count edges;
g
(g, headers)
;;
(* More operations will be added... *)
......@@ -80,7 +80,7 @@ print_endline "Showing graph";
if Array.length Sys.argv < 2 then raise NeedArg;;
print_endline "Showing graph";
(* let g = Graph.read_graph_file Sys.argv.(1) in *)
let g = Graph.read_subgraph_file Sys.argv.(1) in
let (g,_) = Graph.read_subgraph_file Sys.argv.(1) in
print_endline "Showing graph";
let mapfile = if Array.length Sys.argv > 2 then Some Sys.argv.(2) else None in
print_endline "Showing graph";
......
......@@ -37,7 +37,7 @@ let anonfunc (str : string) : unit =
Arg.parse argspec anonfunc "TODO: Write a usage message";;
let g = match !graphfile with
Some(s) -> Graph.read_subgraph_file s
Some(s) -> (let (g,_) = Graph.read_subgraph_file s in g)
| None -> raise NeedArg
in
let hops = Dijkstra.get_all_first_hops g in
......
......@@ -28,7 +28,7 @@ let (combine_blobs : ('a,'b) combine_blobs_f) = Dre.merge_res;;
(* TODO - Better command-line parsing *)
(* let graph = Graph.read_graph_file Sys.argv.(1);; *)
let graph = Graph.read_subgraph_file Sys.argv.(1);;
let (graph, headers) = Graph.read_subgraph_file Sys.argv.(1);;
debug ("Graph size " ^ (string_of_int (List.length graph.Graph.nodes)));;
debug ("Edges " ^ (string_of_int (List.length graph.Graph.edges)));;
let naming = Naming.read_naming_file Sys.argv.(2);;
......
......@@ -31,7 +31,7 @@ Arg.parse argspec (fun x -> edgefile := Some x) "";;
let edgestr = match !edgefile with
None -> raise (Failure "Need an arg")
| Some(x) -> x in
let g = Graph.read_subgraph_file edgestr in
let (g,_) = Graph.read_subgraph_file edgestr in
let hops = compute_all_hops g in
match !src with
Some(x) -> begin
......
......@@ -5,7 +5,7 @@
(* Read in the graph file *)
exception NotATree;;
let g = Graph.read_subgraph_file Sys.argv.(1);;
let (g,_) = Graph.read_subgraph_file Sys.argv.(1);;
let n_nodes = Graph.count_nodes g;;
(*
let heights = Array.make n_nodes ~-1;;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment