mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-26 22:32:50 +02:00
eeshow/sch-parse.c, lib-parse.c: use file name and line number from "file"
This commit is contained in:
parent
05af03a0fd
commit
6793f06aeb
@ -141,8 +141,6 @@ static bool lib_parse_line(const struct file *file,
|
|||||||
unsigned zero1, zero2;
|
unsigned zero1, zero2;
|
||||||
char vis;
|
char vis;
|
||||||
|
|
||||||
lib->lineno++;
|
|
||||||
|
|
||||||
switch (lib->state) {
|
switch (lib->state) {
|
||||||
case lib_skip:
|
case lib_skip:
|
||||||
if (parse_def(lib, line)) {
|
if (parse_def(lib, line)) {
|
||||||
@ -229,7 +227,7 @@ static bool lib_parse_line(const struct file *file,
|
|||||||
if (n == 12) {
|
if (n == 12) {
|
||||||
if (zero1) {
|
if (zero1) {
|
||||||
fprintf(stderr, "%u: only understand 0 x x\n"
|
fprintf(stderr, "%u: only understand 0 x x\n"
|
||||||
"\"%s\"\n", lib->lineno, line);
|
"\"%s\"\n", file->lineno, line);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
obj->u.text.style = decode_style(style);
|
obj->u.text.style = decode_style(style);
|
||||||
@ -249,7 +247,7 @@ static bool lib_parse_line(const struct file *file,
|
|||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%u: cannot parse\n\"%s\"\n", lib->lineno, line);
|
fprintf(stderr, "%u: cannot parse\n\"%s\"\n", file->lineno, line);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +257,6 @@ void lib_parse(struct lib *lib, const char *name)
|
|||||||
struct file file;
|
struct file file;
|
||||||
|
|
||||||
lib->state = lib_skip;
|
lib->state = lib_skip;
|
||||||
lib->lineno = 0;
|
|
||||||
file_open(&file, name, NULL);
|
file_open(&file, name, NULL);
|
||||||
file_read(&file, lib_parse_line, lib);
|
file_read(&file, lib_parse_line, lib);
|
||||||
file_close(&file);
|
file_close(&file);
|
||||||
|
@ -100,7 +100,6 @@ struct comp {
|
|||||||
|
|
||||||
struct lib {
|
struct lib {
|
||||||
enum lib_state state;
|
enum lib_state state;
|
||||||
unsigned lineno;
|
|
||||||
|
|
||||||
struct comp *comps;
|
struct comp *comps;
|
||||||
|
|
||||||
|
@ -296,38 +296,37 @@ static struct sheet *new_sheet(struct sch_ctx *ctx)
|
|||||||
static bool parse_line(const struct file *file, void *user, const char *line);
|
static bool parse_line(const struct file *file, void *user, const char *line);
|
||||||
|
|
||||||
|
|
||||||
static void recurse_sheet(struct sch_ctx *ctx)
|
static void recurse_sheet(struct sch_ctx *ctx, const struct file *parent_file)
|
||||||
{
|
{
|
||||||
struct sch_obj **saved_next_obj = ctx->next_obj;
|
struct sch_obj **saved_next_obj = ctx->next_obj;
|
||||||
const char *parent = ctx->file->name;
|
const char *parent = parent_file->name;
|
||||||
|
const char *name = ctx->obj.u.sheet.file;
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
struct file file;
|
struct file file;
|
||||||
struct sch_file dsc = {
|
struct sch_file dsc = {
|
||||||
.name = ctx->obj.u.sheet.file,
|
|
||||||
.lineno = 0,
|
|
||||||
.parent = ctx->file,
|
.parent = ctx->file,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* @@@ clean this up */
|
/* @@@ clean this up */
|
||||||
|
|
||||||
if (access(dsc.name, R_OK)) {
|
if (access(name, R_OK)) {
|
||||||
const char *slash;
|
const char *slash;
|
||||||
|
|
||||||
slash = strrchr(parent, '/');
|
slash = strrchr(parent, '/');
|
||||||
if (slash) {
|
if (slash) {
|
||||||
unsigned len = slash + 1 - parent;
|
unsigned len = slash + 1 - parent;
|
||||||
|
|
||||||
tmp = alloc_size(len + strlen(dsc.name) + 1);
|
tmp = alloc_size(len + strlen(name) + 1);
|
||||||
memcpy(tmp, parent, len);
|
memcpy(tmp, parent, len);
|
||||||
strcpy(tmp + len, dsc.name);
|
strcpy(tmp + len, name);
|
||||||
dsc.name = tmp;
|
name = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new_sheet(ctx);
|
new_sheet(ctx);
|
||||||
ctx->file = &dsc;
|
ctx->file = &dsc;
|
||||||
ctx->state = sch_descr;
|
ctx->state = sch_descr;
|
||||||
file_open(&file, dsc.name, NULL);
|
file_open(&file, name, NULL);
|
||||||
file_read(&file, parse_line, ctx);
|
file_read(&file, parse_line, ctx);
|
||||||
file_close(&file);
|
file_close(&file);
|
||||||
ctx->file = dsc.parent;
|
ctx->file = dsc.parent;
|
||||||
@ -343,8 +342,6 @@ static bool parse_line(const struct file *file, void *user, const char *line)
|
|||||||
int n = 0;
|
int n = 0;
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
ctx->file->lineno++;
|
|
||||||
|
|
||||||
switch (ctx->state) {
|
switch (ctx->state) {
|
||||||
case sch_basic:
|
case sch_basic:
|
||||||
if (sscanf(line, "$Comp%n", &n) == 0 && n) {
|
if (sscanf(line, "$Comp%n", &n) == 0 && n) {
|
||||||
@ -491,7 +488,7 @@ static bool parse_line(const struct file *file, void *user, const char *line)
|
|||||||
if (sscanf(line, "$EndSheet%n", &n) == 0 && n) {
|
if (sscanf(line, "$EndSheet%n", &n) == 0 && n) {
|
||||||
submit_obj(ctx, sch_obj_sheet);
|
submit_obj(ctx, sch_obj_sheet);
|
||||||
if (ctx->recurse)
|
if (ctx->recurse)
|
||||||
recurse_sheet(ctx);
|
recurse_sheet(ctx, file);
|
||||||
ctx->state = sch_basic;
|
ctx->state = sch_basic;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -536,7 +533,7 @@ static bool parse_line(const struct file *file, void *user, const char *line)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%s:%u: cannot parse\n\"%s\"\n",
|
fprintf(stderr, "%s:%u: cannot parse\n\"%s\"\n",
|
||||||
ctx->file->name, ctx->file->lineno, line);
|
file->name, file->lineno, line);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -545,8 +542,6 @@ void sch_parse(struct sch_ctx *ctx, const char *name, const struct lib *lib)
|
|||||||
{
|
{
|
||||||
struct file file;
|
struct file file;
|
||||||
struct sch_file dsc = {
|
struct sch_file dsc = {
|
||||||
.name = name,
|
|
||||||
.lineno = 0,
|
|
||||||
.parent = NULL,
|
.parent = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,8 +92,6 @@ struct sheet {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct sch_file {
|
struct sch_file {
|
||||||
const char *name;
|
|
||||||
int lineno;
|
|
||||||
struct sch_file *parent;
|
struct sch_file *parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user