txlyre 3 weeks ago
parent
commit
2576a90382
1 changed files with 21 additions and 5 deletions
  1. 21 5
      qic.c

+ 21 - 5
qic.c

@@ -4356,6 +4356,9 @@ int require_once(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
                  list_t *lstk, list_t *sstk, list_t *lbl, char *path) {
   char *source = NULL;
 
+  if (is_required(path))
+    return 1;
+
   for (size_t i = 0; STD[i][0]; i++) {
     if (strcmp(path, STD[i][0]) == 0) {
       source = (char *)STD[i][1];
@@ -4364,13 +4367,26 @@ int require_once(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
     }
   }
 
-  if (is_required(path))
-    return 1;
-
   if (!source) {
     FILE *fd = fopen(path, "rb");
-    if (!fd)
-      return -1;
+    if (!fd) {
+      char *qipath = getenv("QIPATH");
+      if (!qipath)
+        return -1;
+
+      char *n = strtok(qipath, ":");
+
+      while (n) {
+        char tmp[512];
+        snprintf(tmp, sizeof(tmp), "%s/%s", n, path);
+
+        fd = fopen(tmp, "rb");
+        if (fd) { path = strdup(tmp); break; } 
+      }
+
+      if (!fd)
+        return -1;
+    }
 
     buffer_t *fbuf = buffer_new();