yin parser: CHANGE: search for imported/included data models in wrking dir

Before searching in a searchpath, try to find referenced data model in the
current working directory. It means, that working directory data models have
higher priority than data models placed inside the searchpath directory.
diff --git a/src/context.c b/src/context.c
index 834e434..d35b51c 100644
--- a/src/context.c
+++ b/src/context.c
@@ -104,25 +104,20 @@
 	DIR *dir;
 	struct dirent *file;
 	LY_MFORMAT format;
-	struct ly_module *result;
-
-	if (!ctx->models.search_path) {
-		if (revision) {
-			LY_ERR(LY_EVALID, "Unknown data model \"%s\", revision \"%s\" (search path not specified)", name, revision);
-		} else {
-			LY_ERR(LY_EVALID, "Unknown data model \"%s\" (search path not specified)", name);
-		}
-		return NULL;
-	}
+	struct ly_module *result = NULL;
+	int localsearch = 1;
 
 	len = strlen(name);
-	dir = opendir(ctx->models.search_path);
-	if (!dir) {
-		LY_ERR(LY_ESYS, "Unable to open data model search directory \"%s\" (%s).", ctx->models.search_path, strerror(errno));
-		return NULL;
-	}
 	cwd = get_current_dir_name();
-	chdir(ctx->models.search_path);
+	dir = opendir(cwd);
+	LY_VRB("Searching for \"%s\" in %s.", name, cwd);
+	if (!dir) {
+		LY_WRN("Unable to open local directory for searching referenced modules (%s)", strerror(errno));
+		/* try search directory */
+		goto searchpath;
+	}
+
+search:
 	while ((file = readdir(dir))) {
 		if (strncmp(name, file->d_name, len)) {
 			continue;
@@ -162,6 +157,25 @@
 		}
 	}
 
+searchpath:
+	if (!ctx->models.search_path) {
+		LY_WRN("No search path defined for the current context.");
+	} else if (!result && localsearch) {
+		/* search in local directory done, try context's search_path */
+		closedir(dir);
+		dir = opendir(ctx->models.search_path);
+		if (!dir) {
+			LY_ERR(LY_ESYS, "Unable to open data model search directory \"%s\" (%s).", ctx->models.search_path, strerror(errno));
+			goto cleanup;
+		}
+
+		chdir(ctx->models.search_path);
+		LY_VRB("Searching for \"%s\" in %s.", name, ctx->models.search_path);
+
+		localsearch = 0;
+		goto search;
+	}
+
 cleanup:
 	chdir(cwd);
 	free(cwd);