Index: trunk/src/libpcb_fp.c =================================================================== --- trunk/src/libpcb_fp.c (revision 279) +++ trunk/src/libpcb_fp.c (revision 280) @@ -86,6 +86,71 @@ RCSID("$Id$"); + +pcb_fp_type_t pcb_fp_file_type(const char *fn) +{ + int c; + int first_element = 1; + FILE *f; + enum { + ST_WS, + ST_COMMENT, + ST_ELEMENT, + } state = ST_WS; + + f = fopen(fn, "r"); + if (f == NULL) + return PCB_FP_INVALID; + + while((c = fgetc(f)) != EOF) { + switch(state) { + case ST_ELEMENT: + if (isspace(c)) + break; + if ((c == '(') || (c == '[')) { + fclose(f); + return PCB_FP_FILE; + } + case ST_WS: + if (isspace(c)) + break; + if (c == '#') { + state = ST_COMMENT; + break; + } + else if ((first_element) && (c == 'E')) { + char s[8]; + /* Element */ + fgets(s, 7, f); + s[6] = '\0'; + if (strcmp(s, "lement") == 0) { + state = ST_ELEMENT; + break; + } + } + first_element = 0; + /* fall-thru for detecting @ */ + case ST_COMMENT: + if ((c == '\r') || (c == '\n')) + state = ST_WS; + if (c == '@') { + char s[10]; + /* #@@purpose */ + fgets(s, 9, f); + s[8] = '\0'; + if (strcmp(s, "@purpose") == 0) { + fclose(f); + return PCB_FP_PARAMETRIC; + } + } + break; + } + } + + fclose(f); + return PCB_FP_INVALID; +} + /* This is a helper function for ParseLibrary Tree. Given a char *path, * it finds all newlib footprints in that dir and sticks them into the * library menu structure named entry. @@ -165,7 +230,19 @@ /* printf("... Found a footprint %s ... \n", subdirentry->d_name); */ #endif strcpy(fn_end, subdirentry->d_name); - if (subdirentry->d_type == DT_DIR) { + if ((subdirentry->d_type == DT_REG) || (subdirentry->d_type == DT_LNK)) { + pcb_fp_type_t ty; + ty = pcb_fp_file_type(subdirentry->d_name); +printf("TY: %s -> %d\n", subdirentry->d_name, ty); + if ((ty == PCB_FP_FILE) || (ty == PCB_FP_PARAMETRIC)) { + n_footprints++; + if (cb(cookie, subdir, subdirentry->d_name, PCB_FP_FILE)) + break; + continue; + } + } + + if ((subdirentry->d_type == DT_DIR) || (subdirentry->d_type == DT_LNK)) { cb(cookie, subdir, subdirentry->d_name, PCB_FP_DIR); if (recurse) { n_footprints += pcb_fp_list(fn, recurse, cb, cookie); @@ -172,11 +249,7 @@ } continue; } - if ((subdirentry->d_type == DT_REG) || (subdirentry->d_type == DT_LNK)) { - n_footprints++; - if (cb(cookie, subdir, subdirentry->d_name, PCB_FP_FILE)) - break; - } + } } /* Done. Clean up, cd back into old dir, and return */ Index: trunk/src/libpcb_fp.h =================================================================== --- trunk/src/libpcb_fp.h (revision 279) +++ trunk/src/libpcb_fp.h (revision 280) @@ -1,4 +1,5 @@ typedef enum { + PCB_FP_INVALID, PCB_FP_DIR, PCB_FP_FILE, PCB_FP_PARAMETRIC