106 |
|
|
107 |
struct stack_block stackbase; |
struct stack_block stackbase; |
108 |
struct stack_block *stackp = &stackbase; |
struct stack_block *stackp = &stackbase; |
|
struct stackmark *markp; |
|
109 |
char *stacknxt = stackbase.space; |
char *stacknxt = stackbase.space; |
110 |
size_t stacknleft = MINSIZE; |
size_t stacknleft = MINSIZE; |
111 |
char *sstrend = stackbase.space + MINSIZE; |
char *sstrend = stackbase.space + MINSIZE; |
|
int herefd = -1; |
|
112 |
|
|
113 |
pointer |
pointer |
114 |
stalloc(size_t nbytes) |
stalloc(size_t nbytes) |
159 |
|
|
160 |
|
|
161 |
|
|
162 |
void |
void pushstackmark(struct stackmark *mark, size_t len) |
|
setstackmark(struct stackmark *mark) |
|
163 |
{ |
{ |
164 |
mark->stackp = stackp; |
mark->stackp = stackp; |
165 |
mark->stacknxt = stacknxt; |
mark->stacknxt = stacknxt; |
166 |
mark->stacknleft = stacknleft; |
mark->stacknleft = stacknleft; |
167 |
mark->marknext = markp; |
grabstackblock(len); |
168 |
markp = mark; |
} |
169 |
|
|
170 |
|
void setstackmark(struct stackmark *mark) |
171 |
|
{ |
172 |
|
pushstackmark(mark, stacknxt == stackp->space && stackp != &stackbase); |
173 |
} |
} |
174 |
|
|
175 |
|
|
179 |
struct stack_block *sp; |
struct stack_block *sp; |
180 |
|
|
181 |
INTOFF; |
INTOFF; |
|
markp = mark->marknext; |
|
182 |
while (stackp != mark->stackp) { |
while (stackp != mark->stackp) { |
183 |
sp = stackp; |
sp = stackp; |
184 |
stackp = sp->prev; |
stackp = sp->prev; |
214 |
|
|
215 |
if (stacknxt == stackp->space && stackp != &stackbase) { |
if (stacknxt == stackp->space && stackp != &stackbase) { |
216 |
struct stack_block *oldstackp; |
struct stack_block *oldstackp; |
|
struct stackmark *xmark; |
|
217 |
struct stack_block *sp; |
struct stack_block *sp; |
218 |
struct stack_block *prevstackp; |
struct stack_block *prevstackp; |
219 |
size_t grosslen; |
size_t grosslen; |
229 |
stacknxt = sp->space; |
stacknxt = sp->space; |
230 |
stacknleft = newlen; |
stacknleft = newlen; |
231 |
sstrend = sp->space + newlen; |
sstrend = sp->space + newlen; |
|
|
|
|
/* |
|
|
* Stack marks pointing to the start of the old block |
|
|
* must be relocated to point to the new block |
|
|
*/ |
|
|
xmark = markp; |
|
|
while (xmark != NULL && xmark->stackp == oldstackp) { |
|
|
xmark->stackp = stackp; |
|
|
xmark->stacknxt = stacknxt; |
|
|
xmark->stacknleft = stacknleft; |
|
|
xmark = xmark->marknext; |
|
|
} |
|
232 |
INTON; |
INTON; |
233 |
} else { |
} else { |
234 |
char *oldspace = stacknxt; |
char *oldspace = stacknxt; |
241 |
} |
} |
242 |
} |
} |
243 |
|
|
|
void |
|
|
grabstackblock(size_t len) |
|
|
{ |
|
|
len = SHELL_ALIGN(len); |
|
|
stacknxt += len; |
|
|
stacknleft -= len; |
|
|
} |
|
|
|
|
244 |
/* |
/* |
245 |
* The following routines are somewhat easier to use than the above. |
* The following routines are somewhat easier to use than the above. |
246 |
* The user declares a variable of type STACKSTR, which may be declared |
* The user declares a variable of type STACKSTR, which may be declared |
263 |
growstackstr(void) |
growstackstr(void) |
264 |
{ |
{ |
265 |
size_t len = stackblocksize(); |
size_t len = stackblocksize(); |
|
if (herefd >= 0 && len >= 1024) { |
|
|
xwrite(herefd, stackblock(), len); |
|
|
return stackblock(); |
|
|
} |
|
266 |
growstackblock(); |
growstackblock(); |
267 |
return stackblock() + len; |
return stackblock() + len; |
268 |
} |
} |