mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-02 23:35:19 +02:00
111 lines
2.3 KiB
C
111 lines
2.3 KiB
C
/*
|
|
* 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.
|
|
*/
|
|
|
|
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
|
|
#include "util.h"
|
|
#include "fig.h"
|
|
#include "cairo.h"
|
|
#include "gfx.h"
|
|
#include "file.h"
|
|
#include "lib.h"
|
|
#include "sch.h"
|
|
#include "main.h"
|
|
|
|
|
|
static bool do_lib_parse(void *user, const char *line)
|
|
{
|
|
return lib_parse(user, 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"
|
|
, name);
|
|
exit(1);
|
|
}
|
|
|
|
|
|
int main(int argc, char *const *argv)
|
|
{
|
|
struct sch_ctx sch_ctx;
|
|
bool recurse = 0;
|
|
char c;
|
|
int arg, dashdash;
|
|
int gfx_argc;
|
|
char **gfx_argv;
|
|
|
|
for (dashdash = 1; dashdash != argc; dashdash++)
|
|
if (!strcmp(argv[dashdash], "--"))
|
|
break;
|
|
|
|
while ((c = getopt(dashdash, argv, "r")) != EOF)
|
|
switch (c) {
|
|
case 'r':
|
|
recurse = 1;
|
|
break;
|
|
default:
|
|
usage(*argv);
|
|
}
|
|
|
|
if (dashdash - optind < 1)
|
|
usage(*argv);
|
|
|
|
for (arg = optind; arg != dashdash - 1; arg++) {
|
|
struct lib_ctx ctx;
|
|
|
|
lib_init(&ctx);
|
|
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);
|
|
|
|
sch_init(&sch_ctx, recurse);
|
|
sch_parse(&sch_ctx, argv[dashdash - 1]);
|
|
gfx_init(&fig_ops, gfx_argc, gfx_argv);
|
|
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);
|
|
}
|
|
//gfx_init(&cairo_ops, template, n_vars, vars);
|
|
gfx_end();
|
|
}
|