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, '\\')) {
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),
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),