<commit_before>// liteapp.go
package main

/*
extern void cdrv_init(void *fn);
extern int cdrv_main(int argc,char** argv);
//extern void cdrv_cb(void *cb, void *id, void *reply, int size, int flag, void* ctx);

static void cdrv_init_ex()
{
	extern int godrv_call(void* id,int id_size, void* args, int args_size, void* cb, void* ctx);
	cdrv_init(&godrv_call);
}

static void cdrv_cb(void *cb, void *id, int id_size, void *reply, int size, int flag, void* ctx)
{
	typedef void (*DRV_CALLBACK)(void *id, int id_size, void *reply, int len, int flag, void *ctx);
    ((DRV_CALLBACK)(cb))(id,id_size,reply,size,flag,ctx);
}

#cgo windows LDFLAGS: -L../../liteide/bin -lliteapp
#cgo linux LDFLAGS: -L../../liteide/bin -lliteapp
#cgo openbsd LDFLAGS: -L../../liteide/bin -lliteapp
#cgo darwin LDFLAGS: -L../../liteide/bin/liteide.app/Contents/MacOS
*/
import "C"
import (
	"bytes"
	"log"
	"strings"
	"unsafe"

	"github.com/visualfc/gotools/command"
)

func cdrv_main(args []string) int {
	argc := len(args)
	var cargs []*C.char
	for _, arg := range args {
		size := len(arg)
		data := make([]C.char, size+1)
		for i := 0; i < size; i++ {
			data[i] = (C.char)(arg[i])
		}
		data[size] = 0
		cargs = append(cargs, &data[0])
	}
	C.cdrv_init_ex()
	return int(C.cdrv_main(C.int(argc), &cargs[0]))
}

func cdrv_cb(cb unsafe.Pointer, id []byte, reply []byte, flag int, ctx unsafe.Pointer) {
	if len(reply) == 0 {
		C.cdrv_cb(cb, unsafe.Pointer(&id[0]), C.int(len(id)), nil, 0, C.int(flag), ctx)
	} else {
		C.cdrv_cb(cb, unsafe.Pointer(&id[0]), C.int(len(id)), unsafe.Pointer(&reply[0]), C.int(len(reply)), C.int(flag), ctx)
	}<commit_msg>fix liteidex cgo<commit_after>// liteapp.go
package main

/*
#include <stdlib.h>

extern void cdrv_init(void *fn);
extern int cdrv_main(int argc,char** argv);
//extern void cdrv_cb(void *cb, void *id, void *reply, int size, int flag, void* ctx);

static void cdrv_init_ex()
{
	extern int godrv_call(void* id,int id_size, void* args, int args_size, void* cb, void* ctx);
	cdrv_init(&godrv_call);
}

static void cdrv_cb(void *cb, void *id, int id_size, void *reply, int size, int flag, void* ctx)
{
	typedef void (*DRV_CALLBACK)(void *id, int id_size, void *reply, int len, int flag, void *ctx);
    ((DRV_CALLBACK)(cb))(id,id_size,reply,size,flag,ctx);
}

#cgo windows LDFLAGS: -L../../liteide/bin -lliteapp
#cgo linux LDFLAGS: -L../../liteide/bin -lliteapp
#cgo openbsd LDFLAGS: -L../../liteide/bin -lliteapp
#cgo darwin LDFLAGS: -L../../liteide/bin/liteide.app/Contents/MacOS
*/
import "C"
import (
	"bytes"
	"log"
	"strings"
	"unsafe"

	"github.com/visualfc/gotools/command"
)

func cdrv_main(args []string) int {
	argc := len(args)
	var cargs []*C.char
	for _, arg := range args {
		ptr := C.CString(arg)
		defer C.free(unsafe.Pointer(ptr)) //释放内存
		cargs = append(cargs, ptr)
	}
	C.cdrv_init_ex()
	return int(C.cdrv_main(C.int(argc), &cargs[0]))
}

func cdrv_cb(cb unsafe.Pointer, id []byte, reply []byte, flag int, ctx unsafe.Pointer) {
	if len(reply) == 0 {
		C.cdrv_cb(cb, unsafe.Pointer(&id[0]), C.int(len(id)), nil, 0, C.int(flag), ctx)
	} else {
		C.cdrv_cb(cb, unsafe.Pointer(&id[0]), C.int(len(id)), unsafe.Pointer(&reply[0]), C.int(len(reply)), C.int(flag), ctx)
	}
{'fraction_non_alphanumeric': 0.1901342491414299, 'fraction_numerical': 0.004995316890415236, 'mean_word_length': 4.304635761589404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '3723846', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1316, 'n_words': 326}