<commit_before>#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif

#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <iostream>
#include "document.hpp"
#include "eval_apply.hpp"
#include "error.hpp"
#include "sass_interface.h"

extern "C" {
  using namespace std;

  sass_context* sass_new_context()
  { return (sass_context*) calloc(1, sizeof(sass_context)); }

  void sass_free_context(sass_context* ctx)
  {
    if (ctx->output_string) free(ctx->output_string);
    if (ctx->error_message) free(ctx->error_message);

    free(ctx);
  }

  sass_file_context* sass_new_file_context()
  { return (sass_file_context*) calloc(1, sizeof(sass_file_context)); }

  void sass_free_file_context(sass_file_context* ctx)
  {
    if (ctx->output_string) free(ctx->output_string);
    if (ctx->error_message) free(ctx->error_message);

    free(ctx);
  }

  sass_folder_context* sass_new_folder_context()
    { return (sass_folder_context*) calloc(1, sizeof(sass_folder_context)); }

  void sass_free_folder_context(sass_folder_context* ctx)
    { free(ctx); }

  static char* process_document(Sass::Document& doc, int style)
  {
    using namespace Sass;
    Backtrace root_trace(0, "", 0, "");
    doc.parse_scss();
    expand(doc.root,
           Node(),
           doc.context.global_env,
           doc.context.function_env,
           doc.context.new_Node,
           doc.context,
           root_trace);
    // extend_selectors(doc.context.pending_extensions, doc.context.extensions, doc.context.new_Node);
    if (doc.context.has_extensions) extend(doc.root, doc.context.extensions, doc.context.new_Node);
    string output(doc.emit_css(static_cast<Document::CSS_Style>(style)));
    char* c_output = (char*) malloc(output.size() + 1);
    strcpy(c_output, output.c_str());
    return c_output;
  }

  int sass_compile(sass_context* c_ctx)
  {
    using namespace Sass;
    try {
      Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path, c_ctx->options.source_comments);
      if (c_ctx->c_functions) {
        struct Sass_C_Function_Data* this_func_data = c_ctx->c_functions;
        while (this_func_data->signature && this_func_data->function) {
          cpp_ctx.c_function_list.push_back(*this_func_data);
          ++this_func_data;
        }
      }
      Document doc(Document::make_from_source_chars(cpp_ctx, c_ctx->source_string));
      c_ctx->output_string = process_document(doc, c_ctx->options.output_style);
      c_ctx->error_message = 0;
      c_ctx->error_status = 0;
    }
    catch (Error& e) {
      stringstream msg_stream;
      msg_stream << e.path << ":" << e.line << ": error: " << e.message << endl;
      string msg(msg_stream.str());
      char* msg_str = (char*) malloc(msg.size() + 1);<commit_msg>[sass_interface] Need to call register_c_functions() after adding them to the context.<commit_after>#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif

#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <iostream>
#include "document.hpp"
#include "eval_apply.hpp"
#include "error.hpp"
#include "sass_interface.h"

extern "C" {
  using namespace std;

  sass_context* sass_new_context()
  { return (sass_context*) calloc(1, sizeof(sass_context)); }

  void sass_free_context(sass_context* ctx)
  {
    if (ctx->output_string) free(ctx->output_string);
    if (ctx->error_message) free(ctx->error_message);

    free(ctx);
  }

  sass_file_context* sass_new_file_context()
  { return (sass_file_context*) calloc(1, sizeof(sass_file_context)); }

  void sass_free_file_context(sass_file_context* ctx)
  {
    if (ctx->output_string) free(ctx->output_string);
    if (ctx->error_message) free(ctx->error_message);

    free(ctx);
  }

  sass_folder_context* sass_new_folder_context()
    { return (sass_folder_context*) calloc(1, sizeof(sass_folder_context)); }

  void sass_free_folder_context(sass_folder_context* ctx)
    { free(ctx); }

  static char* process_document(Sass::Document& doc, int style)
  {
    using namespace Sass;
    Backtrace root_trace(0, "", 0, "");
    doc.parse_scss();
    expand(doc.root,
           Node(),
           doc.context.global_env,
           doc.context.function_env,
           doc.context.new_Node,
           doc.context,
           root_trace);
    // extend_selectors(doc.context.pending_extensions, doc.context.extensions, doc.context.new_Node);
    if (doc.context.has_extensions) extend(doc.root, doc.context.extensions, doc.context.new_Node);
    string output(doc.emit_css(static_cast<Document::CSS_Style>(style)));
    char* c_output = (char*) malloc(output.size() + 1);
    strcpy(c_output, output.c_str());
    return c_output;
  }

  int sass_compile(sass_context* c_ctx)
  {
    using namespace Sass;
    try {
      Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path, c_ctx->options.source_comments);
      if (c_ctx->c_functions) {
        struct Sass_C_Function_Data* this_func_data = c_ctx->c_functions;
        while (this_func_data->signature && this_func_data->function) {
          cpp_ctx.c_function_list.push_back(*this_func_data);
          ++this_func_data;
        }
      }
      cpp_ctx.register_c_functions();
      Document doc(Document::make_from_source_chars(cpp_ctx, c_ctx->source_string));
      c_ctx->output_string = process_document(doc, c_ctx->options.output_style);
      c_ctx->error_message = 0;
      c_ctx->error_status = 0;
    }
    catch (Error& e) {
      stringstream msg_stream;
      msg_stream << e.path << ":" << e.line << ": error: " << e.message << endl;
      string msg(msg_stream.str());
      char* msg_str = (char*) malloc(msg.size() + 1);
{'fraction_non_alphanumeric': 0.13428120063191154, 'fraction_numerical': 0.0038616815868000704, 'mean_word_length': 3.820642978003384, 'pattern_counts': {'":': 4, '<': 43, '<?xml version=': 0, '>': 59, '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': '5749092', 'n_tokens_mistral': 2016, 'n_tokens_neox': 1973, 'n_words': 334}