diff options
author | Pierre-Marie Pédrot <pierre-marie.pedrot@inria.fr> | 2016-07-18 02:24:42 +0200 |
---|---|---|
committer | Pierre-Marie Pédrot <pierre-marie.pedrot@inria.fr> | 2016-07-26 20:43:15 +0200 |
commit | e3faeb71580f85394042028499bbc9573efc23cb (patch) | |
tree | 266fcba2782bda74910aacb5714979bdc68a2bec /ide/ideutils.ml | |
parent | 1ca19082cf506c304b3c7945e72c0238f2aa9d1a (diff) |
Adding a flag in CoqIDE to configure UNIX/Windows line ending.
Fixes both bugs #4924 and #4437.
Diffstat (limited to 'ide/ideutils.ml')
-rw-r--r-- | ide/ideutils.ml | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/ide/ideutils.ml b/ide/ideutils.ml index f0698a54a..fe69be9e4 100644 --- a/ide/ideutils.ml +++ b/ide/ideutils.ml @@ -112,6 +112,24 @@ let try_convert s = "(* Fatal error: wrong encoding in input. \ Please choose a correct encoding in the preference panel.*)";; +let export file_name s = + let oc = open_out_bin file_name in + let ending = line_ending#get in + let is_windows = ref false in + for i = 0 to String.length s - 1 do + match s.[i] with + | '\r' -> is_windows := true + | '\n' -> + begin match ending with + | `DEFAULT -> + if !is_windows then (output_char oc '\r'; output_char oc '\n') + else output_char oc '\n' + | `WINDOWS -> output_char oc '\r'; output_char oc '\n' + | `UNIX -> output_char oc '\n' + end + | c -> output_char oc c + done; + close_out oc let try_export file_name s = let s = @@ -134,11 +152,7 @@ let try_export file_name s = Minilib.log ("Error ("^str^") in transcoding: falling back to UTF-8"); s in - try - let oc = open_out file_name in - output_string oc s; - close_out oc; - true + try export file_name s; true with e -> Minilib.log (Printexc.to_string e);false type timer = { run : ms:int -> callback:(unit->bool) -> unit; |