<commit_before>#ifdef _WIN32
#include <direct.h>
#define getcwd _getcwd
#define PATH_SEP ';'
#else
#include <unistd.h>
#define PATH_SEP ':'
#endif

#include <cstring>
#include <iostream>
#include <sstream>
#include "context.hpp"
#include "constants.hpp"
#include "color_names.hpp"
#include "prelexer.hpp"

namespace Sass {
  using namespace Constants;
  using std::pair; using std::cerr; using std::endl;

  void Context::collect_include_paths(const char* paths_str)
  {
    const size_t wd_len = 1024;
    char wd[wd_len];
    include_paths.push_back(getcwd(wd, wd_len));
    if (*include_paths.back().rbegin() != '/') include_paths.back() += '/';

    if (paths_str) {
      const char* beg = paths_str;
      const char* end = Prelexer::find_first<PATH_SEP>(beg);

      while (end) {
        string path(beg, end - beg);
        if (!path.empty()) {
          if (*path.rbegin() != '/') path += '/';
          include_paths.push_back(path);
        }
        beg = end + 1;
        end = Prelexer::find_first<PATH_SEP>(beg);
      }

      string path(beg);
      if (!path.empty()) {
        if (*path.rbegin() != '/') path += '/';
        include_paths.push_back(path);
      }
    }

    // for (int i = 0; i < include_paths.size(); ++i) {
    //   cerr << include_paths[i] << endl;
    // }
  }

  Context::Context(const char* paths_str, const char* img_path_str, int sc)
  : global_env(Environment()),
    function_env(map<string, Function>()),
    c_function_list(vector<Sass_C_Function_Data>()),
    extensions(multimap<Node, Node>()),
    pending_extensions(vector<pair<Node, Node> >()),
    source_refs(vector<const char*>()),
    include_paths(vector<string>()),
    color_names_to_values(map<string, Node>()),
    color_values_to_names(map<Node, string>()),
    new_Node(Node_Factory()),
    image_path(0),
    ref_count(0),
    has_extensions(false),
    source_comments(sc)
  {
    register_functions();
    register_c_functions();
    collect_include_paths(paths_str);
    setup_color_map();

    string path_string(img_path_str ? img_path_str : "");
    path_string = "'" + path_string + "/'";
    image_path = new char[path_string.length() + 1];
    std::strcpy(image_path, path_string.c_str());

    // stash this hidden variable for the image-url built-in to use
    global_env[Token::make(image_path_var)] = new_Node(Node::string_constant, "[IMAGE PATH]", 0, Token::make(image_path));
  }
<commit_msg>[context.cpp] Calling register_c_functions() from the constructor is pointless (and confusing).<commit_after>#ifdef _WIN32
#include <direct.h>
#define getcwd _getcwd
#define PATH_SEP ';'
#else
#include <unistd.h>
#define PATH_SEP ':'
#endif

#include <cstring>
#include <iostream>
#include <sstream>
#include "context.hpp"
#include "constants.hpp"
#include "color_names.hpp"
#include "prelexer.hpp"

namespace Sass {
  using namespace Constants;
  using std::pair; using std::cerr; using std::endl;

  void Context::collect_include_paths(const char* paths_str)
  {
    const size_t wd_len = 1024;
    char wd[wd_len];
    include_paths.push_back(getcwd(wd, wd_len));
    if (*include_paths.back().rbegin() != '/') include_paths.back() += '/';

    if (paths_str) {
      const char* beg = paths_str;
      const char* end = Prelexer::find_first<PATH_SEP>(beg);

      while (end) {
        string path(beg, end - beg);
        if (!path.empty()) {
          if (*path.rbegin() != '/') path += '/';
          include_paths.push_back(path);
        }
        beg = end + 1;
        end = Prelexer::find_first<PATH_SEP>(beg);
      }

      string path(beg);
      if (!path.empty()) {
        if (*path.rbegin() != '/') path += '/';
        include_paths.push_back(path);
      }
    }

    // for (int i = 0; i < include_paths.size(); ++i) {
    //   cerr << include_paths[i] << endl;
    // }
  }

  Context::Context(const char* paths_str, const char* img_path_str, int sc)
  : global_env(Environment()),
    function_env(map<string, Function>()),
    c_function_list(vector<Sass_C_Function_Data>()),
    extensions(multimap<Node, Node>()),
    pending_extensions(vector<pair<Node, Node> >()),
    source_refs(vector<const char*>()),
    include_paths(vector<string>()),
    color_names_to_values(map<string, Node>()),
    color_values_to_names(map<Node, string>()),
    new_Node(Node_Factory()),
    image_path(0),
    ref_count(0),
    has_extensions(false),
    source_comments(sc)
  {
    register_functions();
    collect_include_paths(paths_str);
    setup_color_map();

    string path_string(img_path_str ? img_path_str : "");
    path_string = "'" + path_string + "/'";
    image_path = new char[path_string.length() + 1];
    std::strcpy(image_path, path_string.c_str());

    // stash this hidden variable for the image-url built-in to use
    global_env[Token::make(image_path_var)] = new_Node(Node::string_constant, "[IMAGE PATH]", 0, Token::make(image_path));
  }

{'fraction_non_alphanumeric': 0.16177070583435332, 'fraction_numerical': 0.004895960832313341, 'mean_word_length': 3.6037558685446007, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 35, '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': '5231518', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1692, 'n_words': 326}