/** Set the search path for CODA product definition files. * This function should be called before harp_init() is called. * * The CODA C library is used by the HARP C library for import of products that do not use the HARP format. To access * data in a product, the CODA C library requires a definition of the internal structure of the product file (unless * the product is stored in a self-describing file format). This information is stored in CODA product definition * (.codadef) files. * * The path should be a searchpath for CODA .codadef files similar like the PATH environment variable of your system. * Path components should be separated by ';' on Windows and by ':' on other systems. * * The path may contain both references to files and directories. * CODA will load all .codadef files in the path. Any specified files should be valid .codadef files. For directories, * CODA will (non-recursively) search the directory for all .codadef files. * * If multiple files for the same product class exist in the path, CODA will only use the one with the highest revision * number (this is normally equal to a last modification date that is stored in a .codadef file). * If there are two files for the same product class with identical revision numbers, CODA will use the definitions of * the first .codadef file in the path and ingore the second one. * * Specifying a path using this function will prevent CODA from using the CODA_DEFINITION environment variable. * If you still want CODA to acknowledge the CODA_DEFINITION environment variable then use something like this in your * code: * \code{.c} * if (getenv("CODA_DEFINITION") == NULL) * { * harp_set_coda_definition_path("<your path>"); * } * \endcode * * \param path Search path for .codadef files * \return * \arg \c 0, Success. * \arg \c -1, Error occurred (check #harp_errno). */ LIBHARP_API int harp_set_coda_definition_path(const char *path) { if (coda_set_definition_path(path) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } return 0; }
/** Set the directory for CODA product definition files based on the location of another file. * This function should be called before coda_init() is called. * * This function will try to find the file with filename \a file in the provided searchpath \a searchpath. * The first directory in the searchpath where the file \a file exists will be appended with the relative directory * \a relative_location to determine the CODA product definition path. This path will be used as CODA definition path. * If the file could not be found in the searchpath then the CODA definition path will not be set. * * If the CODA_DEFINITION environment variable was set then this function will not perform a search or set the * definition path (i.e. the CODA definition path will be taken from the CODA_DEFINITION variable). * * If you provide NULL for \a searchpath then the PATH environment variable will be used as searchpath. * For instance, you can use coda_set_definition_path_conditional(argv[0], NULL, "../somedir") to set the CODA * definition path to a location relative to the location of your executable. * * The searchpath, if provided, should have a similar format as the PATH environment variable of your system. Path * components should be separated by ';' on Windows and by ':' on other systems. * * The \a relative_location parameter can point either to a directory (in which case all .codadef files in this * directory will be used) or to a single .codadef file. * * Note that this function differs from coda_set_definition_path() in two important ways: * - it will not modify the definition path if the CODA_DEFINITION variable was set * - it will set the definition path to just a single location (either a single file or a single directory) * * \param file Filename of the file to search for * \param searchpath Search path where to look for the file \a file (can be NULL) * \param relative_location Filepath relative to the directory from \a searchpath where \a file was found that should be * used to determine the CODA definition path. * \return * \arg \c 0, Success. * \arg \c -1, Error occurred (check #coda_errno). */ LIBCODA_API int coda_set_definition_path_conditional(const char *file, const char *searchpath, const char *relative_location) { char *location; if (getenv("CODA_DEFINITION") != NULL) { return 0; } if (searchpath == NULL) { if (coda_path_for_program(file, &location) != 0) { return -1; } } else { if (coda_path_find_file(searchpath, file, &location) != 0) { return -1; } } if (location != NULL) { char *path; if (coda_path_from_path(location, 1, relative_location, &path) != 0) { free(location); return -1; } free(location); if (coda_set_definition_path(path) != 0) { free(path); return -1; } free(path); } return 0; }
int main(int argc, char *argv[]) { int i = 1; ascii_col_sep = " "; show_type = 0; show_unit = 0; show_format = 0; show_description = 0; show_quotes = 0; show_hidden = 0; show_expressions = 0; show_parent_types = 0; show_attributes = 0; use_special_types = 1; if (argc > 1) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { print_help(); exit(0); } if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { print_version(); exit(0); } } if (i + 1 < argc && strcmp(argv[i], "-D") == 0) { coda_set_definition_path(argv[i + 1]); i += 2; } else { #ifdef WIN32 const char *definition_path = "../definitions"; #else const char *definition_path = "../share/" PACKAGE "/definitions"; #endif if (coda_set_definition_path_conditional(argv[0], NULL, definition_path) != 0) { fprintf(stderr, "ERROR: %s\n", coda_errno_to_string(coda_errno)); exit(1); } } coda_option_read_all_definitions = 1; if (coda_init() != 0) { fprintf(stderr, "ERROR: %s\n", coda_errno_to_string(coda_errno)); exit(1); } if (i == argc) { coda_done(); exit(0); } coda_set_option_perform_conversions(0); if (strcmp(argv[i], "doc") == 0) { i++; if (i != argc - 1) { fprintf(stderr, "ERROR: invalid arguments\n"); print_help(); exit(1); } generate_html(argv[i]); } else if (strcmp(argv[i], "list") == 0) { const char *product_class = NULL; const char *product_type = NULL; int version = -1; i++; while (i < argc) { if (strcmp(argv[i], "-e") == 0 || strcmp(argv[i], "--expr") == 0) { show_expressions = 1; } else if (strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quote_strings") == 0) { show_quotes = 1; } else if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--type") == 0) { show_type = 1; } else if (strcmp(argv[i], "-u") == 0 || strcmp(argv[i], "--unit") == 0) { show_unit = 1; } else if (strcmp(argv[i], "--description") == 0) { show_description = 1; } else if (strcmp(argv[i], "--hidden") == 0) { show_hidden = 1; } else if (strcmp(argv[i], "--parent-types") == 0) { show_parent_types = 1; } else if (strcmp(argv[i], "--attributes") == 0) { show_attributes = 1; } else if (strcmp(argv[i], "--no_special_types") == 0) { use_special_types = 0; } else if ((strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--column_separator") == 0) && i + 1 < argc && argv[i + 1][0] != '-') { i++; ascii_col_sep = argv[i]; } else if (argv[i][0] != '-') { break; } else { fprintf(stderr, "ERROR: invalid arguments\n"); print_help(); exit(1); } i++; } if (i < argc) { product_class = argv[i]; i++; if (i < argc) { product_type = argv[i]; i++; if (i < argc) { if (sscanf(argv[i], "%d", &version) != 1) { fprintf(stderr, "ERROR: invalid product version argument\n"); print_help(); exit(1); } i++; if (i < argc) { fprintf(stderr, "ERROR: invalid arguments\n"); print_help(); exit(1); } } } } generate_list(product_class, product_type, version); } else if (strcmp(argv[i], "xmlschema") == 0) { const char *output_file_name = NULL; const char *product_class = NULL; const char *product_type = NULL; int version = -1; i++; while (i < argc) { if ((strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "--output") == 0) && i + 1 < argc && argv[i + 1][0] != '-') { i++; output_file_name = argv[i]; } else if (argv[i][0] != '-') { break; } else { fprintf(stderr, "ERROR: invalid arguments\n"); print_help(); exit(1); } i++; } if (i != argc - 3) { fprintf(stderr, "ERROR: invalid arguments\n"); print_help(); exit(1); } product_class = argv[i]; i++; product_type = argv[i]; i++; if (sscanf(argv[i], "%d", &version) != 1) { fprintf(stderr, "ERROR: invalid product version argument\n"); print_help(); exit(1); } generate_xmlschema(output_file_name, product_class, product_type, version); } else if (strcmp(argv[i], "dtree") == 0) { coda_format format; i++; if (i != argc - 1) { fprintf(stderr, "ERROR: invalid arguments\n"); print_help(); exit(1); } if (coda_format_from_string(argv[i], &format) != 0) { fprintf(stderr, "ERROR: invalid arguments\n"); print_help(); exit(1); } generate_detection_tree(format); } else if (strcmp(argv[i], "definition") == 0) { const char *output_file_name = NULL; i++; while (i < argc) { if ((strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "--output") == 0) && i + 1 < argc && argv[i + 1][0] != '-') { i++; output_file_name = argv[i]; } else if (argv[i][0] != '-') { break; } else { fprintf(stderr, "ERROR: invalid arguments\n"); print_help(); exit(1); } i++; } if (i != argc - 1) { fprintf(stderr, "ERROR: invalid arguments\n"); print_help(); exit(1); } generate_definition(output_file_name, argv[i]); } else { fprintf(stderr, "ERROR: invalid arguments\n"); print_help(); exit(1); } coda_done(); return 0; }