forked from Deducteam/lambdapi
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rodolphe Lepigre
committed
Feb 1, 2018
1 parent
b96efc4
commit ccebce2
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module M = Set.Make(String) | ||
|
||
let fold_lines : ('a -> string -> 'a) -> 'a -> string -> 'a = | ||
fun f acc fname -> | ||
let ic = open_in fname in | ||
let acc = ref acc in | ||
try | ||
while true do | ||
acc := f !acc (input_line ic) | ||
done; assert false | ||
with End_of_file -> close_in ic; !acc | ||
|
||
let is_mod_char : char -> bool = fun c -> | ||
match c with | ||
| 'a'..'z' | 'A'..'Z' | '0'..'9' | '_' | '-' | '.' -> true | ||
| _ -> false | ||
|
||
let rec handle_line : M.t -> string -> M.t = fun s l -> | ||
let len = String.length l in | ||
if len = 0 then s else | ||
let pos = ref 0 in | ||
while !pos < len && not (is_mod_char l.[!pos]) do incr pos done; | ||
let start = !pos in | ||
while !pos < len && is_mod_char l.[!pos] do incr pos done; | ||
let siz = !pos - start in | ||
let m = String.sub l start siz in | ||
let m = | ||
let len = String.length m in | ||
if len > 0 && m.[len-1] = '.' then String.sub m 0 (len - 1) else m | ||
in | ||
let get_module m = | ||
let i = try String.index m '.' with _ -> assert false in | ||
String.sub m 0 i | ||
in | ||
let s = | ||
if m <> "" && m <> "." && String.contains m '.' then | ||
M.add (get_module m) s | ||
else s | ||
in | ||
handle_line s (String.sub l !pos (len - !pos)) | ||
|
||
let _ = | ||
let work f n = | ||
let mods = M.remove n (fold_lines handle_line M.empty f) in | ||
M.iter (Printf.printf "#REQUIRE %s.\n%!") mods | ||
in | ||
match Sys.argv with | ||
| [| _ ; f ; n |] -> work f n | ||
| _ -> | ||
Printf.eprintf "Usage: %s file.dk modname\n%!" Sys.argv.(0) |