| 44 |
let ppf_err = Format.err_formatter |
let ppf_err = Format.err_formatter |
| 45 |
|
|
| 46 |
|
|
|
let first_line = ref true |
|
| 47 |
let bol = ref true |
let bol = ref true |
| 48 |
|
|
| 49 |
let read i = |
let outflush s = |
| 50 |
let first = !first_line in |
output_string stdout s; |
| 51 |
if first |
flush stdout |
|
then output_string stdout "* " |
|
|
else if !bol then output_string stdout "> "; |
|
|
flush stdout; |
|
|
first_line := false; |
|
|
let c = input_char stdin in |
|
|
bol := (not first) && c = '\n'; |
|
|
Some c |
|
|
|
|
| 52 |
|
|
| 53 |
let toploop () = |
let toploop () = |
| 54 |
|
Cduce.toplevel := true; |
| 55 |
|
let tcio = |
| 56 |
|
try Unix.tcgetattr Unix.stdin |
| 57 |
|
with Unix.Unix_error (_,_,_) -> |
| 58 |
|
(* The input is not a terminal *) |
| 59 |
Location.push_source `Stream; |
Location.push_source `Stream; |
| 60 |
|
let input = Stream.of_channel stdin in |
| 61 |
|
let ok = Cduce.script ppf ppf_err input in |
| 62 |
|
if not ok then exit 1 else exit 0 |
| 63 |
|
in |
| 64 |
|
let restore () = |
| 65 |
|
Unix.tcsetattr Unix.stdin Unix.TCSADRAIN tcio |
| 66 |
|
in |
| 67 |
|
let quit () = |
| 68 |
|
outflush "\n"; |
| 69 |
|
restore (); |
| 70 |
|
exit 0 |
| 71 |
|
in |
| 72 |
|
Format.fprintf ppf " CDuce version %s\n@." Cduce_config.version; |
| 73 |
|
Unix.tcsetattr Unix.stdin Unix.TCSADRAIN |
| 74 |
|
{ tcio with Unix.c_vquit = '\004' }; |
| 75 |
|
Sys.set_signal Sys.sigquit (Sys.Signal_handle (fun _ -> quit ())); |
| 76 |
|
Sys.catch_break true; |
| 77 |
|
Cduce.toplevel := true; |
| 78 |
|
Location.push_source `Stream; |
| 79 |
|
let read i = |
| 80 |
|
if !bol then outflush "> "; |
| 81 |
|
try |
| 82 |
|
let c = input_char stdin in |
| 83 |
|
bol := c = '\n'; |
| 84 |
|
Some c |
| 85 |
|
with Sys.Break -> quit () |
| 86 |
|
in |
| 87 |
let input = Stream.from read in |
let input = Stream.from read in |
| 88 |
let rec loop () = |
let rec loop () = |
| 89 |
first_line := true; bol := false; |
outflush "# "; |
| 90 |
ignore (Cduce.toplevel ppf ppf_err input); |
bol := false; |
| 91 |
|
ignore (Cduce.topinput ppf ppf_err input); |
| 92 |
|
while (input_char stdin != '\n') do () done; |
| 93 |
loop () in |
loop () in |
| 94 |
try loop () |
(try loop () with End_of_file -> ()); |
| 95 |
with End_of_file -> () |
restore () |
| 96 |
|
|
| 97 |
let do_file s = |
let do_file s = |
| 98 |
let chan = open_in s in |
let chan = open_in s in |
| 131 |
Cduce.enter_global_value (ident (U.mk "argv")) l t |
Cduce.enter_global_value (ident (U.mk "argv")) l t |
| 132 |
); |
); |
| 133 |
(match !src with |
(match !src with |
| 134 |
| [] -> |
| [] -> toploop () |
|
Format.fprintf ppf |
|
|
" CDuce version %s\n@." |
|
|
Cduce_config.version; |
|
|
toploop () |
|
| 135 |
| l -> List.iter do_file l); |
| l -> List.iter do_file l); |
| 136 |
(match !dump with |
(match !dump with |
| 137 |
| Some f -> |
| Some f -> |