void cmd_list_destroy(cmd_list_t* pcmd_list) { cmd_t* pcmd = pcmd_list->head; cmd_t* pcmd_tmp; while (pcmd->next) { pcmd_tmp = pcmd; pcmd = pcmd->next; cmd_destroy(pcmd_tmp); } cmd_destroy(pcmd); my_free(pcmd_list); pcmd_list = NULL; }
void cmd_delete(int cmdnum) { cmd_t *cmd_p; int i = 0; cmd_p = (cmd_t *) & g_cmdlist; while ((cmd_p = (cmd_t *) queue_next(&g_cmdlist, &cmd_p->qn))) { if (cmdnum == i) { cmd_destroy(cmd_p); return; } i++; } } /* end cmd_delete */
int main(int argc, char **argv) { cortex_init(); cmd_init(argc, argv); ctx_msg_out = NULL; ctx_tst_out = stdout; test_status("Tests running k=%i..%i...", get_min_kmer_size(), get_max_kmer_size()); test_status("[version] "VERSION_STATUS_STR"\n"); // Binary Kmer tests should work for all values of MAXK test_bkmer_functions(); test_hash_table(); #if MAX_KMER_SIZE == 31 // not kmer dependent test_util(); test_dna_functions(); test_binary_seq_functions(); // only written in k=31 test_db_node(); test_build_graph(); test_supernode(); test_subgraph(); test_cleaning(); test_paths(); // test_path_sets(); // TODO: replace with test_path_subset() test_graph_walker(); test_corrected_aln(); test_repeat_walker(); test_graph_crawler(); test_bubble_caller(); test_kmer_occur(); test_infer_edges_tests(); #endif cmd_destroy(); // Check we free'd all our memory size_t still_alloced = alloc_get_num_allocs() - alloc_get_num_frees(); TASSERT2(still_alloced == 0, "%zu not free'd", still_alloced); // Finished char num_test_str[100], num_passed_str[100]; size_t tests_num_passed = tests_num_run - tests_num_failed; ulong_to_str(tests_num_run, num_test_str); ulong_to_str(tests_num_passed, num_passed_str); test_status("Tests passed: %s / %s (%.1f%%)", num_passed_str, num_test_str, (100.0*tests_num_passed)/tests_num_run); if(tests_num_failed) test_status("%zu tests failed", tests_num_failed); else test_status("All tests passed."); cortex_destroy(); // Return 1 if any tests failed, 0 on success return tests_num_failed ? 1 : 0; }
int main(int argc, char **argv) { time_t start, end; time(&start); ctx_msg_out = stderr; cortex_init(); cmd_init(argc, argv); if(argc == 1) print_help(stderr, NULL); const CtxCmd *cmd = ctx_get_command(argv[1]); if(cmd == NULL) print_help(stderr, "Unrecognised command: %s", argv[1]); // Once we have set cmd_usage, we can call cmd_print_usage() from anywhere cmd_set_usage(cmd->usage); // If no arguments after command, print help if(argc == 2) cmd_print_usage(NULL); // Look for -q, --quiet argument, if given silence output int argi = 1; while(argi < argc && !(!strcmp(argv[argi],"-q") || !strcmp(argv[argi],"--quiet"))) argi++; if(argi < argc) { // Found -q, --quiet argument ctx_msg_out = NULL; // Remove argument for(--argc; argi < argc; argi++) argv[argi] = argv[argi+1]; } // Print status header cmd_print_status_header(); SWAP(argv[1],argv[0]); int ret = cmd->func(argc-1, argv+1); time(&end); cmd_destroy(); // Warn if more allocations than deallocations size_t still_alloced = alloc_get_num_allocs() - alloc_get_num_frees(); if(still_alloced) warn("%zu allocates not free'd.", still_alloced); char nallocs_str[50]; ulong_to_str(alloc_get_num_allocs(), nallocs_str); status("[memory] We made %s allocs", nallocs_str); status(ret == 0 ? "Done." : "Fail."); // Print time taken double diff = difftime(end,start); if(diff < 60) status("[time] %.2lf seconds\n", diff); else { char timestr[100]; seconds_to_str((size_t)diff, timestr); status("[time] %.2lf seconds (%s)\n", diff, timestr); } cortex_destroy(); return ret; }
int main(int argc, char *argv[]) { int timeout = 0; sp_error error; int notify_cmdline = 0; int notify_events = 0; struct timespec ts; (void)argc; (void)argv; pthread_mutex_init(&g_notify_mutex, NULL); pthread_cond_init(&g_notify_cond, NULL); session_init(); cmd_init(cmd_notify); do { clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec += timeout / 1000; ts.tv_nsec += (timeout % 1000) * 1E6; if (ts.tv_nsec > 1E9) { ts.tv_sec++; ts.tv_nsec -= 1E9; } pthread_mutex_lock(&g_notify_mutex); pthread_cond_timedwait(&g_notify_cond, &g_notify_mutex, &ts); notify_cmdline = g_notify_cmdline; notify_events = g_notify_events; g_notify_cmdline = 0; g_notify_events = 0; pthread_mutex_unlock(&g_notify_mutex); if (notify_cmdline) { cmd_process(); } if (notify_events) { do { error = sp_session_process_events(g_session, &timeout); if (error != SP_ERROR_OK) fprintf(stderr, "error processing events: %s\n", sp_error_message(error)); } while (timeout == 0); } } while (!is_program_finished()); session_logout(); while (session_is_logged_in()) { clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec += 1; pthread_mutex_lock(&g_notify_mutex); pthread_cond_timedwait(&g_notify_cond, &g_notify_mutex, &ts); notify_events = g_notify_events; g_notify_events = 0; pthread_mutex_unlock(&g_notify_mutex); if (notify_events) { do { error = sp_session_process_events(g_session, &timeout); if (error != SP_ERROR_OK) fprintf(stderr, "error processing events: %s\n", sp_error_message(error)); } while (timeout == 0); } } session_release(); cmd_destroy(); pthread_mutex_destroy(&g_notify_mutex); pthread_cond_destroy(&g_notify_cond); return 0; }