Index: src_plugins/fp_wget/fp_wget.c =================================================================== --- src_plugins/fp_wget/fp_wget.c (revision 1572) +++ src_plugins/fp_wget/fp_wget.c (nonexistent) @@ -1,96 +0,0 @@ -#include -#include -#include "fp_wget.h" - -enum { - FCTX_INVALID = 0, - FCTX_POPEN, - FCTX_FOPEN, - FCTX_NOP -}; - -const char *wget_cmd = "wget -U 'pcb-rnd-fp_wget'"; -int fp_wget_offline = 0; - -static int mkdirp(const char *dir) -{ -/* TODO */ - char buff[8192]; - sprintf(buff, "mkdir -p '%s'", dir); - return system(buff); -} - -int fp_wget_open(const char *url, const char *cache_path, FILE **f, int *fctx, int update) -{ - char *cmd, *upds; - int wl = strlen(wget_cmd), ul = strlen(url), cl = strlen(cache_path); - cmd = malloc(wl+ul*2+cl+32); - - *fctx = FCTX_INVALID; - - if (update) - upds = "-c"; - else - upds = ""; - - if (cache_path == NULL) { - sprintf(cmd, "%s -O - %s '%s'", wget_cmd, upds, url); - if (f == NULL) - goto error; - if (!fp_wget_offline) - *f = popen(cmd, "r"); - if (*f == NULL) - goto error; - *fctx = FCTX_POPEN; - } - else { - char *cdir; - cdir = strstr(url, "://"); - 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) - system(cmd); - if (f != NULL) { - char *end; - sprintf(cmd, "%s/%s", cache_path, cdir); - end = strrchr(cmd, '/'); - if (end != NULL) { - *end = '\0'; - if (mkdirp(cmd) != 0) - goto error; - *end = '/'; - } - *f = fopen(cmd, "r"); - if (*f == NULL) - goto error; - *fctx = FCTX_FOPEN; - } - else - *fctx = FCTX_NOP; - } - free(cmd); - return 0; - - error:; - free(cmd); - return -1; -} - -int fp_wget_close(FILE **f, int *fctx) -{ - if (*fctx == FCTX_NOP) - return 0; - - if (*f == NULL) - return -1; - - switch(*fctx) { - case FCTX_POPEN: pclose(*f); *f = NULL; return 0; - case FCTX_FOPEN: fclose(*f); *f = NULL; return 0; - } - - return -1; -} - Index: src_plugins/fp_wget/fp_wget.h =================================================================== --- src_plugins/fp_wget/fp_wget.h (revision 1572) +++ src_plugins/fp_wget/fp_wget.h (nonexistent) @@ -1,4 +0,0 @@ -#include - -int fp_wget_open(const char *url, const char *cache_path, FILE **f, int *fctx, int update); -int fp_wget_close(FILE **f, int *fctx); Index: src_plugins/fp_wget/Makefile =================================================================== --- src_plugins/fp_wget/Makefile (revision 1572) +++ src_plugins/fp_wget/Makefile (revision 1573) @@ -1,4 +1,4 @@ CFLAGS = -Wall -g -I../../src -I../.. -I../../src_3rd -tester: tester.o gedasymbols.o fp_wget.o ../../src_3rd/genvector/gds_char.o +tester: tester.o gedasymbols.o wget_common.o ../../src_3rd/genvector/gds_char.o Index: src_plugins/fp_wget/gedasymbols.c =================================================================== --- src_plugins/fp_wget/gedasymbols.c (revision 1572) +++ src_plugins/fp_wget/gedasymbols.c (revision 1573) @@ -3,7 +3,7 @@ #include #include #include "global.h" -#include "fp_wget.h" +#include "wget_common.h" #include "gedasymbols.h" #include "plugins.h" #include "plug_footprint.h" Index: src_plugins/fp_wget/wget_common.c =================================================================== --- src_plugins/fp_wget/wget_common.c (nonexistent) +++ src_plugins/fp_wget/wget_common.c (revision 1573) @@ -0,0 +1,96 @@ +#include +#include +#include "wget_common.h" + +enum { + FCTX_INVALID = 0, + FCTX_POPEN, + FCTX_FOPEN, + FCTX_NOP +}; + +const char *wget_cmd = "wget -U 'pcb-rnd-fp_wget'"; +int fp_wget_offline = 0; + +static int mkdirp(const char *dir) +{ +/* TODO */ + char buff[8192]; + sprintf(buff, "mkdir -p '%s'", dir); + return system(buff); +} + +int fp_wget_open(const char *url, const char *cache_path, FILE **f, int *fctx, int update) +{ + char *cmd, *upds; + int wl = strlen(wget_cmd), ul = strlen(url), cl = strlen(cache_path); + cmd = malloc(wl+ul*2+cl+32); + + *fctx = FCTX_INVALID; + + if (update) + upds = "-c"; + else + upds = ""; + + if (cache_path == NULL) { + sprintf(cmd, "%s -O - %s '%s'", wget_cmd, upds, url); + if (f == NULL) + goto error; + if (!fp_wget_offline) + *f = popen(cmd, "r"); + if (*f == NULL) + goto error; + *fctx = FCTX_POPEN; + } + else { + char *cdir; + cdir = strstr(url, "://"); + 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) + system(cmd); + if (f != NULL) { + char *end; + sprintf(cmd, "%s/%s", cache_path, cdir); + end = strrchr(cmd, '/'); + if (end != NULL) { + *end = '\0'; + if (mkdirp(cmd) != 0) + goto error; + *end = '/'; + } + *f = fopen(cmd, "r"); + if (*f == NULL) + goto error; + *fctx = FCTX_FOPEN; + } + else + *fctx = FCTX_NOP; + } + free(cmd); + return 0; + + error:; + free(cmd); + return -1; +} + +int fp_wget_close(FILE **f, int *fctx) +{ + if (*fctx == FCTX_NOP) + return 0; + + if (*f == NULL) + return -1; + + switch(*fctx) { + case FCTX_POPEN: pclose(*f); *f = NULL; return 0; + case FCTX_FOPEN: fclose(*f); *f = NULL; return 0; + } + + return -1; +} + Index: src_plugins/fp_wget/wget_common.h =================================================================== --- src_plugins/fp_wget/wget_common.h (nonexistent) +++ src_plugins/fp_wget/wget_common.h (revision 1573) @@ -0,0 +1,4 @@ +#include + +int fp_wget_open(const char *url, const char *cache_path, FILE **f, int *fctx, int update); +int fp_wget_close(FILE **f, int *fctx);