xcdat-Cwrapper/main.c
hashirama 730f93b9c8
add nullptr to perform_search
we need a nullptr at the end, to show where the list ends.
2024-12-22 12:42:33 -04:00

41 lines
1.3 KiB
C

#include <stdio.h>
#include <stdlib.h>
// Assuming the C wrapper functions are defined in an external library or header
// These are the C bindings from the C++ code
typedef void* TrieHandle; // Opaque pointer to represent the trie in C
extern TrieHandle load_trie(const char* dict_file);
extern const char** perform_search(TrieHandle handle, const char* search_str, size_t* result_count);
extern void free_trie(TrieHandle handle);
extern void free_search_results(const char** results);
int main() {
const char* dict_file = "/home/hashirama/.local/share/hakurei/dict.bin"; // Update this with your actual file path
// Load the trie using the wrapper function
TrieHandle trie_handle = load_trie(dict_file);
if (trie_handle == NULL) {
printf("Failed to load trie.\n");
return 1;
}
size_t result_count = 0;
// Perform the search using the wrapper function
const char** results = perform_search(trie_handle, "よくない影響", &result_count);
// Print all the results
printf("Results found:\n");
for (size_t i = 0; i < result_count; ++i) {
printf("Decoded view: %s\n", results[i]);
}
// Free the search results memory
free_search_results(results);
// Free the trie memory
free_trie(trie_handle);
return 0;
}