From a216a8adaaf99021ec2f9b6c3eb2c4074252bbb4 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Thu, 19 Nov 2009 17:01:53 +0000 Subject: [PATCH] generator: open Unix module by default. Add: open Unix at the top of the generator, which means that we don't need to prefix any 'Unix.foo' symbols (we can just use 'foo' instead). Unfortunately the Unix module shadows one symbol in Pervasives (the Pervasives module is opened by default in OCaml code). That symbol is 'stdout'. So we replace this with 'Pervasives.stdout' in two places. Still a net reduction in code size. --- src/generator.ml | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index 4bf5aec..a1d3549 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -35,6 +35,7 @@ #load "unix.cma";; #load "str.cma";; +open Unix open Printf type style = ret * args @@ -346,13 +347,13 @@ and cmd = string list (* Generate a random UUID (used in tests). *) let uuidgen () = - let chan = Unix.open_process_in "uuidgen" in + let chan = open_process_in "uuidgen" in let uuid = input_line chan in - (match Unix.close_process_in chan with - | Unix.WEXITED 0 -> () - | Unix.WEXITED _ -> + (match close_process_in chan with + | WEXITED 0 -> () + | WEXITED _ -> failwith "uuidgen: process exited with non-zero status" - | Unix.WSIGNALED _ | Unix.WSTOPPED _ -> + | WSIGNALED _ | WSTOPPED _ -> failwith "uuidgen: process signalled or stopped by signal" ); uuid @@ -4696,7 +4697,7 @@ let check_functions () = ) all_functions (* 'pr' prints to the current output file. *) -let chan = ref stdout +let chan = ref Pervasives.stdout let pr fs = ksprintf (output_string !chan) fs (* Generate a header block in a number of standard styles. *) @@ -8650,7 +8651,7 @@ and pod2text ~width name longdesc = fprintf chan "=head1 %s\n\n%s\n" name longdesc; close_out chan; let cmd = sprintf "pod2text -w %d %s" width (Filename.quote filename) in - let chan = Unix.open_process_in cmd in + let chan = open_process_in cmd in let lines = ref [] in let rec loop i = let line = input_line chan in @@ -8662,12 +8663,12 @@ and pod2text ~width name longdesc = loop (i+1) ) in let lines = try loop 1 with End_of_file -> List.rev !lines in - Unix.unlink filename; - (match Unix.close_process_in chan with - | Unix.WEXITED 0 -> () - | Unix.WEXITED i -> + unlink filename; + (match close_process_in chan with + | WEXITED 0 -> () + | WEXITED i -> failwithf "pod2text: process exited with non-zero status (%d)" i - | Unix.WSIGNALED i | Unix.WSTOPPED i -> + | WSIGNALED i | WSTOPPED i -> failwithf "pod2text: process signalled or stopped by signal %d" i ); Hashtbl.add pod2text_memo key lines; @@ -10161,33 +10162,33 @@ let output_to filename = chan := open_out filename_new; let close () = close_out !chan; - chan := stdout; + chan := Pervasives.stdout; (* Is the new file different from the current file? *) if Sys.file_exists filename && files_equal filename filename_new then - Unix.unlink filename_new (* same, so skip it *) + unlink filename_new (* same, so skip it *) else ( (* different, overwrite old one *) - (try Unix.chmod filename 0o644 with Unix.Unix_error _ -> ()); - Unix.rename filename_new filename; - Unix.chmod filename 0o444; + (try chmod filename 0o644 with Unix_error _ -> ()); + rename filename_new filename; + chmod filename 0o444; printf "written %s\n%!" filename; ) in close let perror msg = function - | Unix.Unix_error (err, _, _) -> - eprintf "%s: %s\n" msg (Unix.error_message err) + | Unix_error (err, _, _) -> + eprintf "%s: %s\n" msg (error_message err) | exn -> eprintf "%s: %s\n" msg (Printexc.to_string exn) (* Main program. *) let () = let lock_fd = - try Unix.openfile "HACKING" [Unix.O_RDWR] 0 + try openfile "HACKING" [O_RDWR] 0 with - | Unix.Unix_error (Unix.ENOENT, _, _) -> + | Unix_error (ENOENT, _, _) -> eprintf "\ You are probably running this from the wrong directory. Run it from the top source directory using the command @@ -10203,7 +10204,7 @@ Run it from the top source directory using the command * one to finish. Note the lock is released implicitly when the * program exits. *) - (try Unix.lockf lock_fd Unix.F_LOCK 1 + (try lockf lock_fd F_LOCK 1 with exn -> perror "lock: HACKING" exn; exit 1); -- 1.8.3.1