summaryrefslogtreecommitdiff
path: root/kicad
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-01 16:41:34 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-09-01 16:47:29 (GMT)
commit9ee3d030c7695af0a7752a2645a924ebdd5d5761 (patch)
treeae0665c67baf89d9372861bbdb91565152238edd /kicad
parentd21c4c84e7977e658757b7d82209ec4f87b3285c (diff)
downloadeeshow-9ee3d030c7695af0a7752a2645a924ebdd5d5761.zip
eeshow-9ee3d030c7695af0a7752a2645a924ebdd5d5761.tar.gz
eeshow-9ee3d030c7695af0a7752a2645a924ebdd5d5761.tar.bz2
kicad/sch.h (struct sheet): keep track of file name and schematics path
Diffstat (limited to 'kicad')
-rw-r--r--kicad/delta.c16
-rw-r--r--kicad/sch-parse.c31
-rw-r--r--kicad/sch.h2
3 files changed, 49 insertions, 0 deletions
diff --git a/kicad/delta.c b/kicad/delta.c
index c45212f..35ed774 100644
--- a/kicad/delta.c
+++ b/kicad/delta.c
@@ -438,6 +438,8 @@ static void free_obj(struct sch_obj *obj)
static void init_res(struct sheet *res)
{
res->title = NULL;
+ res->file = NULL;
+ res->path = NULL;
res->objs = NULL;
res->next_obj = &res->objs;
res->next = NULL;
@@ -462,6 +464,20 @@ void delta(const struct sheet *a, const struct sheet *b,
res_b->title = b->title;
}
+ if (a->file && b->file && !strcmp(a->file, b->file)) {
+ res_ab->file = a->file;
+ } else {
+ res_a->file = a->file;
+ res_b->file = b->file;
+ }
+
+ if (a->path && b->path && !strcmp(a->path, b->path)) {
+ res_ab->path = a->path;
+ } else {
+ res_a->path = a->path;
+ res_b->path = b->path;
+ }
+
objs_a = objs_clone(a->objs);
objs_b = objs_clone(b->objs);
diff --git a/kicad/sch-parse.c b/kicad/sch-parse.c
index ddca26d..fc81c62 100644
--- a/kicad/sch-parse.c
+++ b/kicad/sch-parse.c
@@ -27,6 +27,27 @@
#include "kicad/sch.h"
+/* ----- Helper functions -------------------------------------------------- */
+
+
+static const char *sanitize_file_name(const char *name)
+{
+ const char *slash = strrchr(name, '/');
+ const char *colon = strrchr(name, ':');
+
+ if (!slash && !colon)
+ return name;
+ if (slash && !colon)
+ return slash + 1;
+ if (!slash && colon)
+ return colon + 1;
+ if (slash > colon)
+ return slash + 1;
+ else
+ return colon + 1;
+}
+
+
/* ----- (Global) Labels --------------------------------------------------- */
@@ -338,6 +359,8 @@ static struct sheet *new_sheet(struct sch_ctx *ctx)
sheet = alloc_type(struct sheet);
sheet->title = NULL;
+ sheet->file = NULL;
+ sheet->path = NULL;
sheet->objs = NULL;
sheet->next_obj = &sheet->objs;
sheet->next = NULL;
@@ -366,6 +389,7 @@ static struct sheet *recurse_sheet(struct sch_ctx *ctx,
const char *name = ctx->obj.u.sheet.file;
struct sheet *parent, *sheet;
struct file file;
+ char *tmp;
void *oid;
bool res;
@@ -374,6 +398,11 @@ static struct sheet *recurse_sheet(struct sch_ctx *ctx,
parent = ctx->curr_sheet;
sheet = new_sheet(ctx);
+ // should get what file_open really uses @@@
+ sheet->file = stralloc(sanitize_file_name(file.name));
+ alloc_printf(&tmp, "%s%s/", parent->path,
+ ctx->obj.u.sheet.name ? ctx->obj.u.sheet.name : "");
+ sheet->path = tmp;
oid = file_oid(&file);
sheet->oid = oid;
@@ -660,6 +689,8 @@ static bool parse_line(const struct file *file, void *user, const char *line)
bool sch_parse(struct sch_ctx *ctx, struct file *file, const struct lib *lib,
const struct sch_ctx *prev)
{
+ ctx->curr_sheet->file = stralloc(sanitize_file_name(file->name));
+ ctx->curr_sheet->path = stralloc("/");
ctx->lib = lib;
ctx->prev = prev;
return file_read(file, parse_line, ctx);
diff --git a/kicad/sch.h b/kicad/sch.h
index 75f02ae..0a49c71 100644
--- a/kicad/sch.h
+++ b/kicad/sch.h
@@ -103,6 +103,8 @@ struct sch_obj {
struct sheet {
const char *title; /* malloced, unless delta */
+ const char *file; /* file name; idem */
+ const char *path; /* schematics path; idem */
struct sch_obj *objs;
struct sch_obj **next_obj;
struct sheet *next;