Index: src_plugins/fp_wget/Makefile =================================================================== --- src_plugins/fp_wget/Makefile (revision 1573) +++ src_plugins/fp_wget/Makefile (revision 1574) @@ -1,4 +1,12 @@ +all: + cd ../../src && make mod_fp_wget + CFLAGS = -Wall -g -I../../src -I../.. -I../../src_3rd +test: tester + tester: tester.o gedasymbols.o wget_common.o ../../src_3rd/genvector/gds_char.o +clean: + rm *.o *.so 2>/dev/null ; true + Index: src_plugins/fp_wget/Plug.tmpasm =================================================================== --- src_plugins/fp_wget/Plug.tmpasm (nonexistent) +++ src_plugins/fp_wget/Plug.tmpasm (revision 1574) @@ -0,0 +1,8 @@ +put /local/pcb/mod {fp_wget} +put /local/pcb/mod/OBJS [@ $(PLUGDIR)/fp_wget/fp_wget.o $(PLUGDIR)/fp_wget/wget_common.o $(PLUGDIR)/fp_wget/gedasymbols.o @] + +switch /local/pcb/fp_wget/controls + case {buildin} include /local/pcb/tmpasm/buildin; end; + case {plugin} include /local/pcb/tmpasm/plugin; end; + case {disable} include /local/pcb/tmpasm/disable; end; +end Index: src_plugins/fp_wget/README =================================================================== --- src_plugins/fp_wget/README (nonexistent) +++ src_plugins/fp_wget/README (revision 1574) @@ -0,0 +1,6 @@ +Footprint: get static (file) footprints from the web, e.g. from +http://gedasymbols.org + +#state: works +#default: buildin +#implements: fp Index: src_plugins/fp_wget/fp_wget.c =================================================================== --- src_plugins/fp_wget/fp_wget.c (nonexistent) +++ src_plugins/fp_wget/fp_wget.c (revision 1574) @@ -0,0 +1,9 @@ +#include "global.h" +#include "gedasymbols.h" +#include "plugins.h" + +pcb_uninit_t hid_fp_wget_init(void) +{ + fp_gedasymbols_init(); + return NULL; +} Index: src_plugins/fp_wget/gedasymbols.c =================================================================== --- src_plugins/fp_wget/gedasymbols.c (revision 1573) +++ src_plugins/fp_wget/gedasymbols.c (revision 1574) @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include "global.h" #include "wget_common.h" #include "gedasymbols.h" @@ -9,7 +11,7 @@ #include "plug_footprint.h" -#define REQUIRE_PATH_PREFIX "gedasymbols://" +#define REQUIRE_PATH_PREFIX "wget@gedasymbols" #define CGI_URL "http://www.gedasymbols.org/scripts/global_list.cgi" #define FP_URL "http://www.gedasymbols.org/" @@ -66,6 +68,10 @@ return changed; } +static int keyeq(char *a, char *b) +{ + return !strcmp(a, b); +} int fp_gedasymbols_load_dir(plug_fp_t *ctx, const char *path) { @@ -72,6 +78,13 @@ FILE *f; int fctx; char *md5_last, *md5_new; + LibraryMenuType *top; + int tmp; + htsp_t *path2menu; + char line[1024]; + fp_get_mode mode; + gds_t vpath; + int vpath_base_len; if (strncmp(path, REQUIRE_PATH_PREFIX, strlen(REQUIRE_PATH_PREFIX)) != 0) return -1; @@ -93,15 +106,59 @@ if (!md5_cmp_free(last_sum_fn, md5_last, md5_new)) { printf("no chg.\n"); - return 0; + mode = FP_WGET_OFFLINE; /* use the cache */ } + else + mode = 0; - if (fp_wget_open(url_idx_list, gedasym_cache, &f, &fctx, 0) != 0) { + if (fp_wget_open(url_idx_list, gedasym_cache, &f, &fctx, mode) != 0) { printf("failed to download the new list\n"); remove(last_sum_fn); /* make sure it is downloaded next time */ return -1; } -/* load_index(); */ + + gds_init(&vpath); + gds_append_str(&vpath, REQUIRE_PATH_PREFIX); + path2menu = htsp_alloc(strhash, keyeq); + htsp_set(path2menu, strdup(vpath.array), top); + + gds_append(&vpath, '/'); + vpath_base_len = vpath.used; + + while(fgets(line, sizeof(line), f) != NULL) { + char *end, *fn; + LibraryMenuType *l, *parent; + + if (*line == '#') + continue; + end = strchr(line, '|'); + if (end == NULL) + continue; + *end = '\0'; + + gds_truncate(&vpath, vpath_base_len); + gds_append_str(&vpath, line); + end = vpath.array + vpath.used - 1; + while((end > vpath.array) && (*end != '/')) { end--; vpath.used--; } + *end = '\0'; + vpath.used--; + end++; + fn = end; + + fprintf(stderr, "FP WGET: '%s' '%s'\n", vpath.array, fn); + l = htsp_get(path2menu, vpath.array); + fprintf(stderr, " vpath='%s' l=%p\n", vpath.array, l); + + if (l == NULL) { + char *new_dir = vpath.array + vpath_base_len; + l = fp_append_topdir(REQUIRE_PATH_PREFIX, new_dir, &tmp); + htsp_set(path2menu, strdup(vpath.array), l); + fprintf(stderr, " added: '%s' -> %p\n", new_dir, l); + } + + fprintf(stderr, " fp: '%s' '%s' under %p\n", vpath.array, fn, l); + fp_append_entry(l, vpath.array, fn, PCB_FP_FILE, NULL); + } fp_wget_close(&f, &fctx); printf("update!\n"); @@ -139,16 +196,14 @@ } -static plug_fp_t fp_wget; +static plug_fp_t fp_gedasymbols; void fp_gedasymbols_init(void) { - fp_wget.plugin_data = NULL; - fp_wget.load_dir = fp_gedasymbols_load_dir; - fp_wget.fopen = fp_gedasymbols_fopen; - fp_wget.fclose = fp_gedasymbols_fclose; + fp_gedasymbols.plugin_data = NULL; + fp_gedasymbols.load_dir = fp_gedasymbols_load_dir; + fp_gedasymbols.fopen = fp_gedasymbols_fopen; + fp_gedasymbols.fclose = fp_gedasymbols_fclose; - HOOK_REGISTER(plug_fp_t, plug_fp_chain, &fp_wget); - - return NULL; + HOOK_REGISTER(plug_fp_t, plug_fp_chain, &fp_gedasymbols); } Index: src_plugins/fp_wget/wget_common.c =================================================================== --- src_plugins/fp_wget/wget_common.c (revision 1573) +++ src_plugins/fp_wget/wget_common.c (revision 1574) @@ -10,7 +10,7 @@ }; const char *wget_cmd = "wget -U 'pcb-rnd-fp_wget'"; -int fp_wget_offline = 0; +int fp_wget_offline = 1; static int mkdirp(const char *dir) { @@ -20,7 +20,7 @@ return system(buff); } -int fp_wget_open(const char *url, const char *cache_path, FILE **f, int *fctx, int update) +int fp_wget_open(const char *url, const char *cache_path, FILE **f, int *fctx, fp_get_mode mode) { char *cmd, *upds; int wl = strlen(wget_cmd), ul = strlen(url), cl = strlen(cache_path); @@ -28,7 +28,7 @@ *fctx = FCTX_INVALID; - if (update) + if (mode & FP_WGET_UPDATE) upds = "-c"; else upds = ""; @@ -49,9 +49,10 @@ if (cdir == NULL) goto error; cdir += 3; - sprintf(cmd, "%s -O '%s/%s' %s '%s'", wget_cmd, cache_path, cdir, upds, url); - if (!fp_wget_offline) + if ((!fp_wget_offline) && !(mode & FP_WGET_OFFLINE)) { + sprintf(cmd, "%s -O '%s/%s' %s '%s'", wget_cmd, cache_path, cdir, upds, url); system(cmd); + } if (f != NULL) { char *end; sprintf(cmd, "%s/%s", cache_path, cdir); Index: src_plugins/fp_wget/wget_common.h =================================================================== --- src_plugins/fp_wget/wget_common.h (revision 1573) +++ src_plugins/fp_wget/wget_common.h (revision 1574) @@ -1,4 +1,9 @@ #include -int fp_wget_open(const char *url, const char *cache_path, FILE **f, int *fctx, int update); +typedef enum { + FP_WGET_UPDATE = 1, /* wget -c: update existing file, don't replace (a.k.a. cache) */ + FP_WGET_OFFLINE = 2 /* do not wget, open cached file or fail */ +} fp_get_mode; + +int fp_wget_open(const char *url, const char *cache_path, FILE **f, int *fctx, fp_get_mode mode); int fp_wget_close(FILE **f, int *fctx);