⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calc.c

📁 事件驱动程序设计很好的框架
💻 C
📖 第 1 页 / 共 2 页
字号:
    }    return Q_SUPER(&Calc_on);}/*..........................................................................*/QState Calc_operand1(Calc *me, QEvent const *e) {    switch (e->sig) {        case Q_ENTRY_SIG: {            BSP_message("operand1-ENTRY;");            return Q_HANDLED();        }        case Q_EXIT_SIG: {            BSP_message("operand1-EXIT;");            return Q_HANDLED();        }        case CE_SIG: {            BSP_clear();            return Q_TRAN(&Calc_begin);        }        case OPER_SIG: {            me->operand1 = BSP_get_value();            me->operator = ((CalcEvt const *)e)->key_code;            return Q_TRAN(&Calc_opEntered);        }    }    return Q_SUPER(&Calc_on);}/*..........................................................................*/QState Calc_zero1(Calc *me, QEvent const *e) {    switch (e->sig) {        case Q_ENTRY_SIG: {            BSP_message("zero1-ENTRY;");            return Q_HANDLED();        }        case Q_EXIT_SIG: {            BSP_message("zero1-EXIT;");            return Q_HANDLED();        }        case DIGIT_0_SIG: {            ;                                          /* explicitly ignore */            return Q_HANDLED();        }        case DIGIT_1_9_SIG: {            BSP_insert(((CalcEvt const *)e)->key_code);            return Q_TRAN(&Calc_int1);        }        case POINT_SIG: {            BSP_insert(((CalcEvt const *)e)->key_code);            return Q_TRAN(&Calc_frac1);        }    }    return Q_SUPER(&Calc_on);}/*..........................................................................*/QState Calc_int1(Calc *me, QEvent const *e) {    switch (e->sig) {        case Q_ENTRY_SIG: {            BSP_message("int1-ENTRY;");            return Q_HANDLED();        }        case Q_EXIT_SIG: {            BSP_message("int1-EXIT;");            return Q_HANDLED();        }        case DIGIT_0_SIG:                     /* intentionally fall through */        case DIGIT_1_9_SIG: {            BSP_insert(((CalcEvt const *)e)->key_code);            return Q_HANDLED();        }        case POINT_SIG: {            BSP_insert(((CalcEvt const *)e)->key_code);            return Q_TRAN(&Calc_frac1);        }    }    return Q_SUPER(&Calc_operand1);}/*..........................................................................*/QState Calc_frac1(Calc *me, QEvent const *e) {    (void)me;               /* avoid compiler warning about unused argument */    switch (e->sig) {        case Q_ENTRY_SIG: {            BSP_message("frac1-ENTRY;");            return Q_HANDLED();        }        case Q_EXIT_SIG: {            BSP_message("frac1-EXIT;");            return Q_HANDLED();        }        case DIGIT_0_SIG:                     /* intentionally fall through */        case DIGIT_1_9_SIG: {            BSP_insert(((CalcEvt const *)e)->key_code);            return Q_HANDLED();        }        case POINT_SIG: {            ;                                          /* explicitly ignore */            return Q_HANDLED();        }    }    return Q_SUPER(&Calc_operand1);}/*..........................................................................*/QState Calc_opEntered(Calc *me, QEvent const *e) {    switch (e->sig) {        case Q_ENTRY_SIG: {            BSP_message("opEntered-ENTRY;");            return Q_HANDLED();        }        case Q_EXIT_SIG: {            BSP_message("opEntered-EXIT;");            return Q_HANDLED();        }        case OPER_SIG: {            if (((CalcEvt const *)e)->key_code == KEY_MINUS) {                BSP_clear();                return Q_TRAN(&Calc_negated2);            }            break;        }        case DIGIT_0_SIG: {            BSP_clear();            return Q_TRAN(&Calc_zero2);        }        case DIGIT_1_9_SIG: {            BSP_clear();            BSP_insert(((CalcEvt const *)e)->key_code);            return Q_TRAN(&Calc_int2);        }        case POINT_SIG: {            BSP_clear();            BSP_insert((int)'0');            BSP_insert((int)'.');            return Q_TRAN(&Calc_frac2);        }    }    return Q_SUPER(&Calc_on);}/*..........................................................................*/QState Calc_operand2(Calc *me, QEvent const *e) {    switch (e->sig) {        case Q_ENTRY_SIG: {            BSP_message("operand2-ENTRY;");            return Q_HANDLED();        }        case Q_EXIT_SIG: {            BSP_message("operand2-EXIT;");            return Q_HANDLED();        }        case CE_SIG: {            BSP_clear();            return Q_TRAN(&Calc_opEntered);        }        case OPER_SIG: {            if (BSP_eval(me->operand1, me->operator)) {                me->operand1 = BSP_get_value();                me->operator = ((CalcEvt const *)e)->key_code;                return Q_TRAN(&Calc_opEntered);            }            else {                return Q_TRAN(&Calc_error);            }        }        case EQUALS_SIG: {            if (BSP_eval(me->operand1, me->operator)) {                return Q_TRAN(&Calc_result);            }            else {                return Q_TRAN(&Calc_error);            }        }    }    return Q_SUPER(&Calc_on);}/*..........................................................................*/QState Calc_zero2(Calc *me, QEvent const *e) {    switch (e->sig) {        case Q_ENTRY_SIG: {            BSP_message("zero2-ENTRY;");            return Q_HANDLED();        }        case Q_EXIT_SIG: {            BSP_message("zero2-EXIT;");            return Q_HANDLED();        }        case DIGIT_0_SIG: {            ;                                          /* explicitly ignore */            return Q_HANDLED();        }        case DIGIT_1_9_SIG: {            BSP_insert(((CalcEvt const *)e)->key_code);            return Q_TRAN(&Calc_int2);        }        case POINT_SIG: {            BSP_insert(((CalcEvt const *)e)->key_code);            return Q_TRAN(&Calc_frac2);        }    }    return Q_SUPER(&Calc_operand2);}/*..........................................................................*/QState Calc_int2(Calc *me, QEvent const *e) {    switch (e->sig) {        case Q_ENTRY_SIG: {            BSP_message("int2-ENTRY;");            return Q_HANDLED();        }        case Q_EXIT_SIG: {            BSP_message("int2-EXIT;");            return Q_HANDLED();        }        case DIGIT_0_SIG:                     /* intentionally fall through */        case DIGIT_1_9_SIG: {            BSP_insert(((CalcEvt const *)e)->key_code);            return Q_HANDLED();        }        case POINT_SIG: {            BSP_insert(((CalcEvt const *)e)->key_code);            return Q_TRAN(&Calc_frac2);        }    }    return Q_SUPER(&Calc_operand2);}/*..........................................................................*/QState Calc_frac2(Calc *me, QEvent const *e) {    (void)me;               /* avoid compiler warning about unused argument */    switch (e->sig) {        case Q_ENTRY_SIG: {            BSP_message("frac2-ENTRY;");            return Q_HANDLED();        }        case Q_EXIT_SIG: {            BSP_message("frac2-EXIT;");            return Q_HANDLED();        }        case DIGIT_0_SIG:                     /* intentionally fall through */        case DIGIT_1_9_SIG: {            BSP_insert(((CalcEvt const *)e)->key_code);            return Q_HANDLED();        }        case POINT_SIG: {            ;                                          /* explicitly ignore */            return Q_HANDLED();        }   }    return Q_SUPER(&Calc_operand2);}/*..........................................................................*/QState Calc_final(Calc *me, QEvent const *e) {    (void)me;               /* avoid compiler warning about unused argument */    switch (e->sig) {        case Q_ENTRY_SIG: {            BSP_message("final-ENTRY;");            BSP_exit();            return Q_HANDLED();        }    }    return Q_SUPER(&QHsm_top);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -