#include #include "quint.h" #include "getcmd.h" #include "help.h" #include "tm.h" void set_watch() { while(1) { getcmd("set watch what? ",ans); if (iscmd(ans,"exit") || iscmd(ans,"quit") || iscmd(ans,".")) break; else if (iscmd(ans,"sy*mbol")) { getcmd("set watch which symbol? ",ans); if (iscmd(ans,"exit") || iscmd(ans,"quit") || iscmd(ans,".")) ; else watch_symbol[++nwatchsymbol] = ans[0]; break; } else if (iscmd(ans,"st*ate")) { getcmd("set watch which state? ",ans); if (iscmd(ans,"exit") || iscmd(ans,"quit") || iscmd(ans,".")) ; else watch_state[++nwatchstate] = ans[0]; break; } else if (iscmd(ans,"h*elp") || iscmd(ans,"?") ) get_help("tm set watch"); else if (iscmd(ans,"#") ) flushcmd("","",0); else flushcmd("invalid watch-point type -> ",ans,1); } } void cancel_watch() { int i; int ptr; ptr = -1; while(1) { getcmd("cancel watch what? ",ans); if (iscmd(ans,"exit") || iscmd(ans,"quit") || iscmd(ans,".")) break; else if (iscmd(ans,"sy*mbol")) { getcmd("cancel watch which symbol? ",ans); if (iscmd(ans,"exit") || iscmd(ans,"quit") || iscmd(ans,".")) ; else { for (i=0; i<=nwatchsymbol; i++) if (ans[0] == watch_symbol[i]) ptr = i; if (ptr == -1) printf("'watch' not set for %c\n",ans[0]); else { for (i=ptr; i<=nwatchsymbol; i++) watch_symbol[i] = watch_symbol[i+1]; nwatchsymbol--; } } break; } else if (iscmd(ans,"st*ate")) { getcmd("cancel watch which state? ",ans); if (iscmd(ans,"exit") || iscmd(ans,"quit") || iscmd(ans,".")) ; else { for (i=0; i<=nwatchstate; i++) if (ans[0] == watch_state[i]) ptr = i; if (ptr == -1) printf("'watch' not set for %c\n",ans[0]); else { for (i=ptr; i<=nwatchstate; i++) watch_state[i] = watch_state[i+1]; nwatchstate--; } } break; } else if (iscmd(ans,"h*elp") || iscmd(ans,"?") ) get_help("tm cancel watch"); else if (iscmd(ans,"#") ) flushcmd("","",0); else flushcmd("invalid watch-point type -> ",ans,1); } } void set_break(struct qlist *qlst, int *status) { struct quint *qptr; if (qlst->root == NULL) { *status = NO_QLIST; return; } qptr = qlst->root->nextptr; if (qptr == NULL) { *status = EMPTY_QLIST; return; } getcmd("which quintuple? (enter two characters) ",ans); if ( iscmd (ans,"exit") || iscmd (ans,"quit") || iscmd (ans,".") ) { *status = OK; return; } if ( ( qptr = find_quint(qlst,ans[0],ans[1],status) ) == NULL ) return; if (qptr->brk == 1) printf("break was already set.\n"); else qptr->brk = 1; *status = OK; } void cancel_break(struct qlist *qlst, int *status) { struct quint *qptr; if (qlst->root == NULL) { *status = NO_QLIST; return; } qptr = qlst->root->nextptr; if (qptr == NULL) { *status = EMPTY_QLIST; return; } getcmd("which quintuple? (enter two characters) ",ans); if ( iscmd (ans,"exit") || iscmd (ans,"quit") || iscmd (ans,".") ) { *status = OK; return; } if ( ( qptr = find_quint(qlst,ans[0],ans[1],status) ) == NULL ) return; if (qptr->brk == 0) printf("break was not set for that quintuple.\n"); else qptr->brk = 0; *status = OK; } void show_watch() { int i, gotone=0; extern int debug; if (nwatchstate > -1) { printf("watch is set for states: "); for (i=0; i<=nwatchstate; i++) printf("%c ",watch_state[i]); printf("\n"); gotone = 1; } if (nwatchsymbol > -1) { printf("watch is set for symbols: "); for (i=0; i<=nwatchsymbol; i++) printf("%c ",watch_symbol[i]); printf("\n"); gotone = 1; } if (!gotone) printf("no watch points are set. \n"); else if (debug==0) printf(" (debug mode is off)\n"); } void show_break(struct qlist *qlst, int *status) { struct quint *qptr; int gotone=0; if (qlst->root == NULL) { *status = NO_QLIST; return; } qptr = qlst->root->nextptr; if (qptr == NULL) { *status = EMPTY_QLIST; return; } while (qptr != NULL) { if (qptr->brk == 1) { if (!gotone) { gotone = 1; printf("breaks are set for quintple(s): \n"); } printf(" (%c,%c,%c,%c,%c)\n",qptr->current_state, qptr->current_symbol, qptr->next_symbol, qptr->next_state, qptr->move); } qptr = qptr->nextptr; } if (!gotone) printf("no breaks are set.\n"); else if (debug==0) printf(" (debug mode is off)\n"); } /* cancel a break point or a watch point */ void cancel(struct qlist *lptr) { int status; while(1) { getcmd("cancel what? ('break' or 'watch') ",ans); if ( ans[0] == 0 ); /* flush invalid input */ else if ((iscmd (ans,"ex*it")) || (iscmd (ans,"quit")) || iscmd(ans,".")) break; else if (iscmd(ans,"b*reak")) { cancel_break(lptr,&status); if ( status != OK ) message("",status); break; } else if (iscmd(ans,"w*atch")) { cancel_watch(); break; } else if (iscmd(ans,"#") ) flushcmd("","",0); else flushcmd("invalid input -> ",ans,1); } }