mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-30 02:03:45 +02:00
sch2fig/: extend command-line parsing to graphics drivers
This commit is contained in:
parent
b8b259bc8d
commit
8491af873e
@ -17,7 +17,6 @@
|
||||
- let user set PNG size or zoom level
|
||||
- implement dashed lines in cairo.c
|
||||
- implement PDF output in cairo.o
|
||||
- generalize gfx option passing
|
||||
- use correct color for hierarchical items, 0x848400 (or close) instead of
|
||||
COLOR_BROWN2
|
||||
- directly pick versions out of git, without requiring checkout to file
|
||||
|
@ -200,7 +200,7 @@ static unsigned cr_text_width(void *ctx, const char *s, unsigned size)
|
||||
/* ----- Initializatio and termination ------------------------------------- */
|
||||
|
||||
|
||||
static void *cr_init(const char *template, int n_vars, const char **vars)
|
||||
static void *cr_init(int argc, char *const *argv)
|
||||
{
|
||||
struct cairo_ctx *cc;
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
@ -21,6 +22,7 @@
|
||||
#include "util.h"
|
||||
#include "style.h"
|
||||
#include "text.h"
|
||||
#include "main.h"
|
||||
#include "fig.h"
|
||||
|
||||
|
||||
@ -214,11 +216,38 @@ static bool apply_vars(char *buf, int n_vars, const char **vars)
|
||||
}
|
||||
|
||||
|
||||
static void *fig_init(const char *template, int n_vars, const char **vars)
|
||||
|
||||
static void *fig_init(int argc, char *const *argv)
|
||||
{
|
||||
const char *template = NULL;
|
||||
const char **vars = NULL;
|
||||
int n_vars = 0;
|
||||
char c;
|
||||
int arg;
|
||||
FILE *file;
|
||||
char buf[1000];
|
||||
|
||||
{ fprintf(stderr, "argc %d\n", argc);
|
||||
int i;
|
||||
for (i = 0; i != argc; i++) fprintf(stderr, "\t%d \"%s\"\n", i, argv[i]); }
|
||||
|
||||
while ((c = getopt(argc, argv, "t:")) != EOF)
|
||||
switch (c) {
|
||||
case 't':
|
||||
template = optarg;
|
||||
break;
|
||||
default:
|
||||
usage(*argv);
|
||||
}
|
||||
|
||||
for (arg = optind; arg != argc; arg++) {
|
||||
if (!strchr(argv[arg], '='))
|
||||
usage(*argv);
|
||||
n_vars++;
|
||||
vars = realloc(vars, sizeof(const char *) * n_vars);
|
||||
vars[n_vars - 1] = argv[arg];
|
||||
}
|
||||
|
||||
if (!template) {
|
||||
fig_header();
|
||||
return NULL;
|
||||
|
@ -85,11 +85,10 @@ unsigned gfx_text_width(const char *s, unsigned size)
|
||||
}
|
||||
|
||||
|
||||
void gfx_init(const struct gfx_ops *ops,
|
||||
const char *template, int n_vars, const char **vars)
|
||||
void gfx_init(const struct gfx_ops *ops, int argc, char *const *argv)
|
||||
{
|
||||
gfx_ops = ops;
|
||||
gfx_ctx = ops->init(template, n_vars, vars);
|
||||
gfx_ctx = ops->init(argc, argv);
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,7 +33,7 @@ struct gfx_ops {
|
||||
void (*text)(void *ctx, int x, int y, const char *s, unsigned size,
|
||||
enum text_align align, int rot, unsigned color, unsigned layer);
|
||||
unsigned (*text_width)(void *ctx, const char *s, unsigned size);
|
||||
void *(*init)(const char *template, int n_vars, const char **vars);
|
||||
void *(*init)(int argc, char *const *argv);
|
||||
void (*new_sheet)(void *ctx);
|
||||
void (*end)(void *ctx);
|
||||
};
|
||||
@ -55,8 +55,7 @@ unsigned gfx_text_width(const char *s, unsigned size);
|
||||
|
||||
/* inititalization and termination */
|
||||
|
||||
void gfx_init(const struct gfx_ops *ops,
|
||||
const char *template, int n_vars, const char **vars);
|
||||
void gfx_init(const struct gfx_ops *ops, int argc, char *const *argv);
|
||||
void gfx_new_sheet(void);
|
||||
bool gfx_multi_sheet(void);
|
||||
void gfx_end(void);
|
||||
|
@ -17,12 +17,14 @@
|
||||
#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)
|
||||
@ -31,57 +33,62 @@ static bool do_lib_parse(void *user, const char *line)
|
||||
}
|
||||
|
||||
|
||||
static void usage(const char *name)
|
||||
void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s [-r] [-t template.fig] [-Dvar=value ...] [file.lib ...] file.sch\n",
|
||||
name);
|
||||
"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 **argv)
|
||||
int main(int argc, char *const *argv)
|
||||
{
|
||||
struct sch_ctx sch_ctx;
|
||||
const char *template = NULL;
|
||||
bool recurse = 0;
|
||||
char c;
|
||||
int arg;
|
||||
int n_vars = 0;
|
||||
const char **vars = NULL;
|
||||
int arg, dashdash;
|
||||
int gfx_argc;
|
||||
char **gfx_argv;
|
||||
|
||||
while ((c = getopt(argc, argv, "rt:D:")) != EOF)
|
||||
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;
|
||||
case 't':
|
||||
template = optarg;
|
||||
break;
|
||||
case 'D':
|
||||
if (!strchr(optarg, '='))
|
||||
usage(*argv);
|
||||
n_vars++;
|
||||
vars = realloc(vars, sizeof(const char *) * n_vars);
|
||||
vars[n_vars - 1] = optarg;
|
||||
break;
|
||||
default:
|
||||
usage(*argv);
|
||||
}
|
||||
|
||||
if (argc - optind < 1)
|
||||
if (dashdash - optind < 1)
|
||||
usage(*argv);
|
||||
|
||||
for (arg = optind; arg != argc - 1; arg++) {
|
||||
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[argc - 1]);
|
||||
gfx_init(&fig_ops, template, n_vars, vars);
|
||||
sch_parse(&sch_ctx, argv[dashdash - 1]);
|
||||
gfx_init(&fig_ops, gfx_argc, gfx_argv);
|
||||
if (recurse) {
|
||||
const struct sheet *sheet;
|
||||
|
||||
|
18
sch2fig/main.h
Normal file
18
sch2fig/main.h
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* main.h - 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.
|
||||
*/
|
||||
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
void usage(const char *name);
|
||||
|
||||
#endif /* !MAIN_H */
|
@ -56,7 +56,7 @@ while [ "$2" ]; do
|
||||
shift
|
||||
done
|
||||
|
||||
./sch2fig "-DTITLE=`basename \"$1\" .sch`" -DNUMBER=$num $template $libs "$1" |
|
||||
./sch2fig $libs "$1" -- $template "TITLE=`basename \"$1\" .sch`" NUMBER=$num |
|
||||
fig2dev -L pdf >"$out"
|
||||
|
||||
sheet=false
|
||||
@ -82,8 +82,8 @@ while read line; do
|
||||
num=`expr $num + 1`
|
||||
|
||||
$quiet || echo "$file" 1>&2
|
||||
./sch2fig "-DTITLE=$name" -DNUMBER=$num $template \
|
||||
$libs `dirname "$1"`/$file |
|
||||
./sch2fig $libs `dirname "$1"`/$file \
|
||||
-- $template "TITLE=$name" NUMBER=$num |
|
||||
fig2dev -L pdf >_tmp.pdf
|
||||
pdfunite "$out" _tmp.pdf _tmp2.pdf
|
||||
mv _tmp2.pdf "$out"
|
||||
|
@ -28,9 +28,9 @@ while [ $sheet -le 38 ]; do
|
||||
in=$dir/neo900-ee/hw/neo900_SS_`expr $sheet - 1`.sch
|
||||
fi
|
||||
file=$dir/$prefix$sn.png
|
||||
$dir/../sch2fig -DSHEET=$sn -t $dir/frame.fig \
|
||||
$dir/neo900-ee/hw/neo900.lib \
|
||||
$dir/kicad-libs/components/powered.lib "$in" |
|
||||
$dir/../sch2fig $dir/neo900-ee/hw/neo900.lib \
|
||||
$dir/kicad-libs/components/powered.lib "$in" \
|
||||
-- -t $dir/frame.fig SHEET=$sn |
|
||||
fig2dev -L png -m 2 >$file
|
||||
sheet=`expr $sheet + 1`
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user