/usr/bin/atdgen-cppo is in libatdgen-ocaml-dev 1.9.1-2+b2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #! /bin/sh -e
version=1.0.0
self="$0"
usage () {
echo "\
Usage: $self [t] [b] [j] [v]
atdgen-cppo makes it possible to use atdgen to derive code from ATD
type definitions embedded in OCaml source files rather than in
separate .atd files. This is similar to how json-static is used,
except that the preprocessor is not camlp4 but the simpler program cppo.
Modes:
t produce a module T containing OCaml type definitions translated from ATD
b produce a module B containing OCaml code for biniou serialization
j produce a module J containing OCaml code JSON serialization
v produce a module V containing OCaml code for validation
Typical usage:
\$ cat example.ml
#ext json
type mytype = string list
#endext
let data = [ \"Hello\"; \"world\" ]
let () = print_endline (J.string_of_mytype data)
\$ ocamlfind opt -o example \\
-pp 'cppo -x \"json:$self t j\"' \\
-package atdgen -linkpkg example.ml
\$ ./example
[\"Hello\",\"world\"]
" >&2
}
case "$1" in
-h|-help|--help) usage; exit 0 ;;
*) ;;
esac
tmp=$(tempfile -p ml- -s -atdgen-cppo.ml)
cat > $tmp
fail () {
rm -f $tmp
exit 1
}
# CPPO_FIRST_LINE is off by one in cppo 0.9.1.
# Should be fixed in cppo rather than here.
gen () {
echo "module $1 = ("
atdgen \
-pos-fname "$CPPO_FILE" \
-pos-lnum $(( $CPPO_FIRST_LINE + 1 )) \
-$2 < $tmp || fail
echo ")"
}
while [ $# != 0 ]; do
case "$1" in
t) gen T t ;;
b) gen B b ;;
j) gen J j ;;
v) gen V v ;;
--help|-help) usage; exit 0 ;;
*) usage; exit 2
esac
shift
done
rm -f $tmp
|