From f44accdad7a831db78260fb64573c641829ebaee Mon Sep 17 00:00:00 2001 From: werner Date: Wed, 23 Mar 2011 07:14:13 +0000 Subject: [PATCH] fped: added option -1 package to select a single package to output with -p/-P git-svn-id: http://svn.openmoko.org/trunk/eda/fped@6003 99fdad57-331a-0410-800a-d7fa5415bdb3 --- dump.c | 5 ++++- dump.h | 6 +++--- file.c | 37 ++++++++++++++++++++----------------- file.h | 14 ++++++++------ fped.c | 22 +++++++++++++++------- kicad.c | 9 ++++++--- kicad.h | 6 +++--- postscript.c | 22 +++++++++++++++------- postscript.h | 8 ++++---- 9 files changed, 78 insertions(+), 51 deletions(-) diff --git a/dump.c b/dump.c index f612b76..12972a3 100644 --- a/dump.c +++ b/dump.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "util.h" @@ -598,10 +599,12 @@ static void reverse_frames(FILE *file, struct frame *last) } -int dump(FILE *file) +int dump(FILE *file, const char *one) { struct frame *frame; + assert(!one); + fprintf(file, "%s\n", MACHINE_GENERATED); for (frame = frames; frame; frame = frame->next) frame->dumped = 0; diff --git a/dump.h b/dump.h index 7f59199..1da0894 100644 --- a/dump.h +++ b/dump.h @@ -1,8 +1,8 @@ /* * dump.h - Dump objects in the native FPD format * - * Written 2009, 2010 by Werner Almesberger - * Copyright 2009, 2010 by Werner Almesberger + * Written 2009-2011 by Werner Almesberger + * Copyright 2009-2011 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 @@ -44,6 +44,6 @@ char *print_meas(const struct obj *obj); struct order *order_frame(const struct frame *frame); -int dump(FILE *file); +int dump(FILE *file, const char *one); #endif /* !DUMP_H */ diff --git a/file.c b/file.c index c8a0e69..926754b 100644 --- a/file.c +++ b/file.c @@ -1,8 +1,8 @@ /* * file.c - File handling * - * Written 2009, 2010 by Werner Almesberger - * Copyright 2009, 2010 by Werner Almesberger + * Written 2009-2011 by Werner Almesberger + * Copyright 2009-2011 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 @@ -57,7 +57,8 @@ int file_exists(const char *name) } -int save_to(const char *name, int (*fn)(FILE *file)) +int save_to(const char *name, int (*fn)(FILE *file, const char *one), + const char *one) { FILE *file; @@ -66,7 +67,7 @@ int save_to(const char *name, int (*fn)(FILE *file)) perror(name); return 0; } - if (!fn(file)) { + if (!fn(file, one)) { perror(name); return 0; } @@ -78,7 +79,8 @@ int save_to(const char *name, int (*fn)(FILE *file)) } -void save_with_backup(const char *name, int (*fn)(FILE *file)) +void save_with_backup(const char *name, int (*fn)(FILE *file, const char *one), + const char *one) { char *s = stralloc(name); char *back, *tmp; @@ -96,7 +98,7 @@ void save_with_backup(const char *name, int (*fn)(FILE *file)) *slash = '/'; } - if (!save_to(tmp, fn)) + if (!save_to(tmp, fn, one)) return; /* move existing file out of harm's way */ @@ -146,9 +148,9 @@ void save_with_backup(const char *name, int (*fn)(FILE *file)) void save_fpd(void) { if (save_file_name) - save_with_backup(save_file_name, dump); + save_with_backup(save_file_name, dump, NULL); else { - if (!dump(stdout)) + if (!dump(stdout, NULL)) perror("stdout"); } } @@ -160,37 +162,38 @@ void write_kicad(void) if (save_file_name) { name = set_extension(save_file_name, "mod"); - save_to(name, kicad); + save_to(name, kicad, NULL); free(name); } else { - if (!kicad(stdout)) + if (!kicad(stdout, NULL)) perror("stdout"); } } -static void do_write_ps(int (*fn)(FILE *file)) +static void do_write_ps(int (*fn)(FILE *file, const char *one), + const char *one) { char *name; if (save_file_name) { name = set_extension(save_file_name, "ps"); - save_to(name, fn); + save_to(name, fn, one); free(name); } else { - if (!fn(stdout)) + if (!fn(stdout, one)) perror("stdout"); } } -void write_ps(void) +void write_ps(const char *one) { - do_write_ps(postscript); + do_write_ps(postscript, one); } -void write_ps_fullpage(void) +void write_ps_fullpage(const char *one) { - do_write_ps(postscript_fullpage); + do_write_ps(postscript_fullpage, one); } diff --git a/file.h b/file.h index 582d712..5309f09 100644 --- a/file.h +++ b/file.h @@ -1,8 +1,8 @@ /* * file.h - File handling * - * Written 2009, 2010 by Werner Almesberger - * Copyright 2009, 2010 by Werner Almesberger + * Written 2009-2011 by Werner Almesberger + * Copyright 2009-2011 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 @@ -23,12 +23,14 @@ int file_exists(const char *name); char *set_extension(const char *name, const char *ext); -int save_to(const char *name, int (*fn)(FILE *file)); -void save_with_backup(const char *name, int (*fn)(FILE *file)); +void save_with_backup(const char *name, int (*fn)(FILE *file, const char *one), + const char *one); +int save_to(const char *name, int (*fn)(FILE *file, const char *one), + const char *one); void save_fpd(void); void write_kicad(void); -void write_ps(void); -void write_ps_fullpage(void); +void write_ps(const char *one); +void write_ps_fullpage(const char *one); #endif /* !FILE_H */ diff --git a/fped.c b/fped.c index 1793676..e41113e 100644 --- a/fped.c +++ b/fped.c @@ -1,8 +1,8 @@ /* * fped.c - Footprint editor, main function * - * Written 2009, 2010 by Werner Almesberger - * Copyright 2009, 2010 by Werner Almesberger + * Written 2009-2011 by Werner Almesberger + * Copyright 2009-2011 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 @@ -67,8 +67,9 @@ static void load_file(const char *name) static void usage(const char *name) { fprintf(stderr, -"usage: %s [-k] [-p|-P [-s scale]] [-T [-T]] [cpp_option ...]\n" +"usage: %s [-k] [-p|-P [-s scale] [-1 package]] [-T [-T]] [cpp_option ...]\n" " %*s [in_file [out_file]]\n\n" +" -1 name output only the specified package\n" " -k write KiCad output, then exit\n" " -p write Postscript output, then exit\n" " -P write Postscript output (full page), then exit\n" @@ -92,12 +93,16 @@ int main(int argc, char **argv) int error; int batch = 0; int test_mode = 0; + const char *one = NULL; int batch_write_kicad = 0; int batch_write_ps = 0, batch_write_ps_fullpage = 0; int c; - while ((c = getopt(argc, argv, "kps:D:I:PTU:")) != EOF) + while ((c = getopt(argc, argv, "1:kps:D:I:PTU:")) != EOF) switch (c) { + case '1': + one = optarg; + break; case 'k': batch_write_kicad = 1; break; @@ -132,6 +137,9 @@ int main(int argc, char **argv) if (batch_write_ps && batch_write_ps_fullpage) usage(name); + if (one && !(batch_write_ps || batch_write_ps_fullpage)) + usage(name); + if (batch_write_kicad || batch_write_ps || batch_write_ps_fullpage) batch = 1; @@ -174,16 +182,16 @@ int main(int argc, char **argv) if (batch_write_kicad) write_kicad(); if (batch_write_ps) - write_ps(); + write_ps(one); if (batch_write_ps_fullpage) - write_ps_fullpage(); + write_ps_fullpage(one); if (!batch) { error = gui_main(); if (error) return error; } if (test_mode > 1) - dump(stdout); + dump(stdout, NULL); purge(); inst_revert(); diff --git a/kicad.c b/kicad.c index 9ab863e..5eb8e2e 100644 --- a/kicad.c +++ b/kicad.c @@ -1,8 +1,8 @@ /* * kicad.c - Dump objects in the KiCad board/module format * - * Written 2009, 2010 by Werner Almesberger - * Copyright 2009, 2010 by Werner Almesberger + * Written 2009-2011 by Werner Almesberger + * Copyright 2009-2011 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 @@ -14,6 +14,7 @@ #include #include #include +#include #include "coord.h" #include "inst.h" @@ -300,11 +301,13 @@ static void kicad_module(FILE *file, const struct pkg *pkg, time_t now) } -int kicad(FILE *file) +int kicad(FILE *file, const char *one) { const struct pkg *pkg; time_t now = time(NULL); + assert(!one); + fprintf(file, "PCBNEW-LibModule-V1 %s", ctime(&now)); fprintf(file, "$INDEX\n"); diff --git a/kicad.h b/kicad.h index 0f91b38..b5b17d6 100644 --- a/kicad.h +++ b/kicad.h @@ -1,8 +1,8 @@ /* * kicad.h - Dump objects in the KiCad board/module format * - * Written 2009 by Werner Almesberger - * Copyright 2009 by Werner Almesberger + * Written 2009, 2011 by Werner Almesberger + * Copyright 2009, 2011 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 @@ -17,6 +17,6 @@ #include -int kicad(FILE *file); +int kicad(FILE *file, const char *one); #endif /* !KICAD_H */ diff --git a/postscript.c b/postscript.c index b1de11c..ccdd03b 100644 --- a/postscript.c +++ b/postscript.c @@ -13,6 +13,7 @@ #include #include +#include #include "util.h" #include "coord.h" @@ -1082,19 +1083,26 @@ static void epilogue(FILE *file) static int ps_for_all_pkg(FILE *file, - void (*fn)(FILE *file, const struct pkg *pkg, int page)) + void (*fn)(FILE *file, const struct pkg *pkg, int page), + const char *one) { struct pkg *pkg; int pages; for (pkg = pkgs; pkg; pkg = pkg->next) if (pkg->name) - pages++; + if (!one || !strcmp(pkg->name, one)) + pages++; + if (one && !pages) { + fprintf(stderr, "no package \"%s\" to select\n", one); + return 0; + } prologue(file, pages); pages = 0; for (pkg = pkgs; pkg; pkg = pkg->next) if (pkg->name) - fn(file, pkg, ++pages); + if (!one || !strcmp(pkg->name, one)) + fn(file, pkg, ++pages); epilogue(file); fflush(file); @@ -1102,9 +1110,9 @@ static int ps_for_all_pkg(FILE *file, } -int postscript(FILE *file) +int postscript(FILE *file, const char *one) { - return ps_for_all_pkg(file, ps_package); + return ps_for_all_pkg(file, ps_package, one); } @@ -1136,7 +1144,7 @@ static void ps_package_fullpage(FILE *file, const struct pkg *pkg, int page) } -int postscript_fullpage(FILE *file) +int postscript_fullpage(FILE *file, const char *one) { - return ps_for_all_pkg(file, ps_package_fullpage); + return ps_for_all_pkg(file, ps_package_fullpage, one); } diff --git a/postscript.h b/postscript.h index 0b5129c..cf6dfba 100644 --- a/postscript.h +++ b/postscript.h @@ -1,8 +1,8 @@ /* * postscript.h - Dump objects in Postscript * - * Written 2009, 2010 by Werner Almesberger - * Copyright 2009, 2010 by Werner Almesberger + * Written 2009-2011 by Werner Almesberger + * Copyright 2009-2011 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 @@ -26,7 +26,7 @@ struct postscript_params { } postscript_params; -int postscript(FILE *file); -int postscript_fullpage(FILE *file); +int postscript(FILE *file, const char *one); +int postscript_fullpage(FILE *file, const char *one); #endif /* !POSTSCRIPT_H */