1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-16 14:41:02 +02:00

zsh-workers/7978

This commit is contained in:
Tanaka Akira 1999-09-22 13:08:37 +00:00
parent fa7abedb5d
commit f98b1581a4
3 changed files with 34 additions and 27 deletions

View file

@ -1412,6 +1412,27 @@ addvars(LinkList l, int export)
} }
} }
/**/
void
setunderscore(char *str)
{
if (str && *str) {
int l = strlen(str) + 1;
if (l > underscorelen || l < (underscorelen >> 2)) {
zfree(underscore, underscorelen);
underscore = (char *) zalloc(underscorelen = l);
}
strcpy(underscore, str);
underscoreused = l;
} else {
zfree(underscore, underscorelen);
underscore = (char *) zalloc(underscorelen = 32);
*underscore = '\0';
underscoreused = 1;
}
}
/**/ /**/
static void static void
execcmd(Cmd cmd, int input, int output, int how, int last1) execcmd(Cmd cmd, int input, int output, int how, int last1)
@ -1629,21 +1650,8 @@ execcmd(Cmd cmd, int input, int output, int how, int last1)
text = NULL; text = NULL;
/* Set up special parameter $_ */ /* Set up special parameter $_ */
if (args && nonempty(args)) {
char *u = (char *) getdata(lastnode(args));
if (u) { setunderscore((args && nonempty(args)) ? ((char *) getdata(lastnode(args))) : "");
int ul = strlen(u);
if (ul >= underscorelen) {
zfree(underscore, underscorelen);
underscore = (char *) zalloc(underscorelen = ul + 32);
}
strcpy(underscore, u);
} else
*underscore = '\0';
} else
*underscore = '\0';
/* Warn about "rm *" */ /* Warn about "rm *" */
if (type == SIMPLE && interact && unset(RMSTARSILENT) if (type == SIMPLE && interact && unset(RMSTARSILENT)
@ -3016,7 +3024,9 @@ void
runshfunc(List list, FuncWrap wrap, char *name) runshfunc(List list, FuncWrap wrap, char *name)
{ {
int cont; int cont;
VARARR(char, ou, underscorelen); VARARR(char, ou, underscoreused);
memcpy(ou, underscore, underscoreused);
while (wrap) { while (wrap) {
wrap->module->wrapper++; wrap->module->wrapper++;
@ -3032,9 +3042,8 @@ runshfunc(List list, FuncWrap wrap, char *name)
wrap = wrap->next; wrap = wrap->next;
} }
startparamscope(); startparamscope();
strcpy(ou, underscore);
execlist(list, 1, 0); execlist(list, 1, 0);
strcpy(underscore, ou); setunderscore(ou);
endparamscope(); endparamscope();
} }
@ -3233,7 +3242,7 @@ execrestore(void)
trapreturn = exstack->trapreturn; trapreturn = exstack->trapreturn;
noerrs = exstack->noerrs; noerrs = exstack->noerrs;
subsh_close = exstack->subsh_close; subsh_close = exstack->subsh_close;
strcpy(underscore, exstack->underscore); setunderscore(exstack->underscore);
zsfree(exstack->underscore); zsfree(exstack->underscore);
en = exstack->next; en = exstack->next;
free(exstack); free(exstack);

View file

@ -43,7 +43,7 @@ int noexitct = 0;
char *underscore; char *underscore;
/**/ /**/
int underscorelen; int underscorelen, underscoreused;
/* what level of sourcing we are at */ /* what level of sourcing we are at */
@ -625,6 +625,7 @@ setupvals(void)
wordchars = ztrdup(DEFAULT_WORDCHARS); wordchars = ztrdup(DEFAULT_WORDCHARS);
postedit = ztrdup(""); postedit = ztrdup("");
underscore = (char *) zalloc(underscorelen = 32); underscore = (char *) zalloc(underscorelen = 32);
underscoreused = 1;
*underscore = '\0'; *underscore = '\0';
zoptarg = ztrdup(""); zoptarg = ztrdup("");

View file

@ -752,14 +752,11 @@ checkmailpath(char **s)
fprintf(shout, "You have new mail.\n"); fprintf(shout, "You have new mail.\n");
fflush(shout); fflush(shout);
} else { } else {
VARARR(char, usav, underscorelen); VARARR(char, usav, underscoreused);
int sl = strlen(*s);
if (sl >= underscorelen) { memcpy(usav, underscore, underscoreused);
zfree(underscore, underscorelen);
underscore = (char *) zalloc(underscorelen = sl + 32); setunderscore(*s);
}
strcpy(underscore, *s);
HEAPALLOC { HEAPALLOC {
u = dupstring(u); u = dupstring(u);
if (! parsestr(u)) { if (! parsestr(u)) {
@ -769,7 +766,7 @@ checkmailpath(char **s)
fflush(shout); fflush(shout);
} }
} LASTALLOC; } LASTALLOC;
strcpy(underscore, usav); setunderscore(usav);
} }
} }
if (isset(MAILWARNING) && st.st_atime > st.st_mtime && if (isset(MAILWARNING) && st.st_atime > st.st_mtime &&