<commit_before>// Copyright © 2015-2019 <NAME> <<EMAIL>>
// All rights reserved.
//
// Use of this source code is governed by the license that can be
// found in the LICENSE file.

package yara

/*
#ifdef _WIN32
#define fdopen _fdopen
#define dup _dup
#endif
#include <stdio.h>
#include <unistd.h>

#include <yara.h>

void compilerCallback(int, char*, int, YR_RULE*, char*, void*);
*/
import "C"
import (
	"errors"
	"runtime"
	"unsafe"
)

//export compilerCallback
func compilerCallback(errorLevel C.int, filename *C.char, linenumber C.int,
	rule *C.YR_RULE, message *C.char, userData unsafe.Pointer) {
	c := callbackData.Get(userData).(*Compiler)
	msg := CompilerMessage{
		Filename: C.GoString(filename),
		Line:     int(linenumber),
		Text:     C.GoString(message),
	}
	switch errorLevel {<commit_msg>Include rule name in error messages generated by the compiler.<commit_after>// Copyright © 2015-2019 <NAME> <<EMAIL>>
// All rights reserved.
//
// Use of this source code is governed by the license that can be
// found in the LICENSE file.

package yara

/*
#ifdef _WIN32
#define fdopen _fdopen
#define dup _dup
#endif
#include <stdio.h>
#include <unistd.h>

#include <yara.h>

// rule_identifier is a union accessor function.
static const char* rule_identifier(YR_RULE* r) {
	return r->identifier;
}

void compilerCallback(int, char*, int, YR_RULE*, char*, void*);
*/
import "C"
import (
	"errors"
	"fmt"
	"runtime"
	"unsafe"
)

//export compilerCallback
func compilerCallback(errorLevel C.int, filename *C.char, linenumber C.int,
	rule *C.YR_RULE, message *C.char, userData unsafe.Pointer) {
	c := callbackData.Get(userData).(*Compiler)
	var text string
	if rule != nil {
		text = fmt.Sprintf("rule \"%s\": %s",
			C.GoString(C.rule_identifier(rule)),
			C.GoString(message))
	} else {
		text = C.GoString(message)
	}
	msg := CompilerMessage{
		Filename: C.GoString(filename),
		Line:     int(linenumber),
		Text:     text,
	}
	switch errorLevel {
{'fraction_non_alphanumeric': 0.13817809621289662, 'fraction_numerical': 0.01023541453428864, 'mean_word_length': 4.10443864229765, 'pattern_counts': {'":': 1, '<': 15, '<?xml version=': 0, '>': 16, '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': '2788614', 'n_tokens_mistral': 717, 'n_tokens_neox': 679, 'n_words': 206}