mirror of
git://projects.qi-hardware.com/fped.git
synced 2024-11-22 06:34:05 +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:
parent
e1f4e03a28
commit
f44accdad7
5
dump.c
5
dump.c
@ -14,6 +14,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "util.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;
|
struct frame *frame;
|
||||||
|
|
||||||
|
assert(!one);
|
||||||
|
|
||||||
fprintf(file, "%s\n", MACHINE_GENERATED);
|
fprintf(file, "%s\n", MACHINE_GENERATED);
|
||||||
for (frame = frames; frame; frame = frame->next)
|
for (frame = frames; frame; frame = frame->next)
|
||||||
frame->dumped = 0;
|
frame->dumped = 0;
|
||||||
|
6
dump.h
6
dump.h
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* dump.h - Dump objects in the native FPD format
|
* dump.h - Dump objects in the native FPD format
|
||||||
*
|
*
|
||||||
* Written 2009, 2010 by Werner Almesberger
|
* Written 2009-2011 by Werner Almesberger
|
||||||
* Copyright 2009, 2010 by Werner Almesberger
|
* Copyright 2009-2011 by Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* 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);
|
struct order *order_frame(const struct frame *frame);
|
||||||
|
|
||||||
int dump(FILE *file);
|
int dump(FILE *file, const char *one);
|
||||||
|
|
||||||
#endif /* !DUMP_H */
|
#endif /* !DUMP_H */
|
||||||
|
37
file.c
37
file.c
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* file.c - File handling
|
* file.c - File handling
|
||||||
*
|
*
|
||||||
* Written 2009, 2010 by Werner Almesberger
|
* Written 2009-2011 by Werner Almesberger
|
||||||
* Copyright 2009, 2010 by Werner Almesberger
|
* Copyright 2009-2011 by Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* 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;
|
FILE *file;
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ int save_to(const char *name, int (*fn)(FILE *file))
|
|||||||
perror(name);
|
perror(name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!fn(file)) {
|
if (!fn(file, one)) {
|
||||||
perror(name);
|
perror(name);
|
||||||
return 0;
|
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 *s = stralloc(name);
|
||||||
char *back, *tmp;
|
char *back, *tmp;
|
||||||
@ -96,7 +98,7 @@ void save_with_backup(const char *name, int (*fn)(FILE *file))
|
|||||||
*slash = '/';
|
*slash = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!save_to(tmp, fn))
|
if (!save_to(tmp, fn, one))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* move existing file out of harm's way */
|
/* 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)
|
void save_fpd(void)
|
||||||
{
|
{
|
||||||
if (save_file_name)
|
if (save_file_name)
|
||||||
save_with_backup(save_file_name, dump);
|
save_with_backup(save_file_name, dump, NULL);
|
||||||
else {
|
else {
|
||||||
if (!dump(stdout))
|
if (!dump(stdout, NULL))
|
||||||
perror("stdout");
|
perror("stdout");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,37 +162,38 @@ void write_kicad(void)
|
|||||||
|
|
||||||
if (save_file_name) {
|
if (save_file_name) {
|
||||||
name = set_extension(save_file_name, "mod");
|
name = set_extension(save_file_name, "mod");
|
||||||
save_to(name, kicad);
|
save_to(name, kicad, NULL);
|
||||||
free(name);
|
free(name);
|
||||||
} else {
|
} else {
|
||||||
if (!kicad(stdout))
|
if (!kicad(stdout, NULL))
|
||||||
perror("stdout");
|
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;
|
char *name;
|
||||||
|
|
||||||
if (save_file_name) {
|
if (save_file_name) {
|
||||||
name = set_extension(save_file_name, "ps");
|
name = set_extension(save_file_name, "ps");
|
||||||
save_to(name, fn);
|
save_to(name, fn, one);
|
||||||
free(name);
|
free(name);
|
||||||
} else {
|
} else {
|
||||||
if (!fn(stdout))
|
if (!fn(stdout, one))
|
||||||
perror("stdout");
|
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
14
file.h
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* file.h - File handling
|
* file.h - File handling
|
||||||
*
|
*
|
||||||
* Written 2009, 2010 by Werner Almesberger
|
* Written 2009-2011 by Werner Almesberger
|
||||||
* Copyright 2009, 2010 by Werner Almesberger
|
* Copyright 2009-2011 by Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -23,12 +23,14 @@
|
|||||||
int file_exists(const char *name);
|
int file_exists(const char *name);
|
||||||
|
|
||||||
char *set_extension(const char *name, const char *ext);
|
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, const char *one),
|
||||||
void save_with_backup(const char *name, int (*fn)(FILE *file));
|
const char *one);
|
||||||
|
int save_to(const char *name, int (*fn)(FILE *file, const char *one),
|
||||||
|
const char *one);
|
||||||
|
|
||||||
void save_fpd(void);
|
void save_fpd(void);
|
||||||
void write_kicad(void);
|
void write_kicad(void);
|
||||||
void write_ps(void);
|
void write_ps(const char *one);
|
||||||
void write_ps_fullpage(void);
|
void write_ps_fullpage(const char *one);
|
||||||
|
|
||||||
#endif /* !FILE_H */
|
#endif /* !FILE_H */
|
||||||
|
22
fped.c
22
fped.c
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* fped.c - Footprint editor, main function
|
* fped.c - Footprint editor, main function
|
||||||
*
|
*
|
||||||
* Written 2009, 2010 by Werner Almesberger
|
* Written 2009-2011 by Werner Almesberger
|
||||||
* Copyright 2009, 2010 by Werner Almesberger
|
* Copyright 2009-2011 by Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* 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)
|
static void usage(const char *name)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
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"
|
" %*s [in_file [out_file]]\n\n"
|
||||||
|
" -1 name output only the specified package\n"
|
||||||
" -k write KiCad output, then exit\n"
|
" -k write KiCad output, then exit\n"
|
||||||
" -p write Postscript output, then exit\n"
|
" -p write Postscript output, then exit\n"
|
||||||
" -P write Postscript output (full page), 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 error;
|
||||||
int batch = 0;
|
int batch = 0;
|
||||||
int test_mode = 0;
|
int test_mode = 0;
|
||||||
|
const char *one = NULL;
|
||||||
int batch_write_kicad = 0;
|
int batch_write_kicad = 0;
|
||||||
int batch_write_ps = 0, batch_write_ps_fullpage = 0;
|
int batch_write_ps = 0, batch_write_ps_fullpage = 0;
|
||||||
int c;
|
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) {
|
switch (c) {
|
||||||
|
case '1':
|
||||||
|
one = optarg;
|
||||||
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
batch_write_kicad = 1;
|
batch_write_kicad = 1;
|
||||||
break;
|
break;
|
||||||
@ -132,6 +137,9 @@ int main(int argc, char **argv)
|
|||||||
if (batch_write_ps && batch_write_ps_fullpage)
|
if (batch_write_ps && batch_write_ps_fullpage)
|
||||||
usage(name);
|
usage(name);
|
||||||
|
|
||||||
|
if (one && !(batch_write_ps || batch_write_ps_fullpage))
|
||||||
|
usage(name);
|
||||||
|
|
||||||
if (batch_write_kicad || batch_write_ps || batch_write_ps_fullpage)
|
if (batch_write_kicad || batch_write_ps || batch_write_ps_fullpage)
|
||||||
batch = 1;
|
batch = 1;
|
||||||
|
|
||||||
@ -174,16 +182,16 @@ int main(int argc, char **argv)
|
|||||||
if (batch_write_kicad)
|
if (batch_write_kicad)
|
||||||
write_kicad();
|
write_kicad();
|
||||||
if (batch_write_ps)
|
if (batch_write_ps)
|
||||||
write_ps();
|
write_ps(one);
|
||||||
if (batch_write_ps_fullpage)
|
if (batch_write_ps_fullpage)
|
||||||
write_ps_fullpage();
|
write_ps_fullpage(one);
|
||||||
if (!batch) {
|
if (!batch) {
|
||||||
error = gui_main();
|
error = gui_main();
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
if (test_mode > 1)
|
if (test_mode > 1)
|
||||||
dump(stdout);
|
dump(stdout, NULL);
|
||||||
|
|
||||||
purge();
|
purge();
|
||||||
inst_revert();
|
inst_revert();
|
||||||
|
9
kicad.c
9
kicad.c
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* kicad.c - Dump objects in the KiCad board/module format
|
* kicad.c - Dump objects in the KiCad board/module format
|
||||||
*
|
*
|
||||||
* Written 2009, 2010 by Werner Almesberger
|
* Written 2009-2011 by Werner Almesberger
|
||||||
* Copyright 2009, 2010 by Werner Almesberger
|
* Copyright 2009-2011 by Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,6 +14,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "coord.h"
|
#include "coord.h"
|
||||||
#include "inst.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;
|
const struct pkg *pkg;
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|
||||||
|
assert(!one);
|
||||||
|
|
||||||
fprintf(file, "PCBNEW-LibModule-V1 %s", ctime(&now));
|
fprintf(file, "PCBNEW-LibModule-V1 %s", ctime(&now));
|
||||||
|
|
||||||
fprintf(file, "$INDEX\n");
|
fprintf(file, "$INDEX\n");
|
||||||
|
6
kicad.h
6
kicad.h
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* kicad.h - Dump objects in the KiCad board/module format
|
* kicad.h - Dump objects in the KiCad board/module format
|
||||||
*
|
*
|
||||||
* Written 2009 by Werner Almesberger
|
* Written 2009, 2011 by Werner Almesberger
|
||||||
* Copyright 2009 by Werner Almesberger
|
* Copyright 2009, 2011 by Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -17,6 +17,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
int kicad(FILE *file);
|
int kicad(FILE *file, const char *one);
|
||||||
|
|
||||||
#endif /* !KICAD_H */
|
#endif /* !KICAD_H */
|
||||||
|
18
postscript.c
18
postscript.c
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "coord.h"
|
#include "coord.h"
|
||||||
@ -1082,18 +1083,25 @@ static void epilogue(FILE *file)
|
|||||||
|
|
||||||
|
|
||||||
static int ps_for_all_pkg(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;
|
struct pkg *pkg;
|
||||||
int pages;
|
int pages;
|
||||||
|
|
||||||
for (pkg = pkgs; pkg; pkg = pkg->next)
|
for (pkg = pkgs; pkg; pkg = pkg->next)
|
||||||
if (pkg->name)
|
if (pkg->name)
|
||||||
|
if (!one || !strcmp(pkg->name, one))
|
||||||
pages++;
|
pages++;
|
||||||
|
if (one && !pages) {
|
||||||
|
fprintf(stderr, "no package \"%s\" to select\n", one);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
prologue(file, pages);
|
prologue(file, pages);
|
||||||
pages = 0;
|
pages = 0;
|
||||||
for (pkg = pkgs; pkg; pkg = pkg->next)
|
for (pkg = pkgs; pkg; pkg = pkg->next)
|
||||||
if (pkg->name)
|
if (pkg->name)
|
||||||
|
if (!one || !strcmp(pkg->name, one))
|
||||||
fn(file, pkg, ++pages);
|
fn(file, pkg, ++pages);
|
||||||
epilogue(file);
|
epilogue(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);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* postscript.h - Dump objects in Postscript
|
* postscript.h - Dump objects in Postscript
|
||||||
*
|
*
|
||||||
* Written 2009, 2010 by Werner Almesberger
|
* Written 2009-2011 by Werner Almesberger
|
||||||
* Copyright 2009, 2010 by Werner Almesberger
|
* Copyright 2009-2011 by Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -26,7 +26,7 @@ struct postscript_params {
|
|||||||
} postscript_params;
|
} postscript_params;
|
||||||
|
|
||||||
|
|
||||||
int postscript(FILE *file);
|
int postscript(FILE *file, const char *one);
|
||||||
int postscript_fullpage(FILE *file);
|
int postscript_fullpage(FILE *file, const char *one);
|
||||||
|
|
||||||
#endif /* !POSTSCRIPT_H */
|
#endif /* !POSTSCRIPT_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user