2016-07-22 06:04:42 +03:00
|
|
|
/*
|
|
|
|
* main.c - Convert Eeschema schematics to FIG
|
|
|
|
*
|
|
|
|
* Written 2016 by Werner Almesberger
|
|
|
|
* Copyright 2016 by Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2016-08-01 02:25:06 +03:00
|
|
|
#include <stdbool.h>
|
2016-07-22 05:54:32 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2016-07-26 08:30:58 +03:00
|
|
|
#include <unistd.h>
|
2016-07-22 05:54:32 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
2016-08-01 02:46:45 +03:00
|
|
|
#include "util.h"
|
2016-07-22 05:54:32 +03:00
|
|
|
#include "fig.h"
|
2016-07-31 06:04:43 +03:00
|
|
|
#include "cairo.h"
|
2016-07-31 03:50:02 +03:00
|
|
|
#include "gfx.h"
|
2016-07-31 21:10:14 +03:00
|
|
|
#include "file.h"
|
2016-07-22 05:54:32 +03:00
|
|
|
#include "lib.h"
|
|
|
|
#include "sch.h"
|
2016-08-01 02:46:45 +03:00
|
|
|
#include "main.h"
|
2016-07-22 05:54:32 +03:00
|
|
|
|
|
|
|
|
2016-08-01 03:52:35 +03:00
|
|
|
static struct gfx_ops const *ops_list[] = {
|
|
|
|
&fig_ops,
|
|
|
|
&cairo_ops,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-07-31 21:10:14 +03:00
|
|
|
static bool do_lib_parse(void *user, const char *line)
|
2016-07-22 05:54:32 +03:00
|
|
|
{
|
2016-07-31 21:10:14 +03:00
|
|
|
return lib_parse(user, line);
|
2016-07-22 05:54:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-01 02:46:45 +03:00
|
|
|
void usage(const char *name)
|
2016-07-22 05:54:32 +03:00
|
|
|
{
|
2016-07-26 08:30:58 +03:00
|
|
|
fprintf(stderr,
|
2016-08-01 03:52:35 +03:00
|
|
|
"usage: %s [-r] [file.lib ...] file.sch -- driver_spec\n\n"
|
|
|
|
" FIG driver spec:\n"
|
|
|
|
" fig [-t template.fig] [var=value ...]\n"
|
2016-08-01 06:18:22 +03:00
|
|
|
" Cairo PNG driver spec:\n"
|
|
|
|
" png [-o output.png] [-s scale]\n"
|
2016-08-01 02:46:45 +03:00
|
|
|
, name);
|
2016-07-22 05:54:32 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-01 02:46:45 +03:00
|
|
|
int main(int argc, char *const *argv)
|
2016-07-22 05:54:32 +03:00
|
|
|
{
|
2016-07-31 07:48:31 +03:00
|
|
|
struct sch_ctx sch_ctx;
|
2016-08-01 02:25:06 +03:00
|
|
|
bool recurse = 0;
|
2016-07-26 08:30:58 +03:00
|
|
|
char c;
|
2016-08-01 02:46:45 +03:00
|
|
|
int arg, dashdash;
|
|
|
|
int gfx_argc;
|
|
|
|
char **gfx_argv;
|
2016-08-01 03:52:35 +03:00
|
|
|
const struct gfx_ops **ops = ops_list;
|
2016-07-22 05:54:32 +03:00
|
|
|
|
2016-08-01 02:46:45 +03:00
|
|
|
for (dashdash = 1; dashdash != argc; dashdash++)
|
|
|
|
if (!strcmp(argv[dashdash], "--"))
|
|
|
|
break;
|
|
|
|
|
|
|
|
while ((c = getopt(dashdash, argv, "r")) != EOF)
|
2016-07-26 08:30:58 +03:00
|
|
|
switch (c) {
|
2016-08-01 02:25:06 +03:00
|
|
|
case 'r':
|
|
|
|
recurse = 1;
|
|
|
|
break;
|
2016-07-26 08:30:58 +03:00
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
|
|
|
|
2016-08-01 02:46:45 +03:00
|
|
|
if (dashdash - optind < 1)
|
2016-07-22 05:54:32 +03:00
|
|
|
usage(*argv);
|
|
|
|
|
2016-08-01 02:46:45 +03:00
|
|
|
for (arg = optind; arg != dashdash - 1; arg++) {
|
2016-07-31 07:48:31 +03:00
|
|
|
struct lib_ctx ctx;
|
2016-07-22 05:54:32 +03:00
|
|
|
|
2016-07-31 07:48:31 +03:00
|
|
|
lib_init(&ctx);
|
2016-07-31 21:10:14 +03:00
|
|
|
file_read(argv[arg], do_lib_parse, &ctx);
|
2016-07-22 05:54:32 +03:00
|
|
|
}
|
2016-07-31 07:48:31 +03:00
|
|
|
|
2016-08-01 03:52:35 +03:00
|
|
|
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:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-01 02:25:06 +03:00
|
|
|
sch_init(&sch_ctx, recurse);
|
2016-08-01 02:46:45 +03:00
|
|
|
sch_parse(&sch_ctx, argv[dashdash - 1]);
|
2016-08-01 03:52:35 +03:00
|
|
|
gfx_init(*ops, gfx_argc, gfx_argv);
|
2016-08-01 02:25:06 +03:00
|
|
|
if (recurse) {
|
|
|
|
const struct sheet *sheet;
|
|
|
|
|
|
|
|
if (!gfx_multi_sheet()) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"graphics backend only supports single sheet\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
for (sheet = sch_ctx.sheets; sheet; sheet = sheet->next) {
|
|
|
|
sch_render(sheet);
|
|
|
|
if (sheet->next)
|
|
|
|
gfx_new_sheet();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sch_render(sch_ctx.sheets);
|
|
|
|
}
|
2016-07-31 07:48:31 +03:00
|
|
|
//gfx_init(&cairo_ops, template, n_vars, vars);
|
2016-07-31 05:02:15 +03:00
|
|
|
gfx_end();
|
2016-07-22 05:54:32 +03:00
|
|
|
}
|