struct stack_block *stackp;
char *stacknxt;
size_t stacknleft;
- struct stackmark *marknext;
};
struct globals_memstack {
struct stack_block *g_stackp; // = &stackbase;
- struct stackmark *markp;
char *g_stacknxt; // = stackbase.space;
char *sstrend; // = stackbase.space + MINSIZE;
size_t g_stacknleft; // = MINSIZE;
extern struct globals_memstack *const ash_ptr_to_globals_memstack;
#define G_memstack (*ash_ptr_to_globals_memstack)
#define g_stackp (G_memstack.g_stackp )
-#define markp (G_memstack.markp )
#define g_stacknxt (G_memstack.g_stacknxt )
#define sstrend (G_memstack.sstrend )
#define g_stacknleft (G_memstack.g_stacknleft)
}
static void
-setstackmark(struct stackmark *mark)
+grabstackblock(size_t len)
+{
+ len = SHELL_ALIGN(len);
+ g_stacknxt += len;
+ g_stacknleft -= len;
+}
+
+static void
+pushstackmark(struct stackmark *mark, size_t len)
{
mark->stackp = g_stackp;
mark->stacknxt = g_stacknxt;
mark->stacknleft = g_stacknleft;
- mark->marknext = markp;
- markp = mark;
+ grabstackblock(len);
+}
+
+static void
+setstackmark(struct stackmark *mark)
+{
+ pushstackmark(mark, g_stacknxt == g_stackp->space && g_stackp != &stackbase);
}
static void
return;
INT_OFF;
- markp = mark->marknext;
while (g_stackp != mark->stackp) {
sp = g_stackp;
g_stackp = sp->prev;
if (g_stacknxt == g_stackp->space && g_stackp != &stackbase) {
struct stack_block *oldstackp;
- struct stackmark *xmark;
struct stack_block *sp;
struct stack_block *prevstackp;
size_t grosslen;
g_stacknxt = sp->space;
g_stacknleft = 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 = g_stackp;
- xmark->stacknxt = g_stacknxt;
- xmark->stacknleft = g_stacknleft;
- xmark = xmark->marknext;
- }
INT_ON;
} else {
char *oldspace = g_stacknxt;
}
}
-static void
-grabstackblock(size_t len)
-{
- len = SHELL_ALIGN(len);
- g_stacknxt += len;
- g_stacknleft -= len;
-}
-
/*
* The following routines are somewhat easier to use than the above.
* The user declares a variable of type STACKSTR, which may be declared
prompt = nullstr;
}
#if ENABLE_ASH_EXPAND_PRMT
- setstackmark(&smark);
- stalloc(stackblocksize());
+ pushstackmark(&smark, stackblocksize());
#endif
putprompt(expandstr(prompt));
#if ENABLE_ASH_EXPAND_PRMT
struct stackmark smark;
INT_OFF;
- setstackmark(&smark);
- dest = expdest;
- startloc = dest - (char *)stackblock();
- grabstackstr(dest);
+ startloc = expdest - (char *)stackblock();
+ pushstackmark(&smark, startloc);
evalbackcmd(cmd, &in);
popstackmark(&smark);