Index: trunk/src/plug_footprint.c =================================================================== --- trunk/src/plug_footprint.c (revision 19629) +++ trunk/src/plug_footprint.c (revision 19630) @@ -38,6 +38,9 @@ #include "compat_misc.h" #include "event.h" +FILE PCB_FP_FOPEN_IN_DST_, *PCB_FP_FOPEN_IN_DST = &PCB_FP_FOPEN_IN_DST; + + pcb_plug_fp_t *pcb_plug_fp_chain = NULL; pcb_fplibrary_t pcb_library; @@ -111,7 +114,7 @@ return (char *) tagid; } -FILE *pcb_fp_fopen(const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx) +FILE *pcb_fp_fopen(const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx, pcb_data_t *dst) { FILE *res = NULL; if (strchr(path, ':') != NULL) { @@ -125,13 +128,13 @@ next++; } - PCB_HOOK_CALL(pcb_plug_fp_t, pcb_plug_fp_chain, fp_fopen, res, != NULL, (self, curr, name, fctx)); + PCB_HOOK_CALL(pcb_plug_fp_t, pcb_plug_fp_chain, fp_fopen, res, != NULL, (self, curr, name, fctx, dst)); curr = next; } free(tmp); } else - PCB_HOOK_CALL(pcb_plug_fp_t, pcb_plug_fp_chain, fp_fopen, res, != NULL, (self, path, name, fctx)); + PCB_HOOK_CALL(pcb_plug_fp_t, pcb_plug_fp_chain, fp_fopen, res, != NULL, (self, path, name, fctx, dst)); return res; } Index: trunk/src/plug_footprint.h =================================================================== --- trunk/src/plug_footprint.h (revision 19629) +++ trunk/src/plug_footprint.h (revision 19630) @@ -3,6 +3,7 @@ #include #include "vtlibrary.h" +#include "data.h" typedef struct pcb_plug_fp_s pcb_plug_fp_t; @@ -15,7 +16,7 @@ } pcb_fp_fopen_ctx_t; /* hook bindings, see below */ -FILE *pcb_fp_fopen(const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx); +FILE *pcb_fp_fopen(const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx, pcb_data_t *dst); void pcb_fp_fclose(FILE * f, pcb_fp_fopen_ctx_t *fctx); /* duplicates the name and splits it into a basename and params; @@ -37,6 +38,8 @@ void pcb_fp_uninit(); /**************************** API definition *********************************/ +extern FILE *PCB_FP_FOPEN_IN_DST; + struct pcb_plug_fp_s { pcb_plug_fp_t *next; void *plugin_data; @@ -51,8 +54,10 @@ If name is not an absolute path, search_path is searched for the first match. The user has to supply a state integer that will be used by pcb_pcb_fp_fclose(). Must fill in fctx->backend, may use any other field of fctx as well. + If dst is non-NULL, some backends (e.g. fp_board) may decide to place the + loaded footprint in dst and return PCB_FP_FOPEN_IN_DST. */ - FILE *(*fp_fopen)(pcb_plug_fp_t *ctx, const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx); + FILE *(*fp_fopen)(pcb_plug_fp_t *ctx, const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx, pcb_data_t *dst); /* Close the footprint file opened by pcb_pcb_fp_fopen(). */ void (*fp_fclose)(pcb_plug_fp_t *ctx, FILE * f, pcb_fp_fopen_ctx_t *fctx); Index: trunk/src/plug_io.c =================================================================== --- trunk/src/plug_io.c (revision 19629) +++ trunk/src/plug_io.c (revision 19630) @@ -248,7 +248,9 @@ FILE *f; pcb_fp_fopen_ctx_t fctx; - f = pcb_fp_fopen(pcb_fp_default_search_path(), Filename, &fctx); + f = pcb_fp_fopen(pcb_fp_default_search_path(), Filename, &fctx, Ptr); + if (f == PCB_FP_FOPEN_IN_DST) + return 0; len = pcb_test_parse_all(f, Filename, fmt, PCB_IOT_FOOTPRINT, available, accepts, &accept_total, sizeof(available)/sizeof(available[0]), 0, 0); if (f != NULL) pcb_fp_fclose(f, &fctx); Index: trunk/src_plugins/fp_board/fp_board.c =================================================================== --- trunk/src_plugins/fp_board/fp_board.c (revision 19629) +++ trunk/src_plugins/fp_board/fp_board.c (revision 19630) @@ -78,7 +78,7 @@ return 0; } -static FILE *fp_board_fopen(pcb_plug_fp_t *ctx, const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx) +static FILE *fp_board_fopen(pcb_plug_fp_t *ctx, const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx, pcb_data_t *dst) { char *fpath, *ids, *end; unsigned long int id, req_id; @@ -85,8 +85,10 @@ pcb_buffer_t buff; FILE *f = NULL; pcb_opctx_t op; - char *tmp_name = ".board.fp"; + if (dst == NULL) + return; + if (strncmp(name, REQUIRE_PATH_PREFIX, strlen(REQUIRE_PATH_PREFIX)) != 0) return NULL; @@ -116,27 +118,16 @@ id++; if (id == req_id) { /* if (strcmp(element->Name[PCB_ELEMNAME_IDX_DESCRIPTION].TextString, l->name)) */ - pcb_buffer_t buff2; #warning TODO: extend the API: /* This is not pretty: we are saving the element to a file so we can return a FILE *. Later on we should just return the footprint. */ memset(&op, 0, sizeof(op)); - op.buffer.dst = calloc(sizeof(pcb_data_t), 1); + op.buffer.dst = dst; pcb_data_set_layer_parents(op.buffer.dst); pcb_subcop_add_to_buffer(&op, subc); - f = pcb_fopen(tmp_name, "w"); - memset(&buff2, 0, sizeof(buff2)); - buff2.Data = op.buffer.dst; - pcb_write_buffer(f, &buff2, NULL, pcb_true); - fclose(f); - - pcb_data_free(op.buffer.dst); - free(op.buffer.dst); - - f = pcb_fopen(tmp_name, "r"); - break; + return PCB_FP_FOPEN_IN_DST; } } PCB_END_LOOP; Index: trunk/src_plugins/fp_fs/fp_fs.c =================================================================== --- trunk/src_plugins/fp_fs/fp_fs.c (revision 19629) +++ trunk/src_plugins/fp_fs/fp_fs.c (revision 19630) @@ -485,7 +485,7 @@ #define F_IS_PARAMETRIC 0 #define F_TMPNAME 1 -static FILE *fp_fs_fopen(pcb_plug_fp_t *ctx, const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx) +static FILE *fp_fs_fopen(pcb_plug_fp_t *ctx, const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx, pcb_data_t *dst) { char *basename, *params, *fullname; FILE *fp, *f = NULL; Index: trunk/src_plugins/fp_wget/edakrill.c =================================================================== --- trunk/src_plugins/fp_wget/edakrill.c (revision 19629) +++ trunk/src_plugins/fp_wget/edakrill.c (revision 19630) @@ -245,7 +245,7 @@ #define FIELD_WGET_CTX 0 -FILE *fp_edakrill_fopen(pcb_plug_fp_t *ctx, const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx) +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; char tmp[1024]; Index: trunk/src_plugins/fp_wget/edakrill.h =================================================================== --- trunk/src_plugins/fp_wget/edakrill.h (revision 19629) +++ trunk/src_plugins/fp_wget/edakrill.h (revision 19630) @@ -1,7 +1,7 @@ #include "plug_footprint.h" #include "fp_wget_conf.h" int fp_edakrill_load_dir(pcb_plug_fp_t *ctx, const char *path, int force); -FILE *fp_edakrill_fopen(pcb_plug_fp_t *ctx, const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx); +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); void fp_edakrill_fclose(pcb_plug_fp_t *ctx, FILE * f, pcb_fp_fopen_ctx_t *fctx); void fp_edakrill_init(void); void fp_edakrill_uninit(void); Index: trunk/src_plugins/fp_wget/gedasymbols.c =================================================================== --- trunk/src_plugins/fp_wget/gedasymbols.c (revision 19629) +++ trunk/src_plugins/fp_wget/gedasymbols.c (revision 19630) @@ -153,7 +153,7 @@ #define FIELD_WGET_CTX 0 -FILE *fp_gedasymbols_fopen(pcb_plug_fp_t *ctx, const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx) +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; char tmp[1024]; Index: trunk/src_plugins/fp_wget/gedasymbols.h =================================================================== --- trunk/src_plugins/fp_wget/gedasymbols.h (revision 19629) +++ trunk/src_plugins/fp_wget/gedasymbols.h (revision 19630) @@ -1,7 +1,7 @@ #include "plug_footprint.h" #include "fp_wget_conf.h" int fp_gedasymbols_load_dir(pcb_plug_fp_t *ctx, const char *path, int force); -FILE *fp_gedasymbols_fopen(pcb_plug_fp_t *ctx, const char *path, const char *name, pcb_fp_fopen_ctx_t *fctx); +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); void fp_gedasymbols_fclose(pcb_plug_fp_t *ctx, FILE * f, pcb_fp_fopen_ctx_t *fctx); void fp_gedasymbols_init(void); void fp_gedasymbols_uninit(void); Index: trunk/src_plugins/io_kicad/read.c =================================================================== --- trunk/src_plugins/io_kicad/read.c (revision 19629) +++ trunk/src_plugins/io_kicad/read.c (revision 19630) @@ -2703,7 +2703,7 @@ read_state_t st; gsx_parse_res_t res; - f = pcb_fp_fopen(pcb_fp_default_search_path(), name, &fpst); + f = pcb_fp_fopen(pcb_fp_default_search_path(), name, &fpst, NULL); if (f == NULL) { return -1; Index: trunk/src_plugins/io_lihata/read.c =================================================================== --- trunk/src_plugins/io_lihata/read.c (revision 19629) +++ trunk/src_plugins/io_lihata/read.c (revision 19630) @@ -2431,7 +2431,7 @@ FILE *f; pcb_subc_t *sc; - f = pcb_fp_fopen(pcb_fp_default_search_path(), name, &st); + f = pcb_fp_fopen(pcb_fp_default_search_path(), name, &st, NULL); if (f != NULL) { doc = lht_dom_load_stream(f, name, &errmsg); Index: trunk/src_plugins/io_pcb/parse_l.c =================================================================== --- trunk/src_plugins/io_pcb/parse_l.c (revision 19629) +++ trunk/src_plugins/io_pcb/parse_l.c (revision 19630) @@ -2459,7 +2459,7 @@ int ret; pcb_fp_fopen_ctx_t st; - f = pcb_fp_fopen(pcb_fp_default_search_path(), name, &st); + f = pcb_fp_fopen(pcb_fp_default_search_path(), name, &st, NULL); /* set up the yy globals only after the pcb_fp_fopen() because it can also call Parse */ Index: trunk/src_plugins/io_pcb/parse_l.l =================================================================== --- trunk/src_plugins/io_pcb/parse_l.l (revision 19629) +++ trunk/src_plugins/io_pcb/parse_l.l (revision 19630) @@ -318,7 +318,7 @@ int ret; pcb_fp_fopen_ctx_t st; - f = pcb_fp_fopen(pcb_fp_default_search_path(), name, &st); + f = pcb_fp_fopen(pcb_fp_default_search_path(), name, &st, NULL); /* set up the yy globals only after the pcb_fp_fopen() because it can also call Parse */