dict: similar fixes, different files. also remove runescpy

This commit is contained in:
BurnZeZ 2016-03-01 21:24:35 -05:00
parent 2a5b2f4c76
commit c6aa11d04e
4 changed files with 17 additions and 34 deletions

View file

@ -74,22 +74,18 @@ main(int argc, char **argv)
} }
ARGBEGIN { ARGBEGIN {
case 'd': case 'd':
p = ARGF(); p = EARGF(usage());
dict = 0; dict = 0;
if(p) {
for(i=0; dicts[i].name; i++) for(i=0; dicts[i].name; i++)
if(strcmp(p, dicts[i].name)==0) { if(strcmp(p, dicts[i].name)==0) {
dict = &dicts[i]; dict = &dicts[i];
break; break;
} }
}
if(!dict) if(!dict)
usage(); usage();
break; break;
case 'c': case 'c':
line = ARGF(); line = EARGF(usage());
if(!line)
usage();
break; break;
case 'k': case 'k':
kflag++; kflag++;
@ -99,7 +95,7 @@ main(int argc, char **argv)
break; break;
default: default:
usage(); usage();
ARGEND } }ARGEND
if(dict == 0){ if(dict == 0){
err("no dictionaries present on this system"); err("no dictionaries present on this system");
exits("nodict"); exits("nodict");
@ -354,7 +350,7 @@ search(char *pat, int dofold)
prelen = getpref(pat+1, pre); prelen = getpref(pat+1, pre);
if(pat[prelen+1] == 0 || pat[prelen+1] == '$') { if(pat[prelen+1] == 0 || pat[prelen+1] == '$') {
runescpy(lit, pre); runestrcpy(lit, pre);
if(dofold) if(dofold)
fold(lit); fold(lit);
needre = 0; needre = 0;
@ -390,10 +386,8 @@ search(char *pat, int dofold)
n = 2*dot->maxn; n = 2*dot->maxn;
dot = realloc(dot, dot = realloc(dot,
sizeof(Addr)+(n-1)*sizeof(long)); sizeof(Addr)+(n-1)*sizeof(long));
if(!dot) { if(dot == nil)
err("out of memory"); sysfatal("realloc: %r");
exits("nomem");
}
dot->maxn = n; dot->maxn = n;
} }
dot->doff[dot->n++] = v; dot->doff[dot->n++] = v;
@ -609,10 +603,8 @@ getentry(int i)
n = e-b; n = e-b;
if(n+1 > anslen) { if(n+1 > anslen) {
ans.start = realloc(ans.start, n+1); ans.start = realloc(ans.start, n+1);
if(!ans.start) { if(ans.start == nil)
err("out of memory"); sysfatal("realloc: %r");
exits("nomem");
}
anslen = n+1; anslen = n+1;
} }
Bseek(bdict, b, 0); Bseek(bdict, b, 0);

View file

@ -109,7 +109,6 @@ void outchar(int);
void outchars(char *); void outchars(char *);
void outnl(int); void outnl(int);
void outpiece(char *, char *); void outpiece(char *, char *);
void runescpy(Rune*, Rune*);
long runetol(Rune*); long runetol(Rune*);
long oednextoff(long); long oednextoff(long);

View file

@ -105,7 +105,8 @@ robertindexentry(Entry e, int cmd)
if(db == 0) if(db == 0)
db = Bouvrir(dfile); db = Bouvrir(dfile);
def.start = malloc(dl+1); if((def.start = malloc(dl+1)) == nil)
sysfatal("malloc: %r");
def.end = def.start + dl; def.end = def.start + dl;
def.doff = da; def.doff = da;
Bseek(db, da, 0); Bseek(db, da, 0);
@ -116,7 +117,8 @@ robertindexentry(Entry e, int cmd)
}else{ }else{
if(eb == 0) if(eb == 0)
eb = Bouvrir(efile); eb = Bouvrir(efile);
etym.start = malloc(el+1); if((etym.start = malloc(el+1)) == nil)
sysfatal("malloc: %r");
etym.end = etym.start + el; etym.end = etym.start + el;
etym.doff = ea; etym.doff = ea;
Bseek(eb, ea, 0); Bseek(eb, ea, 0);

View file

@ -497,16 +497,6 @@ acomp(Rune *s, Rune *t)
return 2; return 2;
} }
/*
* 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 * Conversion of unsigned number to long, no overflow detection
*/ */