* Copyright (c) 1991 The Regents of the University of California.
* This module is believed to contain source code proprietary to AT&T.
* Use and redistribution is subject to the Berkeley Software License
* Agreement and your Software Agreement with AT&T (Western Electric).
static char sccsid
[] = "@(#)command.c 5.5 (Berkeley) 4/4/91";
extern char BADEQ
[]; /* "unexpected `='" */
extern char NOMATCH
[]; /* "cannot locate value" */
extern char BADVAR
[]; /* "bad variable" */
extern char BADCOM
[]; /* "bad command" */
extern char NOFORK
[]; /* "try again" */
* executing is used in main() to see if it is necessary to
* delete any breakpoints that might have been set; if an
* error occurs while a subprocess command is running, executing
/* lastcom remembers the previous command */
int star
; /* true iff it was in alternate space */
* Execute the given command buffer.
* If defcom is nonzero, it is used as the default command.
* Pick up the optional first expression (`dot'),
* then, if the next character is a comma, pick up
* the second optional expression (`ecount').
ditto
= dot
= edot
= expv
;
edot
= dot
; /* probably equal, but possibly truncating */
* Pick up the command. If there is no command, do the
* previous (or default) command, and if no dot was given,
if ((reg
= reglookup()) != NULL
) {
prints("register write failed");
if ((c
= varlookup(rdc())) != -1)
* Perform a format-based command (one in ? / or =).
/* special commands m, lL, wW do not operate in SP_NONE (`=') */
void mcom(), lcom(), wcom();
{ 'l', lcom
}, { 'L', lcom
},
{ 'w', wcom
}, { 'W', wcom
},
static char stformat
[LINELEN
] = "X\"= \"^i";
static char eqformat
[LINELEN
] = "z";
* Are we operating in the alternate `star' space?
/* print as data for instr, and vice versa */
ptype
= (SP_DATA
+ SP_INSTR
) - ptype
;
* Check for the special commands first.
for (f
= fcmd
; f
->c
; f
++) {
(*f
->fn
)(space
, ptype
, isupper(c
));
getformat(eqcom
? eqformat
: stformat
, LINELEN
);
scanform(!eqcom
, eqcom
? eqformat
: stformat
, space
, ptype
);
* Set a map (?m, /m commands).
mcom(space
, ptype
, fullword
)
int space
, ptype
, fullword
;
register struct map
*smap
;
smap
= space
& SP_DATA
? &datmap
: &txtmap
;
mm
= space
& SP_STAR
? &smap
->m2
: &smap
->m1
;
* Locate a value (l, L commands).
lcom(space
, ptype
, fullword
)
int space
, ptype
, fullword
;
register expr_t val
, mask
;
(void) adbread(space
, dot
, &w
, sizeof(w
));
if (iserr() || (w
& mask
) == val
)
(void) adbread(space
, dot
, &hw
, sizeof(hw
));
if (iserr() || (hw
& mask
) == val
)
dot
= inkdot(sizeof(hw
));
psymoff("%R", dot
, ptype
, maxoff
, "");
* Write new values (w, W).
wcom(space
, ptype
, fullword
)
int space
, ptype
, fullword
;
showdot(fullword
, space
, ptype
); /* also advances */
(void) adbwrite(space
, dot
, &expv
, sizeof(expv
));
(void) adbwrite(space
, dot
, &hw
, sizeof(hw
));
showdot(fullword
, space
, ptype
);
} while (oexpr() && !iserr());
* THE vfork CODE BELOW IS CURRENTLY BROKEN
* MUST CHANGE signal TO sigvec BELOW
char *getenv(), *eshell
= getenv("SHELL");
while (readchar() != '\n')
if ((unixpid
= vfork()) == 0) {
(void) signal(SIGINT
, sigint
);
(void) signal(SIGQUIT
, sigquit
);
execl(eshell
, "sh", "-c", argp
, (char *)NULL
);
(void) signal(SIGINT
, SIG_IGN
);
while ((rc
= wait(&status
)) != unixpid
&& rc
!= -1)
(void) signal(SIGINT
, intcatch
);
* Read a format into the given buffer. If nothing is
* read, leave the buffer alone.
register int c
, quote
= 0;
while ((c
= readchar()), quote
? c
!= '\n' : !eol(c
)) {
if (p
!= buf
) /* nonempty */
* Convert a (one-character) variable name to an index, or -1 for
return (isupper(name
) ? name
- 'A' + 10 : name
- 'a' + 10);
* If the text at the current input point matches a register name,
* consume that text and return a pointer to the register; otherwise
* leave it unconsumed and return NULL.
register struct reglist
*p
;
register char *a
, *b
, c0
, c1
;
extern struct reglist reglist
[];
for (p
= reglist
; (a
= p
->r_name
) != NULL
; p
++) {
if (*a
++ != c0
|| *a
++ != c1
)
if (*a
== 0) { /* name matched: stop short */