<commit_before>#!/usr/bin/env ruby

$LOAD_PATH.unshift("./rb")

require 'yaml'

require 'c_formatter'
require 'message'
require 'group'
require 'field'
require 'type'

def validate(hash, *keys)
  h_keys = hash.keys
  unless keys == keys & h_keys
    raise "Missing keys: #{(keys - h_keys).join(", ")}."
  end
end

def compile_files(*files)
  definitions = files.map do |f|
    begin
      YAML.load(File.read(f))
    rescue Exception => e
      $stderr.puts "Unable to parse file: #{f}."
      raise e
    end
  end.reduce {|a,b| a.concat b}

  h_messages = definitions.find_all {|d| d["message"]}
  messages = h_messages.map do |m|
    begin
      Message.from_hash(m)
    rescue Exception => e
      $stderr.puts "Not a message: #{m}."
      raise e
    end
  end

  h_groups = definitions.find_all {|d| d["group"]}
  groups = h_groups.map do |g|
    begin
      Group.from_hash(g)
    rescue Exception => e
      $stderr.puts "Not a group: #{g}."
      raise e
    end
  end

  c = CFormatter.new

  messages.each { |req| req.format_struct(c) }
  groups.each { |grp| grp.format_enumeration(c) }
  groups.each { |grp| grp.format_struct(c) }
  groups.each { |grp| grp.format_packer(c) }
  groups.each { |grp| grp.format_unpacker(c) }

  puts c.to_s
end

compile_files(*ARGV)<commit_msg>Update to pass name and use new name.<commit_after>#!/usr/bin/env ruby

$LOAD_PATH.unshift("./rb")

require 'yaml'

require 'c_formatter'
require 'message'
require 'group'
require 'field'
require 'type'

def validate(hash, *keys)
  h_keys = hash.keys
  unless keys == keys & h_keys
    raise "Missing keys: #{(keys - h_keys).join(", ")}."
  end
end

def compile_files(*files)
  definitions = files.map do |f|
    begin
      YAML.load(File.read(f))
    rescue Exception => e
      $stderr.puts "Unable to parse file: #{f}."
      raise e
    end
  end.reduce {|a,b| a.concat b}

  h_messages = definitions.find_all {|d| d["message"]}
  messages = h_messages.map do |m|
    begin
      Message.from_hash(m)
    rescue Exception => e
      $stderr.puts "Not a message: #{m}."
      raise e
    end
  end

  h_groups = definitions.find_all {|d| d["group"]}
  groups = h_groups.map do |g|
    begin
      Group.from_hash(g)
    rescue Exception => e
      $stderr.puts "Not a group: #{g}."
      raise e
    end
  end

  c = CFormatter.new("cauterize_example")

  messages.each { |req| req.format_struct(c) }
  groups.each { |grp| grp.format_enumeration(c) }
  groups.each { |grp| grp.format_struct(c) }
  groups.each { |grp| grp.format_packer(c) }
  groups.each { |grp| grp.format_unpacker(c) }

  puts c.c_text
end

compile_files(*ARGV)
{'fraction_non_alphanumeric': 0.14383822968332696, 'fraction_numerical': 0.0, 'mean_word_length': 3.003053435114504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5149543', 'n_tokens_mistral': 996, 'n_tokens_neox': 994, 'n_words': 246}