<commit_before>#include "parser.h"
#include "printer.h"
#include "firstpass.h"

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char **argv) {
  for (int i = 1; i < argc; ++i) {
    struct module mod;
    error e = module_open(&mod, argv[i]);
    EXCEPT(e);

    step zeropass_down[] = {
      step_add_builtin_members,
      step_add_builtin_functions,
      step_add_builtin_methods,
      step_add_builtin_self,
      step_add_codegen_variables,
      NULL,
    };
    step zeropass_up[] = {
      step_add_scopes,
      NULL,
    };

    step firstpass_down[] = {
      step_lexical_scoping,
      step_type_definitions,
      step_type_destruct_mark,
      step_type_gather_returns,
      step_type_gather_excepts,
      NULL,
    };
    step firstpass_up[] = {
      step_type_inference,
      step_operator_call_inference,
      step_unary_call_inference,
      step_ctor_call_inference,
      step_call_arguments_prepare,
      step_temporary_inference,
      NULL,
    };

    e = pass(&mod, NULL, zeropass_down, zeropass_up);
    EXCEPT(e);

    e = pass(&mod, NULL, firstpass_down, firstpass_up);
    EXCEPT(e);

    char *out_fn = malloc(strlen(argv[i]) + 4 + 1);
    sprintf(out_fn, "%s.tree.out", argv[i]);

    int fd = creat(out_fn, 00600);
    if (fd < 0) {
      EXCEPTF(errno, "Cannot open output file '%s'", out_fn);
    }
    free(out_fn);

    e = printer_tree(fd, &mod, NULL);
    EXCEPT(e);
    close(fd);

    out_fn = malloc(strlen(argv[i]) + 6 + 1);
    sprintf(out_fn, "%s.pretty.out", argv[i]);

    fd = creat(out_fn, 00600);
    if (fd < 0) {
      EXCEPTF(errno, "Cannot open output file '%s'", out_fn);
    }
    free(out_fn);

    e = printer_pretty(fd, &mod);
    EXCEPT(e);
    close(fd);
  }

  return 0;
}
<commit_msg>ncc0: Allocate enough memory for output filenames<commit_after>#include "parser.h"
#include "printer.h"
#include "firstpass.h"

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char **argv) {
  for (int i = 1; i < argc; ++i) {
    struct module mod;
    error e = module_open(&mod, argv[i]);
    EXCEPT(e);

    step zeropass_down[] = {
      step_add_builtin_members,
      step_add_builtin_functions,
      step_add_builtin_methods,
      step_add_builtin_self,
      step_add_codegen_variables,
      NULL,
    };
    step zeropass_up[] = {
      step_add_scopes,
      NULL,
    };

    step firstpass_down[] = {
      step_lexical_scoping,
      step_type_definitions,
      step_type_destruct_mark,
      step_type_gather_returns,
      step_type_gather_excepts,
      NULL,
    };
    step firstpass_up[] = {
      step_type_inference,
      step_operator_call_inference,
      step_unary_call_inference,
      step_ctor_call_inference,
      step_call_arguments_prepare,
      step_temporary_inference,
      NULL,
    };

    e = pass(&mod, NULL, zeropass_down, zeropass_up);
    EXCEPT(e);

    e = pass(&mod, NULL, firstpass_down, firstpass_up);
    EXCEPT(e);

    char *out_fn = malloc(strlen(argv[i]) + sizeof(".tree.out"));
    sprintf(out_fn, "%s.tree.out", argv[i]);

    int fd = creat(out_fn, 00600);
    if (fd < 0) {
      EXCEPTF(errno, "Cannot open output file '%s'", out_fn);
    }
    free(out_fn);

    e = printer_tree(fd, &mod, NULL);
    EXCEPT(e);
    close(fd);

    out_fn = malloc(strlen(argv[i]) + sizeof(".pretty.out"));
    sprintf(out_fn, "%s.pretty.out", argv[i]);

    fd = creat(out_fn, 00600);
    if (fd < 0) {
      EXCEPTF(errno, "Cannot open output file '%s'", out_fn);
    }
    free(out_fn);

    e = printer_pretty(fd, &mod);
    EXCEPT(e);
    close(fd);
  }

  return 0;
}

{'fraction_non_alphanumeric': 0.13631436314363143, 'fraction_numerical': 0.00894308943089431, 'mean_word_length': 2.889357218124341, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, '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': '5066399', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1400, 'n_words': 272}