static int gt_dev_runner(int argc, const char **argv, int parsed_args, void *tool_arguments, GtError *err) { GtToolbox *dev_toolbox = tool_arguments; GtToolfunc toolfunc; GtTool *tool = NULL; int had_err = 0; char **nargv = NULL; gt_error_check(err); gt_assert(dev_toolbox); /* get development tools */ if (!gt_toolbox_has_tool(dev_toolbox, argv[parsed_args])) { gt_error_set(err, "development tool '%s' not found; option -help lists " "possible tools", argv[parsed_args]); had_err = -1; } /* call development tool */ if (!had_err) { if (!(toolfunc = gt_toolbox_get(dev_toolbox, argv[parsed_args]))) { tool = gt_toolbox_get_tool(dev_toolbox, argv[parsed_args]); gt_assert(tool); } nargv = gt_cstr_array_prefix_first(argv + parsed_args, gt_error_get_progname(err)); gt_error_set_progname(err, nargv[0]); if (toolfunc) had_err = toolfunc(argc - parsed_args, (const char**) nargv, err); else had_err = gt_tool_run(tool, argc - parsed_args, (const char**) nargv, err); } /* free */ gt_cstr_array_delete(nargv); return had_err; }
static int gt_cge_runner(int argc, const char **argv, int parsed_args, void *tool_arguments, GtError *err) { GtToolbox *index_toolbox = tool_arguments; GtToolfunc toolfunc; GtTool *tool = NULL; char **nargv = NULL; int had_err = 0; gt_error_check(err); gt_assert(index_toolbox != NULL); /* determine tool */ if (!gt_toolbox_has_tool(index_toolbox, argv[parsed_args])) { gt_error_set(err, "congruence tool '%s' not found; option -help lists " "possible tools", argv[parsed_args]); had_err = -1; } /* call sub-tool */ if (!had_err) { if (!(toolfunc = gt_toolbox_get(index_toolbox, argv[parsed_args]))) { tool = gt_toolbox_get_tool(index_toolbox, argv[parsed_args]); gt_assert(tool != NULL); } nargv = gt_cstr_array_prefix_first(argv + parsed_args, gt_error_get_progname(err)); gt_error_set_progname(err, nargv[0]); if (toolfunc != NULL) had_err = toolfunc(argc - parsed_args, (const char**) nargv, err); else had_err = gt_tool_run(tool, argc - parsed_args, (const char**) nargv, err); } gt_cstr_array_delete(nargv); return had_err; }
int gtr_run(GtR *gtr, int argc, const char **argv, GtError *err) { GtToolfunc toolfunc; GtTool *tool = NULL; char **nargv = NULL; void *mem, *map; int had_err = 0; gt_error_check(err); gt_assert(gtr); if (gtr->debug) enable_logging(gt_str_get(gtr->debugfp), >r->logfp); if (gtr->quiet) gt_warning_disable(); gtr->seed = gt_ya_rand_init(gtr->seed); gt_log_log("seed=%u", gtr->seed); if (gtr->list) return list_tools(gtr); if (gt_str_length(gtr->manoutdir) > 0) return create_manpages(gtr, gt_str_get(gtr->manoutdir), err); if (gtr->check64bit) return check64bit(); if (gtr->test) return run_tests(gtr, err); if (gt_str_length(gtr->testspacepeak)) { mem = gt_malloc(1 << 26); /* alloc 64 MB */; map = gt_fa_xmmap_read(gt_str_get(gtr->testspacepeak), NULL); gt_fa_xmunmap(map); gt_free(mem); } if (argc == 0 && !gtr->interactive) { gt_error_set(err, "neither tool nor script specified; option -help lists " "possible tools"); had_err = -1; } if (!had_err && argc) { if (!gtr->tools || !gt_toolbox_has_tool(gtr->tools, argv[0])) { /* no tool found -> try to open script */ if (gt_file_exists(argv[0])) { /* export script */ gt_lua_set_script_dir(gtr->L, argv[0]); /* run script */ nargv = gt_cstr_array_prefix_first(argv, gt_error_get_progname(err)); gt_lua_set_arg(gtr->L, nargv[0], (const char**) nargv+1); if (luaL_dofile(gtr->L, argv[0])) { /* error */ gt_assert(lua_isstring(gtr->L, -1)); /* error message on top */ gt_error_set(err, "could not execute script %s", lua_tostring(gtr->L, -1)); had_err = -1; lua_pop(gtr->L, 1); /* pop error message */ } } else { /* neither tool nor script found */ gt_error_set(err, "neither tool nor script '%s' found; option -help " "lists possible tools", argv[0]); had_err = -1; } } else { /* run tool */ if (!(toolfunc = gt_toolbox_get(gtr->tools, argv[0]))) { tool = gt_toolbox_get_tool(gtr->tools, argv[0]); gt_assert(tool); } nargv = gt_cstr_array_prefix_first(argv, gt_error_get_progname(err)); gt_error_set_progname(err, nargv[0]); if (toolfunc) had_err = toolfunc(argc, (const char**) nargv, err); else had_err = gt_tool_run(tool, argc, (const char**) nargv, err); } } gt_cstr_array_delete(nargv); if (!had_err && gtr->interactive) { gt_showshortversion(gt_error_get_progname(err)); gt_lua_set_arg(gtr->L, gt_error_get_progname(err), argv); run_interactive_lua_interpreter(gtr->L); } if (had_err) return EXIT_FAILURE; return EXIT_SUCCESS; }