Skip to content

Commit

Permalink
Add -b output binary option
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahbeckford committed Nov 9, 2024
1 parent 40600e3 commit 67c6612
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -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 `\`,
Expand Down
10 changes: 9 additions & 1 deletion src/cppo_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 67c6612

Please sign in to comment.