mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-26 14:04:39 +02:00
sch2fig/: graphics backend can be selected from the command line
This commit is contained in:
parent
01fed0d456
commit
f3ed4edbd2
@ -232,6 +232,7 @@ static void cr_end(void *ctx)
|
||||
|
||||
|
||||
const struct gfx_ops cairo_ops = {
|
||||
.name = "cairo",
|
||||
// .line = cr_line, @@@ later
|
||||
.poly = cr_poly,
|
||||
.circ = cr_circ,
|
||||
|
@ -268,6 +268,7 @@ static void *fig_init(int argc, char *const *argv)
|
||||
|
||||
|
||||
const struct gfx_ops fig_ops = {
|
||||
.name = "fig",
|
||||
.line = fig_line,
|
||||
.rect = fig_rect,
|
||||
.poly = fig_poly,
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
|
||||
struct gfx_ops {
|
||||
const char *name;
|
||||
void (*line)(void *ctx, int sx, int sy, int ex, int ey,
|
||||
int color, unsigned layer);
|
||||
void (*rect)(void *ctx, int sx, int sy, int ex, int ey,
|
||||
|
@ -27,6 +27,12 @@
|
||||
#include "main.h"
|
||||
|
||||
|
||||
static struct gfx_ops const *ops_list[] = {
|
||||
&fig_ops,
|
||||
&cairo_ops,
|
||||
};
|
||||
|
||||
|
||||
static bool do_lib_parse(void *user, const char *line)
|
||||
{
|
||||
return lib_parse(user, line);
|
||||
@ -36,9 +42,11 @@ static bool do_lib_parse(void *user, const char *line)
|
||||
void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s [-r] [file.lib ...] file.sch -- driver_options\n\n"
|
||||
" FIG driver options:\n"
|
||||
" [-t template.fig] [var=value ...]\n"
|
||||
"usage: %s [-r] [file.lib ...] file.sch -- driver_spec\n\n"
|
||||
" FIG driver spec:\n"
|
||||
" fig [-t template.fig] [var=value ...]\n"
|
||||
" Cairo driver spec:\n"
|
||||
" cairo\n"
|
||||
, name);
|
||||
exit(1);
|
||||
}
|
||||
@ -52,6 +60,7 @@ int main(int argc, char *const *argv)
|
||||
int arg, dashdash;
|
||||
int gfx_argc;
|
||||
char **gfx_argv;
|
||||
const struct gfx_ops **ops = ops_list;
|
||||
|
||||
for (dashdash = 1; dashdash != argc; dashdash++)
|
||||
if (!strcmp(argv[dashdash], "--"))
|
||||
@ -76,19 +85,31 @@ int main(int argc, char *const *argv)
|
||||
file_read(argv[arg], do_lib_parse, &ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Special case: if we have no --, we don't subtract it and argc
|
||||
* becomes 1 (and no 0).
|
||||
*/
|
||||
gfx_argc = argc == dashdash ? 1 : argc - dashdash;
|
||||
gfx_argv = alloc_size(sizeof(const char *) * (gfx_argc + 1));
|
||||
gfx_argv[0] = argv[0];
|
||||
memcpy(gfx_argv + 1, argv + dashdash + 1,
|
||||
sizeof(const char *) * gfx_argc);
|
||||
if (dashdash == argc) {
|
||||
gfx_argc = 1;
|
||||
gfx_argv = alloc_size(sizeof(const char *) * 2);
|
||||
gfx_argv[0] = (char *) (*ops)->name;
|
||||
gfx_argv[1] = NULL;
|
||||
} else {
|
||||
gfx_argc = argc - dashdash - 1;
|
||||
gfx_argv = alloc_size(sizeof(const char *) * (gfx_argc + 1));
|
||||
memcpy(gfx_argv, argv + dashdash + 1,
|
||||
sizeof(const char *) * (gfx_argc + 1));
|
||||
|
||||
for (ops = ops_list; ops != ARRAY_END(ops_list); ops++)
|
||||
if (!strcmp((*ops)->name, *gfx_argv))
|
||||
goto found;
|
||||
fprintf(stderr, "graphics backend \"%s\" not found\n",
|
||||
*gfx_argv);
|
||||
exit(1);
|
||||
found:
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
sch_init(&sch_ctx, recurse);
|
||||
sch_parse(&sch_ctx, argv[dashdash - 1]);
|
||||
gfx_init(&fig_ops, gfx_argc, gfx_argv);
|
||||
gfx_init(*ops, gfx_argc, gfx_argv);
|
||||
if (recurse) {
|
||||
const struct sheet *sheet;
|
||||
|
||||
|
@ -56,7 +56,8 @@ while [ "$2" ]; do
|
||||
shift
|
||||
done
|
||||
|
||||
./sch2fig $libs "$1" -- $template "TITLE=`basename \"$1\" .sch`" NUMBER=$num |
|
||||
./sch2fig $libs "$1" \
|
||||
-- fig $template "TITLE=`basename \"$1\" .sch`" NUMBER=$num |
|
||||
fig2dev -L pdf >"$out"
|
||||
|
||||
sheet=false
|
||||
@ -83,7 +84,7 @@ while read line; do
|
||||
|
||||
$quiet || echo "$file" 1>&2
|
||||
./sch2fig $libs `dirname "$1"`/$file \
|
||||
-- $template "TITLE=$name" NUMBER=$num |
|
||||
-- fig $template "TITLE=$name" NUMBER=$num |
|
||||
fig2dev -L pdf >_tmp.pdf
|
||||
pdfunite "$out" _tmp.pdf _tmp2.pdf
|
||||
mv _tmp2.pdf "$out"
|
||||
|
@ -30,7 +30,7 @@ while [ $sheet -le 38 ]; do
|
||||
file=$dir/$prefix$sn.png
|
||||
$dir/../sch2fig $dir/neo900-ee/hw/neo900.lib \
|
||||
$dir/kicad-libs/components/powered.lib "$in" \
|
||||
-- -t $dir/frame.fig SHEET=$sn |
|
||||
-- fig -t $dir/frame.fig SHEET=$sn |
|
||||
fig2dev -L png -m 2 >$file
|
||||
sheet=`expr $sheet + 1`
|
||||
done
|
||||
|
@ -38,6 +38,10 @@
|
||||
stralloc_tmp; })
|
||||
|
||||
|
||||
#define ARRAY_ELEMENTS(a) (sizeof(a) / sizeof(a[0]))
|
||||
#define ARRAY_END(a) ((a) + ARRAY_ELEMENTS(a))
|
||||
|
||||
|
||||
#define swap(a, b) \
|
||||
({ typeof(a) _tmp = (a); a = (b); b = _tmp; })
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user