50 #define CO_STATEMENT 1 67 #define CONTROLSTACKSIZE 256 94 static struct control *
findlabel(
char*,
struct control*);
100 static void dodump(
struct control*);
154 for (ww = wl; wl; wl = wn) {
156 if (*wl->wl_word !=
'-')
158 else if (strchr(wl->wl_word,
'f') || strchr(wl->wl_word,
'd'))
160 else if (strchr(wl->wl_word,
'p') || strchr(wl->wl_word,
't'))
162 else if (strchr(wl->wl_word,
'a'))
164 else if (strchr(wl->wl_word,
'b'))
218 if (!print && !
remove && !add && !bind)
243 fprintf(
cp_err,
"Error: %s not found, no block added.\n",fname);
303 if (!name || *name ==
'\0')
return;
350 for (ww = wlist; ww; ww = ww->
wl_next)
353 "cp_evloop: Internal Error: NULL word pointer.\n");
396 #define newblock cur->co_children = alloc(struct control); \ 397 cur->co_children->co_parent = cur; \ 398 cur = cur->co_children; \ 399 cur->co_type = CO_UNFILLED; 412 if (
eq(wl->wl_word,
"while")) {
416 fprintf(stderr,
"Error: missing while condition.\n");
420 else if (
eq(wl->wl_word,
"dowhile")) {
424 fprintf(stderr,
"Error: missing dowhile condition.\n");
428 else if (
eq(wl->wl_word,
"repeat")) {
445 "Error: can't repeat a negative number of times.\n");
452 "Error: bad repeat argument %s.\n",s ? s :
"");
458 else if (
eq(wl->wl_word,
"if")) {
462 fprintf(stderr,
"Error: missing if condition.\n");
466 else if (
eq(wl->wl_word,
"foreach")) {
475 fprintf(stderr,
"Error: missing foreach variable.\n");
481 else if (
eq(wl->wl_word,
"label")) {
487 if (wl->wl_next->wl_next)
489 "Warning: ignored extra junk after label.\n");
492 fprintf(stderr,
"Error: missing label.\n");
494 else if (
eq(wl->wl_word,
"goto")) {
502 if (wl->wl_next->wl_next)
504 "Warning: ignored extra junk after goto.\n");
507 fprintf(stderr,
"Error: missing label.\n");
509 else if (
eq(wl->wl_word,
"continue")) {
513 if (wl->wl_next->wl_next)
515 "Warning: ignored extra junk after continue %d.\n",
521 else if (
eq(wl->wl_word,
"break")) {
525 if (wl->wl_next->wl_next)
527 "Warning: ignored extra junk after break %d.\n",
533 else if (
eq(wl->wl_word,
"end")) {
536 fprintf(stderr,
"Error: no block to end.\n");
552 else if (
eq(wl->wl_word,
"else")) {
555 fprintf(stderr,
"Error: misplaced else.\n");
594 "Error: break not in loop or too many break levels given.\n");
599 "Error: continue not in loop or too many continue levels given.\n");
606 "Error: label %s not found.\n",ri.
rt.
label);
635 struct control *ch, *cn =
NULL;
639 switch (bl->co_type) {
642 while (bl->co_cond &&
cp_istrue(bl->co_cond)) {
726 }
while (bl->co_cond &&
cp_istrue(bl->co_cond));
730 while ((bl->co_numtimes > 0) ||
731 (bl->co_numtimes == -1)) {
732 if (bl->co_numtimes != -1)
777 if (bl->co_cond &&
cp_istrue(bl->co_cond)) {
821 for (wl = ww; wl; wl = wl->
wl_next) {
867 if (bl->co_numtimes > 0) {
868 info->
rt.
num = bl->co_numtimes;
872 fprintf(
cp_err,
"Warning: break %d a no-op\n",
877 if (bl->co_numtimes > 0) {
878 info->
rt.
num = bl->co_numtimes;
882 fprintf(
cp_err,
"Warning: continue %d a no-op\n",
908 fprintf(
cp_err,
"Warning: ignoring previous error.\n");
913 "doblock: Internal Error: bad block type %d.\n",
943 if (!name || *name ==
'\0')
return;
945 fprintf(
cp_err,
"Error: block is empty, not added.\n");
979 fprintf(
cp_err,
"Error: named block %s not found.\n",name);
995 static struct control *
1014 struct control *cntrl;
1016 struct control *
cc, *cd;
1018 for (cc = cntrl; cc; cc = cd) {
1038 fprintf(
cp_err,
"Warning: EOF before block terminated\n");
1040 if (!control[
stackp])
break;
1058 fprintf(
cp_err,
"cp_popcontrol: Internal Error: stack empty\n");
1071 fprintf(
cp_err,
"Error: stack overflow -- max depth = %d\n",
1112 struct comm *command;
1115 FILE *lastin, *lastout, *lasterr;
1119 printf(
"docommand ");
1121 (void) putc(
'\n', stdout);
1131 pwlist(wlist,
"After variable substitution");
1134 pwlist(wlist,
"After backquote substitution");
1137 pwlist(wlist,
"After globbing");
1139 if (!wlist || !wlist->wl_word)
1145 for (nextc = wlist; nextc; nextc = nextc->
wl_next)
1156 if (nextc == wlist) {
1168 if (wlist ==
NULL) {
1218 fprintf(
cp_err,
"%s: no such command available in %s\n",
1224 fprintf(
cp_err,
"%s: command available only in spice\n",s);
1237 if (nargs < command->co_minargs) {
1239 (*command->
co_argfn) (wlist->wl_next, command);
1242 fprintf(
cp_err,
"%s: too few args.\n", s);
1246 fprintf(
cp_err,
"%s: too many args.\n", s);
1249 (*command->
co_func) (wlist->wl_next);
1254 wlist->wl_prev = ee;
1260 }
while (nextc && wlist);
1268 static struct comm *
1273 static void *comhash;
1296 static char buf[64];
1300 fprintf(
cp_err,
"calling getcommand %s\n",
1301 string ?
string :
"");
1308 for (j = 0; j < i; j++)
1319 printf(
"getcommand ");
1321 (void) putc(
'\n', stdout);
1339 fprintf(
cp_err,
"%s : [ ", name);
1340 for (wl = wlist; wl; wl = wl->
wl_next)
1365 #define tab(num) for (i = 0; i < num; i++) out_send(" "); 1375 switch (cc->co_type) {
1400 if (cc->co_numtimes != -1)
1437 out_printf(
"foreach %s ", cc->co_foreachvar);
1449 if (cc->co_numtimes != 1)
1456 if (cc->co_numtimes != 1)
1464 out_printf(
"label %s\n", cc->co_text->wl_word);
1468 out_printf(
"goto %s\n", cc->co_text->wl_word);
static char buf[MAXPROMPT]
static struct control * findlabel()
struct control * co_elseblock
bool cp_isblockdef(char *name)
static struct control * cend[CONTROLSTACKSIZE]
int cp_evloop(char *string)
struct wordlist * wl_prev
static char * noredirect[]
struct control * co_children
static struct comm * findcom()
static wordlist * quicksub()
void cp_freeblock(char *name)
void cp_addblock(char *name, wordlist *wl)
struct wordlist * wl_next
void cp_execcontrol(char *name)
static wordlist * getcommand()
struct control * co_parent
static void freecontrol()
void com_cdump(wordlist *wl)
void com_codeblock(wordlist *wl)