mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-30 03:56:13 +02:00
sch2fig/: recursively parse sub-sheets
This commit is contained in:
parent
52b8384008
commit
5d392d1097
@ -1,5 +1,5 @@
|
|||||||
- better text size guessing also for FIG
|
- better text size guessing also for FIG
|
||||||
- recursing into sheets:; use base path as starting point
|
- let user to enable/disable recursion; communicate sheet boundaries to backend
|
||||||
- unify alignment, direction
|
- unify alignment, direction
|
||||||
- support fonts attributes ?
|
- support fonts attributes ?
|
||||||
- support line thickness ?
|
- support line thickness ?
|
||||||
|
@ -24,12 +24,6 @@
|
|||||||
#include "sch.h"
|
#include "sch.h"
|
||||||
|
|
||||||
|
|
||||||
static bool do_sch_parse(void *user, const char *line)
|
|
||||||
{
|
|
||||||
return sch_parse(user, line);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
@ -81,9 +75,9 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sch_init(&sch_ctx);
|
sch_init(&sch_ctx);
|
||||||
file_read(argv[argc - 1], do_sch_parse, &sch_ctx);
|
sch_parse(&sch_ctx, argv[argc - 1]);
|
||||||
gfx_init(&fig_ops, template, n_vars, vars);
|
gfx_init(&fig_ops, template, n_vars, vars);
|
||||||
//gfx_init(&cairo_ops, template, n_vars, vars);
|
//gfx_init(&cairo_ops, template, n_vars, vars);
|
||||||
sch_render(&sch_ctx);
|
sch_render(sch_ctx.sheets);
|
||||||
gfx_end();
|
gfx_end();
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,13 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "dwg.h"
|
#include "dwg.h"
|
||||||
|
#include "file.h"
|
||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
#include "sch.h"
|
#include "sch.h"
|
||||||
|
|
||||||
@ -266,18 +268,78 @@ static void submit_obj(struct sch_ctx *ctx, enum sch_obj_type type)
|
|||||||
obj = alloc_type(struct sch_obj);
|
obj = alloc_type(struct sch_obj);
|
||||||
*obj = ctx->obj;
|
*obj = ctx->obj;
|
||||||
obj->type = type;
|
obj->type = type;
|
||||||
obj->next = ctx->objs;
|
obj->next = NULL;
|
||||||
ctx->objs = obj;
|
|
||||||
|
*ctx->next_obj = obj;
|
||||||
|
ctx->next_obj = &obj->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool sch_parse(struct sch_ctx *ctx, const char *line)
|
static struct sheet *new_sheet(struct sch_ctx *ctx)
|
||||||
{
|
{
|
||||||
|
struct sheet *sheet;
|
||||||
|
|
||||||
|
sheet = alloc_type(struct sheet);
|
||||||
|
sheet->objs = NULL;
|
||||||
|
sheet->next = NULL;
|
||||||
|
|
||||||
|
ctx->next_obj = &sheet->objs;
|
||||||
|
|
||||||
|
*ctx->next_sheet = sheet;
|
||||||
|
ctx->next_sheet = &sheet->next;
|
||||||
|
|
||||||
|
return sheet;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool parse_line(void *user, const char *line);
|
||||||
|
|
||||||
|
|
||||||
|
static void recurse_sheet(struct sch_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct sch_obj **saved_next_obj = ctx->next_obj;
|
||||||
|
const char *parent = ctx->file->name;
|
||||||
|
char *tmp = NULL;
|
||||||
|
struct sch_file dsc = {
|
||||||
|
.name = ctx->obj.u.sheet.file,
|
||||||
|
.lineno = 0,
|
||||||
|
.parent = ctx->file,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* @@@ clean this up */
|
||||||
|
|
||||||
|
if (access(dsc.name, R_OK)) {
|
||||||
|
const char *slash;
|
||||||
|
|
||||||
|
slash = strrchr(parent, '/');
|
||||||
|
if (slash) {
|
||||||
|
unsigned len = slash + 1 - parent;
|
||||||
|
|
||||||
|
tmp = alloc_size(len + strlen(dsc.name) + 1);
|
||||||
|
memcpy(tmp, parent, len);
|
||||||
|
strcpy(tmp + len, dsc.name);
|
||||||
|
dsc.name = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new_sheet(ctx);
|
||||||
|
ctx->file = &dsc;
|
||||||
|
ctx->state = sch_descr;
|
||||||
|
file_read(dsc.name, parse_line, ctx);
|
||||||
|
ctx->file = dsc.parent;
|
||||||
|
ctx->next_obj = saved_next_obj;
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool parse_line(void *user, const char *line)
|
||||||
|
{
|
||||||
|
struct sch_ctx *ctx = user;
|
||||||
struct sch_obj *obj = &ctx->obj;
|
struct sch_obj *obj = &ctx->obj;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
ctx->lineno++;
|
ctx->file->lineno++;
|
||||||
|
|
||||||
switch (ctx->state) {
|
switch (ctx->state) {
|
||||||
case sch_basic:
|
case sch_basic:
|
||||||
@ -423,8 +485,9 @@ bool sch_parse(struct sch_ctx *ctx, const char *line)
|
|||||||
break;
|
break;
|
||||||
case sch_sheet:
|
case sch_sheet:
|
||||||
if (sscanf(line, "$EndSheet%n", &n) == 0 && n) {
|
if (sscanf(line, "$EndSheet%n", &n) == 0 && n) {
|
||||||
ctx->state = sch_basic;
|
|
||||||
submit_obj(ctx, sch_obj_sheet);
|
submit_obj(ctx, sch_obj_sheet);
|
||||||
|
recurse_sheet(ctx);
|
||||||
|
ctx->state = sch_basic;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (sscanf(line, "S %d %d %u %u",
|
if (sscanf(line, "S %d %d %u %u",
|
||||||
@ -467,14 +530,29 @@ bool sch_parse(struct sch_ctx *ctx, const char *line)
|
|||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%u: cannot parse\n\"%s\"\n", ctx->lineno, line);
|
fprintf(stderr, "%s:%u: cannot parse\n\"%s\"\n",
|
||||||
|
ctx->file->name, ctx->file->lineno, line);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void sch_parse(struct sch_ctx *ctx, const char *file)
|
||||||
|
{
|
||||||
|
struct sch_file dsc = {
|
||||||
|
.name = file,
|
||||||
|
.lineno = 0,
|
||||||
|
.parent = NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx->file = &dsc;
|
||||||
|
file_read(file, parse_line, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void sch_init(struct sch_ctx *ctx)
|
void sch_init(struct sch_ctx *ctx)
|
||||||
{
|
{
|
||||||
ctx->state = sch_descr;
|
ctx->state = sch_descr;
|
||||||
ctx->objs = NULL;
|
ctx->sheets = NULL;
|
||||||
ctx->lineno = 0;
|
ctx->next_sheet = &ctx->sheets;
|
||||||
|
new_sheet(ctx);
|
||||||
}
|
}
|
||||||
|
@ -129,11 +129,11 @@ static void render_sheet(const struct sch_obj *obj,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void sch_render(const struct sch_ctx *ctx)
|
void sch_render(const struct sheet *sheet)
|
||||||
{
|
{
|
||||||
const struct sch_obj *obj;
|
const struct sch_obj *obj;
|
||||||
|
|
||||||
for (obj = ctx->objs; obj; obj = obj->next)
|
for (obj = sheet->objs; obj; obj = obj->next)
|
||||||
switch (obj->type) {
|
switch (obj->type) {
|
||||||
case sch_obj_wire:
|
case sch_obj_wire:
|
||||||
{
|
{
|
||||||
|
@ -86,20 +86,34 @@ struct sch_obj {
|
|||||||
struct sch_obj *next;
|
struct sch_obj *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct sheet {
|
||||||
|
struct sch_obj *objs;
|
||||||
|
struct sheet *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sch_file {
|
||||||
|
const char *name;
|
||||||
|
int lineno;
|
||||||
|
struct sch_file *parent;
|
||||||
|
};
|
||||||
|
|
||||||
struct sch_ctx {
|
struct sch_ctx {
|
||||||
enum sch_state state;
|
enum sch_state state;
|
||||||
|
|
||||||
struct sch_obj obj;
|
struct sch_obj obj;
|
||||||
struct sch_obj *objs;
|
struct sch_obj **next_obj;
|
||||||
|
|
||||||
unsigned lineno;
|
struct sheet *sheets;
|
||||||
|
struct sheet **next_sheet;
|
||||||
|
|
||||||
|
struct sch_file *file;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void decode_alignment(struct text *txt, char hor, char vert);
|
void decode_alignment(struct text *txt, char hor, char vert);
|
||||||
|
|
||||||
void sch_render(const struct sch_ctx *ctx);
|
void sch_render(const struct sheet *sheet);
|
||||||
bool sch_parse(struct sch_ctx *ctx, const char *line);
|
void sch_parse(struct sch_ctx *ctx, const char *line);
|
||||||
void sch_init(struct sch_ctx *ctx);
|
void sch_init(struct sch_ctx *ctx);
|
||||||
|
|
||||||
#endif /* !SCH_H */
|
#endif /* !SCH_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user