shithub: mc

Download patch

ref: 6d5d0ec7ee3480347255a9f469c26c8c34b2819a
parent: d29f8b95128b46048e5dbac897dc27fe70efe3c0
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jan 22 21:34:17 EST 2016

Make '.use' suffix on usefiles optional.

--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -162,7 +162,7 @@
 			;;
 		| `Local (l, lnum):
 			if !std.hassuffix(l, ".use")
-				std.fatal("{}:{}: local dependency \"{}\" should end with .use\n", path, lnum, l)
+				l = std.sljoin(l, ".use")
 			;;
 			if obj.len != 0
 				pushdep(g, l, obj)
--- a/parse/use.c
+++ b/parse/use.c
@@ -994,17 +994,34 @@
 	return 1;
 }
 
+int hassuffix(char *str, char *suff)
+{
+	size_t nstr, nsuff;
+
+	nstr = strlen(str);
+	nsuff = strlen(suff);
+	if (nstr < nsuff)
+		return 0;
+	return !strcmp(str + nstr - nsuff, suff);
+}
+
 void readuse(Node *use, Stab *st, Vis vis)
 {
 	size_t i;
 	FILE *fd;
 	char *t, *p;
+	char buf[512];
 
 	/* local (quoted) uses are always relative to the cwd */
 	fd = NULL;
 	p = NULL;
 	if (use->use.islocal) {
-		p = strdup(use->use.name);
+		if (hassuffix(use->use.name, ".use"))
+			snprintf(buf, sizeof buf, "%s", use->use.name);
+		else
+			snprintf(buf,sizeof buf, "%s.use", use->use.name);
+
+		p = strdup(buf);
 		fd = fopen(p, "r");
 		/* nonlocal (barename) uses are always searched on the include path */
 	} else {