Skip to content

Commit

Permalink
Look for jq/main.jq for imports
Browse files Browse the repository at this point in the history
  • Loading branch information
nicowilliams committed Jan 3, 2015
1 parent 736f175 commit 6e7cf81
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions linker.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ static jv build_lib_search_chain(jq_state *jq, jv search_path, jv jq_origin, jv
return expanded;
}

// Doesn't actually check that name not be an absolute path; we could
// just always prepend "./"!
// Doesn't actually check that name not be an absolute path, and we
// don't have to: we always append relative paths to others (with a '/'
// in between).
static jv validate_relpath(jv name) {
const char *s = jv_string_value(name);
if (strchr(s, '\\')) {
Expand Down Expand Up @@ -138,15 +139,25 @@ static jv find_lib(jq_state *jq, jv rel_path, jv search, const char *suffix, jv
jv_free(spath);
continue; /* XXX report non-strings in search path?? */
}
// Try .../module/last/component.jq
// Try ${search_dir}/${rel_path}.jq
jv testpath = jq_realpath(jv_string_fmt("%s/%s%s",
jv_string_value(spath),
jv_string_value(rel_path),
suffix));
ret = stat(jv_string_value(testpath),&st);
if (ret == -1 && errno == ENOENT) {
jv_free(testpath);
// Try .../module/last/component/component.jq
// Try ${search_dir}/$(dirname ${rel_path})/jq/main.jq
testpath = jq_realpath(jv_string_fmt("%s/%s/%s%s",
jv_string_value(spath),
jv_string_value(rel_path),
"jq/main",
suffix));
ret = stat(jv_string_value(testpath),&st);
}
if (ret == -1 && errno == ENOENT) {
jv_free(testpath);
// Try ${search_dir}/${rel_path}/$(basename ${rel_path}).jq
testpath = jq_realpath(jv_string_fmt("%s/%s/%s%s",
jv_string_value(spath),
jv_string_value(rel_path),
Expand Down

0 comments on commit 6e7cf81

Please sign in to comment.