summaryrefslogtreecommitdiff
path: root/kicad/pl-parse.c
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/pl-parse.c
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/pl-parse.c')
-rw-r--r--kicad/pl-parse.c38
1 files changed, 38 insertions, 0 deletions
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;