| 281 | |
| 282 | |
| 283 | static USHORT do_msgs(const TEXT* filename) |
| 284 | { |
| 285 | /************************************** |
| 286 | * |
| 287 | * d o _ m s g s |
| 288 | * |
| 289 | ************************************** |
| 290 | * |
| 291 | * Functional description |
| 292 | * Build the message file |
| 293 | * |
| 294 | **************************************/ |
| 295 | |
| 296 | // Divy up memory among various buffers |
| 297 | // Memory leaking until the program finishes? |
| 298 | msgrec* leaf_node = (msgrec*) malloc((SLONG) MSG_BUCKET); |
| 299 | msgrec* const leaf = leaf_node; |
| 300 | const TEXT* const end_leaf = (TEXT*) leaf + MSG_BUCKET; |
| 301 | |
| 302 | // Open output file |
| 303 | |
| 304 | global_file = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); |
| 305 | if (global_file == -1) |
| 306 | { |
| 307 | printf("Can't open %s\n", filename); |
| 308 | return FINI_ERROR; |
| 309 | } |
| 310 | global_file_position = 0; |
| 311 | |
| 312 | // Format and write header |
| 313 | isc_msghdr header; |
| 314 | header.msghdr_major_version = MSG_MAJOR_VERSION; |
| 315 | header.msghdr_minor_version = MSG_MINOR_VERSION; |
| 316 | header.msghdr_bucket_size = MSG_BUCKET; |
| 317 | // CVC: Since this is an unused field that holds garbage in the *.msg file, |
| 318 | // we'll initialize it to the date the FB project was registered with SF. |
| 319 | header.msghdr_origin = 20000730; // 2000-07-30 |
| 320 | write_bucket((msgnod*) &header, sizeof(header)); |
| 321 | |
| 322 | // Write out messages building B-tree |
| 323 | |
| 324 | USHORT n = 0; |
| 325 | ULONG position = 0, prior_code = 0; |
| 326 | msgnod_ptr_array buckets, nodes; |
| 327 | nodes[0] = NULL; |
| 328 | size_t len = 0; |
| 329 | |
| 330 | for (const auto& message : messages) |
| 331 | { |
| 332 | auto textLen = strlen(message.text); |
| 333 | |
| 334 | if (leaf_node->msgrec_text + textLen >= end_leaf) |
| 335 | { |
| 336 | position = write_bucket((msgnod*) leaf, n); |
| 337 | propagate(buckets, nodes, prior_code, position); |
| 338 | leaf_node = leaf; |
| 339 | } |
| 340 |
no test coverage detected