This commit is contained in:
parent
21d172d884
commit
585b3e10af
3 changed files with 1518 additions and 1 deletions
1458
registry.rec
Normal file
1458
registry.rec
Normal file
File diff suppressed because it is too large
Load diff
10
tools/dune
10
tools/dune
|
|
@ -4,4 +4,12 @@
|
||||||
(modules offline offline_impl offline_sig)
|
(modules offline offline_impl offline_sig)
|
||||||
(libraries cmdliner bos fmt mirage-crypto ptime mte vif))
|
(libraries cmdliner bos fmt mirage-crypto ptime mte vif))
|
||||||
|
|
||||||
; todo depends on curl
|
(executable
|
||||||
|
(public_name gen_signatures_registry)
|
||||||
|
(name gen_signatures_registry)
|
||||||
|
(modules gen_signatures_registry)
|
||||||
|
(libraries angstrom fmt))
|
||||||
|
|
||||||
|
; todo
|
||||||
|
; we depends on curl
|
||||||
|
; fetch "gnunet-signatures/registry.rec"
|
||||||
|
|
|
||||||
51
tools/gen_signatures_registry.ml
Normal file
51
tools/gen_signatures_registry.ml
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
open Angstrom
|
||||||
|
|
||||||
|
type define = {
|
||||||
|
name: string;
|
||||||
|
value: int;
|
||||||
|
}
|
||||||
|
|
||||||
|
let define_line =
|
||||||
|
let is_ident_char = function
|
||||||
|
| 'A' .. 'Z' | '0' .. '9' | '_' -> true
|
||||||
|
| _ -> false
|
||||||
|
in
|
||||||
|
let p =
|
||||||
|
string "#define"
|
||||||
|
*> skip_while (( = ) ' ')
|
||||||
|
*> string "TALER_SIGNATURE_"
|
||||||
|
*> take_while1 is_ident_char
|
||||||
|
>>= fun name ->
|
||||||
|
skip_while (( = ) ' ')
|
||||||
|
*> take_while1 (function '0' .. '9' -> true | _ -> false)
|
||||||
|
>>| fun digits ->
|
||||||
|
let name = String.lowercase_ascii name in
|
||||||
|
let value = int_of_string digits in
|
||||||
|
{ name; value }
|
||||||
|
in
|
||||||
|
p <* end_of_line
|
||||||
|
|
||||||
|
let all_defines =
|
||||||
|
let any_line = take_till (Char.equal '\n') <* end_of_line in
|
||||||
|
many (choice [ define_line >>| Option.some; any_line *> return None ])
|
||||||
|
>>| List.filter_map Fun.id
|
||||||
|
|
||||||
|
let parse input =
|
||||||
|
match parse_string ~consume:All all_defines input with
|
||||||
|
| Ok defs -> defs
|
||||||
|
| Error msg -> failwith msg
|
||||||
|
|
||||||
|
let read_file file = In_channel.with_open_bin file In_channel.input_all
|
||||||
|
|
||||||
|
let () =
|
||||||
|
let content = read_file "taler_signatures.h" in
|
||||||
|
let l = parse content in
|
||||||
|
assert (List.length l = 74);
|
||||||
|
|
||||||
|
let pp_line ppf { name; value } =
|
||||||
|
Fmt.pf ppf "let %s : int32 = %d_l@." name value
|
||||||
|
in
|
||||||
|
|
||||||
|
Fmt.pr "%a@." (Fmt.list ~sep:Fmt.nop pp_line) l;
|
||||||
|
|
||||||
|
()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue