summaryrefslogtreecommitdiff
path: root/kicad
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-08 02:59:41 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-09-08 02:59:41 (GMT)
commit325eabdfe3a97e253862d731ad9604ffda819e6e (patch)
tree5f2af77f9f8ebf092a955461d9207de0b25944cd /kicad
parent2a64264e445dd46121c1e966bbe1d2b44b29d33f (diff)
downloadeeshow-325eabdfe3a97e253862d731ad9604ffda819e6e.zip
eeshow-325eabdfe3a97e253862d731ad9604ffda819e6e.tar.gz
eeshow-325eabdfe3a97e253862d731ad9604ffda819e6e.tar.bz2
kicad/pl-parse.c (pl_parse_search): search in template directories
Diffstat (limited to 'kicad')
-rw-r--r--kicad/kicad.h1
-rw-r--r--kicad/pl-parse.c38
-rw-r--r--kicad/pl.h1
3 files changed, 40 insertions, 0 deletions
diff --git a/kicad/kicad.h b/kicad/kicad.h
index 1a1f9a7..795fcdd 100644
--- a/kicad/kicad.h
+++ b/kicad/kicad.h
@@ -23,5 +23,6 @@
"/usr/local/kicad" append
#define DEFAULT_LIBRARY_PATHS KICAD_DATAS_PATH("/library")
+#define DEFAULT_TEMPLATE_PATHS KICAD_DATAS_PATH("/template")
#endif /* !KICAD_KICAD_H */
diff --git a/kicad/pl-parse.c b/kicad/pl-parse.c
index dec6fd0..386e3db 100644
--- a/kicad/pl-parse.c
+++ b/kicad/pl-parse.c
@@ -19,11 +19,17 @@
#include "misc/diag.h"
#include "gfx/text.h"
#include "file/file.h"
+#include "kicad/kicad.h"
#include "kicad/sexpr.h"
#include "kicad/pl-common.h"
#include "kicad/pl.h"
+static const char *builtin_template_paths[] = {
+ DEFAULT_TEMPLATE_PATHS
+};
+
+
static bool get_coord(const struct expr *e,
float *x, float *y, int *dx, int *dy)
{
@@ -426,6 +432,38 @@ fail:
}
+static bool pl_find_file(struct file *file, const char *name,
+ const struct file *related)
+{
+ if (file_open(file, name, related))
+ return 1;
+ return file_search(file, name,
+ builtin_template_paths, ARRAY_ELEMENTS(builtin_template_paths),
+ related);
+
+}
+
+
+struct pl_ctx *pl_parse_search(const char *name, const struct file *related)
+{
+ struct file file;
+ struct pl_ctx *pl;
+
+ if (name) {
+ if (!pl_find_file(&file, name, related))
+ return NULL;
+ pl = pl_parse(&file);
+ file_close(&file);
+ return pl;
+ }
+
+ /* @@@ provide proper default */
+ pl = alloc_type(struct pl_ctx);
+ pl->objs = NULL;
+ return pl;
+}
+
+
void pl_free(struct pl_ctx *pl)
{
struct pl_obj *next;
diff --git a/kicad/pl.h b/kicad/pl.h
index c727115..1581456 100644
--- a/kicad/pl.h
+++ b/kicad/pl.h
@@ -31,6 +31,7 @@ void pl_render(struct pl_ctx *pl, struct gfx *gfx,
const struct sheet *sheets, const struct sheet *sheet);
struct pl_ctx *pl_parse(struct file *file);
+struct pl_ctx *pl_parse_search(const char *name, const struct file *related);
void pl_free(struct pl_ctx *pl);
#endif /* !KICAD_PL_H */