mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-23 01:14:04 +02:00
sch2fig/: command-line option -r to enable recursive sheet parsing and output
This commit is contained in:
parent
5d392d1097
commit
b8b259bc8d
@ -1,5 +1,4 @@
|
||||
- better text size guessing also for FIG
|
||||
- let user to enable/disable recursion; communicate sheet boundaries to backend
|
||||
- unify alignment, direction
|
||||
- support fonts attributes ?
|
||||
- support line thickness ?
|
||||
|
@ -11,6 +11,8 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "style.h"
|
||||
#include "text.h"
|
||||
#include "gfx.h"
|
||||
@ -91,6 +93,18 @@ void gfx_init(const struct gfx_ops *ops,
|
||||
}
|
||||
|
||||
|
||||
void gfx_new_sheet(void)
|
||||
{
|
||||
if (gfx_ops->new_sheet)
|
||||
gfx_ops->new_sheet(gfx_ctx);
|
||||
}
|
||||
|
||||
|
||||
bool gfx_multi_sheet(void)
|
||||
{
|
||||
return !!gfx_ops->new_sheet;
|
||||
}
|
||||
|
||||
void gfx_end(void)
|
||||
{
|
||||
if (gfx_ops->end)
|
||||
|
@ -14,6 +14,8 @@
|
||||
#ifndef GFX_H
|
||||
#define GFX_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "text.h"
|
||||
|
||||
|
||||
@ -32,6 +34,7 @@ struct gfx_ops {
|
||||
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 (*new_sheet)(void *ctx);
|
||||
void (*end)(void *ctx);
|
||||
};
|
||||
|
||||
@ -54,6 +57,8 @@ 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_new_sheet(void);
|
||||
bool gfx_multi_sheet(void);
|
||||
void gfx_end(void);
|
||||
|
||||
#endif /* !GFX_H */
|
||||
|
@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@ -33,7 +34,7 @@ static bool do_lib_parse(void *user, const char *line)
|
||||
static void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s [-t template.fig] [-Dvar=value ...] [file.lib ...] file.sch\n",
|
||||
"usage: %s [-r] [-t template.fig] [-Dvar=value ...] [file.lib ...] file.sch\n",
|
||||
name);
|
||||
exit(1);
|
||||
}
|
||||
@ -43,13 +44,17 @@ int main(int argc, char **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;
|
||||
|
||||
while ((c = getopt(argc, argv, "t:D:")) != EOF)
|
||||
while ((c = getopt(argc, argv, "rt:D:")) != EOF)
|
||||
switch (c) {
|
||||
case 'r':
|
||||
recurse = 1;
|
||||
break;
|
||||
case 't':
|
||||
template = optarg;
|
||||
break;
|
||||
@ -74,10 +79,25 @@ int main(int argc, char **argv)
|
||||
file_read(argv[arg], do_lib_parse, &ctx);
|
||||
}
|
||||
|
||||
sch_init(&sch_ctx);
|
||||
sch_init(&sch_ctx, recurse);
|
||||
sch_parse(&sch_ctx, argv[argc - 1]);
|
||||
gfx_init(&fig_ops, template, n_vars, vars);
|
||||
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);
|
||||
sch_render(sch_ctx.sheets);
|
||||
gfx_end();
|
||||
}
|
||||
|
@ -486,7 +486,8 @@ static bool parse_line(void *user, const char *line)
|
||||
case sch_sheet:
|
||||
if (sscanf(line, "$EndSheet%n", &n) == 0 && n) {
|
||||
submit_obj(ctx, sch_obj_sheet);
|
||||
recurse_sheet(ctx);
|
||||
if (ctx->recurse)
|
||||
recurse_sheet(ctx);
|
||||
ctx->state = sch_basic;
|
||||
return 1;
|
||||
}
|
||||
@ -549,9 +550,10 @@ void sch_parse(struct sch_ctx *ctx, const char *file)
|
||||
}
|
||||
|
||||
|
||||
void sch_init(struct sch_ctx *ctx)
|
||||
void sch_init(struct sch_ctx *ctx, bool recurse)
|
||||
{
|
||||
ctx->state = sch_descr;
|
||||
ctx->recurse = recurse;
|
||||
ctx->sheets = NULL;
|
||||
ctx->next_sheet = &ctx->sheets;
|
||||
new_sheet(ctx);
|
||||
|
@ -100,6 +100,8 @@ struct sch_file {
|
||||
struct sch_ctx {
|
||||
enum sch_state state;
|
||||
|
||||
bool recurse;
|
||||
|
||||
struct sch_obj obj;
|
||||
struct sch_obj **next_obj;
|
||||
|
||||
@ -114,6 +116,6 @@ void decode_alignment(struct text *txt, char hor, char vert);
|
||||
|
||||
void sch_render(const struct sheet *sheet);
|
||||
void sch_parse(struct sch_ctx *ctx, const char *line);
|
||||
void sch_init(struct sch_ctx *ctx);
|
||||
void sch_init(struct sch_ctx *ctx, bool recurse);
|
||||
|
||||
#endif /* !SCH_H */
|
||||
|
Loading…
Reference in New Issue
Block a user