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