• syn.c: replace expanded use of str_save() with the actual macro
• others: fix 6 (!) cases of non-constant or side-effect arguments to the str_save() or str_nsave() macros, and other abuse of them • also fix some cosmetics and other un-nice code while here
This commit is contained in:
parent
9eae0851ef
commit
0b4f34e0a8
10
eval.c
10
eval.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.46 2008/05/17 18:46:58 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.47 2008/07/12 16:56:38 tg Exp $");
|
||||||
|
|
||||||
#ifdef MKSH_SMALL
|
#ifdef MKSH_SMALL
|
||||||
#define MKSH_NOPWNAM
|
#define MKSH_NOPWNAM
|
||||||
@ -425,7 +425,8 @@ expand(const char *cp, /* input word */
|
|||||||
goto no_repl;
|
goto no_repl;
|
||||||
|
|
||||||
/* prepare string on which to work */
|
/* prepare string on which to work */
|
||||||
sbeg = s = str_save(str_val(st->var), ATEMP);
|
tpat0 = str_val(st->var);
|
||||||
|
sbeg = s = str_save(tpat0, ATEMP);
|
||||||
|
|
||||||
/* first see if we have any match at all */
|
/* first see if we have any match at all */
|
||||||
tpat0 = pat;
|
tpat0 = pat;
|
||||||
@ -769,10 +770,7 @@ expand(const char *cp, /* input word */
|
|||||||
Xlength(ds, dp) == 0) {
|
Xlength(ds, dp) == 0) {
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if ((p = str_nsave(null, 0, ATEMP))
|
*(p = alloc(1, ATEMP)) = '\0';
|
||||||
== NULL)
|
|
||||||
internal_errorf("unable "
|
|
||||||
"to allocate memory");
|
|
||||||
XPput(*wp, p);
|
XPput(*wp, p);
|
||||||
}
|
}
|
||||||
type = XSUBMID;
|
type = XSUBMID;
|
||||||
|
7
expr.c
7
expr.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.17 2008/04/20 00:24:25 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.18 2008/07/12 16:56:38 tg Exp $");
|
||||||
|
|
||||||
/* The order of these enums is constrained by the order of opinfo[] */
|
/* The order of these enums is constrained by the order of opinfo[] */
|
||||||
enum token {
|
enum token {
|
||||||
@ -480,9 +480,12 @@ exprtoken(Expr_state *es)
|
|||||||
tvar = str_nsave(es->tokp, cp - es->tokp, ATEMP);
|
tvar = str_nsave(es->tokp, cp - es->tokp, ATEMP);
|
||||||
goto process_tvar;
|
goto process_tvar;
|
||||||
} else if (ksh_isdigit(c)) {
|
} else if (ksh_isdigit(c)) {
|
||||||
|
int i;
|
||||||
|
|
||||||
while (c != '_' && (ksh_isalnux(c) || c == '#'))
|
while (c != '_' && (ksh_isalnux(c) || c == '#'))
|
||||||
c = *cp++;
|
c = *cp++;
|
||||||
tvar = str_nsave(es->tokp, --cp - es->tokp, ATEMP);
|
i = --cp - es->tokp;
|
||||||
|
tvar = str_nsave(es->tokp, i, ATEMP);
|
||||||
process_tvar:
|
process_tvar:
|
||||||
es->val = tempvar();
|
es->val = tempvar();
|
||||||
es->val->flag &= ~INTEGER;
|
es->val->flag &= ~INTEGER;
|
||||||
|
11
funcs.c
11
funcs.c
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.83 2008/06/08 17:16:25 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.84 2008/07/12 16:56:39 tg Exp $");
|
||||||
|
|
||||||
/* A leading = means assignments before command are kept;
|
/* A leading = means assignments before command are kept;
|
||||||
* a leading * means a POSIX special builtin;
|
* a leading * means a POSIX special builtin;
|
||||||
@ -1074,8 +1074,10 @@ c_alias(const char **wp)
|
|||||||
struct tbl *ap;
|
struct tbl *ap;
|
||||||
int h;
|
int h;
|
||||||
|
|
||||||
if ((val = cstrchr(alias, '=')))
|
if ((val = cstrchr(alias, '='))) {
|
||||||
alias = xalias = str_nsave(alias, val++ - alias, ATEMP);
|
h = val++ - alias;
|
||||||
|
alias = xalias = str_nsave(alias, h, ATEMP);
|
||||||
|
}
|
||||||
h = hash(alias);
|
h = hash(alias);
|
||||||
if (val == NULL && !tflag && !xflag) {
|
if (val == NULL && !tflag && !xflag) {
|
||||||
ap = ktsearch(t, alias, h);
|
ap = ktsearch(t, alias, h);
|
||||||
@ -1103,8 +1105,7 @@ c_alias(const char **wp)
|
|||||||
afree((void*)ap->val.s, APERM);
|
afree((void*)ap->val.s, APERM);
|
||||||
}
|
}
|
||||||
/* ignore values for -t (at&t ksh does this) */
|
/* ignore values for -t (at&t ksh does this) */
|
||||||
newval = tflag ? search(alias, path, X_OK, NULL) :
|
newval = tflag ? search(alias, path, X_OK, NULL) : val;
|
||||||
val;
|
|
||||||
if (newval) {
|
if (newval) {
|
||||||
ap->val.s = str_save(newval, APERM);
|
ap->val.s = str_save(newval, APERM);
|
||||||
ap->flag |= ALLOC|ISSET;
|
ap->flag |= ALLOC|ISSET;
|
||||||
|
21
histrap.c
21
histrap.c
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.65 2008/07/06 22:41:08 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.66 2008/07/12 16:56:39 tg Exp $");
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* MirOS: This is the default mapping type, and need not be specified.
|
* MirOS: This is the default mapping type, and need not be specified.
|
||||||
@ -21,7 +21,7 @@ static int hist_count_lines(unsigned char *, int);
|
|||||||
static int hist_shrink(unsigned char *, int);
|
static int hist_shrink(unsigned char *, int);
|
||||||
static unsigned char *hist_skip_back(unsigned char *,int *,int);
|
static unsigned char *hist_skip_back(unsigned char *,int *,int);
|
||||||
static void histload(Source *, unsigned char *, int);
|
static void histload(Source *, unsigned char *, int);
|
||||||
static void histinsert(Source *, int, unsigned char *);
|
static void histinsert(Source *, int, const char *);
|
||||||
static void writehistfile(int, char *);
|
static void writehistfile(int, char *);
|
||||||
static int sprinkle(int);
|
static int sprinkle(int);
|
||||||
#endif
|
#endif
|
||||||
@ -68,7 +68,8 @@ c_fc(const char **wp)
|
|||||||
sflag++;
|
sflag++;
|
||||||
else {
|
else {
|
||||||
size_t len = strlen(p);
|
size_t len = strlen(p);
|
||||||
editor = str_nsave(p, len + 4, ATEMP);
|
editor = alloc(len + 4, ATEMP);
|
||||||
|
memcpy(editor, p, len);
|
||||||
memcpy(editor + len, " $_", 4);
|
memcpy(editor + len, " $_", 4);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -639,8 +640,7 @@ hist_init(Source *s)
|
|||||||
hist_source = s;
|
hist_source = s;
|
||||||
|
|
||||||
#if HAVE_PERSISTENT_HISTORY
|
#if HAVE_PERSISTENT_HISTORY
|
||||||
hname = str_val(global("HISTFILE"));
|
if ((hname = str_val(global("HISTFILE"))) == NULL)
|
||||||
if (hname == NULL)
|
|
||||||
return;
|
return;
|
||||||
hname = str_save(hname, APERM);
|
hname = str_save(hname, APERM);
|
||||||
|
|
||||||
@ -855,7 +855,7 @@ histload(Source *s, unsigned char *base, int bytes)
|
|||||||
/* worry about line numbers */
|
/* worry about line numbers */
|
||||||
if (histptr >= history && lno-1 != s->line) {
|
if (histptr >= history && lno-1 != s->line) {
|
||||||
/* a replacement ? */
|
/* a replacement ? */
|
||||||
histinsert(s, lno, line);
|
histinsert(s, lno, (char *)line);
|
||||||
} else {
|
} else {
|
||||||
s->line = lno;
|
s->line = lno;
|
||||||
histsave(lno, (char *)line, 0);
|
histsave(lno, (char *)line, 0);
|
||||||
@ -870,7 +870,7 @@ histload(Source *s, unsigned char *base, int bytes)
|
|||||||
* Insert a line into the history at a specified number
|
* Insert a line into the history at a specified number
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
histinsert(Source *s, int lno, unsigned char *line)
|
histinsert(Source *s, int lno, const char *line)
|
||||||
{
|
{
|
||||||
char **hp;
|
char **hp;
|
||||||
|
|
||||||
@ -878,7 +878,7 @@ histinsert(Source *s, int lno, unsigned char *line)
|
|||||||
hp = &histptr[lno - s->line];
|
hp = &histptr[lno - s->line];
|
||||||
if (*hp)
|
if (*hp)
|
||||||
afree((void*)*hp, APERM);
|
afree((void*)*hp, APERM);
|
||||||
*hp = str_save((char *)line, APERM);
|
*hp = str_save(line, APERM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1005,9 +1005,8 @@ inittraps(void)
|
|||||||
else {
|
else {
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
sigtraps[i].name = s = str_save(
|
s = !strncasecmp(cs, "SIG", 3) ? cs + 3 : cs;
|
||||||
!strncasecmp(cs, "SIG", 3) ? cs + 3 : cs,
|
sigtraps[i].name = s = str_save(s, APERM);
|
||||||
APERM);
|
|
||||||
while ((*s = ksh_toupper(*s)))
|
while ((*s = ksh_toupper(*s)))
|
||||||
++s;
|
++s;
|
||||||
}
|
}
|
||||||
|
9
lex.c
9
lex.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.65 2008/07/09 21:32:43 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.66 2008/07/12 16:56:39 tg Exp $");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* states while lexing word
|
* states while lexing word
|
||||||
@ -1290,9 +1290,10 @@ set_prompt(int to, Source *s)
|
|||||||
* unwinding its stack through this code as it
|
* unwinding its stack through this code as it
|
||||||
* exits.
|
* exits.
|
||||||
*/
|
*/
|
||||||
} else
|
} else {
|
||||||
prompt = str_save(substitute(ps1, 0),
|
char *cp = substitute(ps1, 0);
|
||||||
saved_atemp);
|
prompt = str_save(cp, saved_atemp);
|
||||||
|
}
|
||||||
quitenv(NULL);
|
quitenv(NULL);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
4
syn.c
4
syn.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.22 2008/06/28 22:51:56 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.23 2008/07/12 16:56:40 tg Exp $");
|
||||||
|
|
||||||
struct nesting_state {
|
struct nesting_state {
|
||||||
int start_token; /* token than began nesting (eg, FOR) */
|
int start_token; /* token than began nesting (eg, FOR) */
|
||||||
@ -366,7 +366,7 @@ get_command(int cf)
|
|||||||
if (!is_wdvarname(yylval.cp, true))
|
if (!is_wdvarname(yylval.cp, true))
|
||||||
yyerror("%s: bad identifier\n",
|
yyerror("%s: bad identifier\n",
|
||||||
c == FOR ? "for" : "select");
|
c == FOR ? "for" : "select");
|
||||||
t->str = str_nsave(ident, strlen(ident), ATEMP);
|
t->str = str_save(ident, ATEMP);
|
||||||
nesting_push(&old_nesting, c);
|
nesting_push(&old_nesting, c);
|
||||||
t->vars = wordlist();
|
t->vars = wordlist();
|
||||||
t->left = dogroup();
|
t->left = dogroup();
|
||||||
|
9
var.c
9
var.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.56 2008/05/17 18:47:03 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.57 2008/07/12 16:56:40 tg Exp $");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Variables
|
* Variables
|
||||||
@ -642,9 +642,10 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
|
|||||||
}
|
}
|
||||||
val += len;
|
val += len;
|
||||||
}
|
}
|
||||||
if (*val == '=')
|
if (*val == '=') {
|
||||||
tvar = str_nsave(var, val++ - var, ATEMP);
|
int i = val++ - var;
|
||||||
else {
|
tvar = str_nsave(var, i, ATEMP);
|
||||||
|
} else {
|
||||||
/* Importing from original environment: must have an = */
|
/* Importing from original environment: must have an = */
|
||||||
if (set & IMPORT)
|
if (set & IMPORT)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user