open Support.Pervasive open Support.Error let searchpath = ref [""] let swig_dir = ref "/Users/jsiek/SWIG-1.3.24" let argDefs = [ "-I", Arg.String (fun f -> searchpath := f::!searchpath), "Append a directory to the search path"; "--swig", Arg.String (fun f -> swig_dir := f), "Set the SWIG directory"] let parseArgs () = let inFile = ref (None : string option) in Arg.parse argDefs (fun s -> match !inFile with Some(_) -> err "You must specify exactly one input file" | None -> inFile := Some(s)) ""; match !inFile with None -> err "You must specify an input file" | Some(s) -> s let openfile infile = let rec trynext l = match l with [] -> err ("Could not find input file: " ^ infile) | (d::rest) -> let name = if d = "" then infile else (d ^ "/" ^ infile) in try (open_in name, name) with Sys_error m -> trynext rest in trynext !searchpath let findfile infile = let rec trynext l = match l with [] -> err ("Could not find input file: " ^ infile) | (d::rest) -> let name = if d = "" then infile else (d ^ "/" ^ infile) in try let f = open_in name in (close_in f; name) with Sys_error m -> trynext rest in trynext !searchpath let openfile_write infile = let rec trynext l = match l with [] -> err ("Could not find input file: " ^ infile) | (d::rest) -> let name = if d = "" then infile else (d ^ "/" ^ infile) in try open_out name with Sys_error m -> trynext rest in trynext !searchpath let parseFile inFile = let (pi,filename) = openfile inFile in let lexbuf = Lexer.create filename pi in let result = try Parser.main Lexer.main lexbuf with Parsing.Parse_error -> error (Lexer.info lexbuf) "Parse error" in Parsing.clear_parser(); close_in pi; result