<commit_before>#include <cstdio>
#include <cstdlib>
#include <locale>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>  // NOLINT
#include <algorithm>
#include <tr1/array>
#include "config/config.h"

#include "stringpiece.h"
#include "ustringpiece.h"

#include "cmdline.h"
#include "ast.h"

#include "ast-serializer.h"

#include "parser.h"
#include "factory.h"

#include "interpreter.h"
#include "context.h"
#include "jsast.h"
#include "jsval.h"
#include "jsstring.h"
#include "jsscript.h"
#include "print.h"
#include "interactive.h"

#include "icu/ustream.h"
#include "icu/source.h"

#include "fpu.h"

int main(int argc, char **argv) {
  using iv::lv5::JSVal;
  iv::lv5::FixFPU();

  std::locale::global(std::locale(""));

  iv::cmdline::Parser cmd("lv5");

  cmd.Add("help",
          "help",
          'h', "print this message");
  cmd.Add("version",
          "version",
          'v', "print the version");
  cmd.Add("warning",
          "",
          'W', "set warning level 0 - 2", false, 0, iv::cmdline::range(0, 2));
  cmd.Add("ast",
          "ast",
          0, "print ast");
  cmd.Add("copyright",
          "copyright",
          0,   "print the copyright");
  cmd.set_footer("[program_file] [arguments]");

  bool cmd_parse_success = cmd.Parse(argc, argv);
  if (!cmd_parse_success) {
    std::cerr << cmd.error() << std::endl << cmd.usage();
    return EXIT_FAILURE;
  }

  if (cmd.Exist("help")) {
    std::cout << cmd.usage();
    return EXIT_SUCCESS;
  }

  if (cmd.Exist("version")) {
    printf("lv5 %s (compiled %s %s)\n", IV_VERSION, __DATE__, __TIME__);
    return EXIT_SUCCESS;
  }

  if (cmd.Exist("copyright")) {
    printf("lv5 - Copyright (C) 2010 %s\n", IV_DEVELOPER);
    return EXIT_SUCCESS;
  }

  const std::vector<std::string>& rest = cmd.rest();
  const std::string& filename = rest.front();
  if (!rest.empty()) {
    std::string str;
    if (std::FILE* fp = std::fopen(filename.c_str(), "r")) {
      std::tr1::array<char, 1024> buf;
      while (std::size_t len = std::fread(buf.data(),
                                          1,
                                          buf.size(), fp)) {
        str.append(buf.data(), len);
      }
      std::fclose(fp);
    } else {
      std::string err("lv5 can't open \"");
      err.append(filename);
      err.append("\"");
      std::perror(err.c_str());
      return EXIT_FAILURE;
    }

    iv::icu::Source src(str, filename);
    iv::lv5::Context ctx;
    iv::lv5::AstFactory factory(&ctx);
    iv::core::Parser<iv::lv5::AstFactory, iv::icu::Source>
        parser(&factory, &src);
    const iv::lv5::FunctionLiteral* const global = parser.ParseProgram();

    if (!global) {
      std::cerr << parser.error() << std::endl;
      return EXIT_FAILURE;
    }

    if (cmd.Exist("ast")) {
      iv::core::ast::AstSerializer<iv::lv5::AstFactory> ser;
      global->Accept(&ser);
      std::cout << ser.out() << std::endl;
    } else {
      ctx.DefineFunction(&iv::lv5::Print, "print", 1);
      iv::lv5::JSScript* const script = iv::lv5::JSGlobalScript::New(
          &ctx, global, &factory, &src);
      if (ctx.Run(script)) {
        const JSVal e = ctx.ErrorVal();
        ctx.error()->Clear();
        const iv::lv5::JSString* const str = e.ToString(&ctx, ctx.error());
        if (!*ctx.error()) {
          std::cerr << *str << std::endl;
          return EXIT_FAILURE;
        }
      }
    }
  } else {
    // Interactive Shell Mode
    iv::lv5::Interactive shell;
    return shell.Run();
  }
  return 0;
}
<commit_msg>forget fix main.cc<commit_after>#include <cstdio>
#include <cstdlib>
#include <locale>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>  // NOLINT
#include <algorithm>
#include <tr1/array>
#include "config/config.h"

#include "stringpiece.h"
#include "ustringpiece.h"

#include "cmdline.h"
#include "ast.h"

#include "ast_serializer.h"

#include "parser.h"
#include "factory.h"

#include "interpreter.h"
#include "context.h"
#include "jsast.h"
#include "jsval.h"
#include "jsstring.h"
#include "jsscript.h"
#include "print.h"
#include "interactive.h"

#include "icu/ustream.h"
#include "icu/source.h"

#include "fpu.h"

int main(int argc, char **argv) {
  using iv::lv5::JSVal;
  iv::lv5::FixFPU();

  std::locale::global(std::locale(""));

  iv::cmdline::Parser cmd("lv5");

  cmd.Add("help",
          "help",
          'h', "print this message");
  cmd.Add("version",
          "version",
          'v', "print the version");
  cmd.Add("warning",
          "",
          'W', "set warning level 0 - 2", false, 0, iv::cmdline::range(0, 2));
  cmd.Add("ast",
          "ast",
          0, "print ast");
  cmd.Add("copyright",
          "copyright",
          0,   "print the copyright");
  cmd.set_footer("[program_file] [arguments]");

  bool cmd_parse_success = cmd.Parse(argc, argv);
  if (!cmd_parse_success) {
    std::cerr << cmd.error() << std::endl << cmd.usage();
    return EXIT_FAILURE;
  }

  if (cmd.Exist("help")) {
    std::cout << cmd.usage();
    return EXIT_SUCCESS;
  }

  if (cmd.Exist("version")) {
    printf("lv5 %s (compiled %s %s)\n", IV_VERSION, __DATE__, __TIME__);
    return EXIT_SUCCESS;
  }

  if (cmd.Exist("copyright")) {
    printf("lv5 - Copyright (C) 2010 %s\n", IV_DEVELOPER);
    return EXIT_SUCCESS;
  }

  const std::vector<std::string>& rest = cmd.rest();
  const std::string& filename = rest.front();
  if (!rest.empty()) {
    std::string str;
    if (std::FILE* fp = std::fopen(filename.c_str(), "r")) {
      std::tr1::array<char, 1024> buf;
      while (std::size_t len = std::fread(buf.data(),
                                          1,
                                          buf.size(), fp)) {
        str.append(buf.data(), len);
      }
      std::fclose(fp);
    } else {
      std::string err("lv5 can't open \"");
      err.append(filename);
      err.append("\"");
      std::perror(err.c_str());
      return EXIT_FAILURE;
    }

    iv::icu::Source src(str, filename);
    iv::lv5::Context ctx;
    iv::lv5::AstFactory factory(&ctx);
    iv::core::Parser<iv::lv5::AstFactory, iv::icu::Source>
        parser(&factory, &src);
    const iv::lv5::FunctionLiteral* const global = parser.ParseProgram();

    if (!global) {
      std::cerr << parser.error() << std::endl;
      return EXIT_FAILURE;
    }

    if (cmd.Exist("ast")) {
      iv::core::ast::AstSerializer<iv::lv5::AstFactory> ser;
      global->Accept(&ser);
      std::cout << ser.out() << std::endl;
    } else {
      ctx.DefineFunction(&iv::lv5::Print, "print", 1);
      iv::lv5::JSScript* const script = iv::lv5::JSGlobalScript::New(
          &ctx, global, &factory, &src);
      if (ctx.Run(script)) {
        const JSVal e = ctx.ErrorVal();
        ctx.error()->Clear();
        const iv::lv5::JSString* const str = e.ToString(&ctx, ctx.error());
        if (!*ctx.error()) {
          std::cerr << *str << std::endl;
          return EXIT_FAILURE;
        }
      }
    }
  } else {
    // Interactive Shell Mode
    iv::lv5::Interactive shell;
    return shell.Run();
  }
  return 0;
}

{'fraction_non_alphanumeric': 0.19077183575560885, 'fraction_numerical': 0.010159446874559051, 'mean_word_length': 2.788348476750401, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3342795', 'n_tokens_mistral': 2530, 'n_tokens_neox': 2473, 'n_words': 516}