erik's patches to lift 8192 byte word size restriction
This commit is contained in:
parent
7c6c5602ad
commit
a504af8833
2 changed files with 50 additions and 23 deletions
|
@ -71,18 +71,26 @@ Xpipe(void)
|
|||
}
|
||||
}
|
||||
|
||||
enum { Wordmax = 8192, };
|
||||
char*
|
||||
erealloc(char *p, long n)
|
||||
{
|
||||
p = realloc(p, n); /* botch, should be Realloc */
|
||||
if(p==0)
|
||||
panic("Can't realloc %d bytes\n", n);
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Who should wait for the exit from the fork?
|
||||
*/
|
||||
enum { Stralloc = 100, };
|
||||
|
||||
void
|
||||
Xbackq(void)
|
||||
{
|
||||
int c, pid;
|
||||
int c, l, pid;
|
||||
int pfd[2];
|
||||
char wd[Wordmax + 1];
|
||||
char *s, *ewd = &wd[Wordmax], *stop;
|
||||
char *s, *wd, *ewd, *stop;
|
||||
struct io *f;
|
||||
var *ifs = vlook("ifs");
|
||||
word *v, *nextv;
|
||||
|
@ -108,18 +116,16 @@ Xbackq(void)
|
|||
addwaitpid(pid);
|
||||
close(pfd[PWR]);
|
||||
f = openfd(pfd[PRD]);
|
||||
s = wd;
|
||||
s = wd = ewd = 0;
|
||||
v = 0;
|
||||
/*
|
||||
* this isn't quite right for utf. stop could have utf
|
||||
* in it, and we're processing the input as bytes, not
|
||||
* utf encodings of runes. further, if we run out of
|
||||
* room in wd, we can chop in the middle of a utf encoding
|
||||
* (not to mention stepping on one of the bytes).
|
||||
* presotto's Strings seem like the right data structure here.
|
||||
*/
|
||||
while((c = rchr(f))!=EOF){
|
||||
if(strchr(stop, c) || s==ewd){
|
||||
if(s==ewd){
|
||||
l = s-wd;
|
||||
wd = erealloc(wd, l+Stralloc);
|
||||
ewd = wd+l+Stralloc-1;
|
||||
s = wd+l;
|
||||
}
|
||||
if(strchr(stop, c)){
|
||||
if(s!=wd){
|
||||
*s='\0';
|
||||
v = newword(wd, v);
|
||||
|
@ -132,6 +138,8 @@ Xbackq(void)
|
|||
*s='\0';
|
||||
v = newword(wd, v);
|
||||
}
|
||||
if(wd)
|
||||
efree(wd);
|
||||
closeio(f);
|
||||
Waitfor(pid, 0);
|
||||
/* v points to reversed arglist -- reverse it onto argv */
|
||||
|
@ -231,4 +239,4 @@ execforkexec(void)
|
|||
}
|
||||
addwaitpid(pid);
|
||||
return pid;
|
||||
}
|
||||
}
|
|
@ -51,12 +51,23 @@ Xasync(void)
|
|||
setvar("apid", newword(buf, (word *)0));
|
||||
}
|
||||
|
||||
char*
|
||||
erealloc(char *p, long n)
|
||||
{
|
||||
p = realloc(p, n); /* botch, should be Realloc */
|
||||
if(p==0)
|
||||
panic("Can't realloc %d bytes\n", n);
|
||||
return p;
|
||||
}
|
||||
|
||||
enum { Stralloc = 100, };
|
||||
|
||||
void
|
||||
Xbackq(void)
|
||||
{
|
||||
char wd[8193], **argv;
|
||||
int c;
|
||||
char *s, *ewd=&wd[8192], *stop;
|
||||
char **argv;
|
||||
int c, l;
|
||||
char *s, *wd, *ewd, *stop;
|
||||
struct io *f;
|
||||
var *ifs = vlook("ifs");
|
||||
word *v, *nextv;
|
||||
|
@ -84,14 +95,20 @@ Xbackq(void)
|
|||
}
|
||||
|
||||
f = openfd(pfd[0]);
|
||||
s = wd;
|
||||
s = wd = ewd = 0;
|
||||
v = 0;
|
||||
while((c=rchr(f))!=EOF){
|
||||
if(strchr(stop, c) || s==ewd){
|
||||
if(s==ewd){
|
||||
l = s-wd;
|
||||
wd = erealloc(wd, l+Stralloc);
|
||||
ewd = wd+l+Stralloc-1;
|
||||
s = wd+l;
|
||||
}
|
||||
if(strchr(stop, c)){
|
||||
if(s!=wd){
|
||||
*s='\0';
|
||||
v=newword(wd, v);
|
||||
s=wd;
|
||||
v = newword(wd, v);
|
||||
s = wd;
|
||||
}
|
||||
}
|
||||
else *s++=c;
|
||||
|
@ -100,6 +117,8 @@ Xbackq(void)
|
|||
*s='\0';
|
||||
v=newword(wd, v);
|
||||
}
|
||||
if(wd)
|
||||
efree(wd);
|
||||
closeio(f);
|
||||
Waitfor(pid, 1);
|
||||
/* v points to reversed arglist -- reverse it onto argv */
|
||||
|
@ -208,4 +227,4 @@ execforkexec(void)
|
|||
}
|
||||
free(argv);
|
||||
return -1;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue