2012-02-20 00:53:59 +00:00
|
|
|
/* $Header: /p/tcsh/cvsroot/tcsh/sh.set.c,v 3.83 2012/01/15 17:15:28 christos Exp $ */
|
2000-04-15 04:41:27 +00:00
|
|
|
/*
|
|
|
|
* sh.set.c: Setting and Clearing of variables
|
|
|
|
*/
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1980, 1991 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2002-07-24 16:23:10 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2000-04-15 04:41:27 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
#include "sh.h"
|
|
|
|
|
2012-02-20 00:53:59 +00:00
|
|
|
RCSID("$tcsh: sh.set.c,v 3.83 2012/01/15 17:15:28 christos Exp $")
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
#include "ed.h"
|
|
|
|
#include "tw.h"
|
|
|
|
|
2005-04-24 19:41:08 +00:00
|
|
|
#ifdef HAVE_NL_LANGINFO
|
|
|
|
#include <langinfo.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern int GotTermCaps;
|
2004-07-11 02:17:56 +00:00
|
|
|
int numeof = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
static void update_vars (Char *);
|
|
|
|
static Char *getinx (Char *, int *);
|
|
|
|
static void asx (Char *, int, Char *);
|
|
|
|
static struct varent *getvx (Char *, int);
|
|
|
|
static Char *xset (Char *, Char ***);
|
|
|
|
static Char *operate (int, Char *, Char *);
|
2012-02-20 00:53:59 +00:00
|
|
|
static void putn1 (tcsh_number_t);
|
2007-03-11 22:33:41 +00:00
|
|
|
static struct varent *madrof (Char *, struct varent *);
|
|
|
|
static void unsetv1 (struct varent *);
|
|
|
|
static void exportpath (Char **);
|
|
|
|
static void balance (struct varent *, int, int);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* C Shell
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
update_vars(Char *vp)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
if (eq(vp, STRpath)) {
|
2007-03-11 22:33:41 +00:00
|
|
|
struct varent *p = adrof(STRpath);
|
|
|
|
if (p == NULL)
|
|
|
|
stderror(ERR_NAME | ERR_UNDVAR);
|
|
|
|
else {
|
|
|
|
exportpath(p->vec);
|
|
|
|
dohash(NULL, NULL);
|
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
else if (eq(vp, STRhistchars)) {
|
2005-04-24 19:41:08 +00:00
|
|
|
Char *pn = varval(vp);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
HIST = *pn++;
|
2012-02-20 00:53:59 +00:00
|
|
|
if (HIST)
|
|
|
|
HISTSUB = *pn;
|
|
|
|
else
|
|
|
|
HISTSUB = HIST;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
else if (eq(vp, STRpromptchars)) {
|
2005-04-24 19:41:08 +00:00
|
|
|
Char *pn = varval(vp);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
PRCH = *pn++;
|
2012-02-20 00:53:59 +00:00
|
|
|
if (PRCH)
|
|
|
|
PRCHROOT = *pn;
|
|
|
|
else
|
|
|
|
PRCHROOT = PRCH;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
else if (eq(vp, STRhistlit)) {
|
|
|
|
HistLit = 1;
|
|
|
|
}
|
|
|
|
else if (eq(vp, STRuser)) {
|
|
|
|
tsetenv(STRKUSER, varval(vp));
|
|
|
|
tsetenv(STRLOGNAME, varval(vp));
|
|
|
|
}
|
|
|
|
else if (eq(vp, STRgroup)) {
|
|
|
|
tsetenv(STRKGROUP, varval(vp));
|
|
|
|
}
|
|
|
|
else if (eq(vp, STRwordchars)) {
|
|
|
|
word_chars = varval(vp);
|
|
|
|
}
|
|
|
|
else if (eq(vp, STRloginsh)) {
|
|
|
|
loginsh = 1;
|
|
|
|
}
|
2012-02-20 00:53:59 +00:00
|
|
|
else if (eq(vp, STRanyerror)) {
|
|
|
|
anyerror = 1;
|
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
else if (eq(vp, STRsymlinks)) {
|
2005-04-24 19:41:08 +00:00
|
|
|
Char *pn = varval(vp);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (eq(pn, STRignore))
|
|
|
|
symlinks = SYM_IGNORE;
|
|
|
|
else if (eq(pn, STRexpand))
|
|
|
|
symlinks = SYM_EXPAND;
|
|
|
|
else if (eq(pn, STRchase))
|
|
|
|
symlinks = SYM_CHASE;
|
|
|
|
else
|
|
|
|
symlinks = 0;
|
|
|
|
}
|
|
|
|
else if (eq(vp, STRterm)) {
|
|
|
|
Char *cp = varval(vp);
|
|
|
|
tsetenv(STRKTERM, cp);
|
|
|
|
#ifdef DOESNT_WORK_RIGHT
|
|
|
|
cp = getenv("TERMCAP");
|
|
|
|
if (cp && (*cp != '/')) /* if TERMCAP and not a path */
|
|
|
|
Unsetenv(STRTERMCAP);
|
|
|
|
#endif /* DOESNT_WORK_RIGHT */
|
|
|
|
GotTermCaps = 0;
|
|
|
|
if (noediting && Strcmp(cp, STRnetwork) != 0 &&
|
|
|
|
Strcmp(cp, STRunknown) != 0 && Strcmp(cp, STRdumb) != 0) {
|
|
|
|
editing = 1;
|
|
|
|
noediting = 0;
|
2007-03-11 22:33:41 +00:00
|
|
|
setNS(STRedit);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
ed_Init(); /* reset the editor */
|
|
|
|
}
|
|
|
|
else if (eq(vp, STRhome)) {
|
2007-03-11 22:33:41 +00:00
|
|
|
Char *cp, *canon;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
cp = Strsave(varval(vp)); /* get the old value back */
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_push(cp, xfree);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* convert to cononical pathname (possibly resolving symlinks)
|
|
|
|
*/
|
2007-03-11 22:33:41 +00:00
|
|
|
canon = dcanon(cp, cp);
|
|
|
|
cleanup_ignore(cp);
|
|
|
|
cleanup_until(cp);
|
|
|
|
cleanup_push(canon, xfree);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
setcopy(vp, canon, VAR_READWRITE); /* have to save the new val */
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
/* and now mirror home with HOME */
|
2007-03-11 22:33:41 +00:00
|
|
|
tsetenv(STRKHOME, canon);
|
2000-04-15 04:41:27 +00:00
|
|
|
/* fix directory stack for new tilde home */
|
|
|
|
dtilde();
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(canon);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
else if (eq(vp, STRedit)) {
|
|
|
|
editing = 1;
|
|
|
|
noediting = 0;
|
|
|
|
/* PWP: add more stuff in here later */
|
|
|
|
}
|
|
|
|
else if (eq(vp, STRshlvl)) {
|
|
|
|
tsetenv(STRKSHLVL, varval(vp));
|
|
|
|
}
|
2004-07-11 02:17:56 +00:00
|
|
|
else if (eq(vp, STRignoreeof)) {
|
|
|
|
Char *cp;
|
|
|
|
numeof = 0;
|
|
|
|
for ((cp = varval(STRignoreeof)); cp && *cp; cp++) {
|
|
|
|
if (!Isdigit(*cp)) {
|
|
|
|
numeof = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
numeof = numeof * 10 + *cp - '0';
|
|
|
|
}
|
|
|
|
if (numeof <= 0) numeof = 26; /* Sanity check */
|
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
else if (eq(vp, STRbackslash_quote)) {
|
|
|
|
bslash_quote = 1;
|
|
|
|
}
|
2009-07-10 21:47:20 +00:00
|
|
|
else if (eq(vp, STRcompat_expr)) {
|
|
|
|
compat_expr = 1;
|
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
else if (eq(vp, STRdirstack)) {
|
|
|
|
dsetstack();
|
|
|
|
}
|
|
|
|
else if (eq(vp, STRrecognize_only_executables)) {
|
|
|
|
tw_cmd_free();
|
|
|
|
}
|
2001-09-05 17:49:32 +00:00
|
|
|
else if (eq(vp, STRkillring)) {
|
2012-02-20 00:53:59 +00:00
|
|
|
SetKillRing((int)getn(varval(vp)));
|
2001-09-05 17:49:32 +00:00
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
#ifndef HAVENOUTMP
|
|
|
|
else if (eq(vp, STRwatch)) {
|
|
|
|
resetwatch();
|
|
|
|
}
|
|
|
|
#endif /* HAVENOUTMP */
|
|
|
|
else if (eq(vp, STRimplicitcd)) {
|
|
|
|
implicit_cd = ((eq(varval(vp), STRverbose)) ? 2 : 1);
|
|
|
|
}
|
|
|
|
#ifdef COLOR_LS_F
|
|
|
|
else if (eq(vp, STRcolor)) {
|
|
|
|
set_color_context();
|
|
|
|
}
|
|
|
|
#endif /* COLOR_LS_F */
|
|
|
|
#if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
|
|
|
|
else if(eq(vp, CHECK_MBYTEVAR) || eq(vp, STRnokanji)) {
|
|
|
|
update_dspmbyte_vars();
|
|
|
|
}
|
|
|
|
#endif
|
2000-11-30 21:05:33 +00:00
|
|
|
#ifdef NLS_CATALOGS
|
|
|
|
else if (eq(vp, STRcatalog)) {
|
2005-04-24 19:41:08 +00:00
|
|
|
nlsclose();
|
2000-11-30 21:05:33 +00:00
|
|
|
nlsinit();
|
|
|
|
}
|
2002-07-24 16:23:10 +00:00
|
|
|
#if defined(FILEC) && defined(TIOCSTI)
|
|
|
|
else if (eq(vp, STRfilec))
|
|
|
|
filec = 1;
|
|
|
|
#endif
|
2000-11-30 21:05:33 +00:00
|
|
|
#endif /* NLS_CATALOGS */
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
doset(Char **v, struct command *c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
Char *p;
|
2012-02-20 00:53:59 +00:00
|
|
|
Char *vp;
|
2000-04-15 04:41:27 +00:00
|
|
|
Char **vecp;
|
2005-04-24 19:41:08 +00:00
|
|
|
int hadsub;
|
2000-04-15 04:41:27 +00:00
|
|
|
int subscr;
|
|
|
|
int flags = VAR_READWRITE;
|
2005-04-24 19:41:08 +00:00
|
|
|
int first_match = 0;
|
|
|
|
int last_match = 0;
|
|
|
|
int changed = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(c);
|
|
|
|
v++;
|
|
|
|
do {
|
|
|
|
changed = 0;
|
|
|
|
/*
|
|
|
|
* Readonly addition From: Tim P. Starrin <noid@cyborg.larc.nasa.gov>
|
|
|
|
*/
|
|
|
|
if (*v && eq(*v, STRmr)) {
|
|
|
|
flags = VAR_READONLY;
|
|
|
|
v++;
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
if (*v && eq(*v, STRmf) && !last_match) {
|
|
|
|
first_match = 1;
|
|
|
|
v++;
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
if (*v && eq(*v, STRml) && !first_match) {
|
|
|
|
last_match = 1;
|
|
|
|
v++;
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
} while(changed);
|
|
|
|
p = *v++;
|
|
|
|
if (p == 0) {
|
|
|
|
plist(&shvhed, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
hadsub = 0;
|
|
|
|
vp = p;
|
2012-02-20 00:53:59 +00:00
|
|
|
if (!letter(*p))
|
2000-04-15 04:41:27 +00:00
|
|
|
stderror(ERR_NAME | ERR_VARBEGIN);
|
2012-02-20 00:53:59 +00:00
|
|
|
do {
|
|
|
|
p++;
|
|
|
|
} while (alnum(*p));
|
2000-04-15 04:41:27 +00:00
|
|
|
if (*p == '[') {
|
|
|
|
hadsub++;
|
|
|
|
p = getinx(p, &subscr);
|
|
|
|
}
|
2012-02-20 00:53:59 +00:00
|
|
|
if (*p != '\0' && *p != '=')
|
|
|
|
stderror(ERR_NAME | ERR_VARALNUM);
|
|
|
|
if (*p == '=') {
|
|
|
|
*p++ = '\0';
|
|
|
|
if (*p == '\0' && *v != NULL && **v == '(')
|
2000-04-15 04:41:27 +00:00
|
|
|
p = *v++;
|
|
|
|
}
|
|
|
|
else if (*v && eq(*v, STRequal)) {
|
2012-02-20 00:53:59 +00:00
|
|
|
if (*++v != NULL)
|
2000-04-15 04:41:27 +00:00
|
|
|
p = *v++;
|
|
|
|
}
|
|
|
|
if (eq(p, STRLparen)) {
|
2005-04-24 19:41:08 +00:00
|
|
|
Char **e = v;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (hadsub)
|
|
|
|
stderror(ERR_NAME | ERR_SYNTAX);
|
|
|
|
for (;;) {
|
|
|
|
if (!*e)
|
|
|
|
stderror(ERR_NAME | ERR_MISSING, ')');
|
|
|
|
if (**e == ')')
|
|
|
|
break;
|
|
|
|
e++;
|
|
|
|
}
|
|
|
|
p = *e;
|
|
|
|
*e = 0;
|
|
|
|
vecp = saveblk(v);
|
|
|
|
if (first_match)
|
|
|
|
flags |= VAR_FIRST;
|
|
|
|
else if (last_match)
|
|
|
|
flags |= VAR_LAST;
|
|
|
|
|
|
|
|
set1(vp, vecp, &shvhed, flags);
|
|
|
|
*e = p;
|
|
|
|
v = e + 1;
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
else if (hadsub) {
|
|
|
|
Char *copy;
|
|
|
|
|
|
|
|
copy = Strsave(p);
|
|
|
|
cleanup_push(copy, xfree);
|
|
|
|
asx(vp, subscr, copy);
|
|
|
|
cleanup_ignore(copy);
|
|
|
|
cleanup_until(copy);
|
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
else
|
2007-03-11 22:33:41 +00:00
|
|
|
setv(vp, Strsave(p), flags);
|
2000-04-15 04:41:27 +00:00
|
|
|
update_vars(vp);
|
|
|
|
} while ((p = *v++) != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Char *
|
2007-03-11 22:33:41 +00:00
|
|
|
getinx(Char *cp, int *ip)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
*ip = 0;
|
|
|
|
*cp++ = 0;
|
|
|
|
while (*cp && Isdigit(*cp))
|
|
|
|
*ip = *ip * 10 + *cp++ - '0';
|
|
|
|
if (*cp++ != ']')
|
|
|
|
stderror(ERR_NAME | ERR_SUBSCRIPT);
|
|
|
|
return (cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
asx(Char *vp, int subscr, Char *p)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct varent *v = getvx(vp, subscr);
|
2007-03-11 22:33:41 +00:00
|
|
|
Char *prev;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (v->v_flags & VAR_READONLY)
|
|
|
|
stderror(ERR_READONLY|ERR_NAME, v->v_name);
|
2007-03-11 22:33:41 +00:00
|
|
|
prev = v->vec[subscr - 1];
|
|
|
|
cleanup_push(prev, xfree);
|
2000-04-15 04:41:27 +00:00
|
|
|
v->vec[subscr - 1] = globone(p, G_APPEND);
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(prev);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct varent *
|
2007-03-11 22:33:41 +00:00
|
|
|
getvx(Char *vp, int subscr)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct varent *v = adrof(vp);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (v == 0)
|
|
|
|
udvar(vp);
|
|
|
|
if (subscr < 1 || subscr > blklen(v->vec))
|
|
|
|
stderror(ERR_NAME | ERR_RANGE);
|
|
|
|
return (v);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
dolet(Char **v, struct command *dummy)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
Char *p;
|
2000-04-15 04:41:27 +00:00
|
|
|
Char *vp, c, op;
|
2005-04-24 19:41:08 +00:00
|
|
|
int hadsub;
|
2000-04-15 04:41:27 +00:00
|
|
|
int subscr;
|
|
|
|
|
|
|
|
USE(dummy);
|
|
|
|
v++;
|
|
|
|
p = *v++;
|
|
|
|
if (p == 0) {
|
|
|
|
prvars();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
hadsub = 0;
|
|
|
|
vp = p;
|
|
|
|
if (letter(*p))
|
|
|
|
for (; alnum(*p); p++)
|
|
|
|
continue;
|
|
|
|
if (vp == p || !letter(*vp))
|
|
|
|
stderror(ERR_NAME | ERR_VARBEGIN);
|
|
|
|
if (*p == '[') {
|
|
|
|
hadsub++;
|
|
|
|
p = getinx(p, &subscr);
|
|
|
|
}
|
|
|
|
if (*p == 0 && *v)
|
|
|
|
p = *v++;
|
|
|
|
if ((op = *p) != 0)
|
|
|
|
*p++ = 0;
|
|
|
|
else
|
|
|
|
stderror(ERR_NAME | ERR_ASSIGN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if there is no expression after the '=' then print a "Syntax Error"
|
|
|
|
* message - strike
|
|
|
|
*/
|
|
|
|
if (*p == '\0' && *v == NULL)
|
|
|
|
stderror(ERR_NAME | ERR_ASSIGN);
|
|
|
|
|
|
|
|
vp = Strsave(vp);
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_push(vp, xfree);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (op == '=') {
|
|
|
|
c = '=';
|
|
|
|
p = xset(p, &v);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
c = *p++;
|
|
|
|
if (any("+-", c)) {
|
|
|
|
if (c != op || *p)
|
|
|
|
stderror(ERR_NAME | ERR_UNKNOWNOP);
|
|
|
|
p = Strsave(STR1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (any("<>", op)) {
|
|
|
|
if (c != op)
|
|
|
|
stderror(ERR_NAME | ERR_UNKNOWNOP);
|
|
|
|
stderror(ERR_NAME | ERR_SYNTAX);
|
|
|
|
}
|
|
|
|
if (c != '=')
|
|
|
|
stderror(ERR_NAME | ERR_UNKNOWNOP);
|
|
|
|
p = xset(p, &v);
|
|
|
|
}
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_push(p, xfree);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (op == '=') {
|
|
|
|
if (hadsub)
|
|
|
|
asx(vp, subscr, p);
|
|
|
|
else
|
2007-03-11 22:33:41 +00:00
|
|
|
setv(vp, p, VAR_READWRITE);
|
|
|
|
cleanup_ignore(p);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
else if (hadsub) {
|
|
|
|
struct varent *gv = getvx(vp, subscr);
|
2007-03-11 22:33:41 +00:00
|
|
|
Char *val;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
val = operate(op, gv->vec[subscr - 1], p);
|
|
|
|
cleanup_push(val, xfree);
|
|
|
|
asx(vp, subscr, val);
|
|
|
|
cleanup_ignore(val);
|
|
|
|
cleanup_until(val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Char *val;
|
|
|
|
|
|
|
|
val = operate(op, varval(vp), p);
|
|
|
|
cleanup_push(val, xfree);
|
|
|
|
setv(vp, val, VAR_READWRITE);
|
|
|
|
cleanup_ignore(val);
|
|
|
|
cleanup_until(val);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
update_vars(vp);
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(vp);
|
2000-04-15 04:41:27 +00:00
|
|
|
} while ((p = *v++) != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Char *
|
2007-03-11 22:33:41 +00:00
|
|
|
xset(Char *cp, Char ***vp)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
Char *dp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (*cp) {
|
|
|
|
dp = Strsave(cp);
|
|
|
|
--(*vp);
|
2007-03-11 22:33:41 +00:00
|
|
|
xfree(** vp);
|
2000-04-15 04:41:27 +00:00
|
|
|
**vp = dp;
|
|
|
|
}
|
|
|
|
return (putn(expr(vp)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static Char *
|
2007-03-11 22:33:41 +00:00
|
|
|
operate(int op, Char *vp, Char *p)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char opr[2];
|
|
|
|
Char *vec[5];
|
2005-04-24 19:41:08 +00:00
|
|
|
Char **v = vec;
|
2000-04-15 04:41:27 +00:00
|
|
|
Char **vecp = v;
|
2012-02-20 00:53:59 +00:00
|
|
|
tcsh_number_t i;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (op != '=') {
|
|
|
|
if (*vp)
|
|
|
|
*v++ = vp;
|
2007-03-11 22:33:41 +00:00
|
|
|
opr[0] = op;
|
2000-04-15 04:41:27 +00:00
|
|
|
opr[1] = 0;
|
|
|
|
*v++ = opr;
|
|
|
|
if (op == '<' || op == '>')
|
|
|
|
*v++ = opr;
|
|
|
|
}
|
|
|
|
*v++ = p;
|
|
|
|
*v++ = 0;
|
|
|
|
i = expr(&vecp);
|
|
|
|
if (*vecp)
|
|
|
|
stderror(ERR_NAME | ERR_EXPRESSION);
|
|
|
|
return (putn(i));
|
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
static Char *putp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
2012-02-20 00:53:59 +00:00
|
|
|
Char *
|
|
|
|
putn(tcsh_number_t n)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2012-02-20 00:53:59 +00:00
|
|
|
Char nbuf[1024]; /* Enough even for octal */
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
putp = nbuf;
|
|
|
|
if (n < 0) {
|
|
|
|
n = -n;
|
|
|
|
*putp++ = '-';
|
|
|
|
}
|
|
|
|
putn1(n);
|
|
|
|
*putp = 0;
|
|
|
|
return (Strsave(nbuf));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-20 00:53:59 +00:00
|
|
|
putn1(tcsh_number_t n)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
if (n > 9)
|
|
|
|
putn1(n / 10);
|
2012-02-20 00:53:59 +00:00
|
|
|
*putp++ = (Char)(n % 10 + '0');
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-20 00:53:59 +00:00
|
|
|
tcsh_number_t
|
|
|
|
getn(const Char *cp)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2012-02-20 00:53:59 +00:00
|
|
|
tcsh_number_t n;
|
2000-04-15 04:41:27 +00:00
|
|
|
int sign;
|
2009-07-10 21:47:20 +00:00
|
|
|
int base;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (!cp) /* PWP: extra error checking */
|
|
|
|
stderror(ERR_NAME | ERR_BADNUM);
|
|
|
|
|
|
|
|
sign = 0;
|
|
|
|
if (cp[0] == '+' && cp[1])
|
|
|
|
cp++;
|
|
|
|
if (*cp == '-') {
|
|
|
|
sign++;
|
|
|
|
cp++;
|
|
|
|
if (!Isdigit(*cp))
|
|
|
|
stderror(ERR_NAME | ERR_BADNUM);
|
|
|
|
}
|
2009-07-10 21:47:20 +00:00
|
|
|
|
2012-02-20 00:53:59 +00:00
|
|
|
if (cp[0] == '0' && cp[1] && is_set(STRparseoctal))
|
2009-07-10 21:47:20 +00:00
|
|
|
base = 8;
|
|
|
|
else
|
|
|
|
base = 10;
|
|
|
|
|
2000-04-15 04:41:27 +00:00
|
|
|
n = 0;
|
|
|
|
while (Isdigit(*cp))
|
2009-07-10 21:47:20 +00:00
|
|
|
{
|
|
|
|
if (base == 8 && *cp >= '8')
|
|
|
|
stderror(ERR_NAME | ERR_BADNUM);
|
|
|
|
n = n * base + *cp++ - '0';
|
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
if (*cp)
|
|
|
|
stderror(ERR_NAME | ERR_BADNUM);
|
|
|
|
return (sign ? -n : n);
|
|
|
|
}
|
|
|
|
|
|
|
|
Char *
|
2007-03-11 22:33:41 +00:00
|
|
|
value1(Char *var, struct varent *head)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct varent *vp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (!var || !head) /* PWP: extra error checking */
|
|
|
|
return (STRNULL);
|
|
|
|
|
|
|
|
vp = adrof1(var, head);
|
2002-07-24 16:23:10 +00:00
|
|
|
return ((vp == NULL || vp->vec == NULL || vp->vec[0] == NULL) ?
|
|
|
|
STRNULL : vp->vec[0]);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct varent *
|
2007-03-11 22:33:41 +00:00
|
|
|
madrof(Char *pat, struct varent *vp)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct varent *vp1;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
for (vp = vp->v_left; vp; vp = vp->v_right) {
|
|
|
|
if (vp->v_left && (vp1 = madrof(pat, vp)) != NULL)
|
|
|
|
return vp1;
|
|
|
|
if (Gmatch(vp->v_name, pat))
|
|
|
|
return vp;
|
|
|
|
}
|
|
|
|
return vp;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct varent *
|
2007-03-11 22:33:41 +00:00
|
|
|
adrof1(const Char *name, struct varent *v)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
v = v->v_left;
|
|
|
|
while (v && ((cmp = *name - *v->v_name) != 0 ||
|
|
|
|
(cmp = Strcmp(name, v->v_name)) != 0))
|
|
|
|
if (cmp < 0)
|
|
|
|
v = v->v_left;
|
|
|
|
else
|
|
|
|
v = v->v_right;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
void
|
|
|
|
setcopy(const Char *var, const Char *val, int flags)
|
|
|
|
{
|
|
|
|
Char *copy;
|
|
|
|
|
|
|
|
copy = Strsave(val);
|
|
|
|
cleanup_push(copy, xfree);
|
|
|
|
setv(var, copy, flags);
|
|
|
|
cleanup_ignore(copy);
|
|
|
|
cleanup_until(copy);
|
|
|
|
}
|
|
|
|
|
2000-04-15 04:41:27 +00:00
|
|
|
/*
|
|
|
|
* The caller is responsible for putting value in a safe place
|
|
|
|
*/
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
setv(const Char *var, Char *val, int flags)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2007-03-11 22:33:41 +00:00
|
|
|
Char **vec = xmalloc(2 * sizeof(Char **));
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
vec[0] = val;
|
|
|
|
vec[1] = 0;
|
|
|
|
set1(var, vec, &shvhed, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
set1(const Char *var, Char **vec, struct varent *head, int flags)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
Char **oldv = vec;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if ((flags & VAR_NOGLOB) == 0) {
|
2007-03-11 22:33:41 +00:00
|
|
|
int gflag;
|
|
|
|
|
|
|
|
gflag = tglob(oldv);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (gflag) {
|
2007-03-11 22:33:41 +00:00
|
|
|
vec = globall(oldv, gflag);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (vec == 0) {
|
|
|
|
blkfree(oldv);
|
|
|
|
stderror(ERR_NAME | ERR_NOMATCH);
|
|
|
|
}
|
|
|
|
blkfree(oldv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Uniqueness addition from: Michael Veksler <mveksler@vnet.ibm.com>
|
|
|
|
*/
|
|
|
|
if ( flags & (VAR_FIRST | VAR_LAST) ) {
|
|
|
|
/*
|
|
|
|
* Code for -f (VAR_FIRST) and -l (VAR_LAST) options.
|
|
|
|
* Method:
|
|
|
|
* Delete all duplicate words leaving "holes" in the word array (vec).
|
|
|
|
* Then remove the "holes", keeping the order of the words unchanged.
|
|
|
|
*/
|
|
|
|
if (vec && vec[0] && vec[1]) { /* more than one word ? */
|
|
|
|
int i, j;
|
|
|
|
int num_items;
|
|
|
|
|
|
|
|
for (num_items = 0; vec[num_items]; num_items++)
|
|
|
|
continue;
|
|
|
|
if (flags & VAR_FIRST) {
|
|
|
|
/* delete duplications, keeping first occurance */
|
|
|
|
for (i = 1; i < num_items; i++)
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
/* If have earlier identical item, remove i'th item */
|
|
|
|
if (vec[i] && vec[j] && Strcmp(vec[j], vec[i]) == 0) {
|
2007-03-11 22:33:41 +00:00
|
|
|
xfree(vec[i]);
|
2000-04-15 04:41:27 +00:00
|
|
|
vec[i] = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (flags & VAR_LAST) {
|
|
|
|
/* delete duplications, keeping last occurance */
|
|
|
|
for (i = 0; i < num_items - 1; i++)
|
|
|
|
for (j = i + 1; j < num_items; j++)
|
|
|
|
/* If have later identical item, remove i'th item */
|
|
|
|
if (vec[i] && vec[j] && Strcmp(vec[j], vec[i]) == 0) {
|
|
|
|
/* remove identical item (the first) */
|
2007-03-11 22:33:41 +00:00
|
|
|
xfree(vec[i]);
|
2000-04-15 04:41:27 +00:00
|
|
|
vec[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Compress items - remove empty items */
|
|
|
|
for (j = i = 0; i < num_items; i++)
|
|
|
|
if (vec[i])
|
|
|
|
vec[j++] = vec[i];
|
|
|
|
|
|
|
|
/* NULL-fy remaining items */
|
|
|
|
for (; j < num_items; j++)
|
|
|
|
vec[j] = NULL;
|
|
|
|
}
|
|
|
|
/* don't let the attribute propagate */
|
|
|
|
flags &= ~(VAR_FIRST|VAR_LAST);
|
|
|
|
}
|
|
|
|
setq(var, vec, head, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
setq(const Char *name, Char **vec, struct varent *p, int flags)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct varent *c;
|
|
|
|
int f;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
f = 0; /* tree hangs off the header's left link */
|
|
|
|
while ((c = p->v_link[f]) != 0) {
|
|
|
|
if ((f = *name - *c->v_name) == 0 &&
|
|
|
|
(f = Strcmp(name, c->v_name)) == 0) {
|
|
|
|
if (c->v_flags & VAR_READONLY)
|
|
|
|
stderror(ERR_READONLY|ERR_NAME, c->v_name);
|
|
|
|
blkfree(c->vec);
|
|
|
|
c->v_flags = flags;
|
|
|
|
trim(c->vec = vec);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p = c;
|
|
|
|
f = f > 0;
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
p->v_link[f] = c = xmalloc(sizeof(struct varent));
|
2000-04-15 04:41:27 +00:00
|
|
|
c->v_name = Strsave(name);
|
|
|
|
c->v_flags = flags;
|
|
|
|
c->v_bal = 0;
|
|
|
|
c->v_left = c->v_right = 0;
|
|
|
|
c->v_parent = p;
|
|
|
|
balance(p, f, 0);
|
|
|
|
trim(c->vec = vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
unset(Char **v, struct command *c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
int did_roe, did_edit;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(c);
|
|
|
|
did_roe = adrof(STRrecognize_only_executables) != NULL;
|
|
|
|
did_edit = adrof(STRedit) != NULL;
|
|
|
|
unset1(v, &shvhed);
|
2002-07-24 16:23:10 +00:00
|
|
|
|
|
|
|
#if defined(FILEC) && defined(TIOCSTI)
|
|
|
|
if (adrof(STRfilec) == 0)
|
|
|
|
filec = 0;
|
|
|
|
#endif /* FILEC && TIOCSTI */
|
|
|
|
|
2000-04-15 04:41:27 +00:00
|
|
|
if (adrof(STRhistchars) == 0) {
|
|
|
|
HIST = '!';
|
|
|
|
HISTSUB = '^';
|
|
|
|
}
|
2004-07-11 02:17:56 +00:00
|
|
|
if (adrof(STRignoreeof) == 0)
|
|
|
|
numeof = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
if (adrof(STRpromptchars) == 0) {
|
2012-02-20 00:53:59 +00:00
|
|
|
PRCH = tcsh ? '>' : '%';
|
2000-04-15 04:41:27 +00:00
|
|
|
PRCHROOT = '#';
|
|
|
|
}
|
|
|
|
if (adrof(STRhistlit) == 0)
|
|
|
|
HistLit = 0;
|
|
|
|
if (adrof(STRloginsh) == 0)
|
|
|
|
loginsh = 0;
|
2012-02-20 00:53:59 +00:00
|
|
|
if (adrof(STRanyerror) == 0)
|
|
|
|
anyerror = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
if (adrof(STRwordchars) == 0)
|
|
|
|
word_chars = STR_WORD_CHARS;
|
|
|
|
if (adrof(STRedit) == 0)
|
|
|
|
editing = 0;
|
|
|
|
if (adrof(STRbackslash_quote) == 0)
|
|
|
|
bslash_quote = 0;
|
2009-07-10 21:47:20 +00:00
|
|
|
if (adrof(STRcompat_expr) == 0)
|
|
|
|
compat_expr = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
if (adrof(STRsymlinks) == 0)
|
|
|
|
symlinks = 0;
|
|
|
|
if (adrof(STRimplicitcd) == 0)
|
|
|
|
implicit_cd = 0;
|
2001-09-05 17:49:32 +00:00
|
|
|
if (adrof(STRkillring) == 0)
|
|
|
|
SetKillRing(0);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (did_edit && noediting && adrof(STRedit) == 0)
|
|
|
|
noediting = 0;
|
|
|
|
if (did_roe && adrof(STRrecognize_only_executables) == 0)
|
|
|
|
tw_cmd_free();
|
|
|
|
#ifdef COLOR_LS_F
|
|
|
|
if (adrof(STRcolor) == 0)
|
|
|
|
set_color_context();
|
|
|
|
#endif /* COLOR_LS_F */
|
|
|
|
#if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
|
|
|
|
update_dspmbyte_vars();
|
|
|
|
#endif
|
2000-11-30 21:05:33 +00:00
|
|
|
#ifdef NLS_CATALOGS
|
2005-04-24 19:41:08 +00:00
|
|
|
nlsclose();
|
2000-11-30 21:05:33 +00:00
|
|
|
nlsinit();
|
|
|
|
#endif /* NLS_CATALOGS */
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
unset1(Char *v[], struct varent *head)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct varent *vp;
|
|
|
|
int cnt;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
while (*++v) {
|
|
|
|
cnt = 0;
|
|
|
|
while ((vp = madrof(*v, head)) != NULL)
|
|
|
|
if (vp->v_flags & VAR_READONLY)
|
|
|
|
stderror(ERR_READONLY|ERR_NAME, vp->v_name);
|
|
|
|
else
|
|
|
|
unsetv1(vp), cnt++;
|
|
|
|
if (cnt == 0)
|
|
|
|
setname(short2str(*v));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
unsetv(Char *var)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct varent *vp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if ((vp = adrof1(var, &shvhed)) == 0)
|
|
|
|
udvar(var);
|
|
|
|
unsetv1(vp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
unsetv1(struct varent *p)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct varent *c, *pp;
|
|
|
|
int f;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free associated memory first to avoid complications.
|
|
|
|
*/
|
|
|
|
blkfree(p->vec);
|
2007-03-11 22:33:41 +00:00
|
|
|
xfree(p->v_name);
|
2000-04-15 04:41:27 +00:00
|
|
|
/*
|
|
|
|
* If p is missing one child, then we can move the other into where p is.
|
|
|
|
* Otherwise, we find the predecessor of p, which is guaranteed to have no
|
|
|
|
* right child, copy it into p, and move it's left child into it.
|
|
|
|
*/
|
|
|
|
if (p->v_right == 0)
|
|
|
|
c = p->v_left;
|
|
|
|
else if (p->v_left == 0)
|
|
|
|
c = p->v_right;
|
|
|
|
else {
|
|
|
|
for (c = p->v_left; c->v_right; c = c->v_right)
|
|
|
|
continue;
|
|
|
|
p->v_name = c->v_name;
|
|
|
|
p->v_flags = c->v_flags;
|
|
|
|
p->vec = c->vec;
|
|
|
|
p = c;
|
|
|
|
c = p->v_left;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move c into where p is.
|
|
|
|
*/
|
|
|
|
pp = p->v_parent;
|
|
|
|
f = pp->v_right == p;
|
|
|
|
if ((pp->v_link[f] = c) != 0)
|
|
|
|
c->v_parent = pp;
|
|
|
|
/*
|
|
|
|
* Free the deleted node, and rebalance.
|
|
|
|
*/
|
2007-03-11 22:33:41 +00:00
|
|
|
xfree(p);
|
2000-04-15 04:41:27 +00:00
|
|
|
balance(pp, f, 1);
|
|
|
|
}
|
|
|
|
|
2012-02-20 00:53:59 +00:00
|
|
|
/* Set variable name to NULL. */
|
2000-04-15 04:41:27 +00:00
|
|
|
void
|
2012-02-20 00:53:59 +00:00
|
|
|
setNS(const Char *varName)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2012-02-20 00:53:59 +00:00
|
|
|
setcopy(varName, STRNULL, VAR_READWRITE);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
shift(Char **v, struct command *c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct varent *argv;
|
|
|
|
Char *name;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(c);
|
|
|
|
v++;
|
|
|
|
name = *v;
|
|
|
|
if (name == 0)
|
|
|
|
name = STRargv;
|
|
|
|
else
|
|
|
|
(void) strip(name);
|
|
|
|
argv = adrof(name);
|
2002-07-24 16:23:10 +00:00
|
|
|
if (argv == NULL || argv->vec == NULL)
|
2000-04-15 04:41:27 +00:00
|
|
|
udvar(name);
|
|
|
|
if (argv->vec[0] == 0)
|
|
|
|
stderror(ERR_NAME | ERR_NOMORE);
|
|
|
|
lshift(argv->vec, 1);
|
|
|
|
update_vars(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
exportpath(Char **val)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2007-03-11 22:33:41 +00:00
|
|
|
struct Strbuf buf = Strbuf_INIT;
|
|
|
|
Char *exppath;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (val)
|
|
|
|
while (*val) {
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append(&buf, *val++);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (*val == 0 || eq(*val, STRRparen))
|
2007-03-11 22:33:41 +00:00
|
|
|
break;
|
|
|
|
Strbuf_append1(&buf, PATHSEP);
|
|
|
|
}
|
|
|
|
exppath = Strbuf_finish(&buf);
|
|
|
|
cleanup_push(exppath, xfree);
|
|
|
|
tsetenv(STRKPATH, exppath);
|
|
|
|
cleanup_until(exppath);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
/*
|
|
|
|
* Lint thinks these have null effect
|
|
|
|
*/
|
|
|
|
/* macros to do single rotations on node p */
|
|
|
|
# define rright(p) (\
|
|
|
|
t = (p)->v_left,\
|
|
|
|
(t)->v_parent = (p)->v_parent,\
|
|
|
|
(((p)->v_left = t->v_right) != NULL) ?\
|
|
|
|
(t->v_right->v_parent = (p)) : 0,\
|
|
|
|
(t->v_right = (p))->v_parent = t,\
|
|
|
|
(p) = t)
|
|
|
|
# define rleft(p) (\
|
|
|
|
t = (p)->v_right,\
|
|
|
|
((t)->v_parent = (p)->v_parent,\
|
|
|
|
((p)->v_right = t->v_left) != NULL) ? \
|
|
|
|
(t->v_left->v_parent = (p)) : 0,\
|
|
|
|
(t->v_left = (p))->v_parent = t,\
|
|
|
|
(p) = t)
|
|
|
|
#else
|
|
|
|
static struct varent *
|
2007-03-11 22:33:41 +00:00
|
|
|
rleft(struct varent *p)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
static struct varent *
|
2007-03-11 22:33:41 +00:00
|
|
|
rright(struct varent *p)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ! lint */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rebalance a tree, starting at p and up.
|
|
|
|
* F == 0 means we've come from p's left child.
|
|
|
|
* D == 1 means we've just done a delete, otherwise an insert.
|
|
|
|
*/
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
balance(struct varent *p, int f, int d)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct varent *pp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
#ifndef lint
|
2005-04-24 19:41:08 +00:00
|
|
|
struct varent *t; /* used by the rotate macros */
|
2000-04-15 04:41:27 +00:00
|
|
|
#endif /* !lint */
|
2005-04-24 19:41:08 +00:00
|
|
|
int ff;
|
2000-04-15 04:41:27 +00:00
|
|
|
#ifdef lint
|
|
|
|
ff = 0; /* Sun's lint is dumb! */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, from here on, p is the node we're operating on; pp is it's parent; f
|
|
|
|
* is the branch of p from which we have come; ff is the branch of pp which
|
|
|
|
* is p.
|
|
|
|
*/
|
|
|
|
for (; (pp = p->v_parent) != 0; p = pp, f = ff) {
|
|
|
|
ff = pp->v_right == p;
|
|
|
|
if (f ^ d) { /* right heavy */
|
|
|
|
switch (p->v_bal) {
|
|
|
|
case -1: /* was left heavy */
|
|
|
|
p->v_bal = 0;
|
|
|
|
break;
|
|
|
|
case 0: /* was balanced */
|
|
|
|
p->v_bal = 1;
|
|
|
|
break;
|
|
|
|
case 1: /* was already right heavy */
|
|
|
|
switch (p->v_right->v_bal) {
|
2007-03-11 22:33:41 +00:00
|
|
|
case 1: /* single rotate */
|
2000-04-15 04:41:27 +00:00
|
|
|
pp->v_link[ff] = rleft(p);
|
|
|
|
p->v_left->v_bal = 0;
|
|
|
|
p->v_bal = 0;
|
|
|
|
break;
|
|
|
|
case 0: /* single rotate */
|
|
|
|
pp->v_link[ff] = rleft(p);
|
|
|
|
p->v_left->v_bal = 1;
|
|
|
|
p->v_bal = -1;
|
|
|
|
break;
|
|
|
|
case -1: /* double rotate */
|
|
|
|
(void) rright(p->v_right);
|
|
|
|
pp->v_link[ff] = rleft(p);
|
|
|
|
p->v_left->v_bal =
|
|
|
|
p->v_bal < 1 ? 0 : -1;
|
|
|
|
p->v_right->v_bal =
|
|
|
|
p->v_bal > -1 ? 0 : 1;
|
|
|
|
p->v_bal = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* left heavy */
|
|
|
|
switch (p->v_bal) {
|
|
|
|
case 1: /* was right heavy */
|
|
|
|
p->v_bal = 0;
|
|
|
|
break;
|
|
|
|
case 0: /* was balanced */
|
|
|
|
p->v_bal = -1;
|
|
|
|
break;
|
|
|
|
case -1: /* was already left heavy */
|
|
|
|
switch (p->v_left->v_bal) {
|
|
|
|
case -1: /* single rotate */
|
|
|
|
pp->v_link[ff] = rright(p);
|
|
|
|
p->v_right->v_bal = 0;
|
|
|
|
p->v_bal = 0;
|
|
|
|
break;
|
2007-03-11 22:33:41 +00:00
|
|
|
case 0: /* single rotate */
|
2000-04-15 04:41:27 +00:00
|
|
|
pp->v_link[ff] = rright(p);
|
|
|
|
p->v_right->v_bal = -1;
|
|
|
|
p->v_bal = 1;
|
|
|
|
break;
|
|
|
|
case 1: /* double rotate */
|
|
|
|
(void) rleft(p->v_left);
|
|
|
|
pp->v_link[ff] = rright(p);
|
|
|
|
p->v_left->v_bal =
|
|
|
|
p->v_bal < 1 ? 0 : -1;
|
|
|
|
p->v_right->v_bal =
|
|
|
|
p->v_bal > -1 ? 0 : 1;
|
|
|
|
p->v_bal = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If from insert, then we terminate when p is balanced. If from
|
|
|
|
* delete, then we terminate when p is unbalanced.
|
|
|
|
*/
|
|
|
|
if ((p->v_bal == 0) ^ d)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
plist(struct varent *p, int what)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct varent *c;
|
|
|
|
int len;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
while (p->v_left)
|
|
|
|
p = p->v_left;
|
|
|
|
x:
|
|
|
|
if (p->v_parent == 0) /* is it the header? */
|
2007-03-11 22:33:41 +00:00
|
|
|
break;
|
2000-04-15 04:41:27 +00:00
|
|
|
if ((p->v_flags & what) != 0) {
|
2007-03-11 22:33:41 +00:00
|
|
|
if (setintr) {
|
|
|
|
int old_pintr_disabled;
|
|
|
|
|
|
|
|
pintr_push_enable(&old_pintr_disabled);
|
|
|
|
cleanup_until(&old_pintr_disabled);
|
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
len = blklen(p->vec);
|
|
|
|
xprintf("%S\t", p->v_name);
|
|
|
|
if (len != 1)
|
|
|
|
xputchar('(');
|
|
|
|
blkpr(p->vec);
|
|
|
|
if (len != 1)
|
|
|
|
xputchar(')');
|
|
|
|
xputchar('\n');
|
|
|
|
}
|
|
|
|
if (p->v_right) {
|
|
|
|
p = p->v_right;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
c = p;
|
|
|
|
p = p->v_parent;
|
|
|
|
} while (p->v_right == c);
|
|
|
|
goto x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-20 00:53:59 +00:00
|
|
|
#if defined(KANJI)
|
|
|
|
# if defined(SHORT_STRINGS) && defined(DSPMBYTE)
|
2005-04-24 19:41:08 +00:00
|
|
|
extern int dspmbyte_ls;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
update_dspmbyte_vars(void)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
int lp, iskcode;
|
|
|
|
Char *dstr1;
|
|
|
|
struct varent *vp;
|
|
|
|
|
|
|
|
/* if variable "nokanji" is set, multi-byte display is disabled */
|
|
|
|
if ((vp = adrof(CHECK_MBYTEVAR)) && !adrof(STRnokanji)) {
|
|
|
|
_enable_mbdisp = 1;
|
|
|
|
dstr1 = vp->vec[0];
|
2005-04-24 19:41:08 +00:00
|
|
|
if(eq (dstr1, STRsjis))
|
2000-04-15 04:41:27 +00:00
|
|
|
iskcode = 1;
|
2005-04-24 19:41:08 +00:00
|
|
|
else if (eq(dstr1, STReuc))
|
2000-04-15 04:41:27 +00:00
|
|
|
iskcode = 2;
|
2005-04-24 19:41:08 +00:00
|
|
|
else if (eq(dstr1, STRbig5))
|
2001-09-05 17:49:32 +00:00
|
|
|
iskcode = 3;
|
2005-04-24 19:41:08 +00:00
|
|
|
else if (eq(dstr1, STRutf8))
|
2002-07-24 16:23:10 +00:00
|
|
|
iskcode = 4;
|
2000-04-15 04:41:27 +00:00
|
|
|
else if ((dstr1[0] - '0') >= 0 && (dstr1[0] - '0') <= 3) {
|
|
|
|
iskcode = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
xprintf(CGETS(18, 2,
|
|
|
|
"Warning: unknown multibyte display; using default(euc(JP))\n"));
|
|
|
|
iskcode = 2;
|
|
|
|
}
|
|
|
|
if (dstr1 && vp->vec[1] && eq(vp->vec[1], STRls))
|
|
|
|
dspmbyte_ls = 1;
|
|
|
|
else
|
|
|
|
dspmbyte_ls = 0;
|
|
|
|
for (lp = 0; lp < 256 && iskcode > 0; lp++) {
|
|
|
|
switch (iskcode) {
|
|
|
|
case 1:
|
|
|
|
/* Shift-JIS */
|
|
|
|
_cmap[lp] = _cmap_mbyte[lp];
|
|
|
|
_mbmap[lp] = _mbmap_sjis[lp];
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* 2 ... euc */
|
|
|
|
_cmap[lp] = _cmap_mbyte[lp];
|
|
|
|
_mbmap[lp] = _mbmap_euc[lp];
|
|
|
|
break;
|
2001-09-05 17:49:32 +00:00
|
|
|
case 3:
|
|
|
|
/* 3 ... big5 */
|
|
|
|
_cmap[lp] = _cmap_mbyte[lp];
|
|
|
|
_mbmap[lp] = _mbmap_big5[lp];
|
|
|
|
break;
|
2002-07-24 16:23:10 +00:00
|
|
|
case 4:
|
|
|
|
/* 4 ... utf8 */
|
|
|
|
_cmap[lp] = _cmap_mbyte[lp];
|
|
|
|
_mbmap[lp] = _mbmap_utf8[lp];
|
|
|
|
break;
|
2000-04-15 04:41:27 +00:00
|
|
|
default:
|
|
|
|
xprintf(CGETS(18, 3,
|
|
|
|
"Warning: unknown multibyte code %d; multibyte disabled\n"),
|
|
|
|
iskcode);
|
|
|
|
_cmap[lp] = _cmap_c[lp];
|
|
|
|
_mbmap[lp] = 0; /* Default map all 0 */
|
|
|
|
_enable_mbdisp = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (iskcode == 0) {
|
|
|
|
/* check original table */
|
|
|
|
if (Strlen(dstr1) != 256) {
|
|
|
|
xprintf(CGETS(18, 4,
|
|
|
|
"Warning: Invalid multibyte table length (%d); multibyte disabled\n"),
|
|
|
|
Strlen(dstr1));
|
|
|
|
_enable_mbdisp = 0;
|
|
|
|
}
|
|
|
|
for (lp = 0; lp < 256 && _enable_mbdisp == 1; lp++) {
|
|
|
|
if (!((dstr1[lp] - '0') >= 0 && (dstr1[lp] - '0') <= 3)) {
|
|
|
|
xprintf(CGETS(18, 4,
|
|
|
|
"Warning: bad multibyte code at offset +%d; multibyte diabled\n"),
|
|
|
|
lp);
|
|
|
|
_enable_mbdisp = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* set original table */
|
|
|
|
for (lp = 0; lp < 256; lp++) {
|
|
|
|
if (_enable_mbdisp == 1) {
|
|
|
|
_cmap[lp] = _cmap_mbyte[lp];
|
|
|
|
_mbmap[lp] = (unsigned short) ((dstr1[lp] - '0') & 0x0f);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_cmap[lp] = _cmap_c[lp];
|
|
|
|
_mbmap[lp] = 0; /* Default map all 0 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (lp = 0; lp < 256; lp++) {
|
|
|
|
_cmap[lp] = _cmap_c[lp];
|
|
|
|
_mbmap[lp] = 0; /* Default map all 0 */
|
|
|
|
}
|
|
|
|
_enable_mbdisp = 0;
|
|
|
|
dspmbyte_ls = 0;
|
|
|
|
}
|
|
|
|
#ifdef MBYTEDEBUG /* Sorry, use for beta testing */
|
|
|
|
{
|
|
|
|
Char mbmapstr[300];
|
2007-03-11 22:33:41 +00:00
|
|
|
for (lp = 0; lp < 256; lp++)
|
2000-04-15 04:41:27 +00:00
|
|
|
mbmapstr[lp] = _mbmap[lp] + '0';
|
2007-03-11 22:33:41 +00:00
|
|
|
mbmapstr[lp] = 0;
|
|
|
|
setcopy(STRmbytemap, mbmapstr, VAR_READWRITE);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
#endif /* MBYTEMAP */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dspkanji/dspmbyte autosetting */
|
|
|
|
/* PATCH IDEA FROM Issei.Suzuki VERY THANKS */
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
autoset_dspmbyte(const Char *pcp)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
int i;
|
2007-03-11 22:33:41 +00:00
|
|
|
static const struct dspm_autoset_Table {
|
2000-04-15 04:41:27 +00:00
|
|
|
Char *n;
|
|
|
|
Char *v;
|
|
|
|
} dspmt[] = {
|
2005-04-24 19:41:08 +00:00
|
|
|
{ STRLANGEUCJP, STReuc },
|
|
|
|
{ STRLANGEUCKR, STReuc },
|
|
|
|
{ STRLANGEUCZH, STReuc },
|
|
|
|
{ STRLANGEUCJPB, STReuc },
|
|
|
|
{ STRLANGEUCKRB, STReuc },
|
|
|
|
{ STRLANGEUCZHB, STReuc },
|
2012-02-20 00:53:59 +00:00
|
|
|
#ifdef __linux__
|
2005-04-24 19:41:08 +00:00
|
|
|
{ STRLANGEUCJPC, STReuc },
|
2004-07-11 02:17:56 +00:00
|
|
|
#endif
|
2005-04-24 19:41:08 +00:00
|
|
|
{ STRLANGSJIS, STRsjis },
|
|
|
|
{ STRLANGSJISB, STRsjis },
|
|
|
|
{ STRLANGBIG5, STRbig5 },
|
|
|
|
{ STRstarutfstar8, STRutf8 },
|
2000-04-15 04:41:27 +00:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
2007-03-11 22:33:41 +00:00
|
|
|
#if defined(HAVE_NL_LANGINFO) && defined(CODESET)
|
|
|
|
static const struct dspm_autoset_Table dspmc[] = {
|
2005-04-24 19:41:08 +00:00
|
|
|
{ STRstarutfstar8, STRutf8 },
|
|
|
|
{ STReuc, STReuc },
|
|
|
|
{ STRGB2312, STReuc },
|
|
|
|
{ STRLANGBIG5, STRbig5 },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
Char *codeset;
|
|
|
|
|
|
|
|
codeset = str2short(nl_langinfo(CODESET));
|
|
|
|
if (*codeset != '\0') {
|
|
|
|
for (i = 0; dspmc[i].n; i++) {
|
2007-03-11 22:33:41 +00:00
|
|
|
const Char *estr;
|
2005-04-24 19:41:08 +00:00
|
|
|
if (dspmc[i].n[0] && t_pmatch(pcp, dspmc[i].n, &estr, 0) > 0) {
|
2007-03-11 22:33:41 +00:00
|
|
|
setcopy(CHECK_MBYTEVAR, dspmc[i].v, VAR_READWRITE);
|
2005-04-24 19:41:08 +00:00
|
|
|
update_dspmbyte_vars();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-04-15 04:41:27 +00:00
|
|
|
if (*pcp == '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; dspmt[i].n; i++) {
|
2007-03-11 22:33:41 +00:00
|
|
|
const Char *estr;
|
2005-04-24 19:41:08 +00:00
|
|
|
if (dspmt[i].n[0] && t_pmatch(pcp, dspmt[i].n, &estr, 0) > 0) {
|
2007-03-11 22:33:41 +00:00
|
|
|
setcopy(CHECK_MBYTEVAR, dspmt[i].v, VAR_READWRITE);
|
2000-04-15 04:41:27 +00:00
|
|
|
update_dspmbyte_vars();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 00:53:59 +00:00
|
|
|
# elif defined(AUTOSET_KANJI)
|
|
|
|
void
|
|
|
|
autoset_kanji(void)
|
|
|
|
{
|
|
|
|
char *codeset = nl_langinfo(CODESET);
|
|
|
|
|
|
|
|
if (*codeset == '\0') {
|
|
|
|
if (adrof(STRnokanji) == NULL)
|
|
|
|
setNS(STRnokanji);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasestr(codeset, "SHIFT_JIS") == (char*)0) {
|
|
|
|
if (adrof(STRnokanji) == NULL)
|
|
|
|
setNS(STRnokanji);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adrof(STRnokanji) != NULL)
|
|
|
|
unsetv(STRnokanji);
|
|
|
|
}
|
|
|
|
#endif
|
2000-04-15 04:41:27 +00:00
|
|
|
#endif
|