/[svn]/driver/run.ml
ViewVC logotype

Contents of /driver/run.ml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 302 - (show annotations)
Tue Jul 10 17:23:34 2007 UTC (5 years, 10 months ago) by abate
File size: 1746 byte(s)
[r2003-05-09 10:09:30 by cvscast] Empty log message

Original author: cvscast
Date: 2003-05-09 10:09:31+00:00
1 let () = State.close ();;
2
3 let dump = ref None
4 let src = ref []
5
6 let specs =
7 [ "-dump", Arg.String (fun s -> dump := Some s),
8 " specify filename for persistency";
9 "-quiet", Arg.Set Cduce.quiet,
10 "suppress normal output (typing, results)"
11 ]
12
13 let () =
14 Arg.parse specs (fun s -> src := s :: !src)
15 "cduce [options] [script]\n\nOptions:"
16
17 let ppf =
18 if !Cduce.quiet then Format.formatter_of_buffer (Buffer.create 1023)
19 else Format.std_formatter
20 let ppf_err = Format.err_formatter
21
22 let do_file s =
23 let (src, chan) =
24 if s = "" then (`Stream, stdin) else (`File s, open_in s) in
25 Location.push_source src;
26 let input = Stream.of_channel chan in
27 if Stream.peek input = Some '#' then
28 (
29 let rec count n =
30 match Stream.next input with
31 | '\n' -> n
32 | _ -> count (n + 1) in
33 Wlexer.set_delta_loc (count 1)
34 );
35 let ok = Cduce.run ppf ppf_err input in
36 if s <> "" then close_in chan;
37 if not ok then (Format.fprintf ppf_err "@."; exit 1)
38
39
40
41 let main () =
42 (match !dump with
43 | Some f ->
44 (try
45 Format.fprintf ppf "Restoring state: ";
46 let chan = open_in_bin f in
47 let s = Marshal.from_channel chan in
48 close_in chan;
49 State.set s;
50 Format.fprintf ppf "done ...@."
51 with Sys_error _ ->
52 Format.fprintf ppf "failed ...@.")
53 | None -> ());
54 (match !src with
55 | [] ->
56 Format.fprintf ppf "No script specified; using stdin ...@.";
57 do_file ""
58 | l -> List.iter do_file l);
59 (match !dump with
60 | Some f ->
61 Format.fprintf ppf "Saving state ...@\n";
62 let s = State.get () in
63 let chan = open_out_bin f in
64 Marshal.to_channel chan s [ Marshal.Closures ];
65 close_out chan
66 | None -> ())
67
68
69
70 let () = main (); Types.print_stat ppf_err

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5