From e4481450ec90be76adf0822d5bd4aa26a6962d24 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Thu, 12 Jul 2012 00:58:12 -0300 Subject: [PATCH] gencat/: new option -F to use fped footprints (WIP) --- gencat/Makefile | 2 +- gencat/fped.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ gencat/gencat.c | 10 +++++--- gencat/libs.h | 1 + 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 gencat/fped.c diff --git a/gencat/Makefile b/gencat/Makefile index 1f31e21..9116dff 100644 --- a/gencat/Makefile +++ b/gencat/Makefile @@ -11,7 +11,7 @@ PREFIX ?= /usr/local -OBJS = gencat.o tree.o libs.o run.o comp.o pdf.o +OBJS = gencat.o tree.o libs.o run.o comp.o fped.o pdf.o SHELL = /bin/bash CFLAGS = -Wall -g diff --git a/gencat/fped.c b/gencat/fped.c new file mode 100644 index 0000000..399b1f8 --- /dev/null +++ b/gencat/fped.c @@ -0,0 +1,61 @@ +/* + * comp.c - Component libraries + * + * Copyright 2012 by Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#define _GNU_SOURCE /* for asprintf */ +#include +#include +#include + +#include "run.h" +#include "libs.h" + + +static void fped_add_lib(struct lib *lib, const char *path) +{ + FILE *file; + char buf[1024]; /* @@@ */ + char *tmp, *nl; + + asprintf(&tmp, "fped -k '%s' -", path); + file = popen(tmp, "r"); + if (!file) { + perror(path); + exit(1); + } + + while (fgets(buf, sizeof(buf), file)) { + if (strncmp(buf, "$MODULE ", 8)) + continue; + nl = strchr(buf, '\n'); + if (nl) + *nl = 0; + add_name(new_entry(lib, 1), buf+8); + } + + pclose(file); +} + + +static void fped_ps_entry(FILE *file, const struct lib *lib, + const struct entry *e, int unit) +{ + run_cmd("fped -P '%s' -1 '%s' '%s'", + e->file->path, e->names->s, "tmp.ps"); + run_cmd("sed -i -e '/^ /s/\\/sdiv/' tmp.ps"); + cat(file, "tmp.ps"); +} + + +struct lib fped_lib = { + .ext = ".fpd", + .add_lib = fped_add_lib, + .ps_entry = fped_ps_entry, +}; diff --git a/gencat/gencat.c b/gencat/gencat.c index 7ef0549..97da709 100644 --- a/gencat/gencat.c +++ b/gencat/gencat.c @@ -27,12 +27,13 @@ int quiet = 0; static void usage(const char *name) { fprintf(stderr, -"usage: %s [-d|-D] [-p] [-P] [-q] [-L libdir ...] [-l lib ...] hierarchy\n" +"usage: %s [-F] [-d|-D] [-p] [-P] [-q] [-L libdir ...] [-l lib ...] hierarchy\n" " %*s [descriptions ...]\n\n" " -d dump the tree instead of generating a PDF\n" " -D dump all the canonical component names (without aliases)\n" +" -F use fped footprints instead of KiCad components\n" " -L libdir search all libraries in the specified directory\n" -" -l lib search the specified component library\n" +" -l lib search the specified library\n" " -p use portrait orientation; default: landscape\n" " -P generate Postscript instead of PDF (mainly for debugging)\n" " -q don't show progress\n" @@ -49,7 +50,7 @@ int main(int argc, char **argv) int opt_dump_tree = 0, opt_dump_comp = 0, postscript = 0, portrait = 0; char **arg; - while ((c = getopt(argc, argv, "dDL:l:Ppq")) != EOF) + while ((c = getopt(argc, argv, "dDFL:l:Ppq")) != EOF) switch (c) { case 'd': opt_dump_tree = 1; @@ -57,6 +58,9 @@ int main(int argc, char **argv) case 'D': opt_dump_comp = 1; break; + case 'F': + lib = &fped_lib; + break; case 'L': add_libdir(lib, optarg); break; diff --git a/gencat/libs.h b/gencat/libs.h index ec57863..a939bba 100644 --- a/gencat/libs.h +++ b/gencat/libs.h @@ -41,6 +41,7 @@ struct lib { extern struct lib comp_lib; +extern struct lib fped_lib; const struct entry *lookup_sym(const struct lib *lib, const char *name);