shithub: riscv

Download patch

ref: c6aa11d04e721aebe5cb2969166785fa37652cd7
parent: 2a5b2f4c76fe85aa37d5d99adc13f6d1f1e313e3
author: BurnZeZ <brz-9dev@feline.systems>
date: Tue Mar 1 16:24:35 EST 2016

dict: similar fixes, different files. also remove runescpy

--- a/sys/src/cmd/dict/dict.c
+++ b/sys/src/cmd/dict/dict.c
@@ -74,22 +74,18 @@
 	}
 	ARGBEGIN {
 		case 'd':
-			p = ARGF();
+			p = EARGF(usage());
 			dict = 0;
-			if(p) {
-				for(i=0; dicts[i].name; i++)
-					if(strcmp(p, dicts[i].name)==0) {
-						dict = &dicts[i];
-						break;
-					}
-			}
+			for(i=0; dicts[i].name; i++)
+				if(strcmp(p, dicts[i].name)==0) {
+					dict = &dicts[i];
+					break;
+				}
 			if(!dict)
 				usage();
 			break;
 		case 'c':
-			line = ARGF();
-			if(!line)
-				usage();
+			line = EARGF(usage());
 			break;
 		case 'k':
 			kflag++;
@@ -99,7 +95,7 @@
 			break;
 		default:
 			usage();
-	ARGEND }
+	}ARGEND
 	if(dict == 0){
 		err("no dictionaries present on this system");
 		exits("nodict");
@@ -354,7 +350,7 @@
 
 	prelen = getpref(pat+1, pre);
 	if(pat[prelen+1] == 0 || pat[prelen+1] == '$') {
-		runescpy(lit, pre);
+		runestrcpy(lit, pre);
 		if(dofold)
 			fold(lit);
 		needre = 0;
@@ -390,10 +386,8 @@
 				n = 2*dot->maxn;
 				dot = realloc(dot,
 					sizeof(Addr)+(n-1)*sizeof(long));
-				if(!dot) {
-					err("out of memory");
-					exits("nomem");
-				}
+				if(dot == nil)
+					sysfatal("realloc: %r");
 				dot->maxn = n;
 			}
 			dot->doff[dot->n++] = v;
@@ -609,10 +603,8 @@
 		n = e-b;
 		if(n+1 > anslen) {
 			ans.start = realloc(ans.start, n+1);
-			if(!ans.start) {
-				err("out of memory");
-				exits("nomem");
-			}
+			if(ans.start == nil)
+				sysfatal("realloc: %r");
 			anslen = n+1;
 		}
 		Bseek(bdict, b, 0);
--- a/sys/src/cmd/dict/dict.h
+++ b/sys/src/cmd/dict/dict.h
@@ -109,7 +109,6 @@
 void	outchars(char *);
 void	outnl(int);
 void	outpiece(char *, char *);
-void	runescpy(Rune*, Rune*);
 long	runetol(Rune*);
 
 long	oednextoff(long);
--- a/sys/src/cmd/dict/robert.c
+++ b/sys/src/cmd/dict/robert.c
@@ -105,7 +105,8 @@
 
 	if(db == 0)
 		db = Bouvrir(dfile);
-	def.start = malloc(dl+1);
+	if((def.start = malloc(dl+1)) == nil)
+		sysfatal("malloc: %r");
 	def.end = def.start + dl;
 	def.doff = da;
 	Bseek(db, da, 0);
@@ -116,7 +117,8 @@
 	}else{
 		if(eb == 0)
 			eb = Bouvrir(efile);
-		etym.start = malloc(el+1);
+		if((etym.start = malloc(el+1)) == nil)
+			sysfatal("malloc: %r");
 		etym.end = etym.start + el;
 		etym.doff = ea;
 		Bseek(eb, ea, 0);
--- a/sys/src/cmd/dict/utils.c
+++ b/sys/src/cmd/dict/utils.c
@@ -498,16 +498,6 @@
 }
 
 /*
- * Copy null terminated Runes from 'from' to 'to'.
- */
-void
-runescpy(Rune *to, Rune *from)
-{
-	while((*to++ = *from++) != 0)
-		continue;
-}
-
-/*
  * Conversion of unsigned number to long, no overflow detection
  */
 long