<commit_before>#include "backend/compile.h"
#include "parser/parse.h"
#include "parser/symtab.h"
#include "preprocessor/preprocess.h"
#include "preprocessor/input.h"
#include "preprocessor/macro.h"
#include "util/argparse.h"
#include <lacc/context.h>
#include <lacc/ir.h>

#include <assert.h>
#include <stdio.h>
#include <unistd.h>

const char *program;
static FILE *output;

static void help(const char *arg)
{
    fprintf(
        stderr,
        "Usage: %s [-(S|E|c)] [-v] [-I <path>] [-o <file>] <file>\n",
        program);
    exit(1);
}

static void flag(const char *arg)
{
    switch (*arg) {
    case 'c':
        context.target = TARGET_x86_64_ELF;
        break;
    case 'S':
        context.target = TARGET_x86_64_ASM;
        break;
    case 'E':
        context.target = TARGET_NONE;
        break;
    case 'v':
        context.verbose += 1;
        break;
    case 'w':
        context.suppress_warning = 1;
        break;
    default:
        assert(0);
        break;
    }
}

static void open_output_handle(const char *file)
{
    output = fopen(file, "w");
}

static void set_c_std(const char *std)
{
    if (!strcmp("c89", std)) {
        context.standard = STD_C89;
    } else if (!strcmp("c99", std)) {
        context.standard = STD_C99;
    } else {
        fprintf(stderr, "Unrecognized option %s.\n", std);
        exit(1);
    }
}

static char *parse_program_arguments(int argc, char *argv[])
{
    int c;
    char *input;
    struct option optv[] = {
        {"-S", &flag},
        {"-E", &flag},
        {"-c", &flag},
        {"-v", &flag},
        {"-w", &flag},
        {"--help", &help},
        {"-o:", &open_output_handle},
        {"-I:", &add_include_search_path},
        {"-std=", &set_c_std}
    };

    program = argv[0];
    output = stdout;
    context.standard = STD_C89;
    context.target = TARGET_IR_DOT;
    c = parse_args(sizeof(optv)/sizeof(optv[0]), optv, argc, argv);
    if (c == argc - 1) {
        input = argv[c];
    } else if (c < argc - 1) {
        help(argv[0]);
        exit(1);
    }

    return input;
}<commit_msg>Initialize input file name corresponding to stdin<commit_after>#include "backend/compile.h"
#include "parser/parse.h"
#include "parser/symtab.h"
#include "preprocessor/preprocess.h"
#include "preprocessor/input.h"
#include "preprocessor/macro.h"
#include "util/argparse.h"
#include <lacc/context.h>
#include <lacc/ir.h>

#include <assert.h>
#include <stdio.h>
#include <unistd.h>

const char *program;
static FILE *output;

static void help(const char *arg)
{
    fprintf(
        stderr,
        "Usage: %s [-(S|E|c)] [-v] [-I <path>] [-o <file>] <file>\n",
        program);
    exit(1);
}

static void flag(const char *arg)
{
    switch (*arg) {
    case 'c':
        context.target = TARGET_x86_64_ELF;
        break;
    case 'S':
        context.target = TARGET_x86_64_ASM;
        break;
    case 'E':
        context.target = TARGET_NONE;
        break;
    case 'v':
        context.verbose += 1;
        break;
    case 'w':
        context.suppress_warning = 1;
        break;
    default:
        assert(0);
        break;
    }
}

static void open_output_handle(const char *file)
{
    output = fopen(file, "w");
}

static void set_c_std(const char *std)
{
    if (!strcmp("c89", std)) {
        context.standard = STD_C89;
    } else if (!strcmp("c99", std)) {
        context.standard = STD_C99;
    } else {
        fprintf(stderr, "Unrecognized option %s.\n", std);
        exit(1);
    }
}

static char *parse_program_arguments(int argc, char *argv[])
{
    int c;
    char *input = NULL;
    struct option optv[] = {
        {"-S", &flag},
        {"-E", &flag},
        {"-c", &flag},
        {"-v", &flag},
        {"-w", &flag},
        {"--help", &help},
        {"-o:", &open_output_handle},
        {"-I:", &add_include_search_path},
        {"-std=", &set_c_std}
    };

    program = argv[0];
    output = stdout;
    context.standard = STD_C89;
    context.target = TARGET_IR_DOT;
    c = parse_args(sizeof(optv)/sizeof(optv[0]), optv, argc, argv);
    if (c == argc - 1) {
        input = argv[c];
    } else if (c < argc - 1) {
        help(argv[0]);
        exit(1);
    }

    return input;
}
{'fraction_non_alphanumeric': 0.17051129607609988, 'fraction_numerical': 0.013793103448275862, 'mean_word_length': 2.293657008613939, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, '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': '5576060', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1531, 'n_words': 353}