Contains functions for merge command. More...
Go to the source code of this file.
Functions | |
void | command_merge (int argc, int last_arg, const char **argv) |
Parses command-line for merge options and performs merge command. |
Contains functions for merge command.
void command_merge | ( | int | argc, | |
int | last_arg, | |||
const char ** | argv | |||
) |
Parses command-line for merge options and performs merge command.
Performs merge command functionality.
argc | Number of arguments in command-line to parse | |
last_arg | Index of last parsed argument from list | |
argv | List of arguments from command-line to parse |
References bind_perform(), Catch_anonymous, COVERED_HEADER, curr_db, db_close(), db_merge_instance_trees(), db_read(), db_write(), FALSE, free_safe, HEADER, db_s::leading_hier_num, merge_check(), merge_parse_args(), merged_file, str_link_s::next, NORMAL, print_output(), PROFILE, PROFILE_END, READ_MODE_MERGE_NO_MERGE, str_link_s::str, str_link_delete_list(), str_link_s::suppl, Throw, TRUE, Try, user_msg, and USER_MSG_LENGTH.
Referenced by main().
00355 { PROFILE(COMMAND_MERGE); 00356 00357 int i; /* Loop iterator */ 00358 unsigned int rv; /* Return value from snprintf calls */ 00359 bool error = FALSE; 00360 00361 /* Output header information */ 00362 rv = snprintf( user_msg, USER_MSG_LENGTH, COVERED_HEADER ); 00363 assert( rv < USER_MSG_LENGTH ); 00364 print_output( user_msg, HEADER, __FILE__, __LINE__ ); 00365 00366 Try { 00367 00368 str_link* strl; 00369 bool stop_merging; 00370 int curr_leading_hier_num = 0; 00371 00372 /* Parse score command-line */ 00373 if( !merge_parse_args( argc, last_arg, argv ) ) { 00374 00375 /* Check if merge could be executed */ 00376 merge_check(); 00377 00378 /* Read in base database */ 00379 rv = snprintf( user_msg, USER_MSG_LENGTH, "Reading CDD file \"%s\"", merge_in_head->str ); 00380 assert( rv < USER_MSG_LENGTH ); 00381 print_output( user_msg, NORMAL, __FILE__, __LINE__ ); 00382 if( !db_read( merge_in_head->str, READ_MODE_MERGE_NO_MERGE ) ) { 00383 00384 /* The read in CDD was empty so mark it as such */ 00385 merge_in_head->suppl = 2; 00386 00387 } else { 00388 00389 /* If the currently read CDD didn't contain any merged CDDs it is a leaf CDD so mark it as such */ 00390 if( (db_list[curr_db]->leading_hier_num - curr_leading_hier_num) == 1 ) { 00391 merge_in_head->suppl = 1; 00392 } 00393 curr_leading_hier_num = db_list[curr_db]->leading_hier_num; 00394 00395 } 00396 00397 /* Read in databases to merge */ 00398 strl = merge_in_head->next; 00399 stop_merging = (strl == merge_in_head); 00400 while( (strl != NULL) && !stop_merging ) { 00401 rv = snprintf( user_msg, USER_MSG_LENGTH, "Merging CDD file \"%s\"", strl->str ); 00402 assert( rv < USER_MSG_LENGTH ); 00403 print_output( user_msg, NORMAL, __FILE__, __LINE__ ); 00404 if( !db_read( strl->str, READ_MODE_MERGE_NO_MERGE ) ) { 00405 00406 /* The read in CDD was empty so mark it as such */ 00407 merge_in_head->suppl = 2; 00408 00409 } else { 00410 00411 /* If we have not merged any CDD files from this CDD, this is a leaf CDD so mark it as such */ 00412 if( (db_list[curr_db]->leading_hier_num - curr_leading_hier_num) == 1 ) { 00413 strl->suppl = 1; 00414 } 00415 curr_leading_hier_num = db_list[curr_db]->leading_hier_num; 00416 00417 } 00418 00419 stop_merging = (strl == merge_in_cl_last); 00420 strl = strl->next; 00421 } 00422 00423 /* Perform the tree merges */ 00424 db_merge_instance_trees(); 00425 00426 /* Bind */ 00427 bind_perform( TRUE, 0 ); 00428 00429 /* Write out new database to output file */ 00430 db_write( merged_file, FALSE, TRUE ); 00431 00432 print_output( "\n*** Merging completed successfully! ***", NORMAL, __FILE__, __LINE__ ); 00433 00434 } 00435 00436 } Catch_anonymous { 00437 error = TRUE; 00438 } 00439 00440 /* Close database */ 00441 db_close(); 00442 00443 /* Deallocate other memory */ 00444 str_link_delete_list( merge_in_head ); 00445 free_safe( merged_file, (strlen( merged_file ) + 1) ); 00446 00447 if( error ) { 00448 Throw 0; 00449 } 00450 00451 PROFILE_END; 00452 00453 }