summaryrefslogtreecommitdiff
path: root/kicad/pl-parse.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-08 01:42:11 -0300
committerWerner Almesberger <werner@almesberger.net>2016-09-08 01:42:11 -0300
commitf31d15bda0c609910388210d0edbf0bb952afc4a (patch)
treebbe2516a895203c11a765926f33b5f53dee1f05e /kicad/pl-parse.c
parent61c29a9d460573cb1095351c8de48c4f985facbe (diff)
downloadeeshow-f31d15bda0c609910388210d0edbf0bb952afc4a.tar.gz
eeshow-f31d15bda0c609910388210d0edbf0bb952afc4a.tar.bz2
eeshow-f31d15bda0c609910388210d0edbf0bb952afc4a.zip
kicad/: support parsing polygons in page layout
Diffstat (limited to 'kicad/pl-parse.c')
-rw-r--r--kicad/pl-parse.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/kicad/pl-parse.c b/kicad/pl-parse.c
index 27a4628..4cd8b1c 100644
--- a/kicad/pl-parse.c
+++ b/kicad/pl-parse.c
@@ -283,6 +283,45 @@ static bool process_option(struct pl_obj *obj, const struct expr *e)
}
+static bool process_poly(struct pl_obj *obj, const struct expr *e)
+{
+ struct pl_poly *poly;
+ struct pl_point *p, **anchor;
+ const char *s;
+ const struct expr *next;
+
+ poly = alloc_type(struct pl_poly);
+ poly->points = NULL;
+ poly->next = obj->poly;
+ obj->poly = poly;
+ anchor = &poly->points;
+
+ for (; e; e = e->next) {
+ if (!e->e) {
+ warning("pts: ignoring non-list");
+ continue;
+ }
+
+ s = e->e->s;
+ next = e->e->next;
+
+ if (!strcmp(s, "xy")) {
+ p = alloc_type(struct pl_point);
+ *anchor = p;
+ anchor = &p->next;
+ if (!get_xy(next, &p->x, &p->y))
+ return 0;
+ } else {
+ warning("pts: ignoring \"%s\"", s);
+ }
+ }
+
+ *anchor = NULL;
+
+ return 1;
+}
+
+
static bool process_obj(struct pl_ctx *pl, const struct expr *e,
enum pl_obj_type type)
{
@@ -304,6 +343,7 @@ static bool process_obj(struct pl_ctx *pl, const struct expr *e,
obj->hor = text_min;
obj->vert = text_mid;
obj->rotate = 0;
+ obj->poly = 0;
for (; e; e = e->next) {
if (e->s) {
@@ -361,6 +401,9 @@ static bool process_obj(struct pl_ctx *pl, const struct expr *e,
} else if (!strcmp(s, "option")) {
if (!process_option(obj, next))
return 0;
+ } else if (!strcmp(s, "pts")) {
+ if (!process_poly(obj, next))
+ return 0;
} else
warning("pl_obj: ignoring \"%s\"", s);
}
@@ -400,6 +443,9 @@ static bool process_layout(struct pl_ctx *pl, const struct expr *e)
} else if (!strcmp(s, "tbtext")) {
if (!process_obj(pl, next, pl_obj_text))
return 0;
+ } else if (!strcmp(s, "polygon")) {
+ if (!process_obj(pl, next, pl_obj_poly))
+ return 0;
} else {
warning("layout: ignoring \"%s\"", s);
}
@@ -491,6 +537,23 @@ struct pl_ctx *pl_parse_search(const char *name, const struct file *related)
}
+static void free_polys(struct pl_poly *poly)
+{
+ struct pl_poly *next_poly;
+ struct pl_point *p, *next_point;
+
+ while (poly) {
+ next_poly = poly->next;
+ for (p = poly->points; p; p = next_point) {
+ next_point = p->next;
+ free(p);
+ }
+ free(poly);
+ poly = next_poly;
+ }
+}
+
+
void pl_free(struct pl_ctx *pl)
{
struct pl_obj *next;
@@ -498,6 +561,7 @@ void pl_free(struct pl_ctx *pl)
while (pl->objs) {
next = pl->objs->next;
free((void *) pl->objs->s);
+ free_polys(pl->objs->poly);
free(pl->objs);
pl->objs = next;
}