summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstanley lieber <stanley.lieber@gmail.com>2011-04-04 20:22:56 +0000
committerstanley lieber <stanley.lieber@gmail.com>2011-04-04 20:22:56 +0000
commita504af8833847bf82de85c0516dafa8114079388 (patch)
tree886924a03f63cbf4bf193fba0b850ea858ccbbd7
parent7c6c5602ad9467681b2e7988e5d5eedfe7f4da5f (diff)
downloadplan9front-a504af8833847bf82de85c0516dafa8114079388.tar.xz
erik's patches to lift 8192 byte word size restriction
-rw-r--r--sys/src/cmd/rc/havefork.c38
-rw-r--r--sys/src/cmd/rc/haventfork.c35
2 files changed, 50 insertions, 23 deletions
diff --git a/sys/src/cmd/rc/havefork.c b/sys/src/cmd/rc/havefork.c
index 54d8f0925..04921c61c 100644
--- a/sys/src/cmd/rc/havefork.c
+++ b/sys/src/cmd/rc/havefork.c
@@ -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;
-}
+} \ No newline at end of file
diff --git a/sys/src/cmd/rc/haventfork.c b/sys/src/cmd/rc/haventfork.c
index a5464ba5b..914e85f8c 100644
--- a/sys/src/cmd/rc/haventfork.c
+++ b/sys/src/cmd/rc/haventfork.c
@@ -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;
-}
+} \ No newline at end of file