Date:2011-09-04 22:22:10 (6 years 2 months ago)
Author:Werner Almesberger
Commit:6ca5c22ea48babba3cf578f80a19fbb140e17c15
Message:fped.c: cleaned up batch mode selection; batch modes are now mutually exclusive

Files: fped.c (5 diffs)

Change Details

fped.c
6767static void usage(const char *name)
6868{
6969    fprintf(stderr,
70"usage: %s [-k] [-p|-P [-s scale] [-1 package]] [-T [-T]] [cpp_option ...]\n"
71" %*s [in_file [out_file]]\n\n"
72" -1 name output only the specified package\n"
70"usage: %s [batch_mode] [cpp_option ...] [in_file [out_file]]\n\n"
71"Batch mode options:\n"
7372" -k write KiCad output, then exit\n"
7473" -p write Postscript output, then exit\n"
75" -P write Postscript output (full page), then exit\n"
76" -s scale scale factor for -P (default: auto-scale)\n"
74" -P [-s scale] [-1 package]\n"
75" write Postscript output (full page), then exit\n"
76" -1 name output only the specified package\n"
77" -s scale scale factor for -P (default: auto-scale)\n"
7778" -T test mode. Load file, then exit\n"
78" -T -T test mode. Load file, dump to stdout, then exit\n"
79" -T -T test mode. Load file, dump to stdout, then exit\n\n"
80"Common options:\n"
7981" cpp_option -Idir, -Dname[=value], or -Uname\n"
80    , name, (int) strlen(name), "");
82    , name);
8183    exit(1);
8284}
8385
8486
8587int main(int argc, char **argv)
8688{
89    enum {
90        batch_none = 0,
91        batch_kicad,
92        batch_ps,
93        batch_ps_fullpage,
94        batch_test
95    } batch = batch_none;
8796    char *name = *argv;
8897    char **fake_argv;
8998    char *args[2];
...... 
91100    char opt[] = "-?";
92101    char *end;
93102    int error;
94    int batch = 0;
95103    int test_mode = 0;
96104    const char *one = NULL;
97    int batch_write_kicad = 0;
98    int batch_write_ps = 0, batch_write_ps_fullpage = 0;
99105    int c;
100106
101107    while ((c = getopt(argc, argv, "1:kps:D:I:PTU:")) != EOF)
...... 
104110            one = optarg;
105111            break;
106112        case 'k':
107            batch_write_kicad = 1;
113            if (batch)
114                usage(*argv);
115            batch = batch_kicad;
108116            break;
109117        case 'p':
110            batch_write_ps = 1;
118            if (batch)
119                usage(*argv);
120            batch = batch_ps;
111121            break;
112122        case 'P':
113            batch_write_ps_fullpage = 1;
123            if (batch)
124                usage(*argv);
125            batch = batch_ps_fullpage;
114126            break;
115127        case 's':
116            if (!batch_write_ps_fullpage)
128            if (batch != batch_ps_fullpage)
117129                usage(*argv);
118130            postscript_params.zoom = strtod(optarg, &end);
119131            if (*end)
120132                usage(*argv);
121133            break;
122134        case 'T':
123            batch = 1;
135            batch = batch_test;
124136            test_mode++;
125137            break;
126138        case 'D':
...... 
134146            usage(name);
135147        }
136148
137    if (batch_write_ps && batch_write_ps_fullpage)
149    if (one && batch != batch_ps && batch != batch_ps_fullpage)
138150        usage(name);
139151
140    if (one && !(batch_write_ps || batch_write_ps_fullpage))
141        usage(name);
142
143    if (batch_write_kicad || batch_write_ps || batch_write_ps_fullpage)
144        batch = 1;
145
146152    if (!batch) {
147153        args[0] = name;
148154        args[1] = NULL;
...... 
179185    if (!instantiate())
180186        return 1;
181187
182    if (batch_write_kicad)
183        write_kicad();
184    if (batch_write_ps)
185        write_ps(one);
186    if (batch_write_ps_fullpage)
187        write_ps_fullpage(one);
188    if (!batch) {
188    switch (batch) {
189    case batch_none:
189190        error = gui_main();
190191        if (error)
191192            return error;
192    }
193    if (test_mode > 1)
193        break;
194    case batch_kicad:
195        write_kicad();
196        break;
197    case batch_ps:
198        write_ps(one);
199        break;
200    case batch_ps_fullpage:
201        write_ps_fullpage(one);
202        break;
203    case batch_test:
194204        dump(stdout, NULL);
205        break;
206    default:
207        abort();
208    }
195209
196210    purge();
197211    inst_revert();

Archive Download the corresponding diff file

Branches:
master



interactive