Date:2011-03-23 08:14:13 (6 years 7 months 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
1414#include <stdlib.h>
1515#include <stdio.h>
1616#include <string.h>
17#include <assert.h>
1718#include <sys/types.h>
1819
1920#include "util.h"
...... 
598599}
599600
600601
601int dump(FILE *file)
602int dump(FILE *file, const char *one)
602603{
603604    struct frame *frame;
604605
606    assert(!one);
607
605608    fprintf(file, "%s\n", MACHINE_GENERATED);
606609    for (frame = frames; frame; frame = frame->next)
607610        frame->dumped = 0;
dump.h
11/*
22 * dump.h - Dump objects in the native FPD format
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
4444
4545struct order *order_frame(const struct frame *frame);
4646
47int dump(FILE *file);
47int dump(FILE *file, const char *one);
4848
4949#endif /* !DUMP_H */
file.c
11/*
22 * file.c - File handling
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
5757}
5858
5959
60int save_to(const char *name, int (*fn)(FILE *file))
60int save_to(const char *name, int (*fn)(FILE *file, const char *one),
61    const char *one)
6162{
6263    FILE *file;
6364
...... 
6667        perror(name);
6768        return 0;
6869    }
69    if (!fn(file)) {
70    if (!fn(file, one)) {
7071        perror(name);
7172        return 0;
7273    }
...... 
7879}
7980
8081
81void save_with_backup(const char *name, int (*fn)(FILE *file))
82void save_with_backup(const char *name, int (*fn)(FILE *file, const char *one),
83    const char *one)
8284{
8385    char *s = stralloc(name);
8486    char *back, *tmp;
...... 
9698        *slash = '/';
9799    }
98100
99    if (!save_to(tmp, fn))
101    if (!save_to(tmp, fn, one))
100102        return;
101103
102104    /* move existing file out of harm's way */
...... 
146148void save_fpd(void)
147149{
148150    if (save_file_name)
149        save_with_backup(save_file_name, dump);
151        save_with_backup(save_file_name, dump, NULL);
150152    else {
151        if (!dump(stdout))
153        if (!dump(stdout, NULL))
152154            perror("stdout");
153155    }
154156}
...... 
160162
161163    if (save_file_name) {
162164        name = set_extension(save_file_name, "mod");
163        save_to(name, kicad);
165        save_to(name, kicad, NULL);
164166        free(name);
165167    } else {
166        if (!kicad(stdout))
168        if (!kicad(stdout, NULL))
167169            perror("stdout");
168170    }
169171}
170172
171173
172static void do_write_ps(int (*fn)(FILE *file))
174static void do_write_ps(int (*fn)(FILE *file, const char *one),
175    const char *one)
173176{
174177    char *name;
175178
176179    if (save_file_name) {
177180        name = set_extension(save_file_name, "ps");
178        save_to(name, fn);
181        save_to(name, fn, one);
179182        free(name);
180183    } else {
181        if (!fn(stdout))
184        if (!fn(stdout, one))
182185            perror("stdout");
183186    }
184187}
185188
186189
187void write_ps(void)
190void write_ps(const char *one)
188191{
189    do_write_ps(postscript);
192    do_write_ps(postscript, one);
190193}
191194
192195
193void write_ps_fullpage(void)
196void write_ps_fullpage(const char *one)
194197{
195    do_write_ps(postscript_fullpage);
198    do_write_ps(postscript_fullpage, one);
196199}
file.h
11/*
22 * file.h - File handling
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
2323int file_exists(const char *name);
2424
2525char *set_extension(const char *name, const char *ext);
26int save_to(const char *name, int (*fn)(FILE *file));
27void save_with_backup(const char *name, int (*fn)(FILE *file));
26void save_with_backup(const char *name, int (*fn)(FILE *file, const char *one),
27    const char *one);
28int save_to(const char *name, int (*fn)(FILE *file, const char *one),
29    const char *one);
2830
2931void save_fpd(void);
3032void write_kicad(void);
31void write_ps(void);
32void write_ps_fullpage(void);
33void write_ps(const char *one);
34void write_ps_fullpage(const char *one);
3335
3436#endif /* !FILE_H */
fped.c
11/*
22 * fped.c - Footprint editor, main function
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
6767static void usage(const char *name)
6868{
6969    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"
7171" %*s [in_file [out_file]]\n\n"
72" -1 name output only the specified package\n"
7273" -k write KiCad output, then exit\n"
7374" -p write Postscript output, then exit\n"
7475" -P write Postscript output (full page), then exit\n"
...... 
9293    int error;
9394    int batch = 0;
9495    int test_mode = 0;
96    const char *one = NULL;
9597    int batch_write_kicad = 0;
9698    int batch_write_ps = 0, batch_write_ps_fullpage = 0;
9799    int c;
98100
99    while ((c = getopt(argc, argv, "kps:D:I:PTU:")) != EOF)
101    while ((c = getopt(argc, argv, "1:kps:D:I:PTU:")) != EOF)
100102        switch (c) {
103        case '1':
104            one = optarg;
105            break;
101106        case 'k':
102107            batch_write_kicad = 1;
103108            break;
...... 
132137    if (batch_write_ps && batch_write_ps_fullpage)
133138        usage(name);
134139
140    if (one && !(batch_write_ps || batch_write_ps_fullpage))
141        usage(name);
142
135143    if (batch_write_kicad || batch_write_ps || batch_write_ps_fullpage)
136144        batch = 1;
137145
...... 
174182    if (batch_write_kicad)
175183        write_kicad();
176184    if (batch_write_ps)
177        write_ps();
185        write_ps(one);
178186    if (batch_write_ps_fullpage)
179        write_ps_fullpage();
187        write_ps_fullpage(one);
180188    if (!batch) {
181189        error = gui_main();
182190        if (error)
183191            return error;
184192    }
185193    if (test_mode > 1)
186        dump(stdout);
194        dump(stdout, NULL);
187195
188196    purge();
189197    inst_revert();
kicad.c
11/*
22 * kicad.c - Dump objects in the KiCad board/module format
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1414#include <stdlib.h>
1515#include <stdio.h>
1616#include <time.h>
17#include <assert.h>
1718
1819#include "coord.h"
1920#include "inst.h"
...... 
300301}
301302
302303
303int kicad(FILE *file)
304int kicad(FILE *file, const char *one)
304305{
305306    const struct pkg *pkg;
306307    time_t now = time(NULL);
307308
309    assert(!one);
310
308311    fprintf(file, "PCBNEW-LibModule-V1 %s", ctime(&now));
309312
310313    fprintf(file, "$INDEX\n");
kicad.h
11/*
22 * kicad.h - Dump objects in the KiCad board/module format
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1717#include <stdio.h>
1818
1919
20int kicad(FILE *file);
20int kicad(FILE *file, const char *one);
2121
2222#endif /* !KICAD_H */
postscript.c
1313
1414#include <stdlib.h>
1515#include <stdio.h>
16#include <string.h>
1617
1718#include "util.h"
1819#include "coord.h"
...... 
10821083
10831084
10841085static 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)
10861088{
10871089    struct pkg *pkg;
10881090    int pages;
10891091
10901092    for (pkg = pkgs; pkg; pkg = pkg->next)
10911093        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    }
10931100    prologue(file, pages);
10941101    pages = 0;
10951102    for (pkg = pkgs; pkg; pkg = pkg->next)
10961103        if (pkg->name)
1097            fn(file, pkg, ++pages);
1104            if (!one || !strcmp(pkg->name, one))
1105                fn(file, pkg, ++pages);
10981106    epilogue(file);
10991107
11001108    fflush(file);
...... 
11021110}
11031111
11041112
1105int postscript(FILE *file)
1113int postscript(FILE *file, const char *one)
11061114{
1107    return ps_for_all_pkg(file, ps_package);
1115    return ps_for_all_pkg(file, ps_package, one);
11081116}
11091117
11101118
...... 
11361144}
11371145
11381146
1139int postscript_fullpage(FILE *file)
1147int postscript_fullpage(FILE *file, const char *one)
11401148{
1141    return ps_for_all_pkg(file, ps_package_fullpage);
1149    return ps_for_all_pkg(file, ps_package_fullpage, one);
11421150}
postscript.h
11/*
22 * postscript.h - Dump objects in Postscript
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
2626} postscript_params;
2727
2828
29int postscript(FILE *file);
30int postscript_fullpage(FILE *file);
29int postscript(FILE *file, const char *one);
30int postscript_fullpage(FILE *file, const char *one);
3131
3232#endif /* !POSTSCRIPT_H */

Archive Download the corresponding diff file

Branches:
master



interactive