rc: define constants for rc variable names

This commit is contained in:
Giacomo Tesio 2017-10-18 22:38:30 +02:00
parent d3c2605d57
commit 4017b73ab2
9 changed files with 29 additions and 19 deletions

View File

@ -141,7 +141,7 @@ outcode(tree *t, int eflag)
} else {
emitf(Xmark);
emitf(Xword);
emits(estrdup("ifs"));
emits(estrdup(ENV_IFS));
emitf(Xdol);
}
emitf(Xbackq);

View File

@ -175,7 +175,7 @@ main(int argc, char *argv[])
Trapinit();
Vinit();
inttoascii(num, mypid = getpid());
setvar("pid", newword(num, (word *)0));
setvar(ENV_PID, newword(num, (word *)0));
setvar("cflag", flag['c']?newword(flag['c'][0], (word *)0)
:(word *)0);
setvar("rcname", newword(argv[0], (word *)0));
@ -330,7 +330,7 @@ Xexit(void)
if(trapreq->fn){
beenhere = 1;
--runq->pc;
starval = vlook("*")->val;
starval = vlook(ENV_RCARGLIST)->val;
start(trapreq->fn, trapreq->pc, (struct var *)0);
runq->local = newvar("*", runq->local);
runq->local->val = copywords(starval, (struct word *)0);
@ -686,7 +686,7 @@ Xdol(void)
if(n==0 || *t)
a = copywords(vlook(s)->val, a);
else{
star = vlook("*")->val;
star = vlook(ENV_RCARGLIST)->val;
if(star && 1<=n && n<=count(star)){
while(--n) star = star->next;
a = newword(star->word, a);
@ -797,7 +797,7 @@ Xcount(void)
inttoascii(num, count(a));
}
else{
a = vlook("*")->val;
a = vlook(ENV_RCARGLIST)->val;
inttoascii(num, a && 1<=n && n<=count(a)?1:0);
}
poplist();
@ -916,9 +916,9 @@ Xrdcmds(void)
flush(err);
nerror = 0;
if(flag['s'] && !truestatus())
pfmt(err, "status=%v\n", vlook("status")->val);
pfmt(err, "%s=%v\n", ENV_STATUS, vlook(ENV_STATUS)->val);
if(runq->iflag){
prompt = vlook("prompt")->val;
prompt = vlook(ENV_PROMPT)->val;
if(prompt)
promptstr = prompt->word;
else
@ -975,13 +975,13 @@ Xerror1(char *s)
void
setstatus(char *s)
{
setvar("status", newword(s, (word *)0));
setvar(ENV_STATUS, newword(s, (word *)0));
}
char*
getstatus(void)
{
var *status = vlook("status");
var *status = vlook(ENV_STATUS);
return status->val?status->val->word:"";
}

View File

@ -41,7 +41,7 @@ Xasync(void)
close(null);
runq->pc = runq->code[runq->pc].i;
inttoascii(npid, pid);
setvar("apid", newword(npid, (word *)0));
setvar(ENV_APID, newword(npid, (word *)0));
break;
}
}

View File

@ -137,7 +137,7 @@ psubst(io *f, uint8_t *s)
for(u = s; *u && '0' <= *u && *u <= '9'; u++)
n = n*10 + *u - '0';
if(n && *u=='\0'){
star = vlook("*")->val;
star = vlook(ENV_RCARGLIST)->val;
if(star && 1 <= n && n <= count(star)){
while(--n)
star = star->next;

View File

@ -111,7 +111,7 @@ pprompt(void)
}
newwdir = 0;
}
prompt = vlook("prompt");
prompt = vlook(ENV_PROMPT);
if(prompt->val && prompt->val->next)
promptstr = prompt->val->next->word;
else

View File

@ -9,6 +9,16 @@
#include <u.h>
#include <lib9.h>
#define ENV_RCARGLIST "*"
#define ENV_APID "apid"
#define ENV_HOME "home"
#define ENV_IFS "ifs"
#define ENV_PATH "path"
#define ENV_PID "pid"
#define ENV_PROMPT "prompt"
#define ENV_STATUS "status"
#define ENV_CDPATH "cdpath"
#define NSIG 32
#define SIGINT 2
#define SIGQUIT 3

View File

@ -111,7 +111,7 @@ searchpath(char *w)
|| strncmp(w, "#", 1)==0
|| strncmp(w, "./", 2)==0
|| strncmp(w, "../", 3)==0
|| (path = vlook("path")->val)==0)
|| (path = vlook(ENV_PATH)->val)==0)
path=&nullpath;
return path;
}
@ -162,7 +162,7 @@ execcd(void)
char *dir;
setstatus("can't cd");
cdpath = vlook("cdpath")->val;
cdpath = vlook(ENV_CDPATH)->val;
switch(count(a)){
default:
pfmt(err, "Usage: cd [directory]\n");
@ -191,7 +191,7 @@ execcd(void)
pfmt(err, "Can't cd %s: %r\n", a->next->word);
break;
case 1:
a = vlook("home")->val;
a = vlook(ENV_HOME)->val;
if(count(a)>=1){
if(dochdir(a->word)>=0)
setstatus("");
@ -236,7 +236,7 @@ execshift(void)
n = 1;
break;
}
star = vlook("*");
star = vlook(ENV_RCARGLIST);
for(;n>0 && star->val;--n){
a = star->val->next;
free(star->val->word);

View File

@ -62,7 +62,7 @@ yyerror(char *m)
lastdol = 0;
while(lastc!='\n' && lastc!=EOF) advance();
nerror++;
setvar("status", newword(m, (word *)0));
setvar(ENV_STATUS, newword(m, (word *)0));
}
char *bp;

View File

@ -19,7 +19,7 @@ dotrap(void)
int i;
struct var *trapreq;
struct word *starval;
starval = vlook("*")->val;
starval = vlook(ENV_RCARGLIST)->val;
while(ntrap) for(i = 0;i!=NSIG;i++) while(trap[i]){
--trap[i];
--ntrap;
@ -27,7 +27,7 @@ dotrap(void)
trapreq = vlook(Signame[i]);
if(trapreq->fn){
start(trapreq->fn, trapreq->pc, (struct var *)0);
runq->local = newvar("*", runq->local);
runq->local = newvar(ENV_RCARGLIST, runq->local);
runq->local->val = copywords(starval, (struct word *)0);
runq->local->changed = 1;
runq->redir = runq->startredir = 0;