Index: read.c =================================================================== --- read.c (revision 30808) +++ read.c (revision 30809) @@ -808,14 +808,55 @@ return io_bxl_test_parse2(NULL, ctx, typ, filename, f, NULL, NULL); } +/* Append a file name to the footprint map at tail; the first item is appended + assuming there would be only one footprint in the file; from the second item + the head item is converted into a footprint library */ +void pcb_io_fp_map_append(pcb_plug_fp_map_t **tail, pcb_plug_fp_map_t *head, const char *filename, const char *fpname) +{ + pcb_plug_fp_map_t *m; + + switch(head->type) { + case PCB_FP_INVALID: /* first append */ + (*tail)->type = PCB_FP_FILE; + (*tail)->name = pcb_strdup(fpname); + break; + case PCB_FP_FILE: /* second append */ + /* clone the existing head */ + m = calloc(sizeof(pcb_plug_fp_map_t), 1); + m->type = PCB_FP_FILE; + m->libtype = PCB_LIB_FOOTPRINT; + m->name = head->name; + + head->type = PCB_FP_DIR; + head->libtype = PCB_LIB_DIR; + head->name = pcb_strdup(filename); + head->next = m; + + *tail = m; + /* fall through adding the second */ + case PCB_FP_DIR: /* third append */ + m = calloc(sizeof(pcb_plug_fp_map_t), 1); + m->type = PCB_FP_FILE; + m->libtype = PCB_LIB_FOOTPRINT; + m->name = pcb_strdup(fpname); + + (*tail)->next = m; + *tail = m; + break; + } +} + + typedef struct { int has_fp; + const char *fn; + pcb_plug_fp_map_t *curr, *head; } bxl_fp_map_ctx_t; static void pat_cb(void *cbctx_, const char *name) { bxl_fp_map_ctx_t *cbctx = cbctx_; - cbctx->has_fp++; + pcb_io_fp_map_append(&cbctx->curr, cbctx->head, cbctx->fn, name); } pcb_plug_fp_map_t *io_bxl_map_footprint(pcb_plug_io_t *ctx, FILE *f, const char *fn, pcb_plug_fp_map_t *head, int need_tags) @@ -824,11 +865,12 @@ bxl_fp_map_ctx_t cbctx; cbctx.has_fp = 0; + cbctx.curr = cbctx.head = head; + cbctx.fn = fn; res = io_bxl_test_parse2(NULL, ctx, PCB_IOT_FOOTPRINT, fn, f, &cbctx, pat_cb); - if ((res <= 0) || (cbctx.has_fp == 0)) + if (res <= 0) return NULL; - head->type = PCB_FP_FILE; return head; }