Index: trunk/doc-rnd/TODO =================================================================== --- trunk/doc-rnd/TODO (revision 1429) +++ trunk/doc-rnd/TODO (revision 1430) @@ -5,7 +5,6 @@ - nelma and gcode both invent .png name locally - get rid of gcode/lists.h, and vector.[ch] (autorouter) - mods: - - move libpcbfp - gpmi (and other buildins/plugins) not showing up in the about box CLEANUP #4 Index: trunk/src/global.h =================================================================== --- trunk/src/global.h (revision 1429) +++ trunk/src/global.h (revision 1430) @@ -240,11 +240,14 @@ int index; } RouteStyleType, *RouteStyleTypePtr; +typedef struct LibraryEntryTpye_s LibraryEntryType, *LibraryEntryTypePtr; +typedef struct LibraryMenuType_s LibraryMenuType, *LibraryMenuTypePtr; + #include "plug_footprint.h" /* --------------------------------------------------------------------------- * structure used by library routines */ -typedef struct { +struct LibraryEntryTpye_s { char *ListEntry; /* the string for the selection box */ int ListEntry_dontfree; /* do not free(ListEntry) if non-zero */ char *AllocatedMemory, /* pointer to allocated memory; all others */ @@ -254,8 +257,7 @@ *Description; /* some descritional text */ fp_type_t Type; void **Tags; /* an array of void * tag IDs; last tag ID is NULL */ -} LibraryEntryType, *LibraryEntryTypePtr; -/*typedef LibraryEntryType *LibraryEntryTypePtr;*/ +}; /* If the internal flag is set, the only field that is valid is Name, and the struct is allocated with malloc instead of @@ -262,7 +264,7 @@ CreateLibraryEntry. These "internal" entries are used for electrical paths that aren't yet assigned to a real net. */ -typedef struct { +struct LibraryMenuType_s { char *Name, /* name of the menu entry */ *directory, /* Directory name library elements are from */ *Style; /* routing style */ @@ -272,7 +274,7 @@ char flag; /* used by the netlist window to enable/disable nets */ char internal; /* if set, this is an internal-only entry, not part of the global netlist. */ -} LibraryMenuType, *LibraryMenuTypePtr; +}; typedef struct { Cardinal MenuN; /* number of objects */ Index: trunk/src/plug_footprint.c =================================================================== --- trunk/src/plug_footprint.c (revision 1429) +++ trunk/src/plug_footprint.c (revision 1430) @@ -110,3 +110,49 @@ if (fctx->backend->fclose != NULL) fctx->backend->fclose(fctx->backend, f, fctx); } + +LibraryEntryType *fp_append_entry(LibraryMenuType *parent, const char *dirname, const char *name, fp_type_t type, void *tags[]) +{ + LibraryEntryType *entry; /* Pointer to individual menu entry */ + size_t len; + + entry = GetLibraryEntryMemory(parent); + + /* + * entry->AllocatedMemory points to abs path to the footprint. + * entry->ListEntry points to fp name itself. + */ + len = strlen(dirname) + strlen("/") + strlen(name) + 8; + entry->AllocatedMemory = (char *) calloc(1, len); + strcat(entry->AllocatedMemory, dirname); + strcat(entry->AllocatedMemory, PCB_DIR_SEPARATOR_S); + + /* store pointer to start of footprint name */ + entry->ListEntry = entry->AllocatedMemory + strlen(entry->AllocatedMemory); + entry->ListEntry_dontfree = 1; + + /* Now place footprint name into AllocatedMemory */ + strcat(entry->AllocatedMemory, name); + + if (type == PCB_FP_PARAMETRIC) + strcat(entry->AllocatedMemory, "()"); + + entry->Type = type; + + entry->Tags = tags; +} + +LibraryMenuType *fp_append_topdir(const char *parent_dir, const char *dir_name, int *menuidx) +{ + LibraryMenuType *menu; + + /* Get pointer to memory holding menu */ + menu = GetLibraryMenuMemory(&Library, menuidx); + + /* Populate menuname and path vars */ + menu->Name = strdup(dir_name); + menu->directory = strdup(parent_dir); + + return menu; +} + Index: trunk/src/plug_footprint.h =================================================================== --- trunk/src/plug_footprint.h (revision 1429) +++ trunk/src/plug_footprint.h (revision 1430) @@ -75,6 +75,11 @@ /* Return the library shell string (from Settings) */ const char *fp_get_library_shell(void); +/* Append a menu entry in the tree */ +LibraryEntryType *fp_append_entry(LibraryMenuType *parent, const char *dirname, const char *name, fp_type_t type, void *tags[]); + +LibraryMenuType *fp_append_topdir(const char *parent_dir, const char *dir_name, int *menuidx); + /* walk through all lib paths and build the library menu */ int fp_read_lib_all(void); Index: trunk/src_plugins/fp_fs/fp_fs.c =================================================================== --- trunk/src_plugins/fp_fs/fp_fs.c (revision 1429) +++ trunk/src_plugins/fp_fs/fp_fs.c (revision 1430) @@ -75,12 +75,9 @@ int children; } list_st_t; - static int list_cb(void *cookie, const char *subdir, const char *name, fp_type_t type, void *tags[]) { list_st_t *l = (list_st_t *) cookie; - LibraryEntryTypePtr entry; /* Pointer to individual menu entry */ - size_t len; if (type == PCB_FP_DIR) { list_dir_t *d; @@ -96,31 +93,8 @@ } l->children++; - entry = GetLibraryEntryMemory(l->menu); + fp_append_entry(l->menu, subdir, name, type, tags); - /* - * entry->AllocatedMemory points to abs path to the footprint. - * entry->ListEntry points to fp name itself. - */ - len = strlen(subdir) + strlen("/") + strlen(name) + 8; - entry->AllocatedMemory = (char *) calloc(1, len); - strcat(entry->AllocatedMemory, subdir); - strcat(entry->AllocatedMemory, PCB_DIR_SEPARATOR_S); - - /* store pointer to start of footprint name */ - entry->ListEntry = entry->AllocatedMemory + strlen(entry->AllocatedMemory); - entry->ListEntry_dontfree = 1; - - /* Now place footprint name into AllocatedMemory */ - strcat(entry->AllocatedMemory, name); - - if (type == PCB_FP_PARAMETRIC) - strcat(entry->AllocatedMemory, "()"); - - entry->Type = type; - - entry->Tags = tags; - return 0; } @@ -234,10 +208,8 @@ return n_footprints; } - static int fp_fs_load_dir_(const char *subdir, const char *toppath, int is_root) { - LibraryMenuTypePtr menu = NULL; /* Pointer to PCB's library menu structure */ list_st_t l; list_dir_t *d, *nextd; char working_[MAXPATHLEN + 1]; @@ -247,15 +219,7 @@ sprintf(working_, "%s%c%s", toppath, PCB_DIR_SEPARATOR_C, subdir); resolve_path(working_, &working); - /* Get pointer to memory holding menu */ - menu = GetLibraryMenuMemory(&Library, &menuidx); - - - /* Populate menuname and path vars */ - menu->Name = strdup(pcb_basename(subdir)); - menu->directory = strdup(pcb_basename(toppath)); - - l.menu = menu; + l.menu = fp_append_topdir(pcb_basename(toppath), pcb_basename(subdir), &menuidx); l.subdirs = NULL; l.children = 0;