Index: trunk/src/libcschem/hierarchy.c =================================================================== --- trunk/src/libcschem/hierarchy.c (revision 10242) +++ trunk/src/libcschem/hierarchy.c (revision 10243) @@ -30,6 +30,9 @@ #include #include +#include +#include +#include #include #include "concrete.h" @@ -159,9 +162,35 @@ csch_sheet_t *csch_hier_find_by_path(const csch_sheet_t *sheet, const char *path, int add_to_prj_as_aux) { - rnd_message(RND_MSG_ERROR, "cschem/child/path not yet implemented"); - TODO("hierarchical: implement me\n"); - return NULL; + csch_project_t *prj = (csch_project_t *)sheet->hidlib.project; + csch_sheet_t *res; + char *dirname, *new_path, *nr_path; + long n; + + /* refuse invalid and absolute path */ + if ((path == NULL) || (path[0] == '/')) + return NULL; + + dirname = rnd_dirname_real(sheet->hidlib.fullpath); + new_path = rnd_concat(dirname, "/", path, NULL); + free(dirname); + nr_path = rnd_lrealpath(new_path); + free(new_path); + + /* search in project first */ + for(n = 0; n < prj->hdr.designs.used; n++) { + csch_sheet_t *sh = prj->hdr.designs.array[n]; + if (strcmp(sh->hidlib.fullpath, nr_path) == 0) { + res = sh; + goto done; + } + } + + res = csch_app_load_sheet_cb(prj, nr_path); + + done:; + free(nr_path); + return res; } RND_INLINE const char *get_sym_attr(csch_cgrp_t *sym, const char *key)