<commit_before>module: gir-generate-c-ffi
synopsis: generate c-ffi bindings using gobject-introspection
author: <NAME>.
copyright: See LICENSE file in this distribution.

define function main (arguments :: <sequence>)
  // XXX: Check arguments, we want to be able to
  // add to the search path, list the search
  // path, get help, and say what namespace
  // and version to load and generate bindings
  // for.
  // But for now:
  let namespace = "GLib";
  let version = "2.0";
  load-typelib(namespace, version);
  generate-c-ffi(namespace, version);
end function;

define function load-typelib
    (namespace :: <string>, version :: <string>)
 => ()
  let repo = g-irepository-get-default();
  let (typelib, error) = g-irepository-require(repo, namespace, version, 0);
  if (~null-pointer?(error) | null-pointer?(typelib))
    // XXX: signal an error
  end if;
end function;

main(application-arguments());<commit_msg>Add some basic command line parsing + TODOs.<commit_after>module: gir-generate-c-ffi
synopsis: generate c-ffi bindings using gobject-introspection
author: <NAME>, Jr.
copyright: See LICENSE file in this distribution.

define function parse-args
    (args :: <sequence>)
 => (parser :: <command-line-parser>)
  let parser = make(<command-line-parser>);
  add-option(parser,
             make(<optional-parameter-option>,
                  names: #("version"),
                  default: #f,
                  help: "Version of the library to generate bindings for. Defaults to most recent."));
  // XXX: Should add a repeated-option-parameter for the search path.
  block ()
    parse-command-line(parser, args,
                       usage: "gir-generate-c-ffi [options] namespaces...",
                       description: "Generates C-FFI bindings from gobject-introspection data.");
  exception (ex :: <help-requested>)
    exit-application(0);
  exception (ex :: <usage-error>)
    exit-application(2);
  end;
  parser
end;

define function main (arguments :: <sequence>)
  let parser = parse-args(arguments);
  let namespaces = positional-options(parser);
  let version = get-option-value(parser, "version") | null-pointer(<C-string>);
  // XXX: Fail nicely if no namespaces.
  // XXX: Fail if they specify a version and more than one namespace.
  for (namespace in namespaces)
    load-typelib(namespace, version);
    generate-c-ffi(namespace, version);
  end for;
end function;

define function load-typelib
    (namespace :: <string>, version :: <string>)
 => ()
  let repo = g-irepository-get-default();
  // XXX: Check to see if the namespace is valid via g-irepository-is-registered()?
  let (typelib, error) = g-irepository-require(repo, namespace, version, 0);
  if (~null-pointer?(error) | null-pointer?(typelib))
    // XXX: signal an error
  end if;
end function;

main(application-arguments());
{'fraction_non_alphanumeric': 0.13060360042357924, 'fraction_numerical': 0.002117896223085069, 'mean_word_length': 3.3802163833075736, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2203349', 'n_tokens_mistral': 846, 'n_tokens_neox': 838, 'n_words': 270}