1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-21 20:35:21 +02:00

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
This commit is contained in:
werner 2011-03-23 07:14:13 +00:00
parent e1f4e03a28
commit f44accdad7
9 changed files with 78 additions and 51 deletions

5
dump.c
View File

@ -14,6 +14,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#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;

6
dump.h
View File

@ -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 */

37
file.c
View File

@ -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);
}

14
file.h
View File

@ -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 */

22
fped.c
View File

@ -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();

View File

@ -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 <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <assert.h>
#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");

View File

@ -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 <stdio.h>
int kicad(FILE *file);
int kicad(FILE *file, const char *one);
#endif /* !KICAD_H */

View File

@ -13,6 +13,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#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);
}

View File

@ -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 */