<commit_before>/*
 * Copyright (C) 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <unistd.h>
#include <execinfo.h>

#include <csignal>
#include <iostream>

#include <ydsh/ydsh.h>
#include "misc/ArgsParser.hpp"
#include "config.h"

using namespace ydsh;

enum OptionKind {
    DUMP_UAST,
    DUMP_AST,
    PARSE_ONLY,
    DISABLE_ASSERT,
    PRINT_TOPLEVEL,
    TRACE_EXIT,
    VERSION,
    HELP,
};

void exec_interactive(const char *progName, DSContext *ctx);

/**
 * write version string.
 * not write new line.
 */
static std::ostream &version(std::ostream &stream) {
    return stream << "ydsh, version " X_INFO_VERSION
                             " (" X_INFO_SYSTEM "), build by " X_INFO_CPP " " X_INFO_CPP_V;
}

/**
 * write copyright.
 * not write new line.
 */
static std::ostream &copyright(std::ostream &stream) {
    return stream << "Copyright (c) 2015 <NAME>";
}

static void loadRC(DSContext *ctx) {
    std::string path(getenv("HOME"));
    path += "/.ydshrc";
    FILE *fp = fopen(path.c_str(), "rb");
    if(fp == NULL) {
        return; // not read
    }
    DSStatus *s;
    int ret = DSContext_loadAndEval(ctx, path.c_str(), fp, &s);
    int type = DSStatus_getType(s);
    DSStatus_free(&s);
    fclose(fp);
    if(type != DS_STATUS_SUCCESS) {
        DSContext_delete(&ctx);
        exit(ret);
    }
}

static void segvHandler(int num) {
    // write message
    char msg[] = "+++++ catch Segmentation fault +++++\n";
    write(STDERR_FILENO, msg, strlen(msg));

    // get backtrace
    const unsigned int size = 128;
    void *buf[size];
<commit_msg>fix typo<commit_after>/*
 * Copyright (C) 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <unistd.h>
#include <execinfo.h>

#include <csignal>
#include <iostream>

#include <ydsh/ydsh.h>
#include "misc/ArgsParser.hpp"
#include "config.h"

using namespace ydsh;

enum OptionKind {
    DUMP_UAST,
    DUMP_AST,
    PARSE_ONLY,
    DISABLE_ASSERT,
    PRINT_TOPLEVEL,
    TRACE_EXIT,
    VERSION,
    HELP,
};

void exec_interactive(const char *progName, DSContext *ctx);

/**
 * write version string.
 * not write new line.
 */
static std::ostream &version(std::ostream &stream) {
    return stream << "ydsh, version " X_INFO_VERSION
                             " (" X_INFO_SYSTEM "), build by " X_INFO_CPP " " X_INFO_CPP_V;
}

/**
 * write copyright.
 * not write new line.
 */
static std::ostream &copyright(std::ostream &stream) {
    return stream << "Copyright (C) 2015 <NAME>";
}

static void loadRC(DSContext *ctx) {
    std::string path(getenv("HOME"));
    path += "/.ydshrc";
    FILE *fp = fopen(path.c_str(), "rb");
    if(fp == NULL) {
        return; // not read
    }
    DSStatus *s;
    int ret = DSContext_loadAndEval(ctx, path.c_str(), fp, &s);
    int type = DSStatus_getType(s);
    DSStatus_free(&s);
    fclose(fp);
    if(type != DS_STATUS_SUCCESS) {
        DSContext_delete(&ctx);
        exit(ret);
    }
}

static void segvHandler(int num) {
    // write message
    char msg[] = "+++++ catch Segmentation fault +++++\n";
    write(STDERR_FILENO, msg, strlen(msg));

    // get backtrace
    const unsigned int size = 128;
    void *buf[size];

{'fraction_non_alphanumeric': 0.12871052006649253, 'fraction_numerical': 0.007124198527665638, 'mean_word_length': 3.1785714285714284, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4572826', 'n_tokens_mistral': 1397, 'n_tokens_neox': 1356, 'n_words': 423}