shithub: riscv

Download patch

ref: f12f773944dd15f32dbe41b016fd1df34463069b
parent: c60ba7267dbb1eb63b4ccc99031fa6142d099a11
parent: 6e74c7380f5b711e46314f3ad0e3f57e02271e46
author: cinap_lenrek <[email protected]>
date: Fri Oct 12 15:04:22 EDT 2018

merge

--- a/sys/src/libdisk/proto.c
+++ b/sys/src/libdisk/proto.c
@@ -486,9 +486,9 @@
 	level = mkaux->indent;
 	for(;;){
 		mkaux->indent = 0;
-		p = Brdline(mkaux->b, '\n');
 		mkaux->lineno++;
-		if(!p){
+		p = Brdline(mkaux->b, '\n');
+		if(p == nil || p[Blinelen(mkaux->b)-1] != '\n'){
 			mkaux->indent = -1;
 			return;
 		}
@@ -517,16 +517,18 @@
 	int c;
 
 	if(mkaux->indent < 0)
-		return 0;
+		return nil;
 loop:
 	mkaux->indent = 0;
-	p = Brdline(mkaux->b, '\n');
 	mkaux->lineno++;
-	if(!p){
+	p = Brdline(mkaux->b, '\n');
+	s = &p[Blinelen(mkaux->b)-1];
+	if(p == nil || *s != '\n'){
 		mkaux->indent = -1;
-		return 0;
+		return nil;
 	}
-	while((c = *p++) != '\n')
+	*s = 0;
+	while((c = *p++) != 0)
 		if(c == ' ')
 			mkaux->indent++;
 		else if(c == '\t')
@@ -533,22 +535,19 @@
 			mkaux->indent += 8;
 		else
 			break;
-	if(c == '\n' || c == '#')
+	if(c == 0 || c == '#')
 		goto loop;
 	p--;
 	popopt(mkaux);
-	*strchr(p, '\n') = 0;
 	if(s = strchr(p, '=')){
 		*s++ = 0;
 		setopt(mkaux, p, s);
 		goto loop;
-	}else
-		p[strlen(p)] = '\n';
+	}
 	f = emalloc(mkaux, sizeof *f);
 	p = getname(mkaux, p, &elem);
 	if(p == nil)
 		return nil;
-
 	f->new = mkpath(mkaux, old->new, elem);
 	free(elem);
 	f->elem = utfrrune(f->new, L'/') + 1;
@@ -568,7 +567,7 @@
 	f->old = getpath(mkaux, p);
 	if(f->old && strcmp(f->old, "-") == 0){
 		free(f->old);
-		f->old = 0;
+		f->old = nil;
 	}
 	setname(mkaux, &mkaux->oldfile, f);
 
@@ -584,10 +583,10 @@
 	while((c = *p) == ' ' || c == '\t')
 		p++;
 	q = p;
-	while((c = *q) != '\n' && c != ' ' && c != '\t')
+	while((c = *q) != 0 && c != ' ' && c != '\t')
 		q++;
 	if(q == p)
-		return 0;
+		return nil;
 	n = q - p;
 	new = emalloc(mkaux, n + 1);
 	memcpy(new, p, n);
@@ -605,7 +604,7 @@
 		p++;
 
 	start = p;
-	while((c = *p) != '\n' && c != ' ' && c != '\t')
+	while((c = *p) != 0 && c != ' ' && c != '\t')
 		p++;
 
 	*buf = malloc(p+2-start);	/* +2: need at least 2 bytes; might strcpy "-" into buf */
@@ -617,7 +616,7 @@
 
 	if(**buf == '$'){
 		s = getenv(*buf+1);
-		if(s == 0){
+		if(s == nil){
 			warn(mkaux, "can't read environment variable %s", *buf+1);
 			skipdir(mkaux);
 			free(*buf);