<commit_before>#include "parser/PsdParser.h"

#include "formatter/TextFormatter.h"
#include "formatter/XmlFormatter.h"
#include "formatter/JsonFormatter.h"

#include <stdio.h>


int main(int argc, char **argv)
{
	if (argc < 2) {
		printf("Usage: psdump <PSD file name>");
		return -1;
	}

	PsdParser parser(argv[1]);
	Document *doc = parser.parse();

	//	TextFormatter text_dumper;
	// 	text_dumper.dump_doc_to_file(doc, stdout);

	//      JsonFormatter json_dumper;
	//     	json_dumper.dump_doc_to_file(doc, stdout);

		XmlFormatter xml_dumper;
		xml_dumper.dump_doc_to_file(doc, stdout);

	delete doc;

	return 0;
}
<commit_msg>Revamp main.cpp and add a basic command line interface with options.<commit_after>#include "parser/PsdParser.h"

#include "formatter/TextFormatter.h"
#include "formatter/XmlFormatter.h"
#include "formatter/JsonFormatter.h"

#include <stdio.h>


typedef enum {
  kOutputFormatText,
  kOutputFormatXml,
  kOutputFormatJson,
} OutputFormat;


int main(int argc, char **argv)
{
  int option;
  char *f_value = NULL;
  char *o_value = NULL;

  OutputFormat output_format = kOutputFormatText;

  opterr = 0;

  while ((option = getopt(argc, argv, "f:o:")) != -1) {
    switch (option) {
    case 'f':
      f_value = optarg;
      break;

    case 'o':
      o_value = optarg;
      break;

    case '?':
      if (optopt == 'f' || optopt == 'o')
	fprintf(stderr, "Missing argument for option -%c.\n", optopt);
      else if (isprint(optopt))
	fprintf(stderr, "Unknown option '-%c'.\n", optopt);
      else
	fprintf(stderr, "Unknown option character ''\\x%x'.\n", optopt);
      return 1;

    default:
      fprintf(stderr, "Uknown option value '%c'", option);
      abort();
    }
  }

  if (optind >= argc) {
    printf("Usage: psdump [-f FORMAT] [-o OUTPUT_PATH] file ...\n");
    return 2;
  }

  if (f_value) {
    if (strcmp(f_value, "xml") == 0) {
      output_format = kOutputFormatXml;
    } else if (strcmp(f_value, "json") == 0) {
      output_format = kOutputFormatJson;
    }
  }

  TextFormatter *formatter;

  switch (output_format) {
  case kOutputFormatXml:
    formatter = new XmlFormatter();
    break;

  case kOutputFormatJson:
    formatter = new JsonFormatter();
    break;

  default:
    formatter = new TextFormatter();
  }

  for (int index = optind; index < argc; ++index) {
    PsdParser parser(argv[index]);
    Document *doc = parser.parse();

    if (!doc) {
      fprintf(stderr, "Failed to open file '%s'.\n", argv[index]);
      continue;
    }

    formatter->dump_doc_to_file(doc, stdout);

    delete doc;
  }

  delete formatter;

  return 0;
}

{'fraction_non_alphanumeric': 0.14367816091954022, 'fraction_numerical': 0.00421455938697318, 'mean_word_length': 3.2112903225806453, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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': '5059538', 'n_tokens_mistral': 966, 'n_tokens_neox': 918, 'n_words': 224}