From 67c66121f54708021f795f97109532dcb0747f70 Mon Sep 17 00:00:00 2001 From: Jonah Beckford <9566106-jonahbeckford@users.noreply.gitlab.com> Date: Fri, 8 Nov 2024 22:48:31 -0800 Subject: [PATCH] Add -b output binary option --- Changes.md | 2 ++ src/cppo_main.ml | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Changes.md b/Changes.md index f19742a..adf172d 100644 --- a/Changes.md +++ b/Changes.md @@ -1,5 +1,7 @@ ## v1.7.1 (2024-??-??) - [bug] Fix `cppo -version`, which used to print a blank line (#92). +- [+ui] Added the `-b` output binary option so that Windows does + not add CRLF endings. ## v1.7.0 (2024-08-22) - [+ui] Multi-line macros, without line terminators `\`, diff --git a/src/cppo_main.ml b/src/cppo_main.ml index 98e9efb..2189469 100644 --- a/src/cppo_main.ml +++ b/src/cppo_main.ml @@ -78,6 +78,7 @@ let main () = let preserve_quotations = ref false in let show_exact_locations = ref false in let show_no_locations = ref false in + let output_binary = ref false in let options = [ "-D", Arg.String (fun s -> header := ("#define " ^ s ^ "\n") :: !header), "DEF @@ -133,6 +134,10 @@ let main () = Do not output any line directive other than those found in the input (overrides -s)."; + "-b", Arg.Set output_binary, + " + Write output without CRLF normalization on Windows."; + "-version", Arg.Unit (fun () -> print_endline Cppo_version.cppo_version; exit 0), @@ -215,7 +220,10 @@ Options:" Sys.argv.(0) in print_string (Buffer.contents buf); flush stdout | Some file -> - let oc = open_out file in + let oc = + if !output_binary then open_out_bin file + else open_out file + in output_string oc (Buffer.contents buf); close_out oc