rc: define constants for rc variable names
This commit is contained in:
parent
d3c2605d57
commit
4017b73ab2
|
@ -141,7 +141,7 @@ outcode(tree *t, int eflag)
|
||||||
} else {
|
} else {
|
||||||
emitf(Xmark);
|
emitf(Xmark);
|
||||||
emitf(Xword);
|
emitf(Xword);
|
||||||
emits(estrdup("ifs"));
|
emits(estrdup(ENV_IFS));
|
||||||
emitf(Xdol);
|
emitf(Xdol);
|
||||||
}
|
}
|
||||||
emitf(Xbackq);
|
emitf(Xbackq);
|
||||||
|
|
|
@ -175,7 +175,7 @@ main(int argc, char *argv[])
|
||||||
Trapinit();
|
Trapinit();
|
||||||
Vinit();
|
Vinit();
|
||||||
inttoascii(num, mypid = getpid());
|
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)
|
setvar("cflag", flag['c']?newword(flag['c'][0], (word *)0)
|
||||||
:(word *)0);
|
:(word *)0);
|
||||||
setvar("rcname", newword(argv[0], (word *)0));
|
setvar("rcname", newword(argv[0], (word *)0));
|
||||||
|
@ -330,7 +330,7 @@ Xexit(void)
|
||||||
if(trapreq->fn){
|
if(trapreq->fn){
|
||||||
beenhere = 1;
|
beenhere = 1;
|
||||||
--runq->pc;
|
--runq->pc;
|
||||||
starval = vlook("*")->val;
|
starval = vlook(ENV_RCARGLIST)->val;
|
||||||
start(trapreq->fn, trapreq->pc, (struct var *)0);
|
start(trapreq->fn, trapreq->pc, (struct var *)0);
|
||||||
runq->local = newvar("*", runq->local);
|
runq->local = newvar("*", runq->local);
|
||||||
runq->local->val = copywords(starval, (struct word *)0);
|
runq->local->val = copywords(starval, (struct word *)0);
|
||||||
|
@ -686,7 +686,7 @@ Xdol(void)
|
||||||
if(n==0 || *t)
|
if(n==0 || *t)
|
||||||
a = copywords(vlook(s)->val, a);
|
a = copywords(vlook(s)->val, a);
|
||||||
else{
|
else{
|
||||||
star = vlook("*")->val;
|
star = vlook(ENV_RCARGLIST)->val;
|
||||||
if(star && 1<=n && n<=count(star)){
|
if(star && 1<=n && n<=count(star)){
|
||||||
while(--n) star = star->next;
|
while(--n) star = star->next;
|
||||||
a = newword(star->word, a);
|
a = newword(star->word, a);
|
||||||
|
@ -797,7 +797,7 @@ Xcount(void)
|
||||||
inttoascii(num, count(a));
|
inttoascii(num, count(a));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
a = vlook("*")->val;
|
a = vlook(ENV_RCARGLIST)->val;
|
||||||
inttoascii(num, a && 1<=n && n<=count(a)?1:0);
|
inttoascii(num, a && 1<=n && n<=count(a)?1:0);
|
||||||
}
|
}
|
||||||
poplist();
|
poplist();
|
||||||
|
@ -916,9 +916,9 @@ Xrdcmds(void)
|
||||||
flush(err);
|
flush(err);
|
||||||
nerror = 0;
|
nerror = 0;
|
||||||
if(flag['s'] && !truestatus())
|
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){
|
if(runq->iflag){
|
||||||
prompt = vlook("prompt")->val;
|
prompt = vlook(ENV_PROMPT)->val;
|
||||||
if(prompt)
|
if(prompt)
|
||||||
promptstr = prompt->word;
|
promptstr = prompt->word;
|
||||||
else
|
else
|
||||||
|
@ -975,13 +975,13 @@ Xerror1(char *s)
|
||||||
void
|
void
|
||||||
setstatus(char *s)
|
setstatus(char *s)
|
||||||
{
|
{
|
||||||
setvar("status", newword(s, (word *)0));
|
setvar(ENV_STATUS, newword(s, (word *)0));
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
getstatus(void)
|
getstatus(void)
|
||||||
{
|
{
|
||||||
var *status = vlook("status");
|
var *status = vlook(ENV_STATUS);
|
||||||
return status->val?status->val->word:"";
|
return status->val?status->val->word:"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ Xasync(void)
|
||||||
close(null);
|
close(null);
|
||||||
runq->pc = runq->code[runq->pc].i;
|
runq->pc = runq->code[runq->pc].i;
|
||||||
inttoascii(npid, pid);
|
inttoascii(npid, pid);
|
||||||
setvar("apid", newword(npid, (word *)0));
|
setvar(ENV_APID, newword(npid, (word *)0));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ psubst(io *f, uint8_t *s)
|
||||||
for(u = s; *u && '0' <= *u && *u <= '9'; u++)
|
for(u = s; *u && '0' <= *u && *u <= '9'; u++)
|
||||||
n = n*10 + *u - '0';
|
n = n*10 + *u - '0';
|
||||||
if(n && *u=='\0'){
|
if(n && *u=='\0'){
|
||||||
star = vlook("*")->val;
|
star = vlook(ENV_RCARGLIST)->val;
|
||||||
if(star && 1 <= n && n <= count(star)){
|
if(star && 1 <= n && n <= count(star)){
|
||||||
while(--n)
|
while(--n)
|
||||||
star = star->next;
|
star = star->next;
|
||||||
|
|
|
@ -111,7 +111,7 @@ pprompt(void)
|
||||||
}
|
}
|
||||||
newwdir = 0;
|
newwdir = 0;
|
||||||
}
|
}
|
||||||
prompt = vlook("prompt");
|
prompt = vlook(ENV_PROMPT);
|
||||||
if(prompt->val && prompt->val->next)
|
if(prompt->val && prompt->val->next)
|
||||||
promptstr = prompt->val->next->word;
|
promptstr = prompt->val->next->word;
|
||||||
else
|
else
|
||||||
|
|
|
@ -9,6 +9,16 @@
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
#include <lib9.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 NSIG 32
|
||||||
#define SIGINT 2
|
#define SIGINT 2
|
||||||
#define SIGQUIT 3
|
#define SIGQUIT 3
|
||||||
|
|
|
@ -111,7 +111,7 @@ searchpath(char *w)
|
||||||
|| strncmp(w, "#", 1)==0
|
|| strncmp(w, "#", 1)==0
|
||||||
|| strncmp(w, "./", 2)==0
|
|| strncmp(w, "./", 2)==0
|
||||||
|| strncmp(w, "../", 3)==0
|
|| strncmp(w, "../", 3)==0
|
||||||
|| (path = vlook("path")->val)==0)
|
|| (path = vlook(ENV_PATH)->val)==0)
|
||||||
path=&nullpath;
|
path=&nullpath;
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ execcd(void)
|
||||||
char *dir;
|
char *dir;
|
||||||
|
|
||||||
setstatus("can't cd");
|
setstatus("can't cd");
|
||||||
cdpath = vlook("cdpath")->val;
|
cdpath = vlook(ENV_CDPATH)->val;
|
||||||
switch(count(a)){
|
switch(count(a)){
|
||||||
default:
|
default:
|
||||||
pfmt(err, "Usage: cd [directory]\n");
|
pfmt(err, "Usage: cd [directory]\n");
|
||||||
|
@ -191,7 +191,7 @@ execcd(void)
|
||||||
pfmt(err, "Can't cd %s: %r\n", a->next->word);
|
pfmt(err, "Can't cd %s: %r\n", a->next->word);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
a = vlook("home")->val;
|
a = vlook(ENV_HOME)->val;
|
||||||
if(count(a)>=1){
|
if(count(a)>=1){
|
||||||
if(dochdir(a->word)>=0)
|
if(dochdir(a->word)>=0)
|
||||||
setstatus("");
|
setstatus("");
|
||||||
|
@ -236,7 +236,7 @@ execshift(void)
|
||||||
n = 1;
|
n = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
star = vlook("*");
|
star = vlook(ENV_RCARGLIST);
|
||||||
for(;n>0 && star->val;--n){
|
for(;n>0 && star->val;--n){
|
||||||
a = star->val->next;
|
a = star->val->next;
|
||||||
free(star->val->word);
|
free(star->val->word);
|
||||||
|
|
|
@ -62,7 +62,7 @@ yyerror(char *m)
|
||||||
lastdol = 0;
|
lastdol = 0;
|
||||||
while(lastc!='\n' && lastc!=EOF) advance();
|
while(lastc!='\n' && lastc!=EOF) advance();
|
||||||
nerror++;
|
nerror++;
|
||||||
setvar("status", newword(m, (word *)0));
|
setvar(ENV_STATUS, newword(m, (word *)0));
|
||||||
}
|
}
|
||||||
char *bp;
|
char *bp;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ dotrap(void)
|
||||||
int i;
|
int i;
|
||||||
struct var *trapreq;
|
struct var *trapreq;
|
||||||
struct word *starval;
|
struct word *starval;
|
||||||
starval = vlook("*")->val;
|
starval = vlook(ENV_RCARGLIST)->val;
|
||||||
while(ntrap) for(i = 0;i!=NSIG;i++) while(trap[i]){
|
while(ntrap) for(i = 0;i!=NSIG;i++) while(trap[i]){
|
||||||
--trap[i];
|
--trap[i];
|
||||||
--ntrap;
|
--ntrap;
|
||||||
|
@ -27,7 +27,7 @@ dotrap(void)
|
||||||
trapreq = vlook(Signame[i]);
|
trapreq = vlook(Signame[i]);
|
||||||
if(trapreq->fn){
|
if(trapreq->fn){
|
||||||
start(trapreq->fn, trapreq->pc, (struct var *)0);
|
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->val = copywords(starval, (struct word *)0);
|
||||||
runq->local->changed = 1;
|
runq->local->changed = 1;
|
||||||
runq->redir = runq->startredir = 0;
|
runq->redir = runq->startredir = 0;
|
||||||
|
|
Loading…
Reference in New Issue