mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-29 19:17:28 +08:00
[ocaml] fix and update for latest ocaml
fix usage of Bytes and String drop support of ocaml < 4.02 we keep Compat for functions that need ocaml 4.03 until end of life of Ubuntu Xenial 16.04, drop support of previous releases enforce type safe_string option to prevent future errors replace Pervasives by Stdlib (depreciated in latest ocaml vesions) only use ocamlnet >= 4.0.4
This commit is contained in:
@@ -44,12 +44,12 @@ let run_and_log = fun log exit_cb com ->
|
||||
let channel_out_fd = Unix.descr_of_in_channel com_stdout in
|
||||
let channel_out = GMain.Io.channel_of_descr channel_out_fd in
|
||||
let cb = fun _ ->
|
||||
let buf = Compat.bytes_create buf_size in
|
||||
let buf = Bytes.create buf_size in
|
||||
(* loop until input returns zero *)
|
||||
let rec log_input = fun out ->
|
||||
let n = input out buf 0 buf_size in
|
||||
(* split on beginning of new line *)
|
||||
let s = Str.split (Str.regexp "^") (Compat.bytes_sub buf 0 n) in
|
||||
let s = Str.split (Str.regexp "^") (Bytes.to_string (Bytes.sub buf 0 n)) in
|
||||
List.iter (fun l -> log l) s;
|
||||
if n = buf_size then (log_input out) + n else n
|
||||
in
|
||||
@@ -61,18 +61,18 @@ let run_and_log = fun log exit_cb com ->
|
||||
pid, channel_out, com_stdout, io_watch_out
|
||||
|
||||
let strip_prefix = fun dir file subdir ->
|
||||
let n = Compat.bytes_length dir in
|
||||
if not (Compat.bytes_length file > n && Compat.bytes_sub file 0 n = dir) then begin
|
||||
let n = String.length dir in
|
||||
if not (String.length file > n && String.sub file 0 n = dir) then begin
|
||||
let home = Env.paparazzi_home in
|
||||
let nn = Compat.bytes_length home in
|
||||
if (Compat.bytes_length file > nn && Compat.bytes_sub file 0 nn = home) then begin
|
||||
".." // Compat.bytes_sub file (nn+1) (Compat.bytes_length file - nn -1)
|
||||
let nn = String.length home in
|
||||
if (String.length file > nn && String.sub file 0 nn = home) then begin
|
||||
".." // String.sub file (nn+1) (String.length file - nn -1)
|
||||
end else
|
||||
let msg = sprintf "Selected file '%s' should be in '%s'" file dir in
|
||||
GToolbox.message_box ~title:"Error" msg;
|
||||
raise Exit
|
||||
end else
|
||||
subdir // Compat.bytes_sub file (n+1) (Compat.bytes_length file - n - 1)
|
||||
subdir // String.sub file (n+1) (String.length file - n - 1)
|
||||
|
||||
|
||||
let choose_xml_file = fun ?(multiple = false) title subdir cb ->
|
||||
|
||||
@@ -90,7 +90,7 @@ let program_command = fun x ->
|
||||
if cmd.[0] = '/' then
|
||||
cmd
|
||||
else if cmd.[0] = '$' then
|
||||
Compat.bytes_sub cmd 1 ((Compat.bytes_length cmd) - 1)
|
||||
String.sub cmd 1 ((String.length cmd) - 1)
|
||||
else
|
||||
Env.paparazzi_src // cmd
|
||||
with Not_found ->
|
||||
@@ -122,7 +122,7 @@ let flash_modes =
|
||||
let options = List.map (fun o ->
|
||||
sprintf "%s=%s" (Xml.attrib o "name") (Xml.attrib o "value")
|
||||
) (List.filter (fun t -> Xml.tag t = "variable") (Xml.children m)) in
|
||||
let options = Compat.bytes_concat " " options in
|
||||
let options = String.concat " " options in
|
||||
(* add to hash tables *)
|
||||
Hashtbl.add modes mode options;
|
||||
List.iter (fun b ->
|
||||
@@ -161,37 +161,39 @@ let close_programs = fun gui ->
|
||||
let parse_process_args = fun (name, args) ->
|
||||
(* How to do it with a simple regexp split ??? *)
|
||||
(* Mark spaces into args *)
|
||||
let args = Bytes.of_string args in
|
||||
let marked_space = Char.chr 0 in
|
||||
let in_quotes = ref false in
|
||||
for i = 0 to Compat.bytes_length args - 1 do
|
||||
match args.[i] with
|
||||
' ' when !in_quotes -> Compat.bytes_set args i marked_space
|
||||
for i = 0 to Bytes.length args - 1 do
|
||||
match Bytes.get args i with
|
||||
' ' when !in_quotes -> Bytes.set args i marked_space
|
||||
| '"' -> in_quotes := not !in_quotes
|
||||
| _ -> ()
|
||||
done;
|
||||
(* Split *)
|
||||
let args = Str.split (Str.regexp "[ ]+") args in
|
||||
let args = Str.split (Str.regexp "[ ]+") (Bytes.to_string args) in
|
||||
let args = List.map Bytes.of_string args in
|
||||
(* Restore spaces and remove quotes *)
|
||||
let restore_spaces = fun s ->
|
||||
let n = Compat.bytes_length s in
|
||||
let n = Bytes.length s in
|
||||
for i = 0 to n - 1 do
|
||||
if s.[i] = marked_space then Compat.bytes_set s i ' '
|
||||
if Bytes.get s i = marked_space then Bytes.set s i ' '
|
||||
done;
|
||||
if n >= 2 && s.[0] = '"' then
|
||||
Compat.bytes_sub s 1 (n-2)
|
||||
if n >= 2 && Bytes.get s 0 = '"' then
|
||||
Bytes.sub s 1 (n-2)
|
||||
else
|
||||
s in
|
||||
let args = List.map restore_spaces args in
|
||||
(* Remove the first "arg" which is the command *)
|
||||
let args = List.tl args in
|
||||
(* Build the XML arg list *)
|
||||
let is_option = fun s -> Compat.bytes_length s > 0 && s.[0] = '-' in
|
||||
let is_option = fun s -> Bytes.length s > 0 && Bytes.get s 0 = '-' in
|
||||
let rec xml_args = function
|
||||
[] -> []
|
||||
| option::value::l when not (is_option value) ->
|
||||
Xml.Element("arg", ["flag",option; "constant", value],[])::xml_args l
|
||||
Xml.Element("arg", ["flag", Bytes.to_string option; "constant", Bytes.to_string value],[])::xml_args l
|
||||
| option::l ->
|
||||
Xml.Element("arg", ["flag",option],[])::xml_args l in
|
||||
Xml.Element("arg", ["flag", Bytes.to_string option],[])::xml_args l in
|
||||
Xml.Element("program", ["name", name], xml_args args)
|
||||
|
||||
let save_session = fun gui session_combo ->
|
||||
@@ -219,7 +221,7 @@ let save_session = fun gui session_combo ->
|
||||
name
|
||||
|
||||
let double_quote = fun s ->
|
||||
if Compat.bytes_contains s ' ' then
|
||||
if String.contains s ' ' then
|
||||
sprintf "\"%s\"" s
|
||||
else
|
||||
s
|
||||
@@ -291,7 +293,7 @@ let supervision = fun ?file gui log (ac_combo : Gtk_tools.combo) (target_combo :
|
||||
Gtk_tools.add_to_combo session_combo Gtk_tools.combo_separator;
|
||||
let strings = ref [] in
|
||||
Hashtbl.iter (fun name _session -> strings := name :: !strings) sessions;
|
||||
let ordered = List.sort Compat.bytes_compare !strings in
|
||||
let ordered = List.sort String.compare !strings in
|
||||
List.iter (fun name -> Gtk_tools.add_to_combo session_combo name) ordered
|
||||
in
|
||||
|
||||
|
||||
Reference in New Issue
Block a user