Added ECCODES_EXTRA_SAMPLES_PATH (similar to ECCODES_EXTRA_DEFINITION_PATH)

This commit is contained in:
Shahram Najm 2020-02-07 13:20:20 +00:00
parent dc2f7ece32
commit 7189929c57
3 changed files with 30 additions and 22 deletions

View File

@ -27,13 +27,13 @@ int feenableexcept(int excepts);
grib_string_list grib_file_not_found; grib_string_list grib_file_not_found;
/* Windows always has a colon in pathnames e.g. C:\temp\file. So instead we use semi-colons as delimiter */ /* Windows always has a colon in pathnames e.g. C:\temp\file. So instead we use semi-colons as delimiter */
/* in order to have multiple definitions directories */ /* in order to have multiple definitions/samples directories */
#ifdef ECCODES_ON_WINDOWS #ifdef ECCODES_ON_WINDOWS
#define DEFS_PATH_DELIMITER_CHAR ';' #define ECC_PATH_DELIMITER_CHAR ';'
#define DEFS_PATH_DELIMITER_STR ";" #define ECC_PATH_DELIMITER_STR ";"
#else #else
#define DEFS_PATH_DELIMITER_CHAR ':' #define ECC_PATH_DELIMITER_CHAR ':'
#define DEFS_PATH_DELIMITER_STR ":" #define ECC_PATH_DELIMITER_STR ":"
#endif #endif
#if GRIB_PTHREADS #if GRIB_PTHREADS
@ -371,8 +371,8 @@ static grib_context default_grib_context = {
#endif #endif
}; };
/* Hopefully big enough. Note: GRIB_DEFINITION_PATH can contain SEVERAL colon-separated sub-paths */ /* Hopefully big enough. Note: Definitions and samples path environment variables can contain SEVERAL colon-separated directories */
#define DEF_PATH_MAXLEN 8192 #define ECC_PATH_MAXLEN 8192
grib_context* grib_context_get_default() grib_context* grib_context_get_default()
{ {
@ -470,14 +470,14 @@ grib_context* grib_context_get_default()
const char* test_defs = codes_getenv("_ECCODES_ECMWF_TEST_DEFINITION_PATH"); const char* test_defs = codes_getenv("_ECCODES_ECMWF_TEST_DEFINITION_PATH");
const char* test_samp = codes_getenv("_ECCODES_ECMWF_TEST_SAMPLES_PATH"); const char* test_samp = codes_getenv("_ECCODES_ECMWF_TEST_SAMPLES_PATH");
if (test_defs) { if (test_defs) {
char buffer[DEF_PATH_MAXLEN]; char buffer[ECC_PATH_MAXLEN];
strcpy(buffer, default_grib_context.grib_definition_files_path); strcpy(buffer, default_grib_context.grib_definition_files_path);
strcat(buffer, ":"); strcat(buffer, ":");
strcat(buffer, strdup(test_defs)); strcat(buffer, strdup(test_defs));
default_grib_context.grib_definition_files_path = strdup(buffer); default_grib_context.grib_definition_files_path = strdup(buffer);
} }
if (test_samp) { if (test_samp) {
char buffer[DEF_PATH_MAXLEN]; char buffer[ECC_PATH_MAXLEN];
strcpy(buffer, default_grib_context.grib_samples_path); strcpy(buffer, default_grib_context.grib_samples_path);
strcat(buffer, ":"); strcat(buffer, ":");
strcat(buffer, strdup(test_samp)); strcat(buffer, strdup(test_samp));
@ -489,12 +489,22 @@ grib_context* grib_context_get_default()
{ {
const char* defs_extra = getenv("ECCODES_EXTRA_DEFINITION_PATH"); const char* defs_extra = getenv("ECCODES_EXTRA_DEFINITION_PATH");
if (defs_extra) { if (defs_extra) {
char buffer[DEF_PATH_MAXLEN]; char buffer[ECC_PATH_MAXLEN];
ecc_snprintf(buffer, DEF_PATH_MAXLEN, "%s%c%s", defs_extra, DEFS_PATH_DELIMITER_CHAR, default_grib_context.grib_definition_files_path); ecc_snprintf(buffer, ECC_PATH_MAXLEN, "%s%c%s", defs_extra, ECC_PATH_DELIMITER_CHAR, default_grib_context.grib_definition_files_path);
default_grib_context.grib_definition_files_path = strdup(buffer); default_grib_context.grib_definition_files_path = strdup(buffer);
} }
} }
/* Samples path extra: Added at the head of (i.e. before) existing path */
{
const char* samples_extra = getenv("ECCODES_EXTRA_SAMPLES_PATH");
if (samples_extra) {
char buffer[ECC_PATH_MAXLEN];
ecc_snprintf(buffer, ECC_PATH_MAXLEN, "%s%c%s", samples_extra, ECC_PATH_DELIMITER_CHAR, default_grib_context.grib_samples_path);
default_grib_context.grib_samples_path = strdup(buffer);
}
}
grib_context_log(&default_grib_context, GRIB_LOG_DEBUG, "Definitions path: %s", grib_context_log(&default_grib_context, GRIB_LOG_DEBUG, "Definitions path: %s",
default_grib_context.grib_definition_files_path); default_grib_context.grib_definition_files_path);
grib_context_log(&default_grib_context, GRIB_LOG_DEBUG, "Samples path: %s", grib_context_log(&default_grib_context, GRIB_LOG_DEBUG, "Samples path: %s",
@ -576,7 +586,7 @@ static char* resolve_path(grib_context* c, char* path)
#ifdef ECCODES_ON_WINDOWS #ifdef ECCODES_ON_WINDOWS
result = grib_context_strdup(c, path); result = grib_context_strdup(c, path);
#else #else
char resolved[DEF_PATH_MAXLEN + 1]; char resolved[ECC_PATH_MAXLEN + 1];
if (!realpath(path, resolved)) { if (!realpath(path, resolved)) {
result = grib_context_strdup(c, path); /* Failed to resolve. Use original path */ result = grib_context_strdup(c, path); /* Failed to resolve. Use original path */
} }
@ -590,7 +600,7 @@ static char* resolve_path(grib_context* c, char* path)
static int init_definition_files_dir(grib_context* c) static int init_definition_files_dir(grib_context* c)
{ {
int err = 0; int err = 0;
char path[DEF_PATH_MAXLEN]; char path[ECC_PATH_MAXLEN];
char* p = NULL; char* p = NULL;
grib_string_list* next = NULL; grib_string_list* next = NULL;
@ -603,17 +613,17 @@ static int init_definition_files_dir(grib_context* c)
return GRIB_NO_DEFINITIONS; return GRIB_NO_DEFINITIONS;
/* Note: strtok modifies its first argument so we copy */ /* Note: strtok modifies its first argument so we copy */
strncpy(path, c->grib_definition_files_path, DEF_PATH_MAXLEN); strncpy(path, c->grib_definition_files_path, ECC_PATH_MAXLEN);
GRIB_MUTEX_INIT_ONCE(&once, &init); GRIB_MUTEX_INIT_ONCE(&once, &init);
GRIB_MUTEX_LOCK(&mutex_c); GRIB_MUTEX_LOCK(&mutex_c);
p = path; p = path;
while (*p != DEFS_PATH_DELIMITER_CHAR && *p != '\0') while (*p != ECC_PATH_DELIMITER_CHAR && *p != '\0')
p++; p++;
if (*p != DEFS_PATH_DELIMITER_CHAR) { if (*p != ECC_PATH_DELIMITER_CHAR) {
/* No delimiter found so this is a single directory */ /* No delimiter found so this is a single directory */
c->grib_definition_files_dir = (grib_string_list*)grib_context_malloc_clear_persistent(c, sizeof(grib_string_list)); c->grib_definition_files_dir = (grib_string_list*)grib_context_malloc_clear_persistent(c, sizeof(grib_string_list));
c->grib_definition_files_dir->value = resolve_path(c, path); c->grib_definition_files_dir->value = resolve_path(c, path);
@ -621,7 +631,7 @@ static int init_definition_files_dir(grib_context* c)
else { else {
/* Definitions path contains multiple directories */ /* Definitions path contains multiple directories */
char* dir = NULL; char* dir = NULL;
dir = strtok(path, DEFS_PATH_DELIMITER_STR); dir = strtok(path, ECC_PATH_DELIMITER_STR);
while (dir != NULL) { while (dir != NULL) {
if (next) { if (next) {
@ -633,7 +643,7 @@ static int init_definition_files_dir(grib_context* c)
next = c->grib_definition_files_dir; next = c->grib_definition_files_dir;
} }
next->value = resolve_path(c, dir); next->value = resolve_path(c, dir);
dir = strtok(NULL, DEFS_PATH_DELIMITER_STR); dir = strtok(NULL, ECC_PATH_DELIMITER_STR);
} }
} }

View File

@ -113,13 +113,13 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres)
grib_expression_string_compare* e = (grib_expression_string_compare*)g; grib_expression_string_compare* e = (grib_expression_string_compare*)g;
v1 = grib_expression_evaluate_string(h, e->left, b1, &l1, &ret); v1 = grib_expression_evaluate_string(h, e->left, b1, &l1, &ret);
if (!v1) { if (!v1 || ret) {
*lres = 0; *lres = 0;
return ret; return ret;
} }
v2 = grib_expression_evaluate_string(h, e->right, b2, &l2, &ret); v2 = grib_expression_evaluate_string(h, e->right, b2, &l2, &ret);
if (!v2) { if (!v2 || ret) {
*lres = 0; *lres = 0;
return ret; return ret;
} }

View File

@ -1,6 +1,4 @@
leak:tools/grib_filter.c leak:tools/grib_filter.c
leak:tools/bufr_filter.c leak:tools/bufr_filter.c
leak:tools/gts_filter.c leak:tools/gts_filter.c
leak:tools/metar_filter.c
leak:tools/taf_filter.c
leak:src/action_class_rename.c leak:src/action_class_rename.c