1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-23 02:30:36 +02:00

eeshow/sch-parse.c, lib-parse.c: use file name and line number from "file"

This commit is contained in:
Werner Almesberger 2016-08-02 15:44:28 -03:00
parent 05af03a0fd
commit 6793f06aeb
4 changed files with 12 additions and 23 deletions

View File

@ -141,8 +141,6 @@ static bool lib_parse_line(const struct file *file,
unsigned zero1, zero2;
char vis;
lib->lineno++;
switch (lib->state) {
case lib_skip:
if (parse_def(lib, line)) {
@ -229,7 +227,7 @@ static bool lib_parse_line(const struct file *file,
if (n == 12) {
if (zero1) {
fprintf(stderr, "%u: only understand 0 x x\n"
"\"%s\"\n", lib->lineno, line);
"\"%s\"\n", file->lineno, line);
exit(1);
}
obj->u.text.style = decode_style(style);
@ -249,7 +247,7 @@ static bool lib_parse_line(const struct file *file,
default:
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);
}
@ -259,7 +257,6 @@ void lib_parse(struct lib *lib, const char *name)
struct file file;
lib->state = lib_skip;
lib->lineno = 0;
file_open(&file, name, NULL);
file_read(&file, lib_parse_line, lib);
file_close(&file);

View File

@ -100,7 +100,6 @@ struct comp {
struct lib {
enum lib_state state;
unsigned lineno;
struct comp *comps;

View File

@ -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 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;
const char *parent = ctx->file->name;
const char *parent = parent_file->name;
const char *name = ctx->obj.u.sheet.file;
char *tmp = NULL;
struct file file;
struct sch_file dsc = {
.name = ctx->obj.u.sheet.file,
.lineno = 0,
.parent = ctx->file,
};
/* @@@ clean this up */
if (access(dsc.name, R_OK)) {
if (access(name, R_OK)) {
const char *slash;
slash = strrchr(parent, '/');
if (slash) {
unsigned len = slash + 1 - parent;
tmp = alloc_size(len + strlen(dsc.name) + 1);
tmp = alloc_size(len + strlen(name) + 1);
memcpy(tmp, parent, len);
strcpy(tmp + len, dsc.name);
dsc.name = tmp;
strcpy(tmp + len, name);
name = tmp;
}
}
new_sheet(ctx);
ctx->file = &dsc;
ctx->state = sch_descr;
file_open(&file, dsc.name, NULL);
file_open(&file, name, NULL);
file_read(&file, parse_line, ctx);
file_close(&file);
ctx->file = dsc.parent;
@ -343,8 +342,6 @@ static bool parse_line(const struct file *file, void *user, const char *line)
int n = 0;
char *s;
ctx->file->lineno++;
switch (ctx->state) {
case sch_basic:
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) {
submit_obj(ctx, sch_obj_sheet);
if (ctx->recurse)
recurse_sheet(ctx);
recurse_sheet(ctx, file);
ctx->state = sch_basic;
return 1;
}
@ -536,7 +533,7 @@ static bool parse_line(const struct file *file, void *user, const char *line)
abort();
}
fprintf(stderr, "%s:%u: cannot parse\n\"%s\"\n",
ctx->file->name, ctx->file->lineno, line);
file->name, file->lineno, line);
exit(1);
}
@ -545,8 +542,6 @@ void sch_parse(struct sch_ctx *ctx, const char *name, const struct lib *lib)
{
struct file file;
struct sch_file dsc = {
.name = name,
.lineno = 0,
.parent = NULL,
};

View File

@ -92,8 +92,6 @@ struct sheet {
};
struct sch_file {
const char *name;
int lineno;
struct sch_file *parent;
};