summaryrefslogtreecommitdiff
path: root/kicad
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-07 02:00:36 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-09-07 03:00:36 (GMT)
commit38a7235477becdb9c9343a73e20bfddb3d0a99f2 (patch)
tree85da888ef9bcf6c4671c0e4e81f21815b36765f6 /kicad
parent9c960d57be28ba51307f13d6422068349431568b (diff)
downloadeeshow-38a7235477becdb9c9343a73e20bfddb3d0a99f2.zip
eeshow-38a7235477becdb9c9343a73e20bfddb3d0a99f2.tar.gz
eeshow-38a7235477becdb9c9343a73e20bfddb3d0a99f2.tar.bz2
kicad/lib-parse.c (lib_parse_search, lib_find_file): search LibDir and default paths
Diffstat (limited to 'kicad')
-rw-r--r--kicad/lib-parse.c37
-rw-r--r--kicad/lib.h5
2 files changed, 42 insertions, 0 deletions
diff --git a/kicad/lib-parse.c b/kicad/lib-parse.c
index 74870c3..a1783fe 100644
--- a/kicad/lib-parse.c
+++ b/kicad/lib-parse.c
@@ -19,9 +19,20 @@
#include "misc/diag.h"
#include "gfx/text.h"
#include "file/file.h"
+#include "kicad/ext.h"
#include "kicad/lib.h"
+/* according to common/gestfich.cpp:KicadDatasPath */
+
+static const char *builtin_paths[] = {
+ "/usr/share/kicad/library",
+ "/usr/local/share/kicad/library",
+ "/usr/local/kicad/share/library",
+ "/usr/local/kicad/library"
+};
+
+
/* ----- Text -------------------------------------------------------------- */
@@ -369,6 +380,32 @@ bool lib_parse(struct lib *lib, const char *name, const struct file *related)
}
+bool lib_find_file(struct file *file, const char *name,
+ const struct file_names *fn, const struct file *related)
+{
+ if (file_open(file, name, related))
+ return 1;
+ if (file_search(file, name, fn->search, fn->n_search, related))
+ return 1;
+ return file_search(file, name,
+ builtin_paths, ARRAY_ELEMENTS(builtin_paths), related);
+}
+
+
+bool lib_parse_search(struct lib *lib, const char *name,
+ const struct file_names *fn, const struct file *related)
+{
+ struct file file;
+ bool res;
+
+ if (!lib_find_file(&file, name, fn, related))
+ return 0;
+ res = lib_parse_file(lib, &file);
+ file_close(&file);
+ return res;
+}
+
+
void lib_init(struct lib *lib)
{
lib->comps = NULL;
diff --git a/kicad/lib.h b/kicad/lib.h
index f146091..12addc9 100644
--- a/kicad/lib.h
+++ b/kicad/lib.h
@@ -19,6 +19,7 @@
#include "file/file.h"
#include "gfx/text.h"
#include "gfx/gfx.h"
+#include "kicad/ext.h"
enum pin_shape {
@@ -142,6 +143,10 @@ void lib_render_extra(const struct comp *comp, struct gfx *gfx,
bool lib_parse_file(struct lib *lib, struct file *file);
bool lib_parse(struct lib *lib, const char *name, const struct file *related);
+bool lib_find_file(struct file *file, const char *name,
+ const struct file_names *fn, const struct file *related);
+bool lib_parse_search(struct lib *lib, const char *name,
+ const struct file_names *fn, const struct file *related);
void lib_init(struct lib *lib);
void lib_free(struct lib *lib);