git: 9front

Download patch

ref: 6d7126135bff49361775257213aa7a45589a9da6
parent: 153048d2541174ecc17162363038361a7218e9b9
author: Jacob Moody <moody@posixcafe.org>
date: Sun Sep 29 14:35:30 EDT 2024

look: fix case sensitivity when using base > 10

Old attempt at this did not make any sense.
Also fix the reference to look in ascii(1) to be more correct.

--- a/sys/man/1/ascii
+++ b/sys/man/1/ascii
@@ -35,6 +35,10 @@
 .I characters
 .PP
 .B look
+.B -t
+.I ';'
+.B -b
+.I 16
 .I hex
 .B /lib/ucd/UnicodeData.txt
 .SH DESCRIPTION
--- a/sys/src/cmd/look.c
+++ b/sys/src/cmd/look.c
@@ -16,7 +16,6 @@
 #define	tolower(r)	((r)-'A'+'a')
 
 #define	sgn(v)		((v) < 0 ? -1 : ((v) > 0 ? 1 : 0))
-#define	notcase(v)	(v != L'a'-L'A' && v != L'A'-L'a')
 
 #define	WORDSIZ	4000
 char	*filename = "/lib/words";
@@ -86,6 +85,8 @@
 	ARGBEGIN{
 	case 'b':
 		base = atoi(EARGF(usage()));
+		if(base > 10)
+			fold++;
 		compare = ncomp;
 		break;
 	case 'd':
@@ -305,7 +306,7 @@
 	a = 0;
 	if(ssgn == tsgn)
 		while(it>t && is>s)
-			if((b = *--it - *--is) && notcase(b))
+			if(b = *--it - *--is)
 				a = b;
 	while(is > s)
 		if(*--is != '0')
@@ -321,7 +322,7 @@
 		t++;
 	if(ssgn == tsgn)
 		while(isdigit(*s) && isdigit(*t))
-			if((a = *t++ - *s++) && notcase(a))
+			if(a = *t++ - *s++)
 				return sgn(a)*ssgn;
 	while(isdigit(*s))
 		if(*s++ != '0')
@@ -361,8 +362,6 @@
 		v = r - L'0';
 	else if(L'a'<=r && r<=L'z')
 		v = r - L'a' + 10;
-	else if(L'A'<=r && r<=L'Z')
-		v = r - L'A' + 10;
 	if(v < base)
 		return 1;
 	return 0;
--