From 3bd220fe8b7a4eeb3b0507f32aaae0bcfed0b28e Mon Sep 17 00:00:00 2001 From: Romain Beauxis Date: Mon, 11 Nov 2024 12:33:30 -0600 Subject: [PATCH] Get rid of stdlib wrapper. --- src/core/builtins/builtins_files.ml | 10 ++++--- src/core/builtins/builtins_server.ml | 2 +- src/core/builtins/builtins_sqlite.ml | 4 +-- src/core/builtins/builtins_sys.ml | 3 +- src/core/dune | 1 - src/core/encoder/formats/ffmpeg_format.ml | 4 +-- src/core/encoder/lang/lang_ffmpeg.ml | 4 +-- src/core/harbor/harbor.ml | 25 ++++++++-------- src/core/io/ffmpeg_io.ml | 11 ++++--- src/core/io/srt_io.ml | 5 +++- src/core/operators/chord.ml | 9 +++--- src/core/operators/frei0r_op.ml | 10 +++++-- src/core/operators/ladspa_op.ml | 2 +- src/core/outputs/pipe_output.ml | 2 +- src/core/playlists/playlist_basic.ml | 32 ++++++++++---------- src/core/request.ml | 4 +-- src/core/source.ml | 5 +++- src/core/sources/harbor_input.ml | 4 +-- src/core/stream/ffmpeg_raw_content.ml | 8 ++--- src/core/synth/dssi_op.ml | 4 +-- src/core/tools/liq_http.ml | 28 +++++++++--------- src/core/tools/liqcurl.ml | 10 ++++--- src/core/tools/sandbox.ml | 2 +- src/core/tools/server.ml | 4 ++- src/core/tools/tutils.ml | 2 +- src/core/tools/utils.ml | 36 +++++++++++++++-------- src/runtime/dune | 1 - src/runtime/main.ml | 2 +- src/stdlib/dune | 12 -------- src/stdlib/hashtbl.ml | 1 - src/stdlib/hashtbl.mli | 17 ----------- src/stdlib/pcre.ml | 1 - src/stdlib/pcre.mli | 1 - 33 files changed, 134 insertions(+), 132 deletions(-) delete mode 100644 src/stdlib/dune delete mode 100644 src/stdlib/hashtbl.ml delete mode 100644 src/stdlib/hashtbl.mli delete mode 100644 src/stdlib/pcre.ml delete mode 100644 src/stdlib/pcre.mli diff --git a/src/core/builtins/builtins_files.ml b/src/core/builtins/builtins_files.ml index 8035f199ad..0466f3247a 100644 --- a/src/core/builtins/builtins_files.ml +++ b/src/core/builtins/builtins_files.ml @@ -264,21 +264,23 @@ let _ = let pattern = pattern |> Option.map (fun s -> - Pcre.substitute ~rex:(Pcre.regexp "\\.") + Re.Pcre.substitute ~rex:(Re.Pcre.regexp "\\.") ~subst:(fun _ -> "\\.") s) |> Option.map (fun s -> - Pcre.substitute ~rex:(Pcre.regexp "\\*") ~subst:(fun _ -> ".*") s) + Re.Pcre.substitute ~rex:(Re.Pcre.regexp "\\*") + ~subst:(fun _ -> ".*") + s) |> Option.map (fun s -> "^" ^ s ^ "$") |> Option.value ~default:"" in let sorted = List.assoc "sorted" p |> Lang.to_bool in - let rex = Pcre.regexp pattern in + let rex = Re.Pcre.regexp pattern in let dir = Lang.to_string (List.assoc "" p) in let dir = Lang_string.home_unrelate dir in let readdir dir = Array.to_list (Sys.readdir dir) - |> List.filter (fun s -> Pcre.pmatch ~rex s) + |> List.filter (fun s -> Re.Pcre.pmatch ~rex s) in let files = if not recursive then readdir dir diff --git a/src/core/builtins/builtins_server.ml b/src/core/builtins/builtins_server.ml index 3ac73c2336..32524f8928 100644 --- a/src/core/builtins/builtins_server.ml +++ b/src/core/builtins/builtins_server.ml @@ -64,6 +64,6 @@ let _ = in let f = Lang.assoc "" 2 p in let f x = Lang.to_string (Lang.apply f [("", Lang.string x)]) in - let ns = Pcre.split ~rex:(Pcre.regexp "\\.") namespace in + let ns = Re.Pcre.split ~rex:(Re.Pcre.regexp "\\.") namespace in Server.add ~ns ~usage ~descr command f; Lang.unit) diff --git a/src/core/builtins/builtins_sqlite.ml b/src/core/builtins/builtins_sqlite.ml index 82fb6f9aa7..0a659247e4 100644 --- a/src/core/builtins/builtins_sqlite.ml +++ b/src/core/builtins/builtins_sqlite.ml @@ -26,8 +26,8 @@ let error fmt = fmt let escape = - let rex = Pcre.regexp "'" in - fun s -> "'" ^ Pcre.substitute ~rex ~subst:(fun _ -> "''") s ^ "'" + let rex = Re.Pcre.regexp "'" in + fun s -> "'" ^ Re.Pcre.substitute ~rex ~subst:(fun _ -> "''") s ^ "'" let insert_value_constr = let open Type in diff --git a/src/core/builtins/builtins_sys.ml b/src/core/builtins/builtins_sys.ml index 54238b0b9b..dbf5f16b78 100644 --- a/src/core/builtins/builtins_sys.ml +++ b/src/core/builtins/builtins_sys.ml @@ -216,7 +216,8 @@ let _ = let a = Lang.to_string (Lang.assoc "" 2 p) in let s = match a with "" -> c | _ -> c ^ " " ^ a in let r = try Server.exec s with Not_found -> "Command not found!" in - Lang.list (List.map Lang.string (Pcre.split ~rex:(Pcre.regexp "\r?\n") r)) + Lang.list + (List.map Lang.string (Re.Pcre.split ~rex:(Re.Pcre.regexp "\r?\n") r)) in Lang.add_builtin ~base:Modules.server "execute" ~category ~descr params return_t execute diff --git a/src/core/dune b/src/core/dune index 5a5c2c5a1d..6933405e89 100644 --- a/src/core/dune +++ b/src/core/dune @@ -25,7 +25,6 @@ fileutils liquidsoap-lang liquidsoap-lang.console - liquidsoap_stdlib menhirLib camomile.lib curl diff --git a/src/core/encoder/formats/ffmpeg_format.ml b/src/core/encoder/formats/ffmpeg_format.ml index 2066ab5ad5..8aabed7639 100644 --- a/src/core/encoder/formats/ffmpeg_format.ml +++ b/src/core/encoder/formats/ffmpeg_format.ml @@ -137,7 +137,7 @@ let to_string m = | None -> `Var "none" | Some d -> `String d); Printf.sprintf "%%%s(%s%s)" name - (if Pcre.pmatch ~rex:(Pcre.regexp "video") name then "" + (if Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "video") name then "" else "video_content,") (string_of_options stream_opts) :: opts @@ -152,7 +152,7 @@ let to_string m = Hashtbl.replace stream_opts "samplerate" (`Int (Lazy.force options.samplerate)); Printf.sprintf "%s(%s%s)" name - (if Pcre.pmatch ~rex:(Pcre.regexp "audio") name then "" + (if Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "audio") name then "" else "audio_content,") (string_of_options stream_opts) :: opts) diff --git a/src/core/encoder/lang/lang_ffmpeg.ml b/src/core/encoder/lang/lang_ffmpeg.ml index 9fa1e28033..39d00b5563 100644 --- a/src/core/encoder/lang/lang_ffmpeg.ml +++ b/src/core/encoder/lang/lang_ffmpeg.ml @@ -117,8 +117,8 @@ let stream_media_type ~to_pos ~to_static_string name args = match (name, args) with | _ when has_content ~to_static_string "audio_content" args -> `Audio | _ when has_content ~to_static_string "video_content" args -> `Video - | _ when Pcre.pmatch ~rex:(Pcre.regexp "audio") name -> `Audio - | _ when Pcre.pmatch ~rex:(Pcre.regexp "video") name -> `Video + | _ when Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "audio") name -> `Audio + | _ when Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "video") name -> `Video | _ -> ( match List.assoc_opt "codec" args with | Some t -> ( diff --git a/src/core/harbor/harbor.ml b/src/core/harbor/harbor.ml index 3c62adde0e..aed4436454 100644 --- a/src/core/harbor/harbor.ml +++ b/src/core/harbor/harbor.ml @@ -361,7 +361,7 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct let websocket_error n msg = Websocket.to_string (`Close (Some (n, msg))) let parse_icy_request_line ~port h r = - let auth_data = Pcre.split ~rex:(Pcre.regexp ":") r in + let auth_data = Re.Pcre.split ~rex:(Re.Pcre.regexp ":") r in let requested_user, password = match auth_data with | user :: password :: _ -> (user, password) @@ -387,7 +387,7 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct let parse_http_request_line r = try - let data = Pcre.split ~rex:(Pcre.regexp "[ \t]+") r in + let data = Re.Pcre.split ~rex:(Re.Pcre.regexp "[ \t]+") r in let protocol = verb_or_source_of_string (List.nth data 0) in Duppy.Monad.return ( protocol, @@ -409,9 +409,9 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct let parse_headers headers = let split_header h l = try - let rex = Pcre.regexp "([^:\\r\\n]+):\\s*([^\\r\\n]+)" in - let sub = Pcre.exec ~rex h in - (Pcre.get_substring sub 1, Pcre.get_substring sub 2) :: l + let rex = Re.Pcre.regexp "([^:\\r\\n]+):\\s*([^\\r\\n]+)" in + let sub = Re.Pcre.exec ~rex h in + (Re.Pcre.get_substring sub 1, Re.Pcre.get_substring sub 2) :: l with Not_found -> l in let f x = String.uppercase_ascii x in @@ -449,11 +449,12 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct try (* HTTP authentication *) let auth = assoc_uppercase "AUTHORIZATION" headers in - let data = Pcre.split ~rex:(Pcre.regexp "[ \t]+") auth in + let data = Re.Pcre.split ~rex:(Re.Pcre.regexp "[ \t]+") auth in match data with | "Basic" :: x :: _ -> ( let auth_data = - Pcre.split ~rex:(Pcre.regexp ":") (Lang_string.decode64 x) + Re.Pcre.split ~rex:(Re.Pcre.regexp ":") + (Lang_string.decode64 x) in match auth_data with | x :: y :: _ -> (x, y) @@ -767,11 +768,11 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct | _ -> ans_500 uri let handle_http_request ~hmethod ~hprotocol ~port h uri headers = - let rex = Pcre.regexp "^(.+)\\?(.+)$" in + let rex = Re.Pcre.regexp "^(.+)\\?(.+)$" in let base_uri, args = try - let sub = Pcre.exec ~rex uri in - (Pcre.get_substring sub 1, Pcre.get_substring sub 2) + let sub = Re.Pcre.exec ~rex uri in + (Re.Pcre.get_substring sub 1, Re.Pcre.get_substring sub 2) with Not_found -> (uri, "") in let smethod = string_of_verb hmethod in @@ -920,7 +921,7 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct | false -> Duppy.Io.Split "[\r]?\n[\r]?\n") h in - let lines = Pcre.split ~rex:(Pcre.regexp "[\r]?\n") s in + let lines = Re.Pcre.split ~rex:(Re.Pcre.regexp "[\r]?\n") s in let* hmethod, huri, hprotocol = let s = List.hd lines in if icy then parse_icy_request_line ~port h s @@ -1002,7 +1003,7 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct ~priority:`Non_blocking ~marker:(Duppy.Io.Split "[\r]?\n[\r]?\n") h in - let lines = Pcre.split ~rex:(Pcre.regexp "[\r]?\n") s in + let lines = Re.Pcre.split ~rex:(Re.Pcre.regexp "[\r]?\n") s in let headers = parse_headers lines in handle_source_request ~port ~auth:true ~smethod:`Shout hprotocol h huri headers diff --git a/src/core/io/ffmpeg_io.ml b/src/core/io/ffmpeg_io.ml index 052690de3b..189821de85 100644 --- a/src/core/io/ffmpeg_io.ml +++ b/src/core/io/ffmpeg_io.ml @@ -294,15 +294,18 @@ class http_input ~autostart ~self_sync ~poll_delay ~debug ~on_error ~max_buffer Avutil.Options.get_string ~search_children:true ~name:"icy_metadata_headers" (Av.input_obj input) in - let icy_headers = Pcre.split ~rex:(Pcre.regexp "[\r]?\n") icy_headers in + let icy_headers = + Re.Pcre.split ~rex:(Re.Pcre.regexp "[\r]?\n") icy_headers + in List.fold_left (fun ret header -> if header <> "" then ( try let res = - Pcre.exec ~rex:(Pcre.regexp "([^:]*):\\s*(.*)") header + Re.Pcre.exec ~rex:(Re.Pcre.regexp "([^:]*):\\s*(.*)") header in - (Pcre.get_substring res 1, Pcre.get_substring res 2) :: ret + (Re.Pcre.get_substring res 1, Re.Pcre.get_substring res 2) + :: ret with Not_found -> ret) else ret) [] icy_headers @@ -556,7 +559,7 @@ let register_input is_http = (Lang.apply fn [("", Lang.metadata_list m)]) | None -> List.filter (fun (k, _) -> - not (Pcre.pmatch ~rex:(Pcre.regexp "^id3v2_priv") k)) + not (Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "^id3v2_priv") k)) in let deduplicate_metadata = Lang.to_bool (List.assoc "deduplicate_metadata" p) diff --git a/src/core/io/srt_io.ml b/src/core/io/srt_io.ml index f870441e6d..0d0ad63855 100644 --- a/src/core/io/srt_io.ml +++ b/src/core/io/srt_io.ml @@ -300,7 +300,10 @@ let log = Log.make ["srt"] let log_handler { Srt.Log.message } = let message = - Pcre.substitute ~rex:(Pcre.regexp "[ \r\n]+$") ~subst:(fun _ -> "") message + Re.Pcre.substitute + ~rex:(Re.Pcre.regexp "[ \r\n]+$") + ~subst:(fun _ -> "") + message in log#f conf_level#get "%s" message diff --git a/src/core/operators/chord.ml b/src/core/operators/chord.ml index 741742fd4f..aa6561411a 100644 --- a/src/core/operators/chord.ml +++ b/src/core/operators/chord.ml @@ -67,13 +67,14 @@ class chord metadata_name (source : source) = | Some c -> ( try let sub = - Pcre.exec - ~rex:(Pcre.regexp "^([A-G-](?:b|#)?)(|M|m|M7|m7|dim)$") + Re.Pcre.exec + ~rex: + (Re.Pcre.regexp "^([A-G-](?:b|#)?)(|M|m|M7|m7|dim)$") c in - let n = Pcre.get_substring sub 1 in + let n = Re.Pcre.get_substring sub 1 in let n = note_of_string n in - let m = Pcre.get_substring sub 2 in + let m = Re.Pcre.get_substring sub 2 in ans := (t, n, m) :: !ans with Not_found -> self#log#important "Could not parse chord '%s'." c)) diff --git a/src/core/operators/frei0r_op.ml b/src/core/operators/frei0r_op.ml index 8c06e0c5f0..0ace2135a6 100644 --- a/src/core/operators/frei0r_op.ml +++ b/src/core/operators/frei0r_op.ml @@ -39,7 +39,7 @@ let frei0r_enable = let plugin_dirs = try let path = Unix.getenv "LIQ_FREI0R_PATH" in - Pcre.split ~rex:(Pcre.regexp ":") path + Re.Pcre.split ~rex:(Re.Pcre.regexp ":") path with Not_found -> Frei0r.default_paths class frei0r_filter ~name bgra instance params (source : source) = @@ -317,7 +317,9 @@ let register_plugin fname = let explanation = let e = info.Frei0r.explanation in let e = String.capitalize_ascii e in - let e = Pcre.substitute ~rex:(Pcre.regexp "@") ~subst:(fun _ -> "(at)") e in + let e = + Re.Pcre.substitute ~rex:(Re.Pcre.regexp "@") ~subst:(fun _ -> "(at)") e + in if e = "" then e else if e.[String.length e - 1] = '.' then String.sub e 0 (String.length e - 1) @@ -325,7 +327,9 @@ let register_plugin fname = in let author = let a = info.Frei0r.author in - let a = Pcre.substitute ~rex:(Pcre.regexp "@") ~subst:(fun _ -> "(at)") a in + let a = + Re.Pcre.substitute ~rex:(Re.Pcre.regexp "@") ~subst:(fun _ -> "(at)") a + in a in let descr = Printf.sprintf "%s (by %s)." explanation author in diff --git a/src/core/operators/ladspa_op.ml b/src/core/operators/ladspa_op.ml index a492106db5..82b3a79c2f 100644 --- a/src/core/operators/ladspa_op.ml +++ b/src/core/operators/ladspa_op.ml @@ -366,7 +366,7 @@ let register_descr d = in let maker = d.plugin_maker in let maker = - Pcre.substitute ~rex:(Pcre.regexp "@") ~subst:(fun _ -> "(at)") maker + Re.Pcre.substitute ~rex:(Re.Pcre.regexp "@") ~subst:(fun _ -> "(at)") maker in let descr = Printf.sprintf "%s by %s." d.plugin_name maker in let return_t = diff --git a/src/core/outputs/pipe_output.ml b/src/core/outputs/pipe_output.ml index 6f97fbfa20..e3873f03ba 100644 --- a/src/core/outputs/pipe_output.ml +++ b/src/core/outputs/pipe_output.ml @@ -446,7 +446,7 @@ class virtual ['a] file_output_base p = let filename = Lang_string.home_unrelate filename in (* Avoid / in metas for filename.. *) let subst m = - Pcre.substitute ~rex:(Pcre.regexp "/") ~subst:(fun _ -> "-") m + Re.Pcre.substitute ~rex:(Re.Pcre.regexp "/") ~subst:(fun _ -> "-") m in self#interpolate ~subst filename diff --git a/src/core/playlists/playlist_basic.ml b/src/core/playlists/playlist_basic.ml index 68e15bebf8..8a14dc44b9 100644 --- a/src/core/playlists/playlist_basic.ml +++ b/src/core/playlists/playlist_basic.ml @@ -21,7 +21,7 @@ *****************************************************************************) let log = Log.make ["playlist"; "basic"] -let split_lines buf = Pcre.split ~rex:(Pcre.regexp "[\r\n]+") buf +let split_lines buf = Re.Pcre.split ~rex:(Re.Pcre.regexp "[\r\n]+") buf let parse_meta = let processor = @@ -48,20 +48,20 @@ let parse_meta = let parse_extinf s = try - let rex = Pcre.regexp "#EXTINF:(\\d*)\\s*(.*)" in - let sub = Pcre.exec ~rex s in + let rex = Re.Pcre.regexp "#EXTINF:(\\d*)\\s*(.*)" in + let sub = Re.Pcre.exec ~rex s in let meta, song = - match Pcre.get_substring sub 2 with + match Re.Pcre.get_substring sub 2 with | "" -> ([], "") | s when s.[0] = ',' -> ([], String.sub s 1 (String.length s - 1)) | s -> parse_meta s in let meta = - match Pcre.get_substring sub 1 with + match Re.Pcre.get_substring sub 1 with | "" -> meta | duration -> ("extinf_duration", duration) :: meta in - let lines = Pcre.split ~rex:(Pcre.regexp "\\s*-\\s*") song in + let lines = Re.Pcre.split ~rex:(Re.Pcre.regexp "\\s*-\\s*") song in meta @ match lines with @@ -75,7 +75,7 @@ let parse_extinf s = (* This parser cannot detect the format !! *) let parse_mpegurl ?pwd string = let lines = List.filter (fun x -> x <> "") (split_lines string) in - let is_info line = Pcre.pmatch ~rex:(Pcre.regexp "^#EXTINF") line in + let is_info line = Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "^#EXTINF") line in let skip_line line = line.[0] == '#' in let rec get_urls cur lines = match lines with @@ -91,15 +91,15 @@ let parse_mpegurl ?pwd string = let parse_scpls ?pwd string = let string = - Pcre.substitute - ~rex:(Pcre.regexp "#[^\\r\\n]*[\\n\\r]+") + Re.Pcre.substitute + ~rex:(Re.Pcre.regexp "#[^\\r\\n]*[\\n\\r]+") ~subst:(fun _ -> "") string in (* Format check, raise Not_found if invalid *) ignore - (Pcre.exec - ~rex:(Pcre.regexp "^[\\r\\n\\s]*\\[playlist\\]") + (Re.Pcre.exec + ~rex:(Re.Pcre.regexp "^[\\r\\n\\s]*\\[playlist\\]") (String.lowercase_ascii string)); let lines = split_lines string in let urls = @@ -107,10 +107,10 @@ let parse_scpls ?pwd string = (fun s -> try let rex = - Pcre.regexp ~flags:[`CASELESS] "file\\d*\\s*=\\s*(.*)\\s*" + Re.Pcre.regexp ~flags:[`CASELESS] "file\\d*\\s*=\\s*(.*)\\s*" in - let sub = Pcre.exec ~rex s in - Pcre.get_substring sub 1 + let sub = Re.Pcre.exec ~rex s in + Re.Pcre.get_substring sub 1 with Not_found -> "") lines in @@ -233,7 +233,9 @@ let parse_cue ?pwd string = let strings = List.map (fun string -> - Pcre.substitute ~rex:(Pcre.regexp "^\\s+") ~subst:(fun _ -> "") string) + Re.Pcre.substitute ~rex:(Re.Pcre.regexp "^\\s+") + ~subst:(fun _ -> "") + string) strings in let strings = List.filter (fun s -> s <> "") strings in diff --git a/src/core/request.ml b/src/core/request.ml index 6fc204af8a..47d0463d45 100644 --- a/src/core/request.ml +++ b/src/core/request.ml @@ -60,10 +60,10 @@ let pretty_date date = let remove_file_proto s = (* First remove file:// 🤮 *) let s = - Pcre.substitute ~rex:(Pcre.regexp "^file://") ~subst:(fun _ -> "") s + Re.Pcre.substitute ~rex:(Re.Pcre.regexp "^file://") ~subst:(fun _ -> "") s in (* Then remove file: 😇 *) - Pcre.substitute ~rex:(Pcre.regexp "^file:") ~subst:(fun _ -> "") s + Re.Pcre.substitute ~rex:(Re.Pcre.regexp "^file:") ~subst:(fun _ -> "") s let home_unrelate s = Lang_string.home_unrelate (remove_file_proto s) diff --git a/src/core/source.ml b/src/core/source.ml index f3410eb5cf..d3bd3103e0 100644 --- a/src/core/source.ml +++ b/src/core/source.ml @@ -115,7 +115,10 @@ class virtual operator ?(stack = []) ?clock ?(name = "src") sources = method set_id ?(definitive = true) s = let s = - Pcre.substitute ~rex:(Pcre.regexp "[ \t\n.]") ~subst:(fun _ -> "_") s + Re.Pcre.substitute + ~rex:(Re.Pcre.regexp "[ \t\n.]") + ~subst:(fun _ -> "_") + s in if not definitive_id then ( id <- Lang_string.generate_id s; diff --git a/src/core/sources/harbor_input.ml b/src/core/sources/harbor_input.ml index b56bd637ac..a57f924efd 100644 --- a/src/core/sources/harbor_input.ml +++ b/src/core/sources/harbor_input.ml @@ -177,8 +177,8 @@ class http_input_server ~pos ~transport ~dumpfile ~logfile ~bufferize ~max ~icy method register_decoder mime = let mime = try - let sub = Pcre.exec ~rex:(Pcre.regexp "^([^;]+);.*$") mime in - Pcre.get_substring sub 1 + let sub = Re.Pcre.exec ~rex:(Re.Pcre.regexp "^([^;]+);.*$") mime in + Re.Pcre.get_substring sub 1 with Not_found -> mime in match Decoder.get_stream_decoder ~ctype:self#content_type mime with diff --git a/src/core/stream/ffmpeg_raw_content.ml b/src/core/stream/ffmpeg_raw_content.ml index 0a2dd43954..ecf0994cc0 100644 --- a/src/core/stream/ffmpeg_raw_content.ml +++ b/src/core/stream/ffmpeg_raw_content.ml @@ -228,12 +228,12 @@ module VideoSpecs = struct | "pixel_aspect" -> let pixel_aspect = try - let rex = Pcre.regexp "(\\d+)/(\\d+)" in - let sub = Pcre.exec ~rex value in + let rex = Re.Pcre.regexp "(\\d+)/(\\d+)" in + let sub = Re.Pcre.exec ~rex value in Some { - Avutil.num = int_of_string (Pcre.get_substring sub 1); - den = int_of_string (Pcre.get_substring sub 2); + Avutil.num = int_of_string (Re.Pcre.get_substring sub 1); + den = int_of_string (Re.Pcre.get_substring sub 2); } with _ -> None in diff --git a/src/core/synth/dssi_op.ml b/src/core/synth/dssi_op.ml index 1990fe3936..72f61f00b9 100644 --- a/src/core/synth/dssi_op.ml +++ b/src/core/synth/dssi_op.ml @@ -35,13 +35,13 @@ let dssi_enable = let dssi_load = try let venv = Unix.getenv "LIQ_DSSI_LOAD" in - Pcre.split ~rex:(Pcre.regexp ":") venv + Re.Pcre.split ~rex:(Re.Pcre.regexp ":") venv with Not_found -> [] let plugin_dirs = try let path = Unix.getenv "LIQ_DSSI_PATH" in - Pcre.split ~rex:(Pcre.regexp ":") path + Re.Pcre.split ~rex:(Re.Pcre.regexp ":") path with Not_found -> ["/usr/lib/dssi"; "/usr/local/lib/dssi"] (* Number of channels to synthesize when in all mode *) diff --git a/src/core/tools/liq_http.ml b/src/core/tools/liq_http.ml index a119d2815e..d6eae3835c 100644 --- a/src/core/tools/liq_http.ml +++ b/src/core/tools/liq_http.ml @@ -95,7 +95,7 @@ let user_agent = Configure.vendor let args_split s = let args = Hashtbl.create 2 in let fill_arg arg = - match Pcre.split ~rex:(Pcre.regexp "=") arg with + match Re.Pcre.split ~rex:(Re.Pcre.regexp "=") arg with | e :: l -> (* There should be only arg=value *) List.iter @@ -105,38 +105,38 @@ let args_split s = l | [] -> () in - List.iter fill_arg (Pcre.split ~rex:(Pcre.regexp "&") s); + List.iter fill_arg (Re.Pcre.split ~rex:(Re.Pcre.regexp "&") s); args let parse_url url = let basic_rex = - Pcre.regexp "^([Hh][Tt][Tt][Pp][sS]?)://([^/:]+)(:[0-9]+)?(/.*)?$" + Re.Pcre.regexp "^([Hh][Tt][Tt][Pp][sS]?)://([^/:]+)(:[0-9]+)?(/.*)?$" in let sub = - try Pcre.exec ~rex:basic_rex url + try Re.Pcre.exec ~rex:basic_rex url with Not_found -> (* raise Invalid_url *) failwith "Invalid URL." in - let protocol = Pcre.get_substring sub 1 in - let host = Pcre.get_substring sub 2 in + let protocol = Re.Pcre.get_substring sub 1 in + let host = Re.Pcre.get_substring sub 2 in let port = try - let port = Pcre.get_substring sub 3 in + let port = Re.Pcre.get_substring sub 3 in let port = String.sub port 1 (String.length port - 1) in let port = int_of_string port in Some port with Not_found -> None in - let path = try Pcre.get_substring sub 4 with Not_found -> "/" in + let path = try Re.Pcre.get_substring sub 4 with Not_found -> "/" in { protocol; host; port; path } let is_url path = - Pcre.pmatch ~rex:(Pcre.regexp "^[Hh][Tt][Tt][Pp][sS]?://.+") path + Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "^[Hh][Tt][Tt][Pp][sS]?://.+") path let dirname url = - let rex = Pcre.regexp "^([Hh][Tt][Tt][Pp][sS]?://.+/)[^/]*$" in - let s = Pcre.exec ~rex url in - Pcre.get_substring s 1 + let rex = Re.Pcre.regexp "^([Hh][Tt][Tt][Pp][sS]?://.+/)[^/]*$" in + let s = Re.Pcre.exec ~rex url in + Re.Pcre.get_substring s 1 (* An ugly code to read until we see [\r]?\n n times. *) let read_crlf ?(log = fun _ -> ()) ?(max = 4096) ?(count = 2) ~timeout @@ -195,8 +195,8 @@ let really_read ~timeout (socket : socket) len = (* Read chunked transfer. *) let read_chunked ~timeout (socket : socket) = let read = read_crlf ~count:1 ~timeout socket in - let len = List.hd (Pcre.split ~rex:(Pcre.regexp "[\r]?\n") read) in - let len = List.hd (Pcre.split ~rex:(Pcre.regexp ";") len) in + let len = List.hd (Re.Pcre.split ~rex:(Re.Pcre.regexp "[\r]?\n") read) in + let len = List.hd (Re.Pcre.split ~rex:(Re.Pcre.regexp ";") len) in let len = int_of_string ("0x" ^ len) in let s = really_read socket ~timeout len in ignore (read_crlf ~count:1 ~timeout socket); diff --git a/src/core/tools/liqcurl.ml b/src/core/tools/liqcurl.ml index d1847fb617..d432251bf1 100644 --- a/src/core/tools/liqcurl.ml +++ b/src/core/tools/liqcurl.ml @@ -193,7 +193,7 @@ let rec http_request ?headers ?http_version ~follow_redirect ~timeout ~url ~request ~on_body_data ~pos () | _ -> let response_headers = - Pcre.split ~rex:(Pcre.regexp "[\r]?\n") + Re.Pcre.split ~rex:(Re.Pcre.regexp "[\r]?\n") (Buffer.contents response_headers) in let http_version, status_code, status_message = @@ -205,10 +205,12 @@ let rec http_request ?headers ?http_version ~follow_redirect ~timeout ~url if header <> "" then ( try let res = - Pcre.exec ~rex:(Pcre.regexp "([^:]*):\\s*(.*)") header + Re.Pcre.exec + ~rex:(Re.Pcre.regexp "([^:]*):\\s*(.*)") + header in - ( String.lowercase_ascii (Pcre.get_substring res 1), - Pcre.get_substring res 2 ) + ( String.lowercase_ascii (Re.Pcre.get_substring res 1), + Re.Pcre.get_substring res 2 ) :: ret with Not_found -> ret) else ret) diff --git a/src/core/tools/sandbox.ml b/src/core/tools/sandbox.ml index 3fb8e74e63..4cd30955a4 100644 --- a/src/core/tools/sandbox.ml +++ b/src/core/tools/sandbox.ml @@ -41,7 +41,7 @@ let conf_setenv = let get_setenv () = List.fold_left (fun cur s -> - match Pcre.split ~rex:(Pcre.regexp "=") s with + match Re.Pcre.split ~rex:(Re.Pcre.regexp "=") s with | [] -> cur | lbl :: l -> (lbl, String.concat "=" l) :: cur) [] conf_setenv#get diff --git a/src/core/tools/server.ml b/src/core/tools/server.ml index bcb19e0386..d35bc5474e 100644 --- a/src/core/tools/server.ml +++ b/src/core/tools/server.ml @@ -238,7 +238,9 @@ let () = ~descr:"Get information on available commands." (fun args -> try let args = - Pcre.substitute ~rex:(Pcre.regexp "\\s*") ~subst:(fun _ -> "") args + Re.Pcre.substitute ~rex:(Re.Pcre.regexp "\\s*") + ~subst:(fun _ -> "") + args in let _, us, d = Mutex_utils.mutexify lock (Hashtbl.find commands) args in Printf.sprintf "Usage: %s\r\n %s" us d diff --git a/src/core/tools/tutils.ml b/src/core/tools/tutils.ml index 962b3c9ead..b7faea6678 100644 --- a/src/core/tools/tutils.ml +++ b/src/core/tools/tutils.ml @@ -191,7 +191,7 @@ let create ~queue f x s = (Printexc.to_string e); Printexc.raise_with_backtrace e raw_bt with e -> - let l = Pcre.split ~rex:(Pcre.regexp "\n") bt in + let l = Re.Pcre.split ~rex:(Re.Pcre.regexp "\n") bt in List.iter (log#info "%s") l; Mutex_utils.mutexify lock (fun () -> diff --git a/src/core/tools/utils.ml b/src/core/tools/utils.ml index 47baa170e0..b341f3b0ca 100644 --- a/src/core/tools/utils.ml +++ b/src/core/tools/utils.ml @@ -291,10 +291,10 @@ let strftime ?time str : string = ] in let subst sub = - let key = Pcre.get_substring sub 1 in + let key = Re.Pcre.get_substring sub 1 in try List.assoc key assoc with _ -> "%" ^ key in - Re.replace (Pcre.regexp "%(.)") ~f:subst str + Re.replace (Re.Pcre.regexp "%(.)") ~f:subst str (** Check if a directory exists. *) let is_dir d = @@ -327,9 +327,9 @@ let get_tempdir () = (** Get a file/uri extension. *) let get_ext s = try - let rex = Pcre.regexp "\\.([a-zA-Z0-9]+)[^.]*$" in - let ret = Pcre.exec ~rex s in - String.lowercase_ascii (Pcre.get_substring ret 1) + let rex = Re.Pcre.regexp "\\.([a-zA-Z0-9]+)[^.]*$" in + let ret = Re.Pcre.exec ~rex s in + String.lowercase_ascii (Re.Pcre.get_substring ret 1) with _ -> raise Not_found let get_ext_opt s = try Some (get_ext s) with Not_found -> None @@ -354,22 +354,34 @@ let uptime = (** Generate a string which can be used as a parameter name. *) let normalize_parameter_string s = let s = - Pcre.substitute - ~rex:(Pcre.regexp "( *\\([^\\)]*\\)| *\\[[^\\]]*\\])") + Re.Pcre.substitute + ~rex:(Re.Pcre.regexp "( *\\([^\\)]*\\)| *\\[[^\\]]*\\])") ~subst:(fun _ -> "") s in let s = - Pcre.substitute ~rex:(Pcre.regexp "(\\.+|\\++)") ~subst:(fun _ -> "") s + Re.Pcre.substitute + ~rex:(Re.Pcre.regexp "(\\.+|\\++)") + ~subst:(fun _ -> "") + s in - let s = Pcre.substitute ~rex:(Pcre.regexp " +$") ~subst:(fun _ -> "") s in let s = - Pcre.substitute ~rex:(Pcre.regexp "( +|/+|-+)") ~subst:(fun _ -> "_") s + Re.Pcre.substitute ~rex:(Re.Pcre.regexp " +$") ~subst:(fun _ -> "") s + in + let s = + Re.Pcre.substitute + ~rex:(Re.Pcre.regexp "( +|/+|-+)") + ~subst:(fun _ -> "_") + s + in + let s = + Re.Pcre.substitute ~rex:(Re.Pcre.regexp "\"") ~subst:(fun _ -> "") s in - let s = Pcre.substitute ~rex:(Pcre.regexp "\"") ~subst:(fun _ -> "") s in let s = String.lowercase_ascii s in (* Identifiers cannot begin with a digit. *) - let s = if Pcre.pmatch ~rex:(Pcre.regexp "^[0-9]") s then "_" ^ s else s in + let s = + if Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "^[0-9]") s then "_" ^ s else s + in s (** A function to reopen a file descriptor diff --git a/src/runtime/dune b/src/runtime/dune index 9b3c8e8676..859df39273 100644 --- a/src/runtime/dune +++ b/src/runtime/dune @@ -4,7 +4,6 @@ (pps ppx_string)) (libraries liquidsoap_core - liquidsoap_stdlib liquidsoap_optionals liquidsoap_builtins (select diff --git a/src/runtime/main.ml b/src/runtime/main.ml index 3166b70dad..743b01ca16 100644 --- a/src/runtime/main.ml +++ b/src/runtime/main.ml @@ -194,7 +194,7 @@ let format_doc s = let prefix = "\t " in let indent = 8 + 2 in let max_width = 80 in - let s = Pcre.split ~rex:(Pcre.regexp " ") s in + let s = Re.Pcre.split ~rex:(Re.Pcre.regexp " ") s in let s = let rec join line width = function | [] -> [line] diff --git a/src/stdlib/dune b/src/stdlib/dune deleted file mode 100644 index 6c0acc16a2..0000000000 --- a/src/stdlib/dune +++ /dev/null @@ -1,12 +0,0 @@ -(env - (release - (ocamlopt_flags - (:standard -w -9 -alert --deprecated -O2))) - (_ - (flags - (:standard -w -9 -alert --deprecated)))) - -(library - (name liquidsoap_stdlib) - (wrapped false) - (libraries threads liquidsoap_lang)) diff --git a/src/stdlib/hashtbl.ml b/src/stdlib/hashtbl.ml deleted file mode 100644 index 00627f5a19..0000000000 --- a/src/stdlib/hashtbl.ml +++ /dev/null @@ -1 +0,0 @@ -include Stdlib.Hashtbl diff --git a/src/stdlib/hashtbl.mli b/src/stdlib/hashtbl.mli deleted file mode 100644 index 5e8d17006a..0000000000 --- a/src/stdlib/hashtbl.mli +++ /dev/null @@ -1,17 +0,0 @@ -type (!'a, !'b) t = ('a, 'b) Stdlib.Hashtbl.t - -val create : ?random:bool -> int -> ('a, 'b) t -val length : ('a, 'b) t -> int -val copy : ('a, 'b) t -> ('a, 'b) t -val mem : ('a, 'b) t -> 'a -> bool -val find : ('a, 'b) t -> 'a -> 'b -val find_opt : ('a, 'b) t -> 'a -> 'b option -val remove : ('a, 'b) t -> 'a -> unit -val replace : ('a, 'b) t -> 'a -> 'b -> unit -val iter : ('a -> 'b -> unit) -> ('a, 'b) t -> unit -val filter_map_inplace : ('a -> 'b -> 'b option) -> ('a, 'b) t -> unit -val fold : ('a -> 'b -> 'acc -> 'acc) -> ('a, 'b) t -> 'acc -> 'acc -val hash : 'a -> int -val reset : ('a, 'b) t -> unit - -module Make : module type of Stdlib.Hashtbl.Make diff --git a/src/stdlib/pcre.ml b/src/stdlib/pcre.ml deleted file mode 100644 index 68bbc5e16d..0000000000 --- a/src/stdlib/pcre.ml +++ /dev/null @@ -1 +0,0 @@ -include Re.Pcre diff --git a/src/stdlib/pcre.mli b/src/stdlib/pcre.mli deleted file mode 100644 index 9d0cbfad59..0000000000 --- a/src/stdlib/pcre.mli +++ /dev/null @@ -1 +0,0 @@ -include module type of Re.Pcre