Date: | 2011-03-23 08:14:13 (13 years 5 days ago) |
---|---|
Author: | werner |
Commit: | f44accdad7a831db78260fb64573c641829ebaee |
Message: | 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 |
Files: |
dump.c (2 diffs) dump.h (2 diffs) file.c (7 diffs) file.h (2 diffs) fped.c (5 diffs) kicad.c (3 diffs) kicad.h (2 diffs) postscript.c (4 diffs) postscript.h (2 diffs) |
Change Details
dump.c | ||
---|---|---|
14 | 14 | #include <stdlib.h> |
15 | 15 | #include <stdio.h> |
16 | 16 | #include <string.h> |
17 | #include <assert.h> | |
17 | 18 | #include <sys/types.h> |
18 | 19 | |
19 | 20 | #include "util.h" |
... | ... | |
598 | 599 | } |
599 | 600 | |
600 | 601 | |
601 | int dump(FILE *file) | |
602 | int dump(FILE *file, const char *one) | |
602 | 603 | { |
603 | 604 | struct frame *frame; |
604 | 605 | |
606 | assert(!one); | |
607 | ||
605 | 608 | fprintf(file, "%s\n", MACHINE_GENERATED); |
606 | 609 | for (frame = frames; frame; frame = frame->next) |
607 | 610 | frame->dumped = 0; |
dump.h | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * dump.h - Dump objects in the native FPD format |
3 | 3 | * |
4 | * Written 2009, 2010 by Werner Almesberger | |
5 | * Copyright 2009, 2010 by Werner Almesberger | |
4 | * Written 2009-2011 by Werner Almesberger | |
5 | * Copyright 2009-2011 by Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
44 | 44 | |
45 | 45 | struct order *order_frame(const struct frame *frame); |
46 | 46 | |
47 | int dump(FILE *file); | |
47 | int dump(FILE *file, const char *one); | |
48 | 48 | |
49 | 49 | #endif /* !DUMP_H */ |
file.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * file.c - File handling |
3 | 3 | * |
4 | * Written 2009, 2010 by Werner Almesberger | |
5 | * Copyright 2009, 2010 by Werner Almesberger | |
4 | * Written 2009-2011 by Werner Almesberger | |
5 | * Copyright 2009-2011 by Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
57 | 57 | } |
58 | 58 | |
59 | 59 | |
60 | int save_to(const char *name, int (*fn)(FILE *file)) | |
60 | int save_to(const char *name, int (*fn)(FILE *file, const char *one), | |
61 | const char *one) | |
61 | 62 | { |
62 | 63 | FILE *file; |
63 | 64 | |
... | ... | |
66 | 67 | perror(name); |
67 | 68 | return 0; |
68 | 69 | } |
69 | if (!fn(file)) { | |
70 | if (!fn(file, one)) { | |
70 | 71 | perror(name); |
71 | 72 | return 0; |
72 | 73 | } |
... | ... | |
78 | 79 | } |
79 | 80 | |
80 | 81 | |
81 | void save_with_backup(const char *name, int (*fn)(FILE *file)) | |
82 | void save_with_backup(const char *name, int (*fn)(FILE *file, const char *one), | |
83 | const char *one) | |
82 | 84 | { |
83 | 85 | char *s = stralloc(name); |
84 | 86 | char *back, *tmp; |
... | ... | |
96 | 98 | *slash = '/'; |
97 | 99 | } |
98 | 100 | |
99 | if (!save_to(tmp, fn)) | |
101 | if (!save_to(tmp, fn, one)) | |
100 | 102 | return; |
101 | 103 | |
102 | 104 | /* move existing file out of harm's way */ |
... | ... | |
146 | 148 | void save_fpd(void) |
147 | 149 | { |
148 | 150 | if (save_file_name) |
149 | save_with_backup(save_file_name, dump); | |
151 | save_with_backup(save_file_name, dump, NULL); | |
150 | 152 | else { |
151 | if (!dump(stdout)) | |
153 | if (!dump(stdout, NULL)) | |
152 | 154 | perror("stdout"); |
153 | 155 | } |
154 | 156 | } |
... | ... | |
160 | 162 | |
161 | 163 | if (save_file_name) { |
162 | 164 | name = set_extension(save_file_name, "mod"); |
163 | save_to(name, kicad); | |
165 | save_to(name, kicad, NULL); | |
164 | 166 | free(name); |
165 | 167 | } else { |
166 | if (!kicad(stdout)) | |
168 | if (!kicad(stdout, NULL)) | |
167 | 169 | perror("stdout"); |
168 | 170 | } |
169 | 171 | } |
170 | 172 | |
171 | 173 | |
172 | static void do_write_ps(int (*fn)(FILE *file)) | |
174 | static void do_write_ps(int (*fn)(FILE *file, const char *one), | |
175 | const char *one) | |
173 | 176 | { |
174 | 177 | char *name; |
175 | 178 | |
176 | 179 | if (save_file_name) { |
177 | 180 | name = set_extension(save_file_name, "ps"); |
178 | save_to(name, fn); | |
181 | save_to(name, fn, one); | |
179 | 182 | free(name); |
180 | 183 | } else { |
181 | if (!fn(stdout)) | |
184 | if (!fn(stdout, one)) | |
182 | 185 | perror("stdout"); |
183 | 186 | } |
184 | 187 | } |
185 | 188 | |
186 | 189 | |
187 | void write_ps(void) | |
190 | void write_ps(const char *one) | |
188 | 191 | { |
189 | do_write_ps(postscript); | |
192 | do_write_ps(postscript, one); | |
190 | 193 | } |
191 | 194 | |
192 | 195 | |
193 | void write_ps_fullpage(void) | |
196 | void write_ps_fullpage(const char *one) | |
194 | 197 | { |
195 | do_write_ps(postscript_fullpage); | |
198 | do_write_ps(postscript_fullpage, one); | |
196 | 199 | } |
file.h | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * file.h - File handling |
3 | 3 | * |
4 | * Written 2009, 2010 by Werner Almesberger | |
5 | * Copyright 2009, 2010 by Werner Almesberger | |
4 | * Written 2009-2011 by Werner Almesberger | |
5 | * Copyright 2009-2011 by Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
23 | 23 | int file_exists(const char *name); |
24 | 24 | |
25 | 25 | char *set_extension(const char *name, const char *ext); |
26 | int save_to(const char *name, int (*fn)(FILE *file)); | |
27 | void save_with_backup(const char *name, int (*fn)(FILE *file)); | |
26 | void save_with_backup(const char *name, int (*fn)(FILE *file, const char *one), | |
27 | const char *one); | |
28 | int save_to(const char *name, int (*fn)(FILE *file, const char *one), | |
29 | const char *one); | |
28 | 30 | |
29 | 31 | void save_fpd(void); |
30 | 32 | void write_kicad(void); |
31 | void write_ps(void); | |
32 | void write_ps_fullpage(void); | |
33 | void write_ps(const char *one); | |
34 | void write_ps_fullpage(const char *one); | |
33 | 35 | |
34 | 36 | #endif /* !FILE_H */ |
fped.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * fped.c - Footprint editor, main function |
3 | 3 | * |
4 | * Written 2009, 2010 by Werner Almesberger | |
5 | * Copyright 2009, 2010 by Werner Almesberger | |
4 | * Written 2009-2011 by Werner Almesberger | |
5 | * Copyright 2009-2011 by Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
67 | 67 | static void usage(const char *name) |
68 | 68 | { |
69 | 69 | fprintf(stderr, |
70 | "usage: %s [-k] [-p|-P [-s scale]] [-T [-T]] [cpp_option ...]\n" | |
70 | "usage: %s [-k] [-p|-P [-s scale] [-1 package]] [-T [-T]] [cpp_option ...]\n" | |
71 | 71 | " %*s [in_file [out_file]]\n\n" |
72 | " -1 name output only the specified package\n" | |
72 | 73 | " -k write KiCad output, then exit\n" |
73 | 74 | " -p write Postscript output, then exit\n" |
74 | 75 | " -P write Postscript output (full page), then exit\n" |
... | ... | |
92 | 93 | int error; |
93 | 94 | int batch = 0; |
94 | 95 | int test_mode = 0; |
96 | const char *one = NULL; | |
95 | 97 | int batch_write_kicad = 0; |
96 | 98 | int batch_write_ps = 0, batch_write_ps_fullpage = 0; |
97 | 99 | int c; |
98 | 100 | |
99 | while ((c = getopt(argc, argv, "kps:D:I:PTU:")) != EOF) | |
101 | while ((c = getopt(argc, argv, "1:kps:D:I:PTU:")) != EOF) | |
100 | 102 | switch (c) { |
103 | case '1': | |
104 | one = optarg; | |
105 | break; | |
101 | 106 | case 'k': |
102 | 107 | batch_write_kicad = 1; |
103 | 108 | break; |
... | ... | |
132 | 137 | if (batch_write_ps && batch_write_ps_fullpage) |
133 | 138 | usage(name); |
134 | 139 | |
140 | if (one && !(batch_write_ps || batch_write_ps_fullpage)) | |
141 | usage(name); | |
142 | ||
135 | 143 | if (batch_write_kicad || batch_write_ps || batch_write_ps_fullpage) |
136 | 144 | batch = 1; |
137 | 145 | |
... | ... | |
174 | 182 | if (batch_write_kicad) |
175 | 183 | write_kicad(); |
176 | 184 | if (batch_write_ps) |
177 | write_ps(); | |
185 | write_ps(one); | |
178 | 186 | if (batch_write_ps_fullpage) |
179 | write_ps_fullpage(); | |
187 | write_ps_fullpage(one); | |
180 | 188 | if (!batch) { |
181 | 189 | error = gui_main(); |
182 | 190 | if (error) |
183 | 191 | return error; |
184 | 192 | } |
185 | 193 | if (test_mode > 1) |
186 | dump(stdout); | |
194 | dump(stdout, NULL); | |
187 | 195 | |
188 | 196 | purge(); |
189 | 197 | inst_revert(); |
kicad.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * kicad.c - Dump objects in the KiCad board/module format |
3 | 3 | * |
4 | * Written 2009, 2010 by Werner Almesberger | |
5 | * Copyright 2009, 2010 by Werner Almesberger | |
4 | * Written 2009-2011 by Werner Almesberger | |
5 | * Copyright 2009-2011 by Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
14 | 14 | #include <stdlib.h> |
15 | 15 | #include <stdio.h> |
16 | 16 | #include <time.h> |
17 | #include <assert.h> | |
17 | 18 | |
18 | 19 | #include "coord.h" |
19 | 20 | #include "inst.h" |
... | ... | |
300 | 301 | } |
301 | 302 | |
302 | 303 | |
303 | int kicad(FILE *file) | |
304 | int kicad(FILE *file, const char *one) | |
304 | 305 | { |
305 | 306 | const struct pkg *pkg; |
306 | 307 | time_t now = time(NULL); |
307 | 308 | |
309 | assert(!one); | |
310 | ||
308 | 311 | fprintf(file, "PCBNEW-LibModule-V1 %s", ctime(&now)); |
309 | 312 | |
310 | 313 | fprintf(file, "$INDEX\n"); |
kicad.h | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * kicad.h - Dump objects in the KiCad board/module format |
3 | 3 | * |
4 | * Written 2009 by Werner Almesberger | |
5 | * Copyright 2009 by Werner Almesberger | |
4 | * Written 2009, 2011 by Werner Almesberger | |
5 | * Copyright 2009, 2011 by Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
17 | 17 | #include <stdio.h> |
18 | 18 | |
19 | 19 | |
20 | int kicad(FILE *file); | |
20 | int kicad(FILE *file, const char *one); | |
21 | 21 | |
22 | 22 | #endif /* !KICAD_H */ |
postscript.c | ||
---|---|---|
13 | 13 | |
14 | 14 | #include <stdlib.h> |
15 | 15 | #include <stdio.h> |
16 | #include <string.h> | |
16 | 17 | |
17 | 18 | #include "util.h" |
18 | 19 | #include "coord.h" |
... | ... | |
1082 | 1083 | |
1083 | 1084 | |
1084 | 1085 | static int ps_for_all_pkg(FILE *file, |
1085 | void (*fn)(FILE *file, const struct pkg *pkg, int page)) | |
1086 | void (*fn)(FILE *file, const struct pkg *pkg, int page), | |
1087 | const char *one) | |
1086 | 1088 | { |
1087 | 1089 | struct pkg *pkg; |
1088 | 1090 | int pages; |
1089 | 1091 | |
1090 | 1092 | for (pkg = pkgs; pkg; pkg = pkg->next) |
1091 | 1093 | if (pkg->name) |
1092 | pages++; | |
1094 | if (!one || !strcmp(pkg->name, one)) | |
1095 | pages++; | |
1096 | if (one && !pages) { | |
1097 | fprintf(stderr, "no package \"%s\" to select\n", one); | |
1098 | return 0; | |
1099 | } | |
1093 | 1100 | prologue(file, pages); |
1094 | 1101 | pages = 0; |
1095 | 1102 | for (pkg = pkgs; pkg; pkg = pkg->next) |
1096 | 1103 | if (pkg->name) |
1097 | fn(file, pkg, ++pages); | |
1104 | if (!one || !strcmp(pkg->name, one)) | |
1105 | fn(file, pkg, ++pages); | |
1098 | 1106 | epilogue(file); |
1099 | 1107 | |
1100 | 1108 | fflush(file); |
... | ... | |
1102 | 1110 | } |
1103 | 1111 | |
1104 | 1112 | |
1105 | int postscript(FILE *file) | |
1113 | int postscript(FILE *file, const char *one) | |
1106 | 1114 | { |
1107 | return ps_for_all_pkg(file, ps_package); | |
1115 | return ps_for_all_pkg(file, ps_package, one); | |
1108 | 1116 | } |
1109 | 1117 | |
1110 | 1118 | |
... | ... | |
1136 | 1144 | } |
1137 | 1145 | |
1138 | 1146 | |
1139 | int postscript_fullpage(FILE *file) | |
1147 | int postscript_fullpage(FILE *file, const char *one) | |
1140 | 1148 | { |
1141 | return ps_for_all_pkg(file, ps_package_fullpage); | |
1149 | return ps_for_all_pkg(file, ps_package_fullpage, one); | |
1142 | 1150 | } |
postscript.h | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * postscript.h - Dump objects in Postscript |
3 | 3 | * |
4 | * Written 2009, 2010 by Werner Almesberger | |
5 | * Copyright 2009, 2010 by Werner Almesberger | |
4 | * Written 2009-2011 by Werner Almesberger | |
5 | * Copyright 2009-2011 by Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
26 | 26 | } postscript_params; |
27 | 27 | |
28 | 28 | |
29 | int postscript(FILE *file); | |
30 | int postscript_fullpage(FILE *file); | |
29 | int postscript(FILE *file, const char *one); | |
30 | int postscript_fullpage(FILE *file, const char *one); | |
31 | 31 | |
32 | 32 | #endif /* !POSTSCRIPT_H */ |
Branches:
master