#include #include #include #include #include "quint.h" #include "tape.h" #include "macro.h" #include "getcmd.h" #include "help.h" #include "watch.h" #include "tm.h" /* set (add) a new comment */ void get_comment(struct qlist *lptr) { struct quint *qptr; int status; while(1) { getcmd("for which quint? (two characters): ",ans); if ( (iscmd (ans,"ex*it")) || (iscmd (ans,"quit")) || iscmd(ans,".") ) break; else if (iscmd(ans,"#") ) flushcmd("","",0); if ( (qptr = (find_quint(lptr, ans[0],ans[1],&status))) == NULL ) message(ans,status); else { getcmd("enter comment (string): ", ans); quint_comment(qptr, ans); break; } } } /* looping to get answer to 'set what?' */ void set(struct qlist *lptr, struct tape *tptr, struct maclist *mptr) { int status; int intinput; extern int max_step; while(1) { getcmd("set what? ",ans); if ( ans[0] == 0 ); /* flush invalid input */ else if ( iscmd (ans,"ex*it") || iscmd (ans,"quit") || iscmd(ans,".") ) break; else if (iscmd (ans,"tr*ace")) { while(1) { getcmd("set trace 'tape', 'descriptor' or 'off'? ",ans); if ( (iscmd (ans,"ex*it")) || (iscmd(ans,"quit")) || iscmd(ans,".") ) break; else if ( iscmd(ans,"o*ff") ) { trace = 0; break; } else if ( iscmd(ans,"t*ape") ) { trace = 1; break; } else if ( iscmd(ans,"d*escriptor") ) { trace = 2; break; } else if (iscmd(ans,"h*elp") || iscmd(ans,"?") ) get_help("tm set trace"); else flushcmd("invalid input: ",ans,1); } break; } else if (iscmd (ans,"de*bug")) { while(1) { getcmd("set debug 'on' or 'off'? ",ans); if ( (iscmd (ans,"ex*it")) || (iscmd(ans,"quit")) || iscmd(ans,".") ) break; else if ( iscmd(ans,"off") ) { debug = 0; break; } else if ( iscmd(ans,"on") ) { debug = 1; break; } else flushcmd("invalid input: ",ans,1); } break; } else if (iscmd (ans,"d*isplay")) { /* this needs to be moved to a function */ while(1) { getcmd("set display what? ",ans); if ( (iscmd (ans,"ex*it")) || (iscmd (ans,"quit")) || iscmd(ans,".") ) break; if ( iscmd(ans,"com*ments") ) { /* show the comments when listing quintuples*/ while(1) { getcmd("set display 'on' or 'off'? ",ans); if ( (iscmd (ans,"ex*it")) || (iscmd (ans,"quit")) || iscmd(ans,".") ) break; if ( iscmd(ans,"on")) {lptr->show_comment=1; break;} else if ( iscmd(ans,"off") ) {lptr->show_comment=0; break;} else flushcmd("set display 'on' or 'off'? ",ans,1); } break; } else if ( iscmd(ans,"it*erations") ) { /* show the number of times each quint was used*/ while(1) { getcmd("'on' or 'off' ",ans); if ( (iscmd (ans,"ex*it")) || (iscmd (ans,"quit")) || iscmd(ans,".") ) break; if ( iscmd(ans,"on")) {lptr->show_iter=1; break;} else if ( iscmd(ans,"off") ) {lptr->show_iter=0; break;} else flushcmd("'on' or 'off' or exit ",ans,1); } break; } else if (iscmd(ans,"none") ) { lptr->show_iter = 0; lptr->show_comment = 0; break; } else if (iscmd(ans,"h*elp") || iscmd(ans,"?") ) get_help("tm set display"); else flushcmd("invalid or ambiguous set command -> ",ans,1); } break; } else if (iscmd (ans,"max*_step")) { if (getint("enter maximum steps (integer): ",&intinput) == OK) max_step = intinput; break; } else if (iscmd (ans,"t*ape")) { get_new_tape(tptr,&status); if ( status != OK ) message("",status); else { tm_state = '0'; tm_num_exe = 0; zero_quint_iter(lptr); } break; } else if (iscmd (ans,"mac*ro")) { /* get a macro from standard input */ del_all_mac(mptr, &status); set_mac(mptr, &status); break; } else if (iscmd(ans,"sta*te") ) { getcmd("enter new state (a character): ", ans); tm_state=ans[0]; break; } else if (iscmd(ans,"sym*bol") ) { if (tptr->root == NULL) { flushcmd("there is no tape.","",1); return; } getcmd("enter new tape symbol (a character): ",ans); if (tptr->head != NULL) tptr->head->Csymbol = ans[0]; break; } else if (iscmd(ans,"com*ment") ) { /* set a comment for some quintuple */ get_comment(lptr); break; } else if (iscmd(ans,"w*atch")) { set_watch(); break; } else if (iscmd(ans,"br*eak")) { set_break(lptr,&status); if ( status != OK ) message("",status); break; } else if ( iscmd(ans,"?") || iscmd (ans,"h*elp") ) get_help("tm set"); else if (iscmd(ans,"#") ) flushcmd("","",0); else flushcmd("invalid or ambiguous set command -> ",ans,1); } } void show(struct qlist *lptr, struct tape *tptr, struct maclist *mptr) { struct quint *qptr; int status; extern struct quint *lastquint, *nextquint; while(1) { getcmd("show what? ",ans); if ( ans[0] == 0 ); /* flush invalid input */ else if (iscmd (ans,"e*xit") || iscmd(ans,".") ) break; else if (iscmd (ans,"q*uintuple")) { while(1) { getcmd("which quintuple? (two characters) ",ans); if ( iscmd (ans,"exit") || iscmd (ans,"quit") || iscmd (ans,".") ) break; if ( strlen(ans) != 2) { flushcmd("need to enter two characters.","",1); continue; } if ( ( qptr = find_quint(lptr,ans[0],ans[1],&status) ) == NULL ) { message(ans,status); break; } else { print_quint(qptr,lptr); break; } } break; } else if (iscmd (ans,"li*st")) { list_quints(lptr, &status); /*show the quintuples*/ if ( status != OK ) { message("",status); break; } } else if (iscmd (ans,"la*st")) { if (lastquint != NULL) print_quint(lastquint,lptr); else printf("%s\n","(none)"); break; } else if (iscmd (ans,"ne*xt")) { if (nextquint != NULL) print_quint(nextquint,lptr); else printf("%s\n","(none)"); break; } else if (iscmd (ans,"sta*te")) { printf("current machine state is %c\n",tm_state); break; } else if (iscmd(ans,"t*ape")) { show_tape(tptr,&status); if (status != OK) message("",status); break; } else if (iscmd (ans,"de*bug")) { if (debug) printf("debug mode is 'on'\n"); else printf("debug mode is 'off'\n"); break; } else if (iscmd (ans,"f*ilename")) { printf("current quintuple file is %s\n",filename); break; } else if (iscmd (ans,"mac*ro")) { list_mac(mptr, &status); if (status != OK) message("",status); break; } else if (iscmd (ans,"co*unt")) { printf("number of executions performed: %d\n",tm_num_exe); break; } else if (iscmd (ans,"max*_step")) { printf("maximum steps taken during 'go' is %d\n",max_step); break; } else if (iscmd (ans,"le*ngth")) { printf("length of the tape is %d symbols.\n",tptr->tape_len ); break; } else if (iscmd (ans,"hea*der")) { printf("%s\n",lptr->header); break; } else if (iscmd(ans,"w*atch")) { show_watch(); break; } else if (iscmd(ans,"br*eak")) { show_break(lptr,&status); if ( status != OK ) message("",status); break; } else if ( iscmd(ans,"?") || iscmd (ans,"hel*p") ) get_help("tm show"); else if (iscmd(ans,"#") ) flushcmd("","",0); else flushcmd("invalid or ambiguous show command -> ", ans,1); } } /* add a quintuple to the list */ void add(struct qlist *lptr) { int status; while(1) { getcmd("add what? ('quint' or 'comment') ",ans); if ( ans[0] == 0 ); /* flush invalid input */ else if ((iscmd (ans,"ex*it")) || (iscmd (ans,"quit")) || iscmd(ans,".")) break; else if (iscmd (ans,"qu*intuple")) { getcmd("enter quintuple (string): ",ans); if ( new_quint(lptr, ans,"",&status) == NULL ) message(ans,status); break; } else if (iscmd (ans,"co*mment")) { get_comment(lptr); break; } else if (iscmd(ans,"#") ) flushcmd("","",0); else flushcmd("invalid or ambiguous add command -> ",ans,1); } }