📄 main.cpp
字号:
//////////////////////////////////////////////////////////////////////////////// Product: QHsmTst Example for DOS with Borland Turbo C++ 1.01// Last Updated for Version: 3.3.00// Date of the Last Update: Jan 24, 2007//// Q u a n t u m L e a P s// ---------------------------// innovating embedded systems//// Copyright (C) 2002-2007 Quantum Leaps, LLC. All rights reserved.//// This software may be distributed and modified under the terms of the GNU// General Public License version 2 (GPL) as published by the Free Software// Foundation and appearing in the file GPL.TXT included in the packaging of// this file. Please note that GPL Section 2[b] requires that all works based// on this software must also be made publicly available under the terms of// the GPL ("Copyleft").//// Alternatively, this software may be distributed and modified under the// terms of Quantum Leaps commercial licenses, which expressly supersede// the GPL and are specifically designed for licensees interested in// retaining the proprietary status of their code.//// Contact information:// Quantum Leaps Web site: http://www.quantum-leaps.com// e-mail: sales@quantum-leaps.com//////////////////////////////////////////////////////////////////////////////#include "qep_port.h"#include "qhsmtst.h"#include "qassert.h"#include <termios.h>#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <string.h>Q_DEFINE_THIS_FILE// local objects -------------------------------------------------------------static QHsmTst l_test;static FILE *l_outFile = (FILE *)0;struct termios l_saved;//............................................................................void Q_assert_handler(char const Q_ROM * const Q_ROM_VAR file, int line) { fprintf(stderr, "Assertion failed in %s, line %d", file, line); tcsetattr(0, TCSANOW, &l_saved); exit(-1);}//............................................................................void QHsmTst::display(char const *msg) { fprintf(l_outFile, msg);}//............................................................................void QHsmTst::exit(void) { printf("Bye, Bye!"); tcsetattr(0, TCSANOW, &l_saved); ::exit(0);}//............................................................................static void dispatch(QSignal sig) { QEvent e; Q_REQUIRE((A_SIG <= sig) && (sig <= I_SIG)); e.sig = sig; fprintf(l_outFile, "\n%c:", 'A' + sig - A_SIG); l_test.dispatch(&e); // dispatch the event}//............................................................................int main(int argc, char *argv[ ]) { tcgetattr(0, &l_saved); // save the current terminal attributes if (argc > 0) { // file name provided? l_outFile = fopen(argv[1], "w"); } if (l_outFile == (FILE *)0) { // interactive version? struct termios tio; // modified terminal attributes memcpy(&tio, &l_saved, sizeof(struct termios)); // init attributes tio.c_lflag &= ~ICANON; // disable canonical mode tcsetattr(0, TCSANOW, &tio); // set the new attributes l_outFile = stdout; printf("QHsmTst example, built on %s at %s, QEP/C++ %s\n", __DATE__, __TIME__, QEP::getVersion()); l_test.init((QEvent const *)0); // trigger initial transition for (;;) { // event loop QEvent e; char c; printf("\n>"); fflush(stdout); read(0, &c, 1); // read one character from the console printf(": "); fflush(stdout); if ('a' <= c && c <= 'i') { // in range? e.sig = (QSignal)(c - 'a' + A_SIG); } else if ('A' <= c && c <= 'I') { // in range? e.sig = (QSignal)(c - 'A' + A_SIG); } else if (c == '\33') { // the ESC key? e.sig = TERMINATE_SIG; // terminate the interactive test } else { e.sig = IGNORE_SIG; } l_test.dispatch(&e); // dispatch the event } } else { // batch version printf("QHsmTst, output saved to %s\n", argv[1]); fprintf(l_outFile, "QHsmTst example, QEP/C++ %s\n", QEP::getVersion()); l_test.init((QEvent const *)0); // trigger initial transition // dynamic transitions dispatch(A_SIG); dispatch(B_SIG); dispatch(D_SIG); dispatch(E_SIG); dispatch(I_SIG); dispatch(F_SIG); dispatch(I_SIG); dispatch(I_SIG); dispatch(F_SIG); dispatch(A_SIG); dispatch(B_SIG); dispatch(D_SIG); dispatch(D_SIG); dispatch(E_SIG); dispatch(G_SIG); dispatch(H_SIG); dispatch(H_SIG); dispatch(C_SIG); dispatch(G_SIG); dispatch(C_SIG); dispatch(C_SIG); // static transitions dispatch(C_SIG); dispatch(A_SIG); dispatch(A_SIG); dispatch(B_SIG); dispatch(B_SIG); dispatch(D_SIG); dispatch(D_SIG); dispatch(E_SIG); dispatch(I_SIG); dispatch(F_SIG); dispatch(I_SIG); dispatch(I_SIG); dispatch(F_SIG); dispatch(A_SIG); dispatch(A_SIG); dispatch(B_SIG); dispatch(B_SIG); dispatch(D_SIG); dispatch(D_SIG); dispatch(D_SIG); dispatch(D_SIG); dispatch(E_SIG); dispatch(G_SIG); dispatch(H_SIG); dispatch(G_SIG); dispatch(H_SIG); dispatch(F_SIG); dispatch(H_SIG); dispatch(F_SIG); dispatch(C_SIG); dispatch(G_SIG); dispatch(G_SIG); fclose(l_outFile); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -