Index: trunk/src_plugins/io_kicad/io_kicad.c =================================================================== --- trunk/src_plugins/io_kicad/io_kicad.c (revision 30793) +++ trunk/src_plugins/io_kicad/io_kicad.c (revision 30794) @@ -74,6 +74,7 @@ io_kicad.test_parse = io_kicad_test_parse; io_kicad.parse_pcb = io_kicad_read_pcb; io_kicad.parse_footprint = io_kicad_parse_element; + io_kicad.map_footprint = io_kicad_map_footprint; io_kicad.parse_font = NULL; io_kicad.write_buffer = NULL; io_kicad.write_subcs_head = io_kicad_write_subcs_head; Index: trunk/src_plugins/io_kicad/read.c =================================================================== --- trunk/src_plugins/io_kicad/read.c (revision 30793) +++ trunk/src_plugins/io_kicad/read.c (revision 30794) @@ -2869,3 +2869,58 @@ /* hit eof before seeing a valid root -> bad */ return 0; } + +/* Decide about the type of a footprint file: + it is a kicad mdoule if the first non-comment is "(module" + No tags are saved. +*/ +pcb_plug_fp_map_t *io_kicad_map_footprint(pcb_plug_io_t *ctx, FILE *f, const char *fn, pcb_plug_fp_map_t *head, int need_tags) +{ + int c, comment_len; + int first_module = 1; + enum { + ST_WS, + ST_COMMENT, + ST_MODULE + } state = ST_WS; + + head->type = PCB_FP_INVALID; + while ((c = fgetc(f)) != EOF) { + switch (state) { + case ST_MODULE: + if (isspace(c)) + break; + if (c == '(') { + head->type = PCB_FP_FILE; + goto out; + } + case ST_WS: + if (isspace(c)) + break; + if (c == '#') { + comment_len = 0; + state = ST_COMMENT; + break; + } + else if ((first_module) && (c == '(')) { + char s[8]; + fgets(s, 7, f); + s[6] = '\0'; + if (strcmp(s, "module") == 0) { + state = ST_MODULE; + break; + } + } + first_module = 0; + /* fall-thru for detecting @ */ + case ST_COMMENT: + comment_len++; + if ((c == '\r') || (c == '\n')) + state = ST_WS; + break; + } + } + +out:; + return head; +} Index: trunk/src_plugins/io_kicad/read.h =================================================================== --- trunk/src_plugins/io_kicad/read.h (revision 30793) +++ trunk/src_plugins/io_kicad/read.h (revision 30794) @@ -33,4 +33,5 @@ int io_kicad_test_parse(pcb_plug_io_t *ctx, pcb_plug_iot_t typ, const char *Filename, FILE *f); int io_kicad_read_pcb(pcb_plug_io_t *ctx, pcb_board_t *Ptr, const char *Filename, conf_role_t settings_dest); int io_kicad_parse_element(pcb_plug_io_t *ctx, pcb_data_t *Ptr, const char *name); +pcb_plug_fp_map_t *io_kicad_map_footprint(pcb_plug_io_t *ctx, FILE *f, const char *fn, pcb_plug_fp_map_t *head, int need_tags); Index: trunk/src_plugins/io_pcb/file.c =================================================================== --- trunk/src_plugins/io_pcb/file.c (revision 30793) +++ trunk/src_plugins/io_pcb/file.c (revision 30794) @@ -1253,16 +1253,6 @@ break; } } - else if ((first_element) && (c == '(')) { - char s[8]; - /* module */ - fgets(s, 7, f); - s[6] = '\0'; - if (strcmp(s, "module") == 0) { - state = ST_ELEMENT; - break; - } - } first_element = 0; /* fall-thru for detecting @ */ case ST_COMMENT: