| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
| 17 |
#include "file_loader.h" |
#include "file_loader.h" |
|
#include "trie_dict.h" |
|
|
#include "str_process.h" |
|
| 18 |
#include "log.h" |
#include "log.h" |
| 19 |
#include <fcntl.h> |
#include "str_process.h" |
| 20 |
|
#include "trie_dict.h" |
| 21 |
#include <errno.h> |
#include <errno.h> |
| 22 |
#include <unistd.h> |
#include <fcntl.h> |
| 23 |
#include <stdlib.h> |
#include <stdlib.h> |
| 24 |
#include <string.h> |
#include <string.h> |
| 25 |
#include <time.h> |
#include <time.h> |
| 26 |
|
#include <unistd.h> |
| 27 |
|
#include <sys/ipc.h> |
| 28 |
#include <sys/mman.h> |
#include <sys/mman.h> |
|
#include <sys/stat.h> |
|
| 29 |
#include <sys/shm.h> |
#include <sys/shm.h> |
| 30 |
#include <sys/ipc.h> |
#include <sys/stat.h> |
|
|
|
|
#define MAX_SPLIT_FILE_LINES 65536 |
|
| 31 |
|
|
| 32 |
struct shm_header_t |
struct shm_header_t |
| 33 |
{ |
{ |
| 121 |
return -1; |
return -1; |
| 122 |
} |
} |
| 123 |
|
|
| 124 |
line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_SPLIT_FILE_LINES); |
line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_SPLIT_FILE_LINES, 1, NULL); |
|
if (line_total >= MAX_SPLIT_FILE_LINES) |
|
|
{ |
|
|
log_error("split_data_lines() truncated over limit lines\n"); |
|
|
} |
|
| 125 |
|
|
| 126 |
// Allocate shared memory |
// Allocate shared memory |
| 127 |
proj_id = (int)(time(NULL) % getpid()); |
proj_id = (int)(time(NULL) % getpid()); |
| 149 |
((struct shm_header_t *)p_shm)->shmid = shmid; |
((struct shm_header_t *)p_shm)->shmid = shmid; |
| 150 |
((struct shm_header_t *)p_shm)->data_len = data_len; |
((struct shm_header_t *)p_shm)->data_len = data_len; |
| 151 |
((struct shm_header_t *)p_shm)->line_total = line_total; |
((struct shm_header_t *)p_shm)->line_total = line_total; |
| 152 |
memcpy(p_shm + sizeof(struct shm_header_t), p_data, data_len); |
memcpy((char *)p_shm + sizeof(struct shm_header_t), p_data, data_len); |
| 153 |
|
|
| 154 |
if (munmap(p_data, data_len) < 0) |
if (munmap(p_data, data_len) < 0) |
| 155 |
{ |
{ |
| 157 |
return -2; |
return -2; |
| 158 |
} |
} |
| 159 |
|
|
| 160 |
p_data = p_shm + sizeof(struct shm_header_t); |
p_data = (char *)p_shm + sizeof(struct shm_header_t); |
| 161 |
p_line_offsets = p_data + data_len + 1; |
p_line_offsets = (long *)((char *)p_data + data_len + 1); |
| 162 |
memcpy(p_line_offsets, line_offsets, sizeof(long) * (size_t)(line_total + 1)); |
memcpy(p_line_offsets, line_offsets, sizeof(long) * (size_t)(line_total + 1)); |
| 163 |
|
|
| 164 |
if (shmdt(p_shm) == -1) |
if (shmdt(p_shm) == -1) |
| 241 |
|
|
| 242 |
*p_data_len = ((struct shm_header_t *)p_shm)->data_len; |
*p_data_len = ((struct shm_header_t *)p_shm)->data_len; |
| 243 |
*p_line_total = ((struct shm_header_t *)p_shm)->line_total; |
*p_line_total = ((struct shm_header_t *)p_shm)->line_total; |
| 244 |
*pp_data = p_shm + sizeof(struct shm_header_t); |
*pp_data = (char *)p_shm + sizeof(struct shm_header_t); |
| 245 |
*pp_line_offsets = *pp_data + *p_data_len + 1; |
*pp_line_offsets = (const long *)((const char *)(*pp_data) + *p_data_len + 1); |
| 246 |
|
|
| 247 |
return p_shm; |
return p_shm; |
| 248 |
} |
} |