?? main.c
字號:
/****************************************************************************** Product: Quantum Calculator Example* Version: Compatible with QEP/C 3.x.yy* Updated: Oct 24, 2005** Copyright (C) 2002-2005 Quantum Leaps, LLC. All rights reserved.** This example is part of the Quantum Leaps QP/C software, and 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 in conjunction* with a valid QP/C Quantum Leaps commercial license. Quantum Leaps* commercial licenses are designed for users who want to retain proprietary* status of their code. The users who license this software under one of* Quantum Leaps commercial licenses do not use this software under the GPL* and therefore are not subject to any of its terms.** Contact information:* Quantum Leaps Web site: http://www.quantum-leaps.com* Quantum Leaps licensing: http://www.quantum-leaps.com/licensing* Quantum Leaps products: http://www.quantum-leaps.com/products* e-mail: sales@quantum-leaps.com*****************************************************************************/#include "qep_port.h"#include "qcalc.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 QCalc l_qcalc; /* quantum calculator hierarchical state machine */struct termios l_saved; /* structure with saved terminal attributes *//*..........................................................................*/int main() { struct termios tio; /* modified terminal attributes */ tcgetattr(0, &l_saved); /* save the current terminal attributes */ tcgetattr(0, &tio); /* get the current terminal attributes */ tio.c_lflag &= ~ICANON; /* disable canonical mode */ tcsetattr(0, TCSANOW, &tio); /* set the new attributes */ QCalc_ctor(&l_qcalc); printf("QCalc example, built on %s at %s,\n" "QEP/C: %s.\nPress ESC to quit...\n", __DATE__, __TIME__, QEP_getVersion()); QHsm_init((QHsm *)&l_qcalc, (QEvent *)0); /* trigger initial tran. */ for (;;) { /* event loop */ QCalcEvt e; printf("\n[%s] >", QCalc_getDisplay(&l_qcalc)); /* show the display */ fflush(stdout); read(0, &e.keyId, 1); /* read one character from the console */ printf(": "); fflush(stdout); switch (e.keyId) { case 'c': /* intentionally fall through */ case 'C': { ((QEvent *)&e)->sig = C_SIG; break; } case 'e': /* intentionally fall through */ case 'E': { ((QEvent *)&e)->sig = CE_SIG; break; } case '0': { ((QEvent *)&e)->sig = DIGIT_0_SIG; break; } case '1': /* intentionally fall through */ case '2': /* intentionally fall through */ case '3': /* intentionally fall through */ case '4': /* intentionally fall through */ case '5': /* intentionally fall through */ case '6': /* intentionally fall through */ case '7': /* intentionally fall through */ case '8': /* intentionally fall through */ case '9': { ((QEvent *)&e)->sig = DIGIT_1_9_SIG; break; } case '.': { ((QEvent *)&e)->sig = POINT_SIG; break; } case '+': /* intentionally fall through */ case '-': /* intentionally fall through */ case '*': /* intentionally fall through */ case '/': { ((QEvent *)&e)->sig = OPER_SIG; break; } case '=': /* intentionally fall through */ case '\r': { /* Enter key */ ((QEvent *)&e)->sig = EQUALS_SIG; break; } case '\33': { /* ESC key */ ((QEvent *)&e)->sig = TERMINATE_SIG; break; } default: { ((QEvent *)&e)->sig = IGNORE_SIG; break; } } QHsm_dispatch((QHsm *)&l_qcalc, (QEvent *)&e);/* dispatch the event */ } return 0;}/*..........................................................................*/void Q_assert_handler(char const *file, int line) { fprintf(stderr, "Assertion failed in %s, line %d", file, line); exit(-1);}/*..........................................................................*/void QCalc_updateState(QCalc *me, char const *s) { (void)me; /* suppress the "unreferenced parameter" warning */ printf("%s;", s);}/*..........................................................................*/void QCalc_exit(QCalc *me) { (void)me; /* suppress the "unreferenced parameter" warning */ printf("Bye, Bye!"); tcsetattr(0, TCSANOW, &l_saved);/*restore the saved terminal attributes */ exit(0);}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -