add include library: taler_signatures.ml

This commit is contained in:
swrup 2025-10-06 22:26:50 +02:00
parent 46caf0b578
commit b7b28af6fe
4 changed files with 112 additions and 0 deletions

39
include/dune Normal file
View file

@ -0,0 +1,39 @@
(library
(name include)
; (wrapped false)
(modules taler_signatures)
(libraries))
(rule
(targets taler_signatures.ml)
(deps ./gen_taler_signatures.exe)
(action
(with-stdout-to
%{targets}
(run ./gen_taler_signatures.exe))))
(executable
(name gen_taler_signatures)
(modules gen_taler_signatures data)
(libraries fmt angstrom))
(rule
(targets taler_signatures.h)
(action
(run
wget
-q
-O
%{targets}
"https://git.taler.net/exchange.git/plain/src/include/taler/taler_signatures.h")))
(rule
(targets data.ml)
(deps taler_signatures.h)
(action
(with-stdout-to
%{targets}
(progn
(echo "let content = {|")
(cat taler_signatures.h)
(echo "|}")))))

View file

@ -0,0 +1,48 @@
(* script to generate taler_signatures.ml module
get signatures definition form `exchange/src/include/taler/taler_signatures.h` *)
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 () =
let l = parse Data.content in
assert (List.length l = 74);
let pp ppf { name; value } = Fmt.pf ppf "let %s = %d@." name value in
Fmt.pr "%a" (Fmt.list pp) l;
()