diff --git a/sw/ground_segment/cockpit/gcs.ml b/sw/ground_segment/cockpit/gcs.ml index 08bc053387a..14b1fb1925e 100644 --- a/sw/ground_segment/cockpit/gcs.ml +++ b/sw/ground_segment/cockpit/gcs.ml @@ -26,6 +26,7 @@ module G = MapCanvas open Printf open Latlong + let locale = GtkMain.Main.init ~setlocale:false () let soi = string_of_int @@ -377,7 +378,7 @@ let options = "-auto_hide_fp", Arg.Unit (fun () -> Live.auto_hide_fp true; hide_fp := true), "Automatically hide flight plans of unselected aircraft"; "-timestamp", Arg.Set timestamp, "Bind on timestampped telemetry messages"; "-ac_ids", Arg.String (fun s -> Live.filter_ac_ids s), "comma separated list of AC IDs to show in GCS"; - "-no_confirm_kill", Arg.Unit (fun () -> confirm_kill := false), "Disable kill confirmation from strip button"; + "-no_confirm_kill", Arg.Unit (fun () -> confirm_kill := false), "Disable kill confirmation from strip button"; ] @@ -498,7 +499,7 @@ let resize = fun (widget:GObj.widget) orientation size -> let rec pack_widgets = fun orientation xml widgets packing -> let size = try Some (ExtXml.int_attrib xml "size") with _ -> None in - match String.lowercase (Xml.tag xml) with + match Compat.bytes_lowercase (Xml.tag xml) with "widget" -> let name = ExtXml.attrib xml "name" in let widget = @@ -525,7 +526,7 @@ and pack_list = fun resize orientation xmls widgets packing -> let rec find_widget_children = fun name xml -> let xmls = Xml.children xml in - match String.lowercase (Xml.tag xml) with + match Compat.bytes_lowercase (Xml.tag xml) with "widget" when ExtXml.attrib xml "name" = name -> xmls | "rows" | "columns" -> let rec loop = function @@ -539,7 +540,7 @@ let rec find_widget_children = fun name xml -> let rec replace_widget_children = fun name children xml -> let xmls = Xml.children xml - and tag = String.lowercase (Xml.tag xml) in + and tag = Compat.bytes_lowercase (Xml.tag xml) in match tag with "widget" -> Xml.Element("widget", @@ -561,7 +562,7 @@ let rec update_widget_size = fun orientation widgets xml -> if orientation = `HORIZONTAL then rect.Gtk.width else rect.Gtk.height in let xmls = Xml.children xml - and tag = String.lowercase (Xml.tag xml) in + and tag = Compat.bytes_lowercase (Xml.tag xml) in match tag with "widget" -> let name = ExtXml.attrib xml "name" in diff --git a/sw/ground_segment/cockpit/live.ml b/sw/ground_segment/cockpit/live.ml index d9130033dd6..ec4ddbd9d72 100644 --- a/sw/ground_segment/cockpit/live.ml +++ b/sw/ground_segment/cockpit/live.ml @@ -27,6 +27,7 @@ open Latlong module LL = Latlong open Printf + module Tele_Pprz = PprzLink.Messages(struct let name = "telemetry" end) module Ground_Pprz = PprzLink.Messages(struct let name = "ground" end) module Alert_Pprz = PprzLink.Messages(struct let name = "alert" end) @@ -167,7 +168,7 @@ let select_ac = fun acs_notebook ac_id -> if !active_ac <> "" then begin let ac' = find_ac !active_ac in ac'.strip#hide_buttons (); - ac'.notebook_label#set_width_chars (String.length ac'.notebook_label#text); + ac'.notebook_label#set_width_chars (Compat.bytes_length ac'.notebook_label#text); if !_auto_hide_fp then hide_fp ac' end; @@ -339,12 +340,12 @@ let mark = fun (geomap:G.widget) ac_id track plugin_frame -> let attributes_pretty_printer = fun attribs -> (* Remove the optional attributes *) let valid = fun a -> - let a = String.lowercase a in + let a = Compat.bytes_lowercase a in a <> "no" && a <> "strip_icon" && a <> "strip_button" && a <> "pre_call" && a <> "post_call" && a <> "key" && a <> "group" in let sprint_opt = fun b s -> - if String.length b > 0 then + if Compat.bytes_length b > 0 then sprintf " %s%s%s" s b s else "" @@ -631,7 +632,7 @@ let create_ac = fun ?(confirm_kill=true) alert (geomap:G.widget) (acs_notebook:G let settings_file = Http.file_of_url settings_url in let settings_xml = try - if String.compare "replay" settings_file <> 0 then + if Compat.bytes_compare "replay" settings_file <> 0 then ExtXml.parse_file ~noprovedtd:true settings_file else Xml.Element("empty", [], []) @@ -731,7 +732,7 @@ let create_ac = fun ?(confirm_kill=true) alert (geomap:G.widget) (acs_notebook:G and airspeed = sprintf "%.1f" ac.airspeed in let msg_items = ["WIND_INFO"; ac_id; "42"; wind_east; wind_north;airspeed] in - let value = String.concat ";" msg_items in + let value = Compat.bytes_concat ";" msg_items in let vs = ["ac_id", PprzLink.String ac_id; "message", PprzLink.String value] in Ground_Pprz.message_send "dl" "RAW_DATALINK" vs; with diff --git a/sw/ground_segment/cockpit/page_settings.ml b/sw/ground_segment/cockpit/page_settings.ml index 4d0c29f498c..8b6dbf3fbcb 100644 --- a/sw/ground_segment/cockpit/page_settings.ml +++ b/sw/ground_segment/cockpit/page_settings.ml @@ -24,6 +24,7 @@ open Printf + let (//) = Filename.concat @@ -90,7 +91,7 @@ let one_setting = fun (i:int) (do_change:int -> float -> unit) ac_id packing dl_ 1. in (* get number of digits after decimal dot *) - let digits = try String.length (ExtXml.attrib dl_setting "step") - String.index (ExtXml.attrib dl_setting "step") '.' - 1 with _ -> 0 in + let digits = try Compat.bytes_length (ExtXml.attrib dl_setting "step") - Compat.bytes_index (ExtXml.attrib dl_setting "step") '.' - 1 with _ -> 0 in let page_incr = step_incr and page_size = step_incr and show_auto = try ExtXml.attrib dl_setting "auto" = "true" with _ -> false in @@ -248,7 +249,7 @@ let one_setting = fun (i:int) (do_change:int -> float -> unit) ac_id packing dl_ (** Insert the related buttons in the strip and prepare the papgets DnD *) List.iter (fun x -> - match String.lowercase (Xml.tag x) with + match Compat.bytes_lowercase (Xml.tag x) with "strip_button" -> let label = ExtXml.attrib x "name" and sp_value = ExtXml.float_attrib x "value" @@ -292,7 +293,7 @@ let same_tag_for_all = function | x::xs -> let tag_first = Xml.tag x in List.iter (fun y -> assert(ExtXml.tag_is y tag_first)) xs; - String.lowercase tag_first + Compat.bytes_lowercase tag_first (** Build the tree of settings *) @@ -365,4 +366,3 @@ object (self) let settings = Array.fold_right (fun setting r -> try (setting#index, setting#xml, setting#last_known_value)::r with _ -> r) variables [] in SaveSettings.popup airframe_filename (Array.of_list settings) do_change end - diff --git a/sw/ground_segment/cockpit/saveSettings.ml b/sw/ground_segment/cockpit/saveSettings.ml index 6a7fbdb3c41..f0a8c6870ac 100644 --- a/sw/ground_segment/cockpit/saveSettings.ml +++ b/sw/ground_segment/cockpit/saveSettings.ml @@ -22,6 +22,7 @@ * *) + module U = Unix (** How to have them local ? *) @@ -198,7 +199,7 @@ let fill_data = fun (model:GTree.tree_store) settings airframe_xml -> (* Warning if needed *) if !not_in_airframe_file <> [] then begin - GToolbox.message_box ~title:"Warning" (Printf.sprintf "Some parameters not writable in the airframe file:\n\n%s" (String.concat "\n" !not_in_airframe_file)); + GToolbox.message_box ~title:"Warning" (Printf.sprintf "Some parameters not writable in the airframe file:\n\n%s" (Compat.bytes_concat "\n" !not_in_airframe_file)); end diff --git a/sw/ground_segment/cockpit/sectors.ml b/sw/ground_segment/cockpit/sectors.ml index 5c777126487..d1b032880e9 100644 --- a/sw/ground_segment/cockpit/sectors.ml +++ b/sw/ground_segment/cockpit/sectors.ml @@ -2,11 +2,12 @@ open Printf + let (//) = Filename.concat let rec display = fun (geomap:MapCanvas.widget) r -> - match String.lowercase (Xml.tag r) with + match Compat.bytes_lowercase (Xml.tag r) with "disc" -> let rad = float_of_string (ExtXml.attrib r "radius") and geo = Latlong.of_string (ExtXml.attrib (ExtXml.child r "point") "pos") in diff --git a/sw/ground_segment/cockpit/strip.ml b/sw/ground_segment/cockpit/strip.ml index f69ceaf1200..9fd3cbaedd0 100644 --- a/sw/ground_segment/cockpit/strip.ml +++ b/sw/ground_segment/cockpit/strip.ml @@ -23,6 +23,7 @@ *) open Printf + module LL=Latlong let (//) = Filename.concat @@ -327,7 +328,7 @@ object (* add a button widget in a vertical box if it belongs to a group (create new group if needed) *) method add_widget ?(group="") w = - let (vbox, pack) = match String.length group with + let (vbox, pack) = match Compat.bytes_length group with 0 -> (GPack.vbox ~show:true (), true) | _ -> try (Hashtbl.find button_tbl group, false) with Not_found -> diff --git a/sw/ground_segment/tmtc/broadcaster.ml b/sw/ground_segment/tmtc/broadcaster.ml index 5f81760dd61..91471055f0a 100644 --- a/sw/ground_segment/tmtc/broadcaster.ml +++ b/sw/ground_segment/tmtc/broadcaster.ml @@ -1,3 +1,4 @@ + open Printf let () = @@ -24,12 +25,12 @@ let () = (* Forward telemetry on Ivy *) let buffer_size = 256 in - let buffer = String.create buffer_size in + let buffer = Compat.bytes_create buffer_size in let get_tcp = fun _ -> begin try let n = input i buffer 0 buffer_size in - let data = String.sub buffer 0 n in + let data = Compat.bytes_sub buffer 0 n in Ivy.send (sprintf "%s %s" !ivy_to (Base64.encode_string data)) with diff --git a/sw/ground_segment/tmtc/fw_server.ml b/sw/ground_segment/tmtc/fw_server.ml index 7d9c051dfcc..0ed3b0465f0 100644 --- a/sw/ground_segment/tmtc/fw_server.ml +++ b/sw/ground_segment/tmtc/fw_server.ml @@ -22,6 +22,7 @@ * *) + open Printf open Server_globals open Aircraft @@ -57,10 +58,10 @@ let ivalue = fun x -> | _ -> failwith "Receive.log_and_parse: int expected" let format_string_field = fun s -> - let s = String.copy s in - for i = 0 to String.length s - 1 do + let s = Compat.bytes_copy s in + for i = 0 to Compat.bytes_length s - 1 do match s.[i] with - ' ' -> s.[i] <- '_' + ' ' -> Compat.bytes_set s i '_' | _ -> () done; s @@ -356,4 +357,3 @@ let log_and_parse = fun ac_name (a:Aircraft.aircraft) msg values -> a.datalink_status.downlink_rate <- ivalue "downlink_rate"; a.datalink_status.downlink_msgs <- ivalue "downlink_nb_msgs" | _ -> () - diff --git a/sw/ground_segment/tmtc/ivy2serial.ml b/sw/ground_segment/tmtc/ivy2serial.ml index 8f8386ec347..a01c4be83b2 100644 --- a/sw/ground_segment/tmtc/ivy2serial.ml +++ b/sw/ground_segment/tmtc/ivy2serial.ml @@ -38,6 +38,7 @@ module Tm_Pprz = PprzLink.Messages(struct let name = "telemetry" end) module Dl_Pprz = PprzLink.Messages(struct let name = "datalink" end) module PprzTransport = Protocol.Transport(Pprz_transport.Transport) + open Printf let () = @@ -80,12 +81,12 @@ let () = (* The function to be called when data is available *) let buffer_size = 256 in - let buffer = String.create buffer_size in + let buffer = Compat.bytes_create buffer_size in let get_datalink_message = fun _ -> begin try let n = input (Unix.in_channel_of_descr fd) buffer 0 buffer_size in - let b = String.sub buffer 0 n in + let b = Compat.bytes_sub buffer 0 n in Debug.trace 'x' (Debug.xprint b); let use_dl_message = fun payload -> diff --git a/sw/ground_segment/tmtc/ivy2udp.ml b/sw/ground_segment/tmtc/ivy2udp.ml index a2b7cba5a52..59118339339 100644 --- a/sw/ground_segment/tmtc/ivy2udp.ml +++ b/sw/ground_segment/tmtc/ivy2udp.ml @@ -28,6 +28,7 @@ module Tm_Pprz = PprzLink.Messages(struct let name = "telemetry" end) module Dl_Pprz = PprzLink.Messages(struct let name = "datalink" end) module PprzTransport = Protocol.Transport(Pprz_transport.Transport) + open Printf let () = @@ -61,7 +62,7 @@ let () = let (msg_id, vs) = Tm_Pprz.values_of_string args.(0) in let payload = Tm_Pprz.payload_of_values msg_id (int_of_string !id) vs in let buf = Pprz_transport.Transport.packet payload in - let n = String.length buf in + let n = Compat.bytes_length buf in let n' = Unix.sendto socket buf 0 n [] sockaddr in assert (n = n') with _ -> () in @@ -74,12 +75,12 @@ let () = Unix.bind socket sockaddr; let buffer_size = 256 in - let buffer = String.create buffer_size in + let buffer = Compat.bytes_create buffer_size in let get_datalink_message = fun _ -> begin try let n = input (Unix.in_channel_of_descr socket) buffer 0 buffer_size in - let b = String.sub buffer 0 n in + let b = Compat.bytes_sub buffer 0 n in Debug.trace 'x' (Debug.xprint b); let use_dl_message = fun payload -> diff --git a/sw/ground_segment/tmtc/ivy_tcp_aircraft.ml b/sw/ground_segment/tmtc/ivy_tcp_aircraft.ml index e02a961b020..3d5532df85b 100644 --- a/sw/ground_segment/tmtc/ivy_tcp_aircraft.ml +++ b/sw/ground_segment/tmtc/ivy_tcp_aircraft.ml @@ -3,6 +3,7 @@ module Tm_Pprz = PprzLink.Messages(struct let name = "telemetry" end) module Dl_Pprz = PprzLink.Messages(struct let name = "datalink" end) module PprzTransport = Protocol.Transport(Pprz_transport.Transport) + open Printf let () = let ivy_bus = ref Defivybus.default_ivy_bus in @@ -40,12 +41,12 @@ let () = (* Forward a datalink command on the bus *) let buffer_size = 256 in - let buffer = String.create buffer_size in + let buffer = Compat.bytes_create buffer_size in let get_datalink_message = fun _ -> begin try let n = input i buffer 0 buffer_size in - let b = String.sub buffer 0 n in + let b = Compat.bytes_sub buffer 0 n in Debug.trace 'x' (Debug.xprint b); let use_dl_message = fun payload -> diff --git a/sw/ground_segment/tmtc/ivy_tcp_controller.ml b/sw/ground_segment/tmtc/ivy_tcp_controller.ml index 92d5498cb8a..27173d97c20 100644 --- a/sw/ground_segment/tmtc/ivy_tcp_controller.ml +++ b/sw/ground_segment/tmtc/ivy_tcp_controller.ml @@ -1,3 +1,4 @@ + open Printf module Tm_Pprz = PprzLink.Messages(struct let name = "telemetry" end) @@ -28,12 +29,12 @@ let () = let (i, o) = Unix.open_connection sockaddr in let buffer_size = 256 in - let buffer = String.create buffer_size in + let buffer = Compat.bytes_create buffer_size in let get_message = fun _ -> begin try let n = input i buffer 0 buffer_size in - let b = String.sub buffer 0 n in + let b = Compat.bytes_sub buffer 0 n in Debug.trace 'x' (Debug.xprint b); let use_tele_message = fun payload -> diff --git a/sw/ground_segment/tmtc/kml.ml b/sw/ground_segment/tmtc/kml.ml index 841f1a3d1d1..e1ab28b6f03 100644 --- a/sw/ground_segment/tmtc/kml.ml +++ b/sw/ground_segment/tmtc/kml.ml @@ -22,6 +22,7 @@ * *) + open Aircraft open Latlong open Printf @@ -91,7 +92,7 @@ let circle = fun geo radius alt -> let wgs84 = of_utm WGS84 utm in coordinates wgs84 alt in let points = Array.init 360 degree_point in - String.concat " " (points.(359) :: Array.to_list points) + Compat.bytes_concat " " (points.(359) :: Array.to_list points) let ring_around_home = fun utm0 fp -> @@ -236,7 +237,7 @@ let update_horiz_mode = let alt = ac.desired_altitude in match ac.horiz_mode with Segment (p1, p2) -> - let coordinates = String.concat " " (List.map (fun p -> coordinates p alt) [p1; p2]) in + let coordinates = Compat.bytes_concat " " (List.map (fun p -> coordinates p alt) [p1; p2]) in let kml_changes = update_linear_ring url_flight_plan "horiz_mode" coordinates in print_xml ac.name "route_changes.kml" kml_changes | Circle (p, r) -> diff --git a/sw/ground_segment/tmtc/link.ml b/sw/ground_segment/tmtc/link.ml index e486890492f..6f1d9ec90f4 100644 --- a/sw/ground_segment/tmtc/link.ml +++ b/sw/ground_segment/tmtc/link.ml @@ -24,6 +24,7 @@ the Ivy software bus. *) + open Latlong open Printf @@ -194,7 +195,7 @@ let update_ms_since_last_msg = statuss let use_tele_message = fun ?udp_peername ?raw_data_size payload -> - let raw_data_size = match raw_data_size with None -> String.length (Protocol.string_of_payload payload) | Some d -> d in + let raw_data_size = match raw_data_size with None -> Compat.bytes_length (Protocol.string_of_payload payload) | Some d -> d in let buf = Protocol.string_of_payload payload in Debug.call 'l' (fun f -> fprintf f "pprz receiving: %s\n" (Debug.xprint buf)); try @@ -272,13 +273,13 @@ module XB = struct (** XBee module *) | Xbee_transport.RX_Packet_64 (addr64, rssi, options, data) -> Debug.trace 'x' (sprintf "getting XBee RX64: %Lx %d %d %s" addr64 rssi options (Debug.xprint data)); - use_tele_message ~raw_data_size:(String.length frame_data + oversize_packet) (Protocol.payload_of_string data) + use_tele_message ~raw_data_size:(Compat.bytes_length frame_data + oversize_packet) (Protocol.payload_of_string data) | Xbee_transport.RX868_Packet (addr64, options, data) -> Debug.trace 'x' (sprintf "getting XBee868 RX: %Lx %d %s" addr64 options (Debug.xprint data)); - use_tele_message ~raw_data_size:(String.length frame_data + oversize_packet) (Protocol.payload_of_string data) + use_tele_message ~raw_data_size:(Compat.bytes_length frame_data + oversize_packet) (Protocol.payload_of_string data) | Xbee_transport.RX_Packet_16 (addr16, rssi, options, data) -> Debug.trace 'x' (sprintf "getting XBee RX16: from=%x %d %d %s" addr16 rssi options (Debug.xprint data)); - use_tele_message ~raw_data_size:(String.length frame_data + oversize_packet) (Protocol.payload_of_string data) + use_tele_message ~raw_data_size:(Compat.bytes_length frame_data + oversize_packet) (Protocol.payload_of_string data) let send = fun ?ac_id device rf_data -> @@ -309,7 +310,7 @@ let local_broadcast_address = let udp_send = fun fd payload peername -> let buf = Pprz_transport.Transport.packet payload in - let len = String.length buf in + let len = Compat.bytes_length buf in let addr = if !udp_broadcast then (Unix.inet_addr_of_string !udp_broadcast_addr) else peername in Debug.call 'u' (fun f -> fprintf f "udp_send to %s port %i\n" (Unix.string_of_inet_addr addr) !udp_uplink_port); let sockaddr = Unix.ADDR_INET (addr, !udp_uplink_port) in @@ -364,7 +365,7 @@ let parser_of_device = fun device -> match device.transport with | Pprz -> let use = fun s -> - let raw_data_size = String.length (Protocol.string_of_payload s) + 4 (*stx,len,ck_a, ck_b*) in + let raw_data_size = Compat.bytes_length (Protocol.string_of_payload s) + 4 (*stx,len,ck_a, ck_b*) in let udp_peername = if !udp then Some !last_udp_peername @@ -471,7 +472,7 @@ let () = (** Listen on a udp port or a serial device or on pipe *) let on_serial_device = - String.length !port >= 4 && String.sub !port 0 4 = "/dev" in (* FIXME *) + Compat.bytes_length !port >= 4 && Compat.bytes_sub !port 0 4 = "/dev" in (* FIXME *) let fd = if !udp then begin diff --git a/sw/ground_segment/tmtc/modem.ml b/sw/ground_segment/tmtc/modem.ml index a1270baa10e..8686e802569 100644 --- a/sw/ground_segment/tmtc/modem.ml +++ b/sw/ground_segment/tmtc/modem.ml @@ -22,6 +22,7 @@ * *) + open Printf module Protocol = struct @@ -32,20 +33,20 @@ module Protocol = struct let stx = Char.chr 0x02 let etx = 0x03 let index_start = fun buf -> - String.index buf stx + Compat.bytes_index buf stx let payload_length = fun buf start -> Char.code buf.[start+1] - 1 let length = fun buf start -> - let len = String.length buf - start in + let len = Compat.bytes_length buf - start in if len >= 2 then Char.code buf.[start+1] + 3 else raise Serial.Not_enough let checksum = fun msg -> - let l = String.length msg in + let l = Compat.bytes_length msg in let ck_a = ref 0 in for i = 1 to l - 3 do ck_a := Char.code msg.[i] lxor !ck_a @@ -53,9 +54,9 @@ module Protocol = struct !ck_a = Char.code msg.[l-2] && Char.code msg.[l-1] = etx let payload = fun msg -> - let l = String.length msg in + let l = Compat.bytes_length msg in assert(l >= 4); - Serial.payload_of_string (String.sub msg 2 (l-4)) + Serial.payload_of_string (Compat.bytes_sub msg 2 (l-4)) let packet = fun _payload -> failwith "Modem.Protocol.packet not implemented" @@ -95,12 +96,12 @@ let valim = fun x -> float x *. 0.0162863 -. 1.17483 let parse_payload = fun payload -> let payload = Serial.string_of_payload payload in status.detected <- 1; - let len = String.length payload in + let len = Compat.bytes_length payload in status.nb_byte <- status.nb_byte + len; status.nb_msg <- status.nb_msg + 1; let id = Char.code payload.[0] in if id = msg_data then - Some (String.sub payload 1 (len-1)) + Some (Compat.bytes_sub payload 1 (len-1)) else begin begin match id with diff --git a/sw/ground_segment/tmtc/rotorcraft_server.ml b/sw/ground_segment/tmtc/rotorcraft_server.ml index 72a6b14df81..6266393dc5f 100644 --- a/sw/ground_segment/tmtc/rotorcraft_server.ml +++ b/sw/ground_segment/tmtc/rotorcraft_server.ml @@ -69,10 +69,10 @@ let foi32value = fun x -> | _ -> failwith "Receive.log_and_parse: int32 expected" let format_string_field = fun s -> - let s = String.copy s in - for i = 0 to String.length s - 1 do + let s = Compat.bytes_copy s in + for i = 0 to Compat.bytes_length s - 1 do match s.[i] with - ' ' -> s.[i] <- '_' + ' ' -> Compat.bytes_set s i '_' | _ -> () done; s diff --git a/sw/ground_segment/tmtc/server.ml b/sw/ground_segment/tmtc/server.ml index a9f738d3497..7c4ff523c71 100644 --- a/sw/ground_segment/tmtc/server.ml +++ b/sw/ground_segment/tmtc/server.ml @@ -27,6 +27,7 @@ let gps_mode_3D = 3 let no_md5_check = ref false let replay_old_log = ref false + open Printf open Latlong open Server_globals @@ -66,7 +67,7 @@ let wind_msg_period = 5000 (* ms *) let aircraft_alerts_period = 1000 (* ms *) let send_aircrafts_msg = fun _asker _values -> assert(_values = []); - let names = String.concat "," (Hashtbl.fold (fun k _v r -> k::r) aircrafts []) ^ "," in + let names = Compat.bytes_concat "," (Hashtbl.fold (fun k _v r -> k::r) aircrafts []) ^ "," in ["ac_list", PprzLink.String names] @@ -449,9 +450,9 @@ let send_aircraft_msg = fun ac -> (** Check if it is a replayed A/C (c.f. sw/logalizer/play.ml) *) let replayed = fun ac_id -> - let n = String.length ac_id in - if n > 6 && String.sub ac_id 0 6 = "replay" then - (true, String.sub ac_id 6 (n - 6), "/var/replay/", ExtXml.parse_file (Env.paparazzi_home // "var/replay/conf/conf.xml")) + let n = Compat.bytes_length ac_id in + if n > 6 && Compat.bytes_sub ac_id 0 6 = "replay" then + (true, Compat.bytes_sub ac_id 6 (n - 6), "/var/replay/", ExtXml.parse_file (Env.paparazzi_home // "var/replay/conf/conf.xml")) else (false, ac_id, "", conf_xml) @@ -479,7 +480,7 @@ let check_md5sum = fun ac_name alive_md5sum aircraft_conf_dir -> match alive_md5sum with PprzLink.Array array -> let n = Array.length array in - assert(n = String.length md5sum / 2); + assert(n = Compat.bytes_length md5sum / 2); for i = 0 to n - 1 do let x = int_of_string (sprintf "0x%c%c" md5sum.[2*i] md5sum.[2*i+1]) in assert (x = PprzLink.int_of_value array.(i)) @@ -490,7 +491,7 @@ let check_md5sum = fun ac_name alive_md5sum aircraft_conf_dir -> match alive_md5sum with PprzLink.Array array -> let n = Array.length array in - assert(n = String.length md5sum / 2); + assert(n = Compat.bytes_length md5sum / 2); for i = 0 to n - 1 do let x = 0 in assert (x = PprzLink.int_of_value array.(i)) @@ -788,8 +789,8 @@ let jump_block = fun logging _sender vs -> let raw_datalink = fun logging _sender vs -> let ac_id = PprzLink.string_assoc "ac_id" vs and m = PprzLink.string_assoc "message" vs in - for i = 0 to String.length m - 1 do - if m.[i] = ';' then m.[i] <- ' ' + for i = 0 to Compat.bytes_length m - 1 do + if m.[i] = ';' then Compat.bytes_set m i ' ' done; let msg_id, vs = Dl_Pprz.values_of_string m in let msg = Dl_Pprz.message_of_id msg_id in diff --git a/sw/ground_segment/tmtc/server_globals.ml b/sw/ground_segment/tmtc/server_globals.ml index 636a35da33e..97171cfea3c 100644 --- a/sw/ground_segment/tmtc/server_globals.ml +++ b/sw/ground_segment/tmtc/server_globals.ml @@ -1,5 +1,6 @@ exception Telemetry_error of string * string + (* options for serving xml config files and kml via http *) let hostname = ref "localhost" let port = ref 8889 @@ -18,4 +19,4 @@ let horiz_modes = [|"WAYPOINT";"ROUTE";"CIRCLE";"ATTITUDE";"MANUAL"|] let if_modes = [|"OFF";"DOWN";"UP"|] let string_of_values = fun values -> - String.concat " " (List.map (fun (_, v) -> PprzLink.string_of_value v) values) + Compat.bytes_concat " " (List.map (fun (_, v) -> PprzLink.string_of_value v) values) diff --git a/sw/lib/ocaml/Makefile b/sw/lib/ocaml/Makefile index b022fa8d568..719430a07d9 100644 --- a/sw/lib/ocaml/Makefile +++ b/sw/lib/ocaml/Makefile @@ -49,25 +49,39 @@ ifeq ($(LABLGTK2GNOMECANVAS),) LABLGTK2GNOMECANVAS = $(shell ocamlfind query -p-format lablgtk2.gnomecanvas 2>/dev/null) endif +CAMLP4_DEFS ?= NETCLIENT_VER := $(shell ocamlfind query -format '%v' netclient) NETCLIENT_MAJOR := $(shell echo $(NETCLIENT_VER) | cut -f1 -d.) +NETCLIENT_MINOR1 := $(shell echo $(NETCLIENT_VER) | cut -f2 -d.) +NETCLIENT_MINOR2 := $(shell echo $(NETCLIENT_VER) | cut -f3 -d.) ifeq ($(shell test $(NETCLIENT_MAJOR) -ge 4; echo $$?),0) -CAMLP4_DEFS = -DNETCLIENT_V_4 +CAMLP4_DEFS += -DNETCLIENT_V_4 +ifeq ($(shell test $(NETCLIENT_MINOR2) -ge 4; echo $$?),0) +CAMLP4_DEFS += -DNETCLIENT_V_404 +else ifeq ($(shell test $(NETCLIENT_MINOR1) -g 0; echo $$?),0) +CAMLP4_DEFS += -DNETCLIENT_V_404 +endif +endif +OCAMLC_VER := $(shell ocamlc -version) +OCAMLC_MAJOR := $(shell echo $(OCAMLC_VER) | cut -f1 -d.) +OCAMLC_MINOR := $(shell echo $(OCAMLC_VER) | cut -f2 -d.) +ifeq ($(shell test $(OCAMLC_MAJOR) -ge 4; echo $$?),0) +ifeq ($(shell test $(OCAMLC_MINOR) -ge 2; echo $$?),0) +# the Bytes module is available since OCaml 4.02.0 +CAMLP4_DEFS += -DHAS_BYTES_MODULE +endif endif -CAMLP4_DEFS ?= PP_OPTS = -pp "camlp4o pa_macro.cmo $(CAMLP4_DEFS)" # which source files to run through caml4p -PP_SRC = http.ml -PP_CMO = $(PP_SRC:.ml=.cmo) -PP_CMX = $(PP_SRC:.ml=.cmx) +PP_SRC = http.ml compat.ml INCLUDES= PKGCOMMON=pprzlink,xml-light,netclient,glibivy,lablgtk2 XINCLUDES= XPKGCOMMON=pprzlink,xml-light,glibivy,$(LABLGTK2GNOMECANVAS),lablgtk2.glade -SRC = fig.ml debug.ml base64.ml serial.ml ocaml_tools.ml expr_syntax.ml expr_parser.ml expr_lexer.ml extXml.ml env.ml xml2h.ml latlong.ml egm96.ml srtm.ml http.ml maps_support.ml gm.ml iGN.ml geometry_2d.ml cserial.o ubx.ml xmlCom.ml os_calls.ml editAirframe.ml defivybus.ml fp_proc.ml gen_common.ml +SRC = compat.ml fig.ml debug.ml base64.ml serial.ml ocaml_tools.ml expr_syntax.ml expr_parser.ml expr_lexer.ml extXml.ml env.ml xml2h.ml latlong.ml egm96.ml srtm.ml http.ml maps_support.ml gm.ml iGN.ml geometry_2d.ml cserial.o ubx.ml xmlCom.ml os_calls.ml editAirframe.ml defivybus.ml fp_proc.ml gen_common.ml CMO = $(SRC:.ml=.cmo) CMX = $(SRC:.ml=.cmx) @@ -131,22 +145,21 @@ ml_gtk_drag.o : ml_gtk_drag.c @echo OC $< $(Q)$(OCAMLC) $(INCLUDES) -package $(PKGCOMMON) -c -ccopt "$(GTKCFLAGS)" $< -# bit of a hack: only run some specifc files through caml4p -$(PP_CMO) : $(PP_SRC) - @echo OC $< - $(Q)$(OCAMLC) $(INCLUDES) $(PP_OPTS) -package $(PKGCOMMON) -c $< - -$(PP_CMX) : $(PP_SRC) - @echo OOC $< - $(Q)$(OCAMLOPT) $(INCLUDES) $(PP_OPTS) -package $(PKGCOMMON) -c $< - %.cmo : %.ml @echo OC $< - $(Q)$(OCAMLC) $(INCLUDES) -package $(PKGCOMMON) -c $< + @if test $(findstring $<,$(PP_SRC)); then \ + $(OCAMLC) $(INCLUDES) $(PP_OPTS) -package $(PKGCOMMON) -c $<; \ + else \ + $(OCAMLC) $(INCLUDES) -package $(PKGCOMMON) -c $<; \ + fi; %.cmx : %.ml @echo OOC $< - $(Q)$(OCAMLOPT) $(INCLUDES) -package $(PKGCOMMON) -c $< + @if test $(findstring $<,$(PP_SRC)); then \ + $(OCAMLOPT) $(INCLUDES) $(PP_OPTS) -package $(PKGCOMMON) -c $<; \ + else \ + $(OCAMLOPT) $(INCLUDES) -package $(PKGCOMMON) -c $<; \ + fi; %.cmi : %.mli @echo OC $< diff --git a/sw/lib/ocaml/base64.ml b/sw/lib/ocaml/base64.ml index 922ca789237..545ad7be820 100644 --- a/sw/lib/ocaml/base64.ml +++ b/sw/lib/ocaml/base64.ml @@ -28,6 +28,8 @@ (** Exception raised when there's an attempt to encode a chunk incorrectly *) exception Invalid_encode_chunk of int + + (** The character map of all base64 characters *) let char_map = [| @@ -48,27 +50,27 @@ let encode_chunk chars = let llength = List.length chars in if(llength = 0 || llength > 3) then raise (Invalid_encode_chunk(llength)); - let chunk = String.make 4 '=' in + let chunk = Compat.bytes_make 4 '=' in let a = List.hd chars in let tmpa = (((Char.code a) land 3) lsl 4) in - chunk.[0] <- char_map.( (Char.code a) lsr 2); + Compat.bytes_set chunk 0 char_map.( (Char.code a) lsr 2); (* Check for another character *) if (llength < 2) then ( - chunk.[1] <- char_map.(tmpa); + Compat.bytes_set chunk 1 char_map.(tmpa); chunk; ) else ( let b = List.nth chars 1 in let tmpb = ((Char.code b) lsr 4) in let tmpa2 = ((Char.code b) land 0x0f) lsl 2 in - chunk.[1] <- char_map.(tmpa lor tmpb); + Compat.bytes_set chunk 1 char_map.(tmpa lor tmpb); if (llength < 3) then ( - chunk.[2] <- char_map.(tmpa2); + Compat.bytes_set chunk 2 char_map.(tmpa2); chunk ) else ( let c = List.nth chars 2 in let tmpb2 = ((Char.code c) land 0xc0) lsr 6 in - chunk.[2] <- char_map.(tmpa2 lor tmpb2); - chunk.[3] <- char_map.((Char.code c) land 0x3f); + Compat.bytes_set chunk 2 char_map.(tmpa2 lor tmpb2); + Compat.bytes_set chunk 3 char_map.((Char.code c) land 0x3f); chunk ) ) @@ -200,7 +202,7 @@ let decode_string s = decode_to_string (Stream.of_string s) (** Simple test function. *) let test() = - let wordlist = ["A";"AB";"ABC";"Dustin";String.create 128] in + let wordlist = ["A";"AB";"ABC";"Dustin";Compat.bytes_create 128] in print_endline("String:"); List.iter (fun x -> print_endline(encode_string x)) wordlist; diff --git a/sw/lib/ocaml/compat.ml b/sw/lib/ocaml/compat.ml new file mode 100644 index 00000000000..0d888af199f --- /dev/null +++ b/sw/lib/ocaml/compat.ml @@ -0,0 +1,77 @@ +(* + * Abstract some String/Byte functions for compatibility between OCaml 3.x and 4.x + * + * Copyright (C) 2016 Felix Ruess + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + *) + + IFDEF HAS_BYTES_MODULE THEN + module BYTES = Bytes + ELSE + module BYTES = String + END + +let bytes_create = fun len -> + BYTES.create len + +let bytes_contains = fun c s -> + BYTES.contains c s + +let bytes_length = fun len -> + BYTES.length len + +let bytes_make = fun n c-> + BYTES.make n c + +let bytes_copy = fun s-> + BYTES.copy s + +let bytes_lowercase = fun s-> + BYTES.lowercase s + +let bytes_uppercase = fun s-> + BYTES.uppercase s + +let bytes_blit = fun src srcoff dst dstoff len-> + BYTES.blit src srcoff dst dstoff len + +let bytes_sub = fun s start len-> + BYTES.sub s start len + +let bytes_index = fun c s -> + BYTES.index c s + +let bytes_concat = fun sep sl-> + BYTES.concat sep sl + +let bytes_index_from = fun s i c -> + BYTES.index_from s i c + +let bytes_get = fun s n-> + BYTES.get s n + +let bytes_compare = fun s1 s2-> + BYTES.compare s1 s2 + +let bytes_set = fun s n c-> + BYTES.set s n c + +let bytes_iter = fun f s-> + BYTES.iter f s diff --git a/sw/lib/ocaml/compat.mli b/sw/lib/ocaml/compat.mli new file mode 100644 index 00000000000..df0f3ebdc25 --- /dev/null +++ b/sw/lib/ocaml/compat.mli @@ -0,0 +1,40 @@ +(* + * Abstract some String/Byte functions for compatibility between OCaml 3.x and 4.x + * + * Copyright (C) 2016 Felix Ruess + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + *) + +val bytes_create : int -> string +val bytes_contains : string -> char -> bool +val bytes_length : string -> int +val bytes_make : int -> char -> string +val bytes_copy : string -> string +val bytes_lowercase : string -> string +val bytes_uppercase : string -> string +val bytes_blit : string -> int -> string -> int -> int -> unit +val bytes_sub : string -> int -> int -> string +val bytes_index : string -> char -> int +val bytes_concat : string -> string list -> string +val bytes_index_from : string -> int -> char -> int +val bytes_get : string -> int -> char +val bytes_compare : string -> string -> int +val bytes_set : string -> int -> char -> unit +val bytes_iter : (char -> unit) -> string -> unit diff --git a/sw/lib/ocaml/debug.ml b/sw/lib/ocaml/debug.ml index 23674976632..0c688424ae8 100644 --- a/sw/lib/ocaml/debug.ml +++ b/sw/lib/ocaml/debug.ml @@ -22,11 +22,12 @@ * *) + let level = ref (try Sys.getenv "PPRZ_DEBUG" with Not_found -> "") let log = ref stderr let call lev f = assert( (* assert permet au compilo de tout virer avec l'option -noassert *) - if (String.contains !level '*' || String.contains !level lev) + if (Compat.bytes_contains !level '*' || Compat.bytes_contains !level lev) then begin f !log; flush !log @@ -36,11 +37,11 @@ let call lev f = let trace lev s = call lev (fun f -> Printf.fprintf f "%s\n" s) let xprint = fun s -> - let n = String.length s in - let a = String.make (3*n) ' ' in + let n = Compat.bytes_length s in + let a = Compat.bytes_make (3*n) ' ' in for i = 0 to n - 1 do let x = Printf.sprintf "%02x" (Char.code s.[i]) in - a.[3*i] <- x.[0]; - a.[3*i+1] <- x.[1] + Compat.bytes_set a (3*i) x.[0]; + Compat.bytes_set a (3*i+1) x.[1] done; a diff --git a/sw/lib/ocaml/defivybus.ml b/sw/lib/ocaml/defivybus.ml index b87b0a1e4d9..eabc6480198 100644 --- a/sw/lib/ocaml/defivybus.ml +++ b/sw/lib/ocaml/defivybus.ml @@ -21,7 +21,9 @@ * Boston, MA 02111-1307, USA. * *) -let default_ivy_bus = String.copy ( + + +let default_ivy_bus = Compat.bytes_copy ( try (Sys.getenv "IVY_BUS" ) with Not_found -> (if Os_calls.contains (Os_calls.os_name) "Darwin" then diff --git a/sw/lib/ocaml/egm96.ml b/sw/lib/ocaml/egm96.ml index 306ab6f345e..fafed11ffd0 100644 --- a/sw/lib/ocaml/egm96.ml +++ b/sw/lib/ocaml/egm96.ml @@ -24,6 +24,7 @@ open Latlong + let (//) = Filename.concat let ncols = 1440 @@ -33,7 +34,7 @@ let data = let path = [Env.paparazzi_home // "data" // "srtm"] in let f = Ocaml_tools.open_compress (Ocaml_tools.find_file path "WW15MGH.DAC") in let n = ncols * nrows * 2 in - let buf = String.create n in + let buf = Compat.bytes_create n in really_input f buf 0 n; buf) diff --git a/sw/lib/ocaml/env.ml b/sw/lib/ocaml/env.ml index abbd76caccf..bcd2f5bec4d 100644 --- a/sw/lib/ocaml/env.ml +++ b/sw/lib/ocaml/env.ml @@ -24,6 +24,7 @@ open Printf + let (//) = Filename.concat let space_regexp = Str.regexp "[ \t]+" let make_element = fun t a c -> Xml.Element (t,a,c) @@ -80,8 +81,8 @@ let filter_absolute_path = fun path -> (* filter settings and keep the ones without brackets *) let filter_settings = fun settings -> let sl = Str.split (Str.regexp "[ ]+") settings in - let sl = List.filter (fun s -> not (s.[0] = '[' && s.[String.length s - 1] = ']')) sl in - String.concat " " sl + let sl = List.filter (fun s -> not (s.[0] = '[' && s.[Compat.bytes_length s - 1] = ']')) sl in + Compat.bytes_concat " " sl (* filter on modules based on target *) let filter_modules_target = fun module_file -> @@ -170,7 +171,7 @@ let expand_ac_xml = fun ?(raise_exception = true) ac_conf -> let read_process command = let buffer_size = 2048 in let buffer = Buffer.create buffer_size in - let string = String.create buffer_size in + let string = Compat.bytes_create buffer_size in let in_channel = Unix.open_process_in command in let chars_read = ref 1 in while !chars_read <> 0 do @@ -196,5 +197,4 @@ let key_modifiers_of_string = fun key -> | "Meta" -> "" | x -> x ) key_split in - String.concat "" keys - + Compat.bytes_concat "" keys diff --git a/sw/lib/ocaml/expr_lexer.mll b/sw/lib/ocaml/expr_lexer.mll index eb50d083274..a0583142478 100644 --- a/sw/lib/ocaml/expr_lexer.mll +++ b/sw/lib/ocaml/expr_lexer.mll @@ -1,6 +1,6 @@ -(* - * Lexical tokens à la C - * +(* + * Lexical tokens � la C + * * Copyright (C) 2003-2010 Antoine Drouin, Pascal Brisset, ENAC * * This file is part of paparazzi. @@ -22,6 +22,7 @@ *) { open Expr_parser + } rule token = parse [' ' '\t' '\n'] { token lexbuf} @@ -29,7 +30,7 @@ rule token = parse | ['0'-'9']+ { INT (int_of_string (Lexing.lexeme lexbuf)) } | ['0'-'9']+'.'['0'-'9']* { FLOAT (float_of_string (Lexing.lexeme lexbuf)) } | '$'?['a'-'z' '_' 'A'-'Z'] (['a'-'z' 'A'-'Z' '_' '0'-'9']*) { IDENT (Lexing.lexeme lexbuf) } - | '\''[^'\'']+'\'' { let s = Lexing.lexeme lexbuf in IDENT (String.sub s 1 (String.length s - 2)) } + | '\''[^'\'']+'\'' { let s = Lexing.lexeme lexbuf in IDENT (Compat.bytes_sub s 1 (Compat.bytes_length s - 2)) } | ',' { COMMA } | '.' { DOT } | ';' { SEMICOLON } @@ -38,7 +39,7 @@ rule token = parse | ')' { RP } | '{' { LC } | '}' { RC } - | '[' { LB } + | '[' { LB } | ']' { RB } | "->" { DEREF } | "==" { EQ } diff --git a/sw/lib/ocaml/expr_syntax.ml b/sw/lib/ocaml/expr_syntax.ml index f600a9cb2d1..e8bbffad557 100644 --- a/sw/lib/ocaml/expr_syntax.ml +++ b/sw/lib/ocaml/expr_syntax.ml @@ -1,5 +1,5 @@ (* - * Syntax of expressions à la C + * Syntax of expressions � la C * * Copyright (C) 2003-2010 Antoine Drouin, Pascal Brisset, ENAC * @@ -24,6 +24,7 @@ open Printf + type ident = string type operator = string @@ -45,7 +46,7 @@ let sprint = fun ?call_assoc expr -> | Some (n, l) -> Some n, l in let rec eval = function - | Ident i when i.[0] = '$' -> sprintf "%s" (c_var_of_ident (String.sub i 1 (String.length i - 1))) + | Ident i when i.[0] = '$' -> sprintf "%s" (c_var_of_ident (Compat.bytes_sub i 1 (Compat.bytes_length i - 1))) | Ident i -> sprintf "%s" i | Int i -> sprintf "%d" i | Float i -> sprintf "%f" i @@ -59,7 +60,7 @@ let sprint = fun ?call_assoc expr -> sprintf "%d" index | Call (i, es) -> let ses = List.map eval es in - sprintf "%s(%s)" i (String.concat "," ses) + sprintf "%s(%s)" i (Compat.bytes_concat "," ses) | Index (i,e) -> sprintf "%s[%s]" i (eval e) | Field (i,f) -> sprintf "%s.%s" i f | Deref (e,f) -> sprintf "(%s)->%s" (eval e) f diff --git a/sw/lib/ocaml/extXml.ml b/sw/lib/ocaml/extXml.ml index 10d674359c3..25f7bb05e30 100644 --- a/sw/lib/ocaml/extXml.ml +++ b/sw/lib/ocaml/extXml.ml @@ -24,6 +24,7 @@ open Printf + exception Error of string let sep = Str.regexp "\\." @@ -74,7 +75,7 @@ let attrib_option = fun xml attr -> try Some (Xml.attrib xml attr) with Xml.No_attribute _ -> None -let tag_is = fun x v -> String.lowercase (Xml.tag x) = String.lowercase v +let tag_is = fun x v -> Compat.bytes_lowercase (Xml.tag x) = Compat.bytes_lowercase v let attrib_or_default = fun x a default -> try Xml.attrib x a @@ -88,7 +89,7 @@ let buffer_attr = fun indent tab (n,v) -> Buffer.add_char tmp ' '; Buffer.add_string tmp n; Buffer.add_string tmp "=\""; - let l = String.length v in + let l = Compat.bytes_length v in for p = 0 to l-1 do match v.[p] with | '\\' -> Buffer.add_string tmp "\\\\" @@ -147,7 +148,7 @@ let my_to_string_fmt = fun tab_attribs x -> let to_string_fmt = fun ?(tab_attribs = false) xml -> - let l = String.lowercase in + let l = Compat.bytes_lowercase in let rec lower = function | Xml.PCData _ as x -> x | Xml.Element (t, ats, cs) -> @@ -158,7 +159,7 @@ let to_string_fmt = fun ?(tab_attribs = false) xml -> let subst_attrib = fun attrib value xml -> - let u = String.uppercase in + let u = Compat.bytes_uppercase in let uattrib = u attrib in match xml with | Xml.Element (tag, attrs, children) -> diff --git a/sw/lib/ocaml/fig.ml b/sw/lib/ocaml/fig.ml index 36d60f562c4..cfb1cd3d688 100644 --- a/sw/lib/ocaml/fig.ml +++ b/sw/lib/ocaml/fig.ml @@ -24,6 +24,7 @@ open Printf + let version = "3.2" type units = int @@ -466,7 +467,7 @@ let font_flags = fun rigid special font hidden -> bit hidden 3 let code_string = fun f s -> - for i = 0 to String.length s - 1 do + for i = 0 to Compat.bytes_length s - 1 do if Char.code s.[i] > 0o177 then fprintf f "\\%3o" (Char.code s.[i]) else @@ -499,8 +500,8 @@ let rec read_comments = fun s -> bscanf s " %0c" (fun c -> if c = '#' then bscanf s " %s@\n" (fun l -> - let n = String.length l in - String.sub l 2 (n-2) :: read_comments s) + let n = Compat.bytes_length l in + Compat.bytes_sub l 2 (n-2) :: read_comments s) else []) @@ -621,9 +622,9 @@ let read_text = fun s -> bscanf s " %d %d %d %d %d %d %f %d %f %f" (fun st c depth _ps ft fs angle ff h l -> let p = read_point s in bscanf s "%c%s@\n" (fun _space text -> - let n = String.length text in - assert (String.sub text (n-4) 4 = "\\001"); - let text = String.sub text 0 (n - 4) in + let n = Compat.bytes_length text in + assert (Compat.bytes_sub text (n-4) 4 = "\\001"); + let text = Compat.bytes_sub text 0 (n - 4) in Text (justification_of_int st, c, depth, font_of_int (bit2 ff) ft, fs, angle, ff, h, l, p,text))) @@ -648,7 +649,7 @@ let read = fun file -> let s = Scanning.from_file file in bscanf s "#FIG %s@\n%s %s@\n %s %s %f %s %d" (fun v o j u p m multi t -> - if String.sub v 0 3 <> "3.2" then + if Compat.bytes_sub v 0 3 <> "3.2" then failwith ("Unknown FIG format version: "^v); let comments = read_comments s in diff --git a/sw/lib/ocaml/gen_common.ml b/sw/lib/ocaml/gen_common.ml index 44cfba23787..87e87cc8d7b 100644 --- a/sw/lib/ocaml/gen_common.ml +++ b/sw/lib/ocaml/gen_common.ml @@ -24,6 +24,7 @@ open Printf + (** simple boolean expressions *) type bool_expr = | Var of string @@ -91,8 +92,8 @@ let targets_of_field = let pipe = Str.regexp "|" in fun field default -> let f = ExtXml.attrib_or_default field "target" default in - if String.length f > 0 && String.get f 0 = '!' then - Not (expr_of_targets (fun x y -> Or(x,y)) (Str.split pipe (String.sub f 1 ((String.length f) - 1)))) + if Compat.bytes_length f > 0 && Compat.bytes_get f 0 = '!' then + Not (expr_of_targets (fun x y -> Or(x,y)) (Str.split pipe (Compat.bytes_sub f 1 ((Compat.bytes_length f) - 1)))) else expr_of_targets (fun x y -> Or(x,y)) (Str.split pipe f) @@ -114,7 +115,7 @@ let get_autopilot_of_airframe = fun xml -> * Returns the boolean expression of targets of a module *) let get_targets_of_module = fun xml -> Xml.fold (fun a x -> - match String.lowercase (Xml.tag x) with + match Compat.bytes_lowercase (Xml.tag x) with | "makefile" when a = Var "" -> targets_of_field x Env.default_module_targets | "makefile" -> Or (a, targets_of_field x Env.default_module_targets) | _ -> a @@ -344,4 +345,3 @@ let is_element_unselected = fun ?(verbose=false) target modules name -> unselected | _ -> false with _ -> false - diff --git a/sw/lib/ocaml/gm.ml b/sw/lib/ocaml/gm.ml index ae4f7993bce..1425a8fda69 100644 --- a/sw/lib/ocaml/gm.ml +++ b/sw/lib/ocaml/gm.ml @@ -27,6 +27,7 @@ let (//) = Filename.concat open Latlong open Printf + let tile_size = 256, 256 let zoom_max = 22 let zoom_min = 18 @@ -131,7 +132,7 @@ let tile_of_key = fun keyholeStr -> and lat = ref (-1.) and latLonSize = ref 2. in - for i = 1 to String.length keyholeStr - 1 do + for i = 1 to Compat.bytes_length keyholeStr - 1 do latLonSize /.= 2.; match keyholeStr.[i] with @@ -148,14 +149,14 @@ let tile_of_key = fun keyholeStr -> let is_prefix = fun a b -> - String.length b >= String.length a && - a = String.sub b 0 (String.length a) + Compat.bytes_length b >= Compat.bytes_length a && + a = Compat.bytes_sub b 0 (Compat.bytes_length a) (** Get the tile or one which contains it from the cache *) let get_from_cache = fun dir f -> let files = Sys.readdir dir in (* sort files to have the longest names first *) - Array.sort (fun a b -> String.length b - String.length a) files; + Array.sort (fun a b -> Compat.bytes_length b - Compat.bytes_length a) files; let rec loop = fun i -> if i < Array.length files then let fi = files.(i) in @@ -172,11 +173,11 @@ let get_from_cache = fun dir f -> (** Get the tile or one which contains it from the a hash table *) let get_from_hashtbl = fun tbl key -> - let l = String.length key in + let l = Compat.bytes_length key in let rec loop = fun i -> if i = 0 then raise Not_found; try - let subkey = String.sub key 0 i in + let subkey = Compat.bytes_sub key 0 i in let file = Hashtbl.find tbl subkey in (tile_of_key subkey, file) with _ -> loop (i-1) @@ -188,7 +189,7 @@ let get_from_hashtbl = fun tbl key -> let xyz_of_qsrt = fun s -> let x = ref 0 and y = ref 0 - and n = String.length s in + and n = Compat.bytes_length s in for i = 1 to n - 1 do (* Skip the first t *) x := !x * 2; y := !y * 2; @@ -202,17 +203,17 @@ let xyz_of_qsrt = fun s -> (!x, !y, n-1) let ms_key = fun key -> - let n = String.length key in + let n = Compat.bytes_length key in if n = 1 then invalid_arg "Gm.ms_key"; - let ms_key = String.create (n-1) in + let ms_key = Compat.bytes_create (n-1) in for i = 1 to n - 1 do - ms_key.[i-1] <- - match key.[i] with + Compat.bytes_set ms_key (i-1) + (match key.[i] with 'q' -> '0' | 'r' -> '1' | 's' -> '3' | 't' -> '2' - | _ -> invalid_arg "Gm.ms_key" + | _ -> invalid_arg "Gm.ms_key") done; (ms_key, ms_key.[n-2]) @@ -257,7 +258,7 @@ let set_policy = fun p -> let get_policy = fun () -> !policy -let remove_last_char = fun s -> String.sub s 0 (String.length s - 1) +let remove_last_char = fun s -> Compat.bytes_sub s 0 (Compat.bytes_length s - 1) type hashtbl_cache = (string, string) Hashtbl.t @@ -277,7 +278,7 @@ let get_image = fun ?tbl key -> let cache_dir = get_cache_dir !maps_source in mkdir cache_dir; let rec get_from_http = fun k -> - if String.length k >= 1 then + if Compat.bytes_length k >= 1 then let url = url_of_tile_key !maps_source k in let jpg_file = cache_dir // (k ^ ".jpg") in try @@ -301,7 +302,7 @@ let get_image = fun ?tbl key -> | Some ht -> get_from_hashtbl ht key in (* if not exact match from cache, try http if CacheOrHttp policy *) - if !policy = CacheOrHttp && (String.length t.key < String.length key) then + if !policy = CacheOrHttp && (Compat.bytes_length t.key < Compat.bytes_length key) then try get_from_http key with _ -> (t, f) else (t, f) with diff --git a/sw/lib/ocaml/gtk_tools.ml b/sw/lib/ocaml/gtk_tools.ml index 146c90f74e5..f39654c53f3 100644 --- a/sw/lib/ocaml/gtk_tools.ml +++ b/sw/lib/ocaml/gtk_tools.ml @@ -25,6 +25,7 @@ (** GTK utilities *) + class pixmap_in_drawin_area = fun ?drawing_area ?width ?height ?packing () -> let da = match drawing_area with @@ -148,7 +149,7 @@ let tree_values = fun ?(only_checked=true) (tree : tree) -> store#foreach (fun _ row -> let v = store#get ~row ~column:name and c = store#get ~row ~column:check in - let space = if String.length !values > 0 then " " else "" in + let space = if Compat.bytes_length !values > 0 then " " else "" in let v = if c then v else if only_checked then "" @@ -171,9 +172,9 @@ let get_selected_in_tree = fun (tree : tree) -> let add_to_tree = fun ?(force_unselect=false) (tree : tree) string -> let (store, name, check, _) = tree_model tree in let row = store#append () in - let l = String.length string in + let l = Compat.bytes_length string in let checked = not (string.[0] = '[' && string.[l - 1] = ']') in - let string = if not checked then String.sub string 1 (l - 2) else string in + let string = if not checked then Compat.bytes_sub string 1 (l - 2) else string in store#set ~row ~column:check (checked && not force_unselect); store#set ~row ~column:name string diff --git a/sw/lib/ocaml/http.ml b/sw/lib/ocaml/http.ml index 22249b04218..fd01bc65297 100644 --- a/sw/lib/ocaml/http.ml +++ b/sw/lib/ocaml/http.ml @@ -9,8 +9,8 @@ module H = Http_client END let file_of_url = fun ?dest url -> - if String.sub url 0 7 = "file://" then - String.sub url 7 (String.length url - 7) + if Compat.bytes_sub url 0 7 = "file://" then + Compat.bytes_sub url 7 (Compat.bytes_length url - 7) else let tmp_file = match dest with @@ -19,9 +19,13 @@ let file_of_url = fun ?dest url -> let call = new H.get url in call#set_response_body_storage (`File (fun () -> tmp_file)); let pipeline = new H.pipeline in - pipeline#set_proxy_from_environment (); - pipeline#add call; - pipeline#run (); + IFDEF NETCLIENT_V_404 THEN + pipeline # set_proxy_from_environment (~insecure:false) () + ELSE + pipeline # set_proxy_from_environment () + END; + pipeline # add call; + pipeline # run (); match call#status with | `Successful -> (* prerr_endline (Printf.sprintf "file sucessfull: %s, '%s'" tmp_file url); *) diff --git a/sw/lib/ocaml/mapFP.ml b/sw/lib/ocaml/mapFP.ml index f494690c567..9d68f392a69 100644 --- a/sw/lib/ocaml/mapFP.ml +++ b/sw/lib/ocaml/mapFP.ml @@ -24,6 +24,7 @@ open Printf open Latlong + let (//) = Filename.concat let sof = string_of_float @@ -33,7 +34,7 @@ let float_attr = fun xml a -> float_of_string (ExtXml.attrib xml a) let rec assoc_nocase at = function [] -> raise Not_found | (a, v)::avs -> - if String.uppercase at = String.uppercase a then v else assoc_nocase at avs + if Compat.bytes_uppercase at = Compat.bytes_uppercase a then v else assoc_nocase at avs (** Returns the WGS84 coordinates of a waypoint, either from its relative x and y coordinates or from its lat and long *) @@ -63,7 +64,7 @@ XmlEdit.Deleted -> wp#delete () let wgs84 = geo_of_xml utm_ref float_attrib in wp#geomap#edit_georef_name wp#name (assoc_nocase "name" attribs); - wp#set wgs84; + wp#set wgs84; wp#set_name (assoc_nocase "name" attribs) with _ -> () @@ -202,7 +203,7 @@ let display_kml = fun ?group color geomap xml -> try let document = ExtXml.child xml "Document" in let rec loop = fun child -> - let tag = String.lowercase (Xml.tag child) in + let tag = Compat.bytes_lowercase (Xml.tag child) in match tag with | "linestring" | "linearring" -> let coordinates = ExtXml.child child "coordinates" in @@ -265,7 +266,7 @@ class flight_plan = fun ?format_attribs ?editable ~show_moved geomap color fp_dt let waypoints = ExtXml.child xml "waypoints" in try List.fold_left (fun l x -> - match String.lowercase (Xml.tag x) with + match Compat.bytes_lowercase (Xml.tag x) with "kml" -> let file = ExtXml.attrib x "file" in display_kml ~group:wpts_group#group color geomap (ExtXml.parse_file (Env.flight_plans_path // file)); diff --git a/sw/lib/ocaml/mapGoogle.ml b/sw/lib/ocaml/mapGoogle.ml index 779241af585..2c627443248 100644 --- a/sw/lib/ocaml/mapGoogle.ml +++ b/sw/lib/ocaml/mapGoogle.ml @@ -27,6 +27,7 @@ let array_forall = fun f a -> open Printf + module LL = Latlong (** Quadtreee of displayed tiles *) @@ -48,7 +49,7 @@ let char_of = function let mem_tile = fun tile_key -> let rec loop = fun i tree -> tree = Tile || - i < String.length tile_key && + i < Compat.bytes_length tile_key && match tree with Empty -> false | Tile -> true @@ -58,7 +59,7 @@ let mem_tile = fun tile_key -> (** Adding a tile to the store *) let add_tile = fun tile_key -> let rec loop = fun i tree j -> - if i < String.length tile_key then + if i < Compat.bytes_length tile_key then match tree.(j) with Empty -> let sons = Array.make 4 Empty in @@ -103,7 +104,7 @@ let display_tile = fun (geomap:MapCanvas.widget) wgs84 level -> let key = desired_tile.Gm.key in if not (mem_tile key) then let (tile, jpg_file) = Gm.get_image key in - display_the_tile geomap tile jpg_file (String.length tile.Gm.key) + display_the_tile geomap tile jpg_file (Compat.bytes_length tile.Gm.key) exception New_displayed of int @@ -130,7 +131,7 @@ let fill_window = fun (geomap:MapCanvas.widget) zoomlevel -> (** Go through the quadtree and look for the holes *) let rec loop = fun twest tsouth tsize trees i zoom key -> (* Check for intersection *) - if not (twest > east || (twest+.tsize < west && (east < 1. (* Standard case *) || twest+.2.>east (* Over 180° *))) || tsouth > north || tsouth+.tsize < south) then + if not (twest > east || (twest+.tsize < west && (east < 1. (* Standard case *) || twest+.2.>east (* Over 180� *))) || tsouth > north || tsouth+.tsize < south) then let tsize2 = tsize /. 2. in try match trees.(i) with @@ -138,16 +139,16 @@ let fill_window = fun (geomap:MapCanvas.widget) zoomlevel -> | Empty -> if zoom = 1 then let tile, image = Gm.get_image ~tbl key in - let level = String.length tile.Gm.key in + let level = Compat.bytes_length tile.Gm.key in display_the_tile geomap tile image level; - raise (New_displayed (zoomlevel+1-String.length tile.Gm.key)) + raise (New_displayed (zoomlevel+1-Compat.bytes_length tile.Gm.key)) else begin trees.(i) <- Node (Array.make 4 Empty); loop twest tsouth tsize trees i zoom key end | Node sons -> let continue = fun j tw ts -> - loop tw ts tsize2 sons j (zoom-1) (key^String.make 1 (char_of j)) in + loop tw ts tsize2 sons j (zoom-1) (key^Compat.bytes_make 1 (char_of j)) in continue 0 twest (tsouth+.tsize2); continue 1 (twest+.tsize2) (tsouth+.tsize2); @@ -195,10 +196,10 @@ let pixbuf = fun sw ne zoomlevel-> if zoom = 1 then let tile, image = Gm.get_image key in - raise (To_copy (zoomlevel+1-String.length tile.Gm.key, image)) + raise (To_copy (zoomlevel+1-Compat.bytes_length tile.Gm.key, image)) else begin let continue = fun j tw ts -> - loop tw ts tsize2 (zoom-1) (key^String.make 1 (char_of j)) in + loop tw ts tsize2 (zoom-1) (key^Compat.bytes_make 1 (char_of j)) in continue 0 twest (tsouth+.tsize2); continue 1 (twest+.tsize2) (tsouth+.tsize2); continue 2 (twest+.tsize2) tsouth; diff --git a/sw/lib/ocaml/os_calls.ml b/sw/lib/ocaml/os_calls.ml index 22ccb1745fe..b7ec496be47 100644 --- a/sw/lib/ocaml/os_calls.ml +++ b/sw/lib/ocaml/os_calls.ml @@ -21,12 +21,14 @@ * Boston, MA 02111-1307, USA. * *) + + let current_os = ref "not_set" let read_process_output command = let buffer_size = 2048 in let buffer = Buffer.create buffer_size in - let string = String.create buffer_size in + let string = Compat.bytes_create buffer_size in let in_channel = Unix.open_process_in command in let chars_read = ref 1 in while !chars_read <> 0 do @@ -41,7 +43,7 @@ let contains s substring = try ignore (Str.search_forward (Str.regexp_string substring) s 0); true with Not_found -> false -let os_name = String.copy ( +let os_name = Compat.bytes_copy ( if contains !current_os "not_set" then ( current_os := read_process_output "uname" ); !current_os diff --git a/sw/lib/ocaml/papget.ml b/sw/lib/ocaml/papget.ml index 440e9287f8a..b69da8032de 100644 --- a/sw/lib/ocaml/papget.ml +++ b/sw/lib/ocaml/papget.ml @@ -23,6 +23,7 @@ *) open Printf + module PC = Papget_common module PR = Papget_renderer module E = Expr_syntax @@ -367,7 +368,7 @@ object (self) let (x, y) = item#xy in let attrs = [ "type", msg_obj#type_; - "display", String.lowercase item#renderer#tag; + "display", Compat.bytes_lowercase item#renderer#tag; "x", sprintf "%.0f" x; "y", sprintf "%.0f" y ] in Xml.Element ("papget", attrs, scale_prop::val_props@renderer_props) end @@ -386,7 +387,7 @@ object let (x, y) = item#xy in let attrs = [ "type", type_; - "display", String.lowercase item#renderer#tag; + "display", Compat.bytes_lowercase item#renderer#tag; "x", sprintf "%.0f" x; "y", sprintf "%.0f" y ] in Xml.Element ("papget", attrs, properties@props) end @@ -415,9 +416,8 @@ object (self) let (x, y) = item#xy in let attrs = [ "type", "video_plugin"; - "display", String.lowercase item#renderer#tag; + "display", Compat.bytes_lowercase item#renderer#tag; "x", sprintf "%.0f" x; "y", sprintf "%.0f" y ] in Xml.Element ("papget", attrs, properties@props) initializer ignore(adj#connect#value_changed (fun () -> self#update_zoom (string_of_float adj#value))) end - diff --git a/sw/lib/ocaml/serial.ml b/sw/lib/ocaml/serial.ml index 42edcf2cfa1..795519cf10d 100644 --- a/sw/lib/ocaml/serial.ml +++ b/sw/lib/ocaml/serial.ml @@ -24,6 +24,7 @@ open Printf + type speed = B0 | B50 @@ -87,11 +88,11 @@ type 'a closure = Closure of 'a (*let buffer_len = 256 *) let buffer_len = 2048 let input = fun ?(read = Unix.read) f -> - let buffer = String.create buffer_len + let buffer = Compat.bytes_create buffer_len and index = ref 0 in let wait = fun start n -> - String.blit buffer start buffer 0 n; + Compat.bytes_blit buffer start buffer 0 n; index := n in Closure (fun fd -> @@ -102,7 +103,7 @@ let input = fun ?(read = Unix.read) f -> Debug.call 'T' (fun f -> fprintf f "input: %d %d\n" !index n); let rec parse = fun start n -> Debug.call 'T' (fun f -> fprintf f "input parse: %d %d\n" start n); - let nb_used = f (String.sub buffer start n) in + let nb_used = f (Compat.bytes_sub buffer start n) in (* Printf.fprintf stderr "n'=%d\n" nb_used; flush stderr; *) if nb_used > 0 then parse (start + nb_used) (n - nb_used) @@ -113,5 +114,3 @@ let input = fun ?(read = Unix.read) f -> else wait start n in parse 0 n) - - diff --git a/sw/lib/ocaml/srtm.ml b/sw/lib/ocaml/srtm.ml index 22d3b7a1aed..7a19b3d5454 100644 --- a/sw/lib/ocaml/srtm.ml +++ b/sw/lib/ocaml/srtm.ml @@ -24,6 +24,7 @@ open Latlong + let (//) = Filename.concat type error = string @@ -56,7 +57,7 @@ let find = fun tile -> try let f = open_compressed (tile_name ^".hgt") in let n = tile_size*tile_size*2 in - let buf = String.create n in + let buf = Compat.bytes_create n in really_input f buf 0 n; Hashtbl.add htiles tile buf; buf @@ -147,6 +148,3 @@ let horizon_slope = fun geo r psi alpha d -> (* Printf.printf "debut calcul \n"; *) calc_horizon 0.0 0.0 0.0; end - - - diff --git a/sw/lib/ocaml/ubx.ml b/sw/lib/ocaml/ubx.ml index 5b534b75aac..8875ef28afe 100644 --- a/sw/lib/ocaml/ubx.ml +++ b/sw/lib/ocaml/ubx.ml @@ -22,6 +22,7 @@ * *) + module UbxProtocol = struct (** SYNC1 SYNC2 CLASS ID LENGTH(2) UBX_PAYLOAD CK_A CK_B LENGTH is the lentgh of UBX_PAYLOAD @@ -32,8 +33,8 @@ module UbxProtocol = struct let offset_length=4 let index_start = fun buf -> let rec loop = fun i -> - let i' = String.index_from buf i sync1 in - if String.length buf > i'+1 && buf.[i'+1] = sync2 then + let i' = Compat.bytes_index_from buf i sync1 in + if Compat.bytes_length buf > i'+1 && buf.[i'+1] = sync2 then i' else loop (i'+1) in @@ -43,20 +44,20 @@ module UbxProtocol = struct Char.code buf.[start+5] lsl 8 + Char.code buf.[start+4] + 4 let length = fun buf start -> - let len = String.length buf - start in + let len = Compat.bytes_length buf - start in if len >= offset_length+2 then payload_length buf start + 4 else raise Protocol.Not_enough let payload = fun buf -> - Protocol.payload_of_string (String.sub buf offset_payload (payload_length buf 0)) + Protocol.payload_of_string (Compat.bytes_sub buf offset_payload (payload_length buf 0)) let uint8_t = fun x -> x land 0xff let (+=) = fun r x -> r := uint8_t (!r + x) let compute_checksum = fun buf -> let ck_a = ref 0 and ck_b = ref 0 in - let l = String.length buf in + let l = Compat.bytes_length buf in for i = offset_payload to l - 1 - 4 do ck_a += Char.code buf.[i]; ck_b += !ck_a @@ -70,15 +71,15 @@ module UbxProtocol = struct let packet = fun payload -> let payload = Protocol.string_of_payload payload in - let n = String.length payload in + let n = Compat.bytes_length payload in let msg_length = n + 4 in - let m = String.create msg_length in - m.[0] <- sync1; - m.[1] <- sync2; - String.blit payload 0 m 2 n; + let m = Compat.bytes_create msg_length in + Compat.bytes_set m 0 sync1; + Compat.bytes_set m 1 sync2; + Compat.bytes_blit payload 0 m 2 n; let (ck_a, ck_b) = compute_checksum m in - m.[msg_length-2] <- Char.chr ck_a; - m.[msg_length-1] <- Char.chr ck_b; + Compat.bytes_set m (msg_length-2) (Char.chr ck_a); + Compat.bytes_set m (msg_length-1) (Char.chr ck_b); m end @@ -134,7 +135,7 @@ type message_spec = Xml.xml let ubx_payload = fun msg_xml values -> let n = int_of_string (ExtXml.attrib msg_xml "length") in - let p = String.make n '#' in + let p = Compat.bytes_make n '#' in let fields = Xml.children msg_xml in List.iter (fun (label, value) -> @@ -147,19 +148,19 @@ let ubx_payload = fun msg_xml values -> match fmt with | "U1" -> assert(value >= 0 && value < 0x100); - p.[pos] <- byte value + Compat.bytes_set p (pos) (byte value) | "I1" -> assert(value >= -0x80 && value <= 0x80); - p.[pos] <- byte value + Compat.bytes_set p pos (byte value) | "I4" | "U4" -> assert(fmt <> "U4" || value >= 0); - p.[pos+3] <- byte (value asr 24); - p.[pos+2] <- byte (value lsr 16); - p.[pos+1] <- byte (value lsr 8); - p.[pos+0] <- byte value + Compat.bytes_set p (pos+3) (byte (value asr 24)); + Compat.bytes_set p (pos+2) (byte (value lsr 16)); + Compat.bytes_set p (pos+1) (byte (value lsr 8)); + Compat.bytes_set p (pos+0) (byte value) | "U2" | "I2" -> - p.[pos+1] <- byte (value lsr 8); - p.[pos+0] <- byte value + Compat.bytes_set p (pos+1) (byte (value lsr 8)); + Compat.bytes_set p (pos+0) (byte value) | _ -> failwith (Printf.sprintf "Ubx.make_payload: unknown format '%s'" fmt) ) values; @@ -176,13 +177,13 @@ let message = fun class_name msg_name -> let payload = fun class_name msg_name values -> let class_id, msg_id, msg = message class_name msg_name in let u_payload = ubx_payload msg values in - let n = String.length u_payload in + let n = Compat.bytes_length u_payload in (** Just add CLASS_ID, MSG_ID and LENGTH(2) to the ubx payload *) - let m = String.create (n+4) in - m.[0] <- Char.chr class_id; - m.[1] <- Char.chr msg_id; - m.[2] <- Char.chr (n land 0xff); - m.[3] <- Char.chr ((n land 0xff00) lsr 8); - String.blit u_payload 0 m 4 n; + let m = Compat.bytes_create (n+4) in + Compat.bytes_set m 0 (Char.chr class_id); + Compat.bytes_set m 1 (Char.chr msg_id); + Compat.bytes_set m 2 (Char.chr (n land 0xff)); + Compat.bytes_set m 3 (Char.chr ((n land 0xff00) lsr 8)); + Compat.bytes_blit u_payload 0 m 4 n; Protocol.payload_of_string m diff --git a/sw/lib/ocaml/xmlEdit.ml b/sw/lib/ocaml/xmlEdit.ml index 3427e8f1b0f..9a2f468a024 100644 --- a/sw/lib/ocaml/xmlEdit.ml +++ b/sw/lib/ocaml/xmlEdit.ml @@ -22,6 +22,7 @@ * *) + let default_background = "white" type gtkTreeViewDropPosition = @@ -104,7 +105,7 @@ let string_of_attribs = fun attribs -> match attribs with ["PCData", data] -> data | _ -> - String.concat " " (List.map (fun (a,v) -> sprintf "%s=\"%s\"" a v) attribs) + Compat.bytes_concat " " (List.map (fun (a,v) -> sprintf "%s=\"%s\"" a v) attribs) type id = int let gen_id = @@ -131,18 +132,18 @@ let encode_crs = *) let recode_crs = fun s -> - let n = String.length s in - let s' = String.create n in + let n = Compat.bytes_length s in + let s' = Compat.bytes_create n in let i = ref 0 and j = ref 0 in while !i < n do if !i < n-1 && s.[!i] == '\\' && s.[!i+1] == 'n' then begin - s'.[!j] <- '\n'; + Compat.bytes_set s' (!j) '\n'; incr i end else - s'.[!j] <- s.[!i]; + Compat.bytes_set s' (!j) s.[!i]; incr i; incr j done; - String.sub s' 0 !j + Compat.bytes_sub s' 0 !j @@ -351,21 +352,21 @@ let set_attribs = fun ((model, path):node) attribs -> let rec replace_assoc a v = function [] -> [(a, v)] | (a', v')::l -> - if a = String.uppercase a' + if a = Compat.bytes_uppercase a' then (a, v)::l else (a', v')::replace_assoc a v l let set_attrib = fun node (a, v) -> let atbs = attribs node in - set_attribs node (replace_assoc (String.uppercase a) v atbs) + set_attribs node (replace_assoc (Compat.bytes_uppercase a) v atbs) let attrib = fun node at -> - let at = String.uppercase at in + let at = Compat.bytes_uppercase at in let ats = attribs node in let rec loop = function [] -> raise Not_found | (a,v)::avs -> - if String.uppercase a = at then v else loop avs in + if Compat.bytes_uppercase a = at then v else loop avs in loop ats let tag = fun ((model, path):node) -> diff --git a/sw/logalizer/sd2log.ml b/sw/logalizer/sd2log.ml index c4fab9d892c..b9d714aeaee 100644 --- a/sw/logalizer/sd2log.ml +++ b/sw/logalizer/sd2log.ml @@ -24,6 +24,7 @@ *) open Printf + module U = Unix let (//) = Filename.concat let var_path = Env.paparazzi_home // "var" @@ -86,11 +87,11 @@ let hex_of_array = function | PprzLink.Array array -> let n = Array.length array in (* One integer -> 2 chars *) - let s = String.create (2*n) in + let s = Compat.bytes_create (2*n) in Array.iteri (fun i dec -> let hex = sprintf "%02x" (PprzLink.int_of_value array.(i)) in - String.blit hex 0 s (2*i) 2) + Compat.bytes_blit hex 0 s (2*i) 2) array; s | value -> @@ -110,8 +111,8 @@ let search_conf = fun md5 -> let files = Sys.readdir dir in let rec loop = fun i -> if i < Array.length files then begin - if String.length files.(i) > (md5_ofs + md5_len) - && String.sub files.(i) md5_ofs md5_len = md5 then + if Compat.bytes_length files.(i) > (md5_ofs + md5_len) + && Compat.bytes_sub files.(i) md5_ofs md5_len = md5 then dir // files.(i) else loop (i+1) diff --git a/sw/simulator/diffusion.ml b/sw/simulator/diffusion.ml index 5f50e243671..4b6d31c24c6 100644 --- a/sw/simulator/diffusion.ml +++ b/sw/simulator/diffusion.ml @@ -1,3 +1,4 @@ + open Printf module Ground_Pprz = PprzLink.Messages(struct let name = "ground" end) @@ -67,10 +68,10 @@ let send_on_ivy = fun () -> ys := sprintf "%.6f" ((Rad>>Deg)wgs84.posn_long) :: !ys; vs := sprintf "%d" plume.value :: !vs) plumes ; - let ids = String.concat "," !ids - and xs = String.concat "," !xs - and ys = String.concat "," !ys - and vs = String.concat "," !vs in + let ids = Compat.bytes_concat "," !ids + and xs = Compat.bytes_concat "," !xs + and ys = Compat.bytes_concat "," !ys + and vs = Compat.bytes_concat "," !vs in Ground_Pprz.message_send my_id "PLUMES" [ "ids", PprzLink.String ids; "lats", PprzLink.String xs; diff --git a/sw/simulator/sim.ml b/sw/simulator/sim.ml index e44af59b2ab..8a3ba909511 100644 --- a/sw/simulator/sim.ml +++ b/sw/simulator/sim.ml @@ -22,6 +22,7 @@ * *) + open Printf open Stdlib open Latlong @@ -239,9 +240,9 @@ module Make(AircraftItl : AIRCRAFT_ITL) = struct (* and theta_ = s.Gps.course *) and (phi, theta, psi) = FlightModel.get_attitude !state in fg_msg buffer lat lon alt phi theta psi; - (** for i = 0 to String.length buffer - 1 do fprintf stderr "%x " (Char.code buffer.[i]) done; fprintf stderr "\n"; **) + (** for i = 0 to Compat.bytes_length buffer - 1 do fprintf stderr "%x " (Char.code buffer.[i]) done; fprintf stderr "\n"; **) try - ignore (Unix.sendto socket buffer 0 (String.length buffer) [] sockaddr) + ignore (Unix.sendto socket buffer 0 (Compat.bytes_length buffer) [] sockaddr) with Unix.Unix_error (e,f,a) -> Printf.fprintf stderr "Error sending to FlightGear: %s (%s(%s))\n" (Unix.error_message e) f a; flush stderr in @@ -274,7 +275,7 @@ module Make(AircraftItl : AIRCRAFT_ITL) = struct let inet_addr = Unix.inet_addr_of_string !fg_client in let socket = Unix.socket Unix.PF_INET Unix.SOCK_DGRAM 0 in (* Unix.connect socket (Unix.ADDR_INET (inet_addr, 5501)); *) - let buffer = String.create (fg_sizeof ()) in + let buffer = Compat.bytes_create (fg_sizeof ()) in let sockaddr = (Unix.ADDR_INET (inet_addr, 5501)) in Stdlib.timer ~scale:time_scale fg_period (fg_task socket buffer sockaddr); fprintf stdout "Sending to FlightGear at %s\n" !fg_client; flush stdout diff --git a/sw/supervision/pc_common.ml b/sw/supervision/pc_common.ml index f274770cde3..c46474095f9 100644 --- a/sw/supervision/pc_common.ml +++ b/sw/supervision/pc_common.ml @@ -22,6 +22,7 @@ * *) + open Printf let (//) = Filename.concat @@ -43,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 = String.create buf_size in + let buf = Compat.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 "^") (String.sub buf 0 n) in + let s = Str.split (Str.regexp "^") (Compat.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 @@ -60,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 = String.length dir in - if not (String.length file > n && String.sub file 0 n = dir) then begin + let n = Compat.bytes_length dir in + if not (Compat.bytes_length file > n && Compat.bytes_sub file 0 n = dir) then begin let home = Env.paparazzi_home in - 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) + 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) 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 // String.sub file (n+1) (String.length file - n - 1) + subdir // Compat.bytes_sub file (n+1) (Compat.bytes_length file - n - 1) let choose_xml_file = fun ?(multiple = false) title subdir cb -> diff --git a/sw/supervision/pc_control_panel.ml b/sw/supervision/pc_control_panel.ml index 60c542f1ab8..3ef9ba84bc5 100644 --- a/sw/supervision/pc_control_panel.ml +++ b/sw/supervision/pc_control_panel.ml @@ -22,6 +22,7 @@ * *) + open Printf module Utils = Pc_common @@ -44,7 +45,7 @@ let program_command = fun x -> if cmd.[0] = '/' then cmd else if cmd.[0] = '$' then - String.sub cmd 1 ((String.length cmd) - 1) + Compat.bytes_sub cmd 1 ((Compat.bytes_length cmd) - 1) else Env.paparazzi_src // cmd with Not_found -> @@ -76,7 +77,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 = String.concat " " options in + let options = Compat.bytes_concat " " options in (* add to hash tables *) Hashtbl.add modes mode options; List.iter (fun b -> @@ -117,9 +118,9 @@ let parse_process_args = fun (name, args) -> (* Mark spaces into args *) let marked_space = Char.chr 0 in let in_quotes = ref false in - for i = 0 to String.length args - 1 do + for i = 0 to Compat.bytes_length args - 1 do match args.[i] with - ' ' when !in_quotes -> args.[i] <- marked_space + ' ' when !in_quotes -> Compat.bytes_set args i marked_space | '"' -> in_quotes := not !in_quotes | _ -> () done; @@ -127,19 +128,19 @@ let parse_process_args = fun (name, args) -> let args = Str.split (Str.regexp "[ ]+") args in (* Restore spaces and remove quotes *) let restore_spaces = fun s -> - let n = String.length s in + let n = Compat.bytes_length s in for i = 0 to n - 1 do - if s.[i] = marked_space then s.[i] <- ' ' + if s.[i] = marked_space then Compat.bytes_set s i ' ' done; if n >= 2 && s.[0] = '"' then - String.sub s 1 (n-2) + Compat.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 -> String.length s > 0 && s.[0] = '-' in + let is_option = fun s -> Compat.bytes_length s > 0 && s.[0] = '-' in let rec xml_args = function [] -> [] | option::value::l when not (is_option value) -> @@ -173,7 +174,7 @@ let save_session = fun gui session_combo -> name let double_quote = fun s -> - if String.contains s ' ' then + if Compat.bytes_contains s ' ' then sprintf "\"%s\"" s else s @@ -245,7 +246,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 String.compare !strings in + let ordered = List.sort Compat.bytes_compare !strings in List.iter (fun name -> Gtk_tools.add_to_combo session_combo name) ordered in @@ -336,4 +337,3 @@ let supervision = fun ?file gui log (ac_combo : Gtk_tools.combo) (target_combo : in ignore (gui#menu_item_delete_session#connect#activate ~callback); session_combo, execute_custom - diff --git a/sw/tools/generators/gen_aircraft.ml b/sw/tools/generators/gen_aircraft.ml index e9f7c749b34..a8e851c7d16 100644 --- a/sw/tools/generators/gen_aircraft.ml +++ b/sw/tools/generators/gen_aircraft.ml @@ -22,6 +22,7 @@ * *) + open Printf module U = Unix @@ -57,14 +58,14 @@ let check_unique_id_and_name = fun conf conf_xml -> let configure_xml2mk = fun f xml -> (* all makefiles variables are forced to uppercase *) - let name = String.uppercase (ExtXml.attrib xml "name") + let name = Compat.bytes_uppercase (ExtXml.attrib xml "name") and value = ExtXml.attrib_or_default xml "value" "" and default = ExtXml.attrib_or_default xml "default" "" and case = ExtXml.attrib_or_default xml "case" "" in (* Only print variable if value is not empty *) - if String.length value > 0 then + if Compat.bytes_length value > 0 then fprintf f "%s = %s\n" name value - else if String.length default > 0 then + else if Compat.bytes_length default > 0 then fprintf f "%s ?= %s\n" name default; (* also providing lower and upper case version on request *) if Str.string_match (Str.regexp ".*lower.*") case 0 then @@ -115,11 +116,11 @@ let file_xml2mk = fun f ?(arch = false) dir_name target xml -> let module_xml2mk = fun f target firmware m -> let name = ExtXml.attrib m.xml "name" in let dir = try Xml.attrib m.xml "dir" with Xml.No_attribute _ -> name in - let dir_name = String.uppercase dir ^ "_DIR" in + let dir_name = Compat.bytes_uppercase dir ^ "_DIR" in (* print global flags as compilation defines and flags *) fprintf f "\n# makefile for module %s in modules/%s\n" name dir; List.iter (fun flag -> - match String.lowercase (Xml.tag flag) with + match Compat.bytes_lowercase (Xml.tag flag) with | "configure" -> configure_xml2mk f flag | "define" -> define_xml2mk f ~target flag | _ -> ()) m.param; @@ -140,7 +141,7 @@ let module_xml2mk = fun f target firmware m -> in Xml.iter (fun field -> - match String.lowercase (Xml.tag field) with + match Compat.bytes_lowercase (Xml.tag field) with | "configure" -> configure_xml2mk f field | "define" -> define_xml2mk f ~target field | "include" -> include_xml2mk f ~target ~vpath:m.vpath field @@ -164,7 +165,7 @@ let modules_xml2mk = fun f target xml fp -> (** include modules directory for ALL targets, not just the defined ones **) fprintf f "$(TARGET).CFLAGS += -Imodules -Iarch/$(ARCH)/modules\n"; List.iter - (fun dir -> fprintf f "%s_DIR = modules/%s\n" (String.uppercase dir) dir + (fun dir -> fprintf f "%s_DIR = modules/%s\n" (Compat.bytes_uppercase dir) dir ) dir_list; (* add vpath for external modules *) List.iter @@ -198,7 +199,7 @@ let subsystem_xml2mk = fun f firmware s -> List.iter (fun def -> define_xml2mk f def) s_defines; (* include subsystem *) (* TODO test if file exists with the generator ? *) let s_name = name ^ s_type ^ ".makefile" in - let s_dir = "CFG_" ^ String.uppercase (Xml.attrib firmware "name") in + let s_dir = "CFG_" ^ Compat.bytes_uppercase (Xml.attrib firmware "name") in fprintf f "ifneq ($(strip $(wildcard $(%s)/%s)),)\n" s_dir s_name; fprintf f "\tinclude $(%s)/%s\n" s_dir s_name; fprintf f "else\n"; @@ -352,13 +353,13 @@ let () = (* remove settings if not supported for the current target *) let settings = List.fold_left (fun l s -> if Gen_common.is_element_unselected ~verbose:true target modules s then l else l @ [s]) [] (Str.split (Str.regexp " ") settings) in (* update aircraft_xml *) - let aircraft_xml = ExtXml.subst_attrib "settings" (String.concat " " settings) aircraft_xml in + let aircraft_xml = ExtXml.subst_attrib "settings" (Compat.bytes_concat " " settings) aircraft_xml in (* add modules settings *) let settings_modules = try Env.filter_settings (value "settings_modules") with _ -> "" in (* remove settings if not supported for the current target *) let settings_modules = List.fold_left (fun l s -> if Gen_common.is_element_unselected ~verbose:true target modules s then l else l @ [s]) [] (Str.split (Str.regexp " ") settings_modules) in (* update aircraft_xml *) - let aircraft_xml = ExtXml.subst_attrib "settings_modules" (String.concat " " settings_modules) aircraft_xml in + let aircraft_xml = ExtXml.subst_attrib "settings_modules" (Compat.bytes_concat " " settings_modules) aircraft_xml in (* finally, concat all settings *) let settings = settings @ settings_modules in let settings = if List.length settings = 0 then @@ -366,7 +367,7 @@ let () = fprintf stderr "\nInfo: No 'settings' attribute specified for A/C '%s', using 'settings/dummy.xml'\n\n%!" aircraft; "settings/dummy.xml" end - else String.concat " " settings + else Compat.bytes_concat " " settings in (** Expands the configuration of the A/C into one single file *) diff --git a/sw/tools/generators/gen_airframe.ml b/sw/tools/generators/gen_airframe.ml index f44a7508ff5..53b86bc0d94 100644 --- a/sw/tools/generators/gen_airframe.ml +++ b/sw/tools/generators/gen_airframe.ml @@ -24,6 +24,7 @@ let max_pprz = 9600. (* !!!! MAX_PPRZ From paparazzi.h !!!! *) + open Printf open Xml2h @@ -104,7 +105,7 @@ let rec string_from_type = fun name v t -> let sprint_array = fun v t -> let vs = Str.split array_sep v in let sl = List.map (fun vl -> string_from_type name vl t) vs in - "{ "^(String.concat " , " sl)^" }" + "{ "^(Compat.bytes_concat " , " sl)^" }" in let rm_leading_trailing_spaces = fun s -> let s = Str.global_replace (Str.regexp "^ *") "" s in @@ -291,8 +292,8 @@ let rec parse_section = fun ac_id s -> let servos = Xml.children s in let nb_servos = List.fold_right (fun s m -> Pervasives.max (int_of_string (ExtXml.attrib s "no")) m) servos min_int + 1 in - define (sprintf "SERVOS_%s_NB" (String.uppercase driver)) (string_of_int nb_servos); - printf "#include \"subsystems/actuators/actuators_%s.h\"\n" (String.lowercase driver); + define (sprintf "SERVOS_%s_NB" (Compat.bytes_uppercase driver)) (string_of_int nb_servos); + printf "#include \"subsystems/actuators/actuators_%s.h\"\n" (Compat.bytes_lowercase driver); nl (); List.iter (parse_servo driver) servos; nl () @@ -357,14 +358,14 @@ let rec parse_section = fun ac_id s -> let h_name = "AIRFRAME_H" let hex_to_bin = fun s -> - let n = String.length s in + let n = Compat.bytes_length s in assert(n mod 2 = 0); - let b = String.make (2*n) 'x' in + let b = Compat.bytes_make (2*n) 'x' in for i = 0 to n/2 - 1 do - b.[4*i] <- '\\'; - Scanf.sscanf (String.sub s (2*i) 2) "%2x" + Compat.bytes_set b (4*i) '\\'; + Scanf.sscanf (Compat.bytes_sub s (2*i) 2) "%2x" (fun x -> - String.blit (sprintf "%03o" x) 0 b (4*i+1) 3) + Compat.bytes_blit (sprintf "%03o" x) 0 b (4*i+1) 3) done; b