Quizzer
view release on metacpan or search on metacpan
exercises/compile-tcsh/tcsh-6.10.00/sh.set.c view on Meta::CPAN
* 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"
RCSID("$Id: sh.set.c,v 3.37 2000/07/15 19:58:51 christos Exp $")
#include "ed.h"
#include "tw.h"
extern Char HistLit;
extern bool GotTermCaps;
static void update_vars __P((Char *));
static Char *getinx __P((Char *, int *));
static void asx __P((Char *, int, Char *));
static struct varent *getvx __P((Char *, int));
static Char *xset __P((Char *, Char ***));
static Char *operate __P((int, Char *, Char *));
static void putn1 __P((int));
static struct varent *madrof __P((Char *, struct varent *));
static void unsetv1 __P((struct varent *));
static void exportpath __P((Char **));
static void balance __P((struct varent *, int, int));
/*
* C Shell
*/
static void
update_vars(vp)
Char *vp;
{
if (eq(vp, STRpath)) {
exportpath(adrof(STRpath)->vec);
dohash(NULL, NULL);
}
else if (eq(vp, STRhistchars)) {
register Char *pn = varval(vp);
HIST = *pn++;
HISTSUB = *pn;
}
else if (eq(vp, STRpromptchars)) {
register Char *pn = varval(vp);
PRCH = *pn++;
PRCHROOT = *pn;
}
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;
}
else if (eq(vp, STRsymlinks)) {
register Char *pn = varval(vp);
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;
set(STRedit, Strsave(STRNULL), VAR_READWRITE);
}
ed_Init(); /* reset the editor */
}
else if (eq(vp, STRhome)) {
register Char *cp;
cp = Strsave(varval(vp)); /* get the old value back */
/*
* convert to cononical pathname (possibly resolving symlinks)
*/
cp = dcanon(cp, cp);
set(vp, Strsave(cp), VAR_READWRITE); /* have to save the new val */
/* and now mirror home with HOME */
tsetenv(STRKHOME, cp);
/* fix directory stack for new tilde home */
dtilde();
xfree((ptr_t) cp);
}
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));
}
else if (eq(vp, STRbackslash_quote)) {
bslash_quote = 1;
}
else if (eq(vp, STRdirstack)) {
dsetstack();
}
else if (eq(vp, STRrecognize_only_executables)) {
tw_cmd_free();
}
#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
#ifdef NLS_CATALOGS
else if (eq(vp, STRcatalog)) {
(void) catclose(catd);
nlsinit();
}
#endif /* NLS_CATALOGS */
}
/*ARGSUSED*/
void
doset(v, c)
register Char **v;
struct command *c;
{
register Char *p;
Char *vp, op;
Char **vecp;
bool hadsub;
int subscr;
int flags = VAR_READWRITE;
bool first_match = 0;
bool last_match = 0;
bool changed = 0;
USE(c);
v++;
do {
changed = 0;
/*
* Readonly addition From: Tim P. Starrin <noid@cyborg.larc.nasa.gov>
*/
exercises/compile-tcsh/tcsh-6.10.00/sh.set.c view on Meta::CPAN
void
setNS(cp)
Char *cp;
{
set(cp, Strsave(STRNULL), VAR_READWRITE);
}
/*ARGSUSED*/
void
shift(v, c)
register Char **v;
struct command *c;
{
register struct varent *argv;
register Char *name;
USE(c);
v++;
name = *v;
if (name == 0)
name = STRargv;
else
(void) strip(name);
argv = adrof(name);
if (argv == 0)
udvar(name);
if (argv->vec[0] == 0)
stderror(ERR_NAME | ERR_NOMORE);
lshift(argv->vec, 1);
update_vars(name);
}
static Char STRsep[2] = { PATHSEP, '\0' };
static void
exportpath(val)
Char **val;
{
Char *exppath;
size_t exppath_size = BUFSIZE;
exppath = (Char *)xmalloc(sizeof(Char)*exppath_size);
exppath[0] = 0;
if (val)
while (*val) {
while (Strlen(*val) + Strlen(exppath) + 2 > exppath_size) {
if ((exppath
= (Char *)xrealloc(exppath, sizeof(Char)*(exppath_size *= 2)))
== NULL) {
xprintf(CGETS(18, 1,
"Warning: ridiculously long PATH truncated\n"));
break;
}
}
(void) Strcat(exppath, *val++);
if (*val == 0 || eq(*val, STRRparen))
break;
(void) Strcat(exppath, STRsep);
}
tsetenv(STRKPATH, exppath);
free(exppath);
}
#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 *
rleft(p)
struct varent *p;
{
return (p);
}
static struct varent *
rright(p)
struct varent *p;
{
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
balance(p, f, d)
register struct varent *p;
register int f, d;
{
register struct varent *pp;
#ifndef lint
register struct varent *t; /* used by the rotate macros */
#endif /* !lint */
register int ff;
#ifdef lint
ff = 0; /* Sun's lint is dumb! */
#endif
/*
( run in 0.793 second using v1.01-cache-2.11-cpan-f0ff5d10edf )