Index: edakrill.c =================================================================== --- edakrill.c (revision 28563) +++ edakrill.c (revision 28564) @@ -245,6 +245,45 @@ #define FIELD_WGET_CTX 0 +static int search_edakrill(char *out, int out_len, FILE *f, const char *fn) +{ + char *line, line_[8192], *end; + + *out = '\0'; + + if (f == NULL) + return -1; + + while((line = fgets(line_, sizeof(line_), f)) != NULL) { + size_t len; + if (*line != 'f') + continue; + next:; + line += 2; + len = strlen(line); + if ((strstr(line, fn) != NULL) && (len < out_len)) { + while((line = fgets(line_, sizeof(line_), f)) != NULL) { + if (*line == 'f') + goto next; /* no suitable 'm' line but bumped into the next 'f' line -> process the next fp */ + if (*line == 'm') { + line += 2; + + end = strstr(line, ".cnv.fp "); /* accept only converted pcb footprints for now */ + if (end != NULL) { + end += 7; + *end = '\0'; + end++; + strcpy(out, line); + return 0; + } + } + } + } + } + return -1; +} + + FILE *fp_edakrill_fopen(pcb_plug_fp_t *ctx, const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx, pcb_data_t *dst) { gds_t s; @@ -263,7 +302,7 @@ name++; if (from_path) { - if (fp_wget_search(tmp, sizeof(tmp), name, !conf_fp_wget.plugins.fp_wget.auto_update_edakrill, url_idx_list, conf_fp_wget.plugins.fp_wget.cache_dir) != 0) + if (fp_wget_search(tmp, sizeof(tmp), name, !conf_fp_wget.plugins.fp_wget.auto_update_edakrill, url_idx_list, conf_fp_wget.plugins.fp_wget.cache_dir, search_edakrill) != 0) goto bad; name = tmp; } Index: gedasymbols.c =================================================================== --- gedasymbols.c (revision 28563) +++ gedasymbols.c (revision 28564) @@ -153,6 +153,30 @@ #define FIELD_WGET_CTX 0 +static int search_gedasyms(char *out, int out_len, FILE *f, const char *fn) +{ + char *line, line_[8192]; + + *out = '\0'; + + if (f == NULL) + return -1; + + while((line = fgets(line_, sizeof(line_), f)) != NULL) { + char *sep; + sep = strchr(line, '|'); + if (sep == NULL) + continue; + *sep = '\0'; + if ((strstr(line, fn) != NULL) && (strlen(line) < out_len)) { + strcpy(out, line); + return 0; + } + } + return -1; +} + + FILE *fp_gedasymbols_fopen(pcb_plug_fp_t *ctx, const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx, pcb_data_t *dst) { gds_t s; @@ -171,7 +195,7 @@ name++; if (from_path) { - if (fp_wget_search(tmp, sizeof(tmp), name, !conf_fp_wget.plugins.fp_wget.auto_update_gedasymbols, url_idx_list, conf_fp_wget.plugins.fp_wget.cache_dir) != 0) + if (fp_wget_search(tmp, sizeof(tmp), name, !conf_fp_wget.plugins.fp_wget.auto_update_gedasymbols, url_idx_list, conf_fp_wget.plugins.fp_wget.cache_dir, search_gedasyms) != 0) goto bad; name = tmp; } Index: wget_common.c =================================================================== --- wget_common.c (revision 28563) +++ wget_common.c (revision 28564) @@ -183,32 +183,8 @@ return changed; } -int fp_wget_search_(char *out, int out_len, FILE *f, const char *fn) +int fp_wget_search(char *out, int out_len, const char *name, int offline, const char *url, const char *cache, int (*fp_wget_search_)(char *out, int out_len, FILE *f, const char *fn)) { - char *line, line_[8192]; - - *out = '\0'; - - if (f == NULL) - return -1; - - while((line = fgets(line_, sizeof(line_), f)) != NULL) { - char *sep; - sep = strchr(line, '|'); - if (sep == NULL) - continue; - *sep = '\0'; - if ((strstr(line, fn) != NULL) && (strlen(line) < out_len)) { - strcpy(out, line); - return 0; - } - } - return -1; -} - - -int fp_wget_search(char *out, int out_len, const char *name, int offline, const char *url, const char *cache) -{ FILE *f_idx; int fctx; fp_get_mode mode = offline ? FP_WGET_OFFLINE : 0; Index: wget_common.h =================================================================== --- wget_common.h (revision 28563) +++ wget_common.h (revision 28564) @@ -12,10 +12,7 @@ int md5_cmp_free(const char *last_fn, char *md5_last, char *md5_new); /* search fn in an auto updated index file; return 0 on success and - fill in out with the full path from the index. */ -int fp_wget_search(char *out, int out_len, const char *fn, int offline, const char *idx_url, const char *idx_cache); - -/* search fn in an index file; return 0 on success and fill in out with the + fill in out with the full path from the index. Search_cb: + search fn in an index file; return 0 on success and fill in out with the full path from the index. */ -int fp_wget_search_(char *out, int out_len, FILE *f_idx, const char *fn); - +int fp_wget_search(char *out, int out_len, const char *fn, int offline, const char *idx_url, const char *idx_cache, int (*search_cb)(char *out, int out_len, FILE *f, const char *fn));