shithub: mc

Download patch

ref: de0f5a18ec216eea6efb58c84ebcb9cfbb5f782c
parent: bc05485833aa6d18041678cdc2510cc827957f41
author: Ori Bernstein <[email protected]>
date: Thu Apr 23 16:57:05 EDT 2015

Give more useful error on failing to find matching pkg.

    It used to be that to find the matching use package, you had
    to poke around in a debugger with trial and error.

--- a/muse/muse.c
+++ b/muse/muse.c
@@ -42,7 +42,7 @@
     f = fopen(path, "r");
     if (!f)
         die("Couldn't open %s\n", path);
-    loaduse(f, st, Visexport);
+    loaduse(path, f, st, Visexport);
     fclose(f);
 }
 
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -571,7 +571,7 @@
 Node *genericname(Node *n, Type *t);
 
 /* usefiles */
-int  loaduse(FILE *f, Stab *into, Vis vis);
+int  loaduse(char *path, FILE *f, Stab *into, Vis vis);
 void readuse(Node *use, Stab *into, Vis vis);
 void writeuse(FILE *fd, Node *file);
 void tagexports(Stab *st, int hidelocal);
--- a/parse/use.c
+++ b/parse/use.c
@@ -803,7 +803,7 @@
  *     D<picled-decl>
  *     G<pickled-decl><pickled-initializer>
  */
-int loaduse(FILE *f, Stab *st, Vis vis)
+int loaduse(char *path, FILE *f, Stab *st, Vis vis)
 {
     intptr_t tid;
     size_t i;
@@ -842,7 +842,7 @@
         }
     }
     if (!s) {
-        printf("could not find matching package for merge: %s\n", st->name);
+        printf("could not find matching package for merge: %s in %s\n", st->name, path);
         exit(1);
     }
     tidmap = mkht(ptrhash, ptreq);
@@ -919,21 +919,21 @@
 {
     size_t i;
     FILE *fd;
-    char *p, *q;
+    char *t, *p;
 
     /* local (quoted) uses are always relative to the cwd */
     fd = NULL;
     if (use->use.islocal) {
-        fd = fopen(use->use.name, "r");
+        p = strdup(use->use.name);
+        fd = fopen(p, "r");
     /* nonlocal (barename) uses are always searched on the include path */
     } else {
         for (i = 0; i < nincpaths; i++) {
-            p = strjoin(incpaths[i], "/");
-            q = strjoin(p, use->use.name);
-            fd = fopen(q, "r");
+            t = strjoin(incpaths[i], "/");
+            p = strjoin(t, use->use.name);
+            fd = fopen(p, "r");
             if (fd) {
-                free(p);
-                free(q);
+                free(t);
                 break;
             }
         }
@@ -941,8 +941,9 @@
     if (!fd)
         fatal(use, "Could not open %s", use->use.name);
 
-    if (!loaduse(fd, st, vis))
-        die("Could not load usefile %s", use->use.name);
+    if (!loaduse(p, fd, st, vis))
+        die("Could not load usefile %s from %s", use->use.name);
+    free(p);
 }
 
 /* Usefile format: