| 12 |
|
|
| 13 |
#include "file_loader.h" |
#include "file_loader.h" |
| 14 |
#include "log.h" |
#include "log.h" |
|
#include "trie_dict.h" |
|
| 15 |
#include <errno.h> |
#include <errno.h> |
| 16 |
|
#include <libgen.h> |
| 17 |
#include <stdio.h> |
#include <stdio.h> |
| 18 |
|
#include <string.h> |
| 19 |
#include <unistd.h> |
#include <unistd.h> |
|
#include <sys/shm.h> |
|
|
|
|
|
static const char TRIE_DICT_SHM_FILE[] = "~trie_dict_shm.dat"; |
|
| 20 |
|
|
| 21 |
const char *files[] = { |
const char *files[] = { |
| 22 |
"../data/welcome.txt", |
"../data/welcome.txt", |
| 30 |
|
|
| 31 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
| 32 |
{ |
{ |
|
int ret; |
|
| 33 |
int i; |
int i; |
| 34 |
const void *p_shm; |
void *p_shm; |
| 35 |
size_t data_len; |
size_t data_len; |
| 36 |
long line_total; |
long line_total; |
| 37 |
const void *p_data; |
const void *p_data; |
| 38 |
const long *p_line_offsets; |
const long *p_line_offsets; |
|
FILE *fp; |
|
| 39 |
|
|
| 40 |
if (log_begin("../log/bbsd.log", "../log/error.log") < 0) |
if (log_begin("../log/bbsd.log", "../log/error.log") < 0) |
| 41 |
{ |
{ |
| 46 |
log_common_redir(STDOUT_FILENO); |
log_common_redir(STDOUT_FILENO); |
| 47 |
log_error_redir(STDERR_FILENO); |
log_error_redir(STDERR_FILENO); |
| 48 |
|
|
|
if ((fp = fopen(TRIE_DICT_SHM_FILE, "w")) == NULL) |
|
|
{ |
|
|
log_error("fopen(%s) error\n", TRIE_DICT_SHM_FILE); |
|
|
return -1; |
|
|
} |
|
|
fclose(fp); |
|
|
|
|
|
if (trie_dict_init(TRIE_DICT_SHM_FILE, TRIE_NODE_PER_POOL) < 0) |
|
|
{ |
|
|
printf("trie_dict_init failed\n"); |
|
|
return -1; |
|
|
} |
|
|
|
|
|
ret = file_loader_init(); |
|
|
if (ret < 0) |
|
|
{ |
|
|
printf("file_loader_init() error (%d)\n", ret); |
|
|
return ret; |
|
|
} |
|
|
|
|
|
ret = file_loader_init(); |
|
|
if (ret == 0) |
|
|
{ |
|
|
printf("Rerun file_loader_init() error\n"); |
|
|
} |
|
|
|
|
| 49 |
printf("Testing #1\n"); |
printf("Testing #1\n"); |
| 50 |
|
|
| 51 |
for (i = 0; i < files_cnt; i++) |
for (i = 0; i < files_cnt; i++) |
| 129 |
} |
} |
| 130 |
} |
} |
| 131 |
|
|
|
file_loader_cleanup(); |
|
|
file_loader_cleanup(); |
|
|
|
|
|
trie_dict_cleanup(); |
|
|
|
|
|
if (unlink(TRIE_DICT_SHM_FILE) < 0) |
|
|
{ |
|
|
log_error("unlink(%s) error\n", TRIE_DICT_SHM_FILE); |
|
|
return -1; |
|
|
} |
|
|
|
|
| 132 |
log_end(); |
log_end(); |
| 133 |
|
|
| 134 |
return 0; |
return 0; |