summaryrefslogtreecommitdiff
path: root/ocaml/scripts/process_pill.ml
blob: c02f6ed35cf7630df82922ecfc647410ad26d0bf (plain)
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
open Nock_lib

let read_bytes path =
  let ic = open_in_bin path in
  let len = in_channel_length ic in
  let data = really_input_string ic len in
  close_in ic;
  Bytes.of_string data

let describe_root noun =
  match noun with
  | Noun.Cell (tag, _) ->
      begin match tag with
      | Noun.Atom z -> Printf.printf "tag=%s\n" (Z.to_string z)
      | _ -> Printf.printf "tag=cell\n"
      end
  | Noun.Atom _ -> Printf.printf "atom pill\n"

let () =
  if Array.length Sys.argv < 2 then begin
    prerr_endline "usage: process_pill path";
    exit 1
  end;
  let path = Sys.argv.(1) in
  let bytes = read_bytes path in
  let noun = Serial.cue bytes in
  describe_root noun