static corto_dl corto_load_validLibrary(corto_string fileName, corto_string *build_out) { corto_dl result = NULL; corto_string ___ (*build)(void); corto_string ___ (*library)(void); if (build_out) { *build_out = NULL; } if (!(result = corto_dlOpen(fileName))) { corto_seterr("%s", corto_dlError()); goto error; } /* Lookup build function */ build = (corto_string ___ (*)(void))corto_dlProc(result, "corto_getBuild"); library = (corto_string ___ (*)(void))corto_dlProc(result, "corto_getLibrary"); /* Validate version */ if (build && strcmp(build(), corto_getBuild())) { corto_seterr( "corto: library '%s' links with conflicting corto library\n" " links with: '%s' (%s)\n" " current: '%s' (%s)\n", fileName, library ? library() : "???", build(), corto_getLibrary(), corto_getBuild()); /* Library is linked with different Corto version */ if (build_out) { *build_out = corto_strdup(build()); } goto error; } else if (build) { corto_debug( "loader: '%s' links with correct corto library\n build: '%s'\n library: '%s'\n", fileName, build(), library()); } else { corto_trace("loader: found '%s' which doesn't link with corto", fileName); } /* If no build function is available, the library is not linked with * Corto, and probably represents a --nocorto package */ return result; error: if (result) corto_dlClose(result); return NULL; }
int main(int argc, char* argv[]) { int i; corto_bool mute = FALSE; corto_bool startShell = FALSE; /* Parse debugging options before starting the core */ for(i = 1; i < argc; i++) { if (*argv[i] == '-') { if (*(argv[i]+1) == 'd') { CORTO_DEBUG_ENABLED = TRUE; }else if (*(argv[i]+1) == 't') { CORTO_TRACE_OBJECT = argv[i + 1]; i ++; }else if (*(argv[i]+1) == 'h') { cortotool_printUsage(FALSE); break; } else if (*(argv[i]+1) == 'v') { printf("%s\n", CORTO_VERSION); } else if (*(argv[i]+1) == '-') { if (!strcmp(argv[i], "--backtrace")) { CORTO_BACKTRACE_ENABLED = TRUE; } } } } /* Start corto */ corto_start(); /* Parse arguments */ if (argc == 1) { if (cortotool_shell(argc, argv)) { goto error; } } else { for(i=1; i<argc; i++) { if (*argv[i] == '-') { if (*(argv[i]+1) == 'd') { /* Already handled */ }else if (*(argv[i]+1) == 't') { /* Already handled */ i ++; }else if (*(argv[i]+1) == 'h') { /* Already handled */ break; } else if (*(argv[i]+1) == 'v') { /* Already handled */ } else if (*(argv[i]+1) == 'c') { if (corto_loadComponent(argv[i + 1], 0, NULL)) { corto_error("%s: %s", argv[i + 1], corto_lasterr()); goto error; } i++; } else if (*(argv[i]+1) == 'p') { if (corto_load(argv[i + 1], 0, NULL)) { corto_error("%s: %s", argv[i + 1], corto_lasterr()); goto error; } i++; } else if (*(argv[i]+1) == '-') { if (!strcmp(argv[i] + 2, "version")) { printf("corto version %s (%s) build %s\n\n", CORTO_VERSION, CORTO_PLATFORM_STRING, corto_getBuild()); } else if (!strcmp(argv[i] + 2, "minor")) { printf("%s.%s\n", CORTO_VERSION_MAJOR, CORTO_VERSION_MINOR); } else if (!strcmp(argv[i] + 2, "help")) { cortotool_printUsage(FALSE); } else if (!strcmp(argv[i] + 2, "expert")) { cortotool_printUsage(TRUE); } else if (!strcmp(argv[i] + 2, "mute")) { mute = TRUE; } else if (!strcmp(argv[i] + 2, "backtrace")) { /* Already handled */ } else { corto_error("corto: unknown option '%s'", argv[i] + 2); cortotool_printUsage(FALSE); goto error; } } else { corto_error("corto: unknown option '%s'", argv[i] + 1); cortotool_printUsage(FALSE); goto error; } } else if (!strcmp(argv[i], "create")) { if (cortotool_create(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "add")) { if (cortotool_add(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "remove")) { if (cortotool_remove(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "list")) { if (cortotool_list(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "pp")) { if (cortotool_pp(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "publish")) { if (cortotool_publish(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "build")) { if (cortotool_build(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "rebuild")) { if (cortotool_rebuild(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "test")) { if (cortotool_test(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "clean")) { if (cortotool_clean(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "install")) { if (cortotool_install(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "uninstall")) { if (cortotool_uninstall(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "update")) { if (cortotool_update(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "locate")) { if (cortotool_locate(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "run")) { if (cortotool_run(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "debug")) { if (cortotool_debug(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[i], "shell")) { startShell = TRUE; } else if (!strcmp(argv[1], "tar")) { if (cortotool_tar(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[1], "untar")) { if (cortotool_untar(argc-i, &argv[i])) { goto error; } break; } else if (!strcmp(argv[1], "help")) { if (cortotool_help(argc-i, &argv[i])) { goto error; } break; } else { if (corto_load(argv[i], argc-i, &argv[i])) { if (!mute) { if (corto_lasterr()) { corto_error("corto: %s: %s", argv[i], corto_lasterr()); } else { corto_error("corto: %s: input error", argv[i]); } } goto error; } break; } } } if (startShell) { if (cortotool_shell(argc-i, &argv[i])) { goto error; } } /* Stop corto */ corto_stop(); return 0; error: return -1; }