Skip to content

Commit

Permalink
Merge pull request #101 from avsm/2.1.0
Browse files Browse the repository at this point in the history
release 2.1.0
  • Loading branch information
avsm committed May 4, 2016
2 parents 99fea69 + dc3af96 commit acf815d
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 38 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.1.0 (2016-05-04):
* Add `hexdump_pp` that uses the Format module. This works better with the
Logs library than using `hexdump_to_buffer`, and also makes it easy to
indent the hexdump (#100 via @talex5).

2.0.0 (2016-04-26):
* Remove camlp4 extension as it is no longer maintained (#95).
* Add support for OCaml 4.03 in the PPX extension (#96).
Expand Down
2 changes: 1 addition & 1 deletion _oasis
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
OASISFormat: 0.4
Name: cstruct
Version: 2.0.0
Version: 2.1.0
Synopsis: Manipulate external buffers as C-like structs
Authors: Anil Madhavapeddy, Richard Mortier, Thomas Gazagnaire,
Pierre Chambart, David Kaloper, Jeremy Yallop, Hannes Mehnert
Expand Down
10 changes: 5 additions & 5 deletions lib/META
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OASIS_START
# DO NOT EDIT (digest: 6703f2730ed43249652bba9166b1333d)
version = "2.0.0"
# DO NOT EDIT (digest: b31e1f4fb49e5a628c483cf08bc25c80)
version = "2.1.0"
description = "Manipulate external buffers as C-like structs"
requires = "bytes bigarray ocplib-endian ocplib-endian.bigstring sexplib"
archive(byte) = "cstruct.cma"
Expand All @@ -9,7 +9,7 @@ archive(native) = "cstruct.cmxa"
archive(native, plugin) = "cstruct.cmxs"
exists_if = "cstruct.cma"
package "unix" (
version = "2.0.0"
version = "2.1.0"
description = "Manipulate external buffers as C-like structs"
requires = "cstruct unix"
archive(byte) = "unix_cstruct.cma"
Expand All @@ -20,7 +20,7 @@ package "unix" (
)

package "lwt" (
version = "2.0.0"
version = "2.1.0"
description = "Manipulate external buffers as C-like structs"
requires = "cstruct lwt.unix"
archive(byte) = "lwt_cstruct.cma"
Expand All @@ -31,7 +31,7 @@ package "lwt" (
)

package "async" (
version = "2.0.0"
version = "2.1.0"
description = "Manipulate external buffers as C-like structs"
requires = "cstruct async threads"
archive(byte) = "async_cstruct.cma"
Expand Down
174 changes: 167 additions & 7 deletions myocamlbuild.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* OASIS_START *)
(* DO NOT EDIT (digest: 51516879eeeef9c4571a10d0d5ad7b1a) *)
(* DO NOT EDIT (digest: f43efae5a77d2acd4796985623006383) *)
module OASISGettext = struct
(* # 22 "src/oasis/OASISGettext.ml" *)

Expand Down Expand Up @@ -29,6 +29,166 @@ module OASISGettext = struct

end

module OASISString = struct
(* # 22 "src/oasis/OASISString.ml" *)


(** Various string utilities.
Mostly inspired by extlib and batteries ExtString and BatString libraries.
@author Sylvain Le Gall
*)


let nsplitf str f =
if str = "" then
[]
else
let buf = Buffer.create 13 in
let lst = ref [] in
let push () =
lst := Buffer.contents buf :: !lst;
Buffer.clear buf
in
let str_len = String.length str in
for i = 0 to str_len - 1 do
if f str.[i] then
push ()
else
Buffer.add_char buf str.[i]
done;
push ();
List.rev !lst


(** [nsplit c s] Split the string [s] at char [c]. It doesn't include the
separator.
*)
let nsplit str c =
nsplitf str ((=) c)


let find ~what ?(offset=0) str =
let what_idx = ref 0 in
let str_idx = ref offset in
while !str_idx < String.length str &&
!what_idx < String.length what do
if str.[!str_idx] = what.[!what_idx] then
incr what_idx
else
what_idx := 0;
incr str_idx
done;
if !what_idx <> String.length what then
raise Not_found
else
!str_idx - !what_idx


let sub_start str len =
let str_len = String.length str in
if len >= str_len then
""
else
String.sub str len (str_len - len)


let sub_end ?(offset=0) str len =
let str_len = String.length str in
if len >= str_len then
""
else
String.sub str 0 (str_len - len)


let starts_with ~what ?(offset=0) str =
let what_idx = ref 0 in
let str_idx = ref offset in
let ok = ref true in
while !ok &&
!str_idx < String.length str &&
!what_idx < String.length what do
if str.[!str_idx] = what.[!what_idx] then
incr what_idx
else
ok := false;
incr str_idx
done;
if !what_idx = String.length what then
true
else
false


let strip_starts_with ~what str =
if starts_with ~what str then
sub_start str (String.length what)
else
raise Not_found


let ends_with ~what ?(offset=0) str =
let what_idx = ref ((String.length what) - 1) in
let str_idx = ref ((String.length str) - 1) in
let ok = ref true in
while !ok &&
offset <= !str_idx &&
0 <= !what_idx do
if str.[!str_idx] = what.[!what_idx] then
decr what_idx
else
ok := false;
decr str_idx
done;
if !what_idx = -1 then
true
else
false


let strip_ends_with ~what str =
if ends_with ~what str then
sub_end str (String.length what)
else
raise Not_found


let replace_chars f s =
let buf = Buffer.create (String.length s) in
String.iter (fun c -> Buffer.add_char buf (f c)) s;
Buffer.contents buf

let lowercase_ascii =
replace_chars
(fun c ->
if (c >= 'A' && c <= 'Z') then
Char.chr (Char.code c + 32)
else
c)

let uncapitalize_ascii s =
if s <> "" then
(lowercase_ascii (String.sub s 0 1)) ^ (String.sub s 1 ((String.length s) - 1))
else
s

let uppercase_ascii =
replace_chars
(fun c ->
if (c >= 'a' && c <= 'z') then
Char.chr (Char.code c - 32)
else
c)

let capitalize_ascii s =
if s <> "" then
(uppercase_ascii (String.sub s 0 1)) ^ (String.sub s 1 ((String.length s) - 1))
else
s

end

module OASISExpr = struct
(* # 22 "src/oasis/OASISExpr.ml" *)

Expand Down Expand Up @@ -129,7 +289,7 @@ module OASISExpr = struct
end


# 132 "myocamlbuild.ml"
# 292 "myocamlbuild.ml"
module BaseEnvLight = struct
(* # 22 "src/base/BaseEnvLight.ml" *)

Expand Down Expand Up @@ -234,7 +394,7 @@ module BaseEnvLight = struct
end


# 237 "myocamlbuild.ml"
# 397 "myocamlbuild.ml"
module MyOCamlbuildFindlib = struct
(* # 22 "src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *)

Expand Down Expand Up @@ -516,7 +676,7 @@ module MyOCamlbuildBase = struct
| nm, [], intf_modules ->
ocaml_lib nm;
let cmis =
List.map (fun m -> (String.uncapitalize m) ^ ".cmi")
List.map (fun m -> (OASISString.uncapitalize_ascii m) ^ ".cmi")
intf_modules in
dep ["ocaml"; "link"; "library"; "file:"^nm^".cma"] cmis
| nm, dir :: tl, intf_modules ->
Expand All @@ -529,7 +689,7 @@ module MyOCamlbuildBase = struct
["compile"; "infer_interface"; "doc"])
tl;
let cmis =
List.map (fun m -> dir^"/"^(String.uncapitalize m)^".cmi")
List.map (fun m -> dir^"/"^(OASISString.uncapitalize_ascii m)^".cmi")
intf_modules in
dep ["ocaml"; "link"; "library"; "file:"^dir^"/"^nm^".cma"]
cmis)
Expand Down Expand Up @@ -603,7 +763,7 @@ module MyOCamlbuildBase = struct
end


# 606 "myocamlbuild.ml"
# 766 "myocamlbuild.ml"
open Ocamlbuild_plugin;;
let package_default =
{
Expand Down Expand Up @@ -638,6 +798,6 @@ let conf = {MyOCamlbuildFindlib.no_automatic_syntax = false}

let dispatch_default = MyOCamlbuildBase.dispatch_default conf package_default;;

# 642 "myocamlbuild.ml"
# 802 "myocamlbuild.ml"
(* OASIS_STOP *)
Ocamlbuild_plugin.dispatch dispatch_default;;
Loading

0 comments on commit acf815d

Please sign in to comment.