Index: trunk/src/safe_fs.c =================================================================== --- trunk/src/safe_fs.c (revision 11833) +++ trunk/src/safe_fs.c (revision 11834) @@ -39,6 +39,9 @@ #include "globalconst.h" #include "paths.h" +/* opendir, readdir */ +#include "compat_inc.h" + /* Evaluates op(arg1,arg2); returns 0 if the operation is permitted */ static int pcb_safe_fs_check(const char *op, const char *arg1, const char *arg2) { @@ -169,9 +172,34 @@ return res; } -FILE *pcb_fopen_first(const conflist_t *paths, const char *fn, const char *mode, char **full_path) +static FILE *pcb_fopen_at_(const char *dir, const char *fn, char **full_path, pcb_bool recursive) { + +} + +FILE *pcb_fopen_at(const char *dir, const char *fn, const char *mode, char **full_path, pcb_bool recursive) +{ + char tmp[PCB_PATH_MAX]; FILE *res; + + if (full_path != NULL) + *full_path = NULL; + + /* try the trivial: directly under the target dir */ + pcb_snprintf(tmp, sizeof(tmp), "%s%c%s", dir, PCB_DIR_SEPARATOR_C, fn); + res = pcb_fopen(tmp, mode); + if (res == NULL) { + + } + else if (full_path != NULL) + *full_path = pcb_strdup(tmp); + + return res; +} + +FILE *pcb_fopen_first(const conflist_t *paths, const char *fn, const char *mode, char **full_path, pcb_bool recursive) +{ + FILE *res; char *real_fn = pcb_build_fn(fn); conf_listitem_t *ci; @@ -192,8 +220,6 @@ /* have to search paths */ { - char tmp[PCB_PATH_MAX]; - for (ci = conflist_first((conflist_t *)paths); ci != NULL; ci = conflist_next(ci)) { const char *p = ci->val.string[0]; if (ci->type != CFN_STRING) @@ -200,11 +226,8 @@ continue; if (*p == '?') p++; - pcb_snprintf(tmp, sizeof(tmp), "%s%c%s", p, PCB_DIR_SEPARATOR_C, real_fn); - res = pcb_fopen(tmp, mode); + res = pcb_fopen_at(p, real_fn, mode, full_path, recursive); if (res != NULL) { - if (full_path != NULL) - *full_path = pcb_strdup(tmp); free(real_fn); return res; } Index: trunk/src/safe_fs.h =================================================================== --- trunk/src/safe_fs.h (revision 11833) +++ trunk/src/safe_fs.h (revision 11834) @@ -51,7 +51,9 @@ the file name. If fn is not an absolute path, search paths for the first directory from which fn is accessible. If the call doesn't fail and full_path is not NULL, it is set to point to the final full path - (or NULL on failure); the caller needs to call free() on it. */ -FILE *pcb_fopen_first(const conflist_t *paths, const char *fn, const char *mode, char **full_path); + (or NULL on failure); the caller needs to call free() on it. + If recursive is set, all subcirectories under each path is also searched for the file. + */ +FILE *pcb_fopen_first(const conflist_t *paths, const char *fn, const char *mode, char **full_path, pcb_bool recursive); #endif Index: trunk/src_plugins/export_openscad/scad_models.c =================================================================== --- trunk/src_plugins/export_openscad/scad_models.c (revision 11833) +++ trunk/src_plugins/export_openscad/scad_models.c (revision 11834) @@ -20,6 +20,8 @@ * */ +#include "conf_core.h" + static void scad_insert_model(htsp_t *models, const char *name, pcb_coord_t x0, pcb_coord_t y0) { FILE *fin; @@ -26,13 +28,18 @@ char *ref; if (!htsp_has(models, name)) { - char buff[1024]; - fin = pcb_fopen(name, "r"); + char buff[1024], *full_path; + fin = pcb_fopen_first(&conf_core.rc.library_search_paths, name, "r", &full_path, pcb_true); + if (fin != NULL) { char *s, *safe_name = pcb_strdup(name); for(s = safe_name; *s != '\0'; s++) if (!isalnum(*s)) *s = '_'; + + fprintf(f, "// Model loaded from '%s'\n", full_path); + free(full_path); + /* replace the module line */ while(fgets(buff, sizeof(buff), fin) != NULL) { if (strstr(buff, "module") != NULL) { @@ -55,8 +62,10 @@ htsp_set(models, (char *)name, pcb_strdup(buff)); free(safe_name); } - else + else { htsp_set(models, (char *)name, NULL); + pcb_message(PCB_MSG_WARNING, "openscad: can't find model file for %s in the footprint library\n", name); + } } ref = htsp_get(models, (char *)name); if (ref != NULL)