<commit_before>mapping(string:int) cat = ([]);
mapping(string:object) stderrs = ([]);
mapping(string:int(0..1)) bt = ([]);

int default_lvl = 0;
object default_stderr;
// categories of debug -> their current levels
//

void set_default_debug(int lvl) {
    default_lvl = lvl;
}

int get_default_debug() {
    return default_lvl;
}

void set_default_stderr(object o) {
    default_stderr = o;
}

object unset_default_stderr() {
    object t = default_stderr;

    default_stderr = 0;
    return t;
}

object get_default_stderr() {
    return default_stderr;
}

void set_debug(string c, int lvl) {
    cat[c] = lvl;
    werror("%O %O %O\n", cat, c, lvl);
}

int unset_debug(string c) {
    return m_delete(cat, c);
}

int get_debug(string c) {
    return cat[c];
}

void set_stderr(string c, object o) {
    stderrs[c] = o; 
}

object unset_stderr(string c) {
    return m_delete(stderrs, c);
}

object get_stderr(string c) {
    return stderrs[c]; 
}

string diff_paths(string f1, string f2) {
    array a1 = f1 / "/"; 
    array a2 = f2 / "/"; 
    array npath = ({ });
    int i;

    for (i = 0; i < min(sizeof(a1), sizeof(a2)); i++) {
	 if (a1[i] == a2[i]) {
	 } else {
	    npath += ({ ".." }) * (min(sizeof(a1), sizeof(a2)) - i);
	    break;
	 }
    }

    if (sizeof(a1) > sizeof(a2)) {
	for (int i = sizeof(a2); i < sizeof(a1); i++) {
	    npath += ({ ".." });
	}
	npath += ({ a2[-1] });
    } else {
	npath += ({ a2[i] });
	for (int i = sizeof(a1); i < sizeof(a2); i++) {
	    npath += ({ a2[i] });
	}
    }

    return npath * "/";
}

void debug(string c, int lvl, string fmt, mixed ... args) {
    if ((has_index(cat, c) && cat[c] >= lvl) || default_lvl >= lvl) {
	if (bt[c]) {
	    array backtrace = backtrace();
	   
	    Pike.BacktraceFrame debug, fun;
	    debug = backtrace[-1];
	    fun = backtrace[-2];

	    string nfmt = "%s:%d:%s(";

	    array t = ({ "%O" }) * (sizeof(fun) - 3);
	    array funargs = ({ });

	    nfmt += t * ", " + ")\t";
	    fmt = nfmt + fmt;

	    for (int i = 3; i < sizeof(fun); i++) {
		funargs += ({ fun[i] });
	    }
	    
	    string path = diff_paths(getcwd(), debug[0]);
	    if (sizeof(path) > sizeof(debug[0])) {
		path = debug[0];
	    }

	    args = ({path, debug[1], function_name(fun[2])||"!!!UNKNOWN!!!" }) + funargs + args;
	}

	if (stderrs[c]) {
	    stderrs[c]->write(fmt, @args);
	} else if (default_stderr) {
	    default_stderr->write(fmt, @args);
	} else {
	    werror(fmt, @args);
	}
    }
}

void set_backtrace(string c, int(0..1) trace) {
    bt[c] = trace;
}

int(0..1) unset_backtrace(string c) {
    return m_delete(bt, c);
}

int(0..1) get_backtrace(string c) {
    return bt[c];
}

void do_throw(string c, string fmt, mixed ... args) {
    string s = sprintf(fmt, @args);
    array trace;

    if (bt[c]) {
	trace = backtrace();
	trace = trace[..sizeof(trace) - 2];
    }

    throw(({ s, trace }));
}<commit_msg>default backtrace setting<commit_after>mapping(string:int) cat = ([]);
mapping(string:object) stderrs = ([]);
mapping(string:int(0..1)) bt = ([]);

int(0..1) dbt;

int default_lvl = 0;
object default_stderr;
// categories of debug -> their current levels
//

void set_default_debug(int lvl) {
    default_lvl = lvl;
}

int get_default_debug() {
    return default_lvl;
}

void set_default_stderr(object o) {
    default_stderr = o;
}

void set_default_backtrace(int(0..1) i) {
    dbt = i;
}

int(0..1) unset_default_backtrace() {
    int i = dbt;

    dbt = 0;
    return i;
}
int(0..1) get_default_backtrace() {
    return dbt;
}

object unset_default_stderr() {
    object t = default_stderr;

    default_stderr = 0;
    return t;
}

object get_default_stderr() {
    return default_stderr;
}

void set_debug(string c, int lvl) {
    cat[c] = lvl;
    werror("%O %O %O\n", cat, c, lvl);
}

int unset_debug(string c) {
    return m_delete(cat, c);
}

int get_debug(string c) {
    return cat[c];
}

void set_stderr(string c, object o) {
    stderrs[c] = o; 
}

object unset_stderr(string c) {
    return m_delete(stderrs, c);
}

object get_stderr(string c) {
    return stderrs[c]; 
}

string diff_paths(string f1, string f2) {
    array a1 = f1 / "/"; 
    array a2 = f2 / "/"; 
    array npath = ({ });
    int i;

    for (i = 0; i < min(sizeof(a1), sizeof(a2)); i++) {
	 if (a1[i] == a2[i]) {
	 } else {
	    npath += ({ ".." }) * (min(sizeof(a1), sizeof(a2)) - i);
	    break;
	 }
    }

    if (sizeof(a1) > sizeof(a2)) {
	for (int i = sizeof(a2); i < sizeof(a1); i++) {
	    npath += ({ ".." });
	}
	npath += ({ a2[-1] });
    } else {
	npath += ({ a2[i] });
	for (int i = sizeof(a1); i < sizeof(a2); i++) {
	    npath += ({ a2[i] });
	}
    }

    return npath * "/";
}

void debug(string c, int lvl, string fmt, mixed ... args) {
    if ((has_index(cat, c) && cat[c] >= lvl) || default_lvl >= lvl) {
	if (dbt && !has_index(bt, c) || bt[c]) {
	    array backtrace = backtrace();
	   
	    Pike.BacktraceFrame debug, fun;
	    debug = backtrace[-1];
	    fun = backtrace[-2];

	    string nfmt = "%s:%d:%s(";

	    array t = ({ "%O" }) * (sizeof(fun) - 3);
	    array funargs = ({ });

	    nfmt += t * ", " + ")\t";
	    fmt = nfmt + fmt;

	    for (int i = 3; i < sizeof(fun); i++) {
		funargs += ({ fun[i] });
	    }
	    
	    string path = diff_paths(getcwd(), debug[0]);
	    if (sizeof(path) > sizeof(debug[0])) {
		path = debug[0];
	    }

	    args = ({path, debug[1], function_name(fun[2])||"!!!UNKNOWN!!!" }) + funargs + args;
	}

	if (stderrs[c]) {
	    stderrs[c]->write(fmt, @args);
	} else if (default_stderr) {
	    default_stderr->write(fmt, @args);
	} else {
	    werror(fmt, @args);
	}
    }
}

void set_backtrace(string c, int(0..1) trace) {
    bt[c] = trace;
}

int(0..1) unset_backtrace(string c) {
    return m_delete(bt, c);
}

int(0..1) get_backtrace(string c) {
    return bt[c];
}

void do_throw(string c, string fmt, mixed ... args) {
    string s = sprintf(fmt, @args);
    array trace;

    if (dbt && !has_index(bt, c) || bt[c]) {
	trace = backtrace();
	trace = trace[..sizeof(trace) - 2];
    }

    throw(({ s, trace }));
}
{'fraction_non_alphanumeric': 0.19844679444811633, 'fraction_numerical': 0.01569729015201586, 'mean_word_length': 2.699877750611247, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '2966528', 'n_tokens_mistral': 2514, 'n_tokens_neox': 2421, 'n_words': 558}