Changeset 1721 for trunk/src/kmk
- Timestamp:
- Sep 4, 2008, 5:19:08 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/ifcond.c
r1719 r1721 706 706 707 707 /** 708 * Logical NOT. 709 * 710 * @returns Status code. 711 * @param pThis The instance. 712 */ 713 static IFCONDRET ifcond_op_logical_not(PIFCOND pThis) 714 { 715 PIFCONDVAR pVar = &pThis->aVars[pThis->iVar]; 716 assert(pThis->iVar >= 0); 717 718 ifcond_var_assign_bool(pVar, !ifcond_var_make_bool(pVar)); 719 720 return kIfCondRet_Ok; 721 } 722 723 724 ///// 725 726 727 /** 728 * Not equal. 729 * 730 * @returns Status code. 731 * @param pThis The instance. 732 */ 733 static IFCONDRET ifcond_op_equal(PIFCOND pThis) 734 { 735 PIFCONDVAR pVar1 = &pThis->aVars[pThis->iVar - 1]; 736 PIFCONDVAR pVar2 = &pThis->aVars[pThis->iVar]; 737 assert(pThis->iVar >= 1); 738 739 /* 740 * If it's the same type, things are simple. 741 */ 742 if (ifcond_var_is_string(pVar1) == ifcond_var_is_string(pVar2)) 743 { 744 if (ifcond_var_is_string(pVar1)) 745 { 746 ifcond_var_make_simple_string(pVar1); 747 ifcond_var_make_simple_string(pVar2); 748 ifcond_var_assign_bool(pVar1, !strcmp(pVar1->uVal.psz, pVar2->uVal.psz)); 749 } 750 else 751 ifcond_var_assign_bool(pVar1, pVar1->uVal.i == pVar2->uVal.i); 752 } 753 else 754 { 755 /* 756 * If the type differs, there are now two options: 757 * 1. Convert the string to a valid number and compare the numbers. 758 * 2. Convert an empty string to a 'false' boolean value and compare 759 * numerically. This one is a bit questionable, so it's currently 760 * not enabled. 761 */ 762 IFCONDINT64 iVal1; 763 PIFCONDVAR pVarRet = pVar1; 764 765 /* switch so pVar1 is the string. */ 766 if (!ifcond_var_is_string(pVar1)) 767 { 768 pVar1 = pVar2; 769 pVar2 = pVarRet; 770 } 771 772 ifcond_var_make_simple_string(pVar1); 773 if (ifcond_string_to_num(NULL, &iVal1, pVar1->uVal.psz, 1 /* fQuiet */) >= kIfCondRet_Ok) 774 ifcond_var_assign_bool(pVar1, iVal1 == pVar2->uVal.i); 775 else 776 { 777 #if 0 /* bogus consept */ 778 const char *psz = pVar1->uVal.psz; 779 while (isspace((unsigned char)*psz)) 780 psz++; 781 if (!*psz) 782 ifcond_var_assign_bool(pVar1, iVal1 == pVar2->uVal.i); 783 else 784 #endif 785 { 786 ifcond_error(pThis, "Cannot compare strings and numbers"); 787 return kIfCondRet_Error; 788 } 789 } 790 } 791 792 ifcond_pop_and_delete_var(pThis); 793 return kIfCondRet_Ok; 794 } 795 796 797 /** 798 * Not equal. 799 * 800 * @returns Status code. 801 * @param pThis The instance. 802 */ 803 static IFCONDRET ifcond_op_not_equal(PIFCOND pThis) 804 { 805 IFCONDRET rc = ifcond_op_equal(pThis); 806 if (rc >= kIfCondRet_Ok) 807 rc = ifcond_op_logical_not(pThis); 808 return rc; 809 } 810 811 812 /** 813 * Bitwise AND. 814 * 815 * @returns Status code. 816 * @param pThis The instance. 817 */ 818 static IFCONDRET ifcond_op_bitwise_and(PIFCOND pThis) 819 { 820 IFCONDRET rc; 821 assert(pThis->iVar >= 1); 822 823 rc = ifcond_var_make_num(pThis, &pThis->aVars[pThis->iVar - 1]); 824 if (rc >= kIfCondRet_Ok) 825 { 826 rc = ifcond_var_make_num(pThis, &pThis->aVars[pThis->iVar]); 827 if (rc >= kIfCondRet_Ok) 828 pThis->aVars[pThis->iVar - 1].uVal.i &= pThis->aVars[pThis->iVar].uVal.i; 829 } 830 831 ifcond_pop_and_delete_var(pThis); 832 return kIfCondRet_Ok; 833 } 834 835 836 /** 837 * Bitwise XOR. 838 * 839 * @returns Status code. 840 * @param pThis The instance. 841 */ 842 static IFCONDRET ifcond_op_bitwise_xor(PIFCOND pThis) 843 { 844 IFCONDRET rc; 845 assert(pThis->iVar >= 1); 846 847 rc = ifcond_var_make_num(pThis, &pThis->aVars[pThis->iVar - 1]); 848 if (rc >= kIfCondRet_Ok) 849 { 850 rc = ifcond_var_make_num(pThis, &pThis->aVars[pThis->iVar]); 851 if (rc >= kIfCondRet_Ok) 852 pThis->aVars[pThis->iVar - 1].uVal.i ^= pThis->aVars[pThis->iVar].uVal.i; 853 } 854 855 ifcond_pop_and_delete_var(pThis); 856 return kIfCondRet_Ok; 857 } 858 859 860 /** 708 861 * Bitwise OR. 709 862 * … … 843 996 IFCOND_OP(">=", 60, 2, ifcond_op_greater_or_equal_than), 844 997 IFCOND_OP(">", 60, 2, ifcond_op_greater_than), 998 #endif 845 999 IFCOND_OP("==", 55, 2, ifcond_op_equal), 846 1000 IFCOND_OP("!=", 55, 2, ifcond_op_not_equal), 847 1001 IFCOND_OP("!", 80, 1, ifcond_op_logical_not), 848 1002 IFCOND_OP("^", 45, 2, ifcond_op_bitwise_xor), 849 #endif850 1003 IFCOND_OP("&&", 35, 2, ifcond_op_logical_and), 851 /*IFCOND_OP("&", 50, 2, ifcond_op_bitwise_and),*/1004 IFCOND_OP("&", 50, 2, ifcond_op_bitwise_and), 852 1005 IFCOND_OP("||", 30, 2, ifcond_op_logical_or), 853 1006 IFCOND_OP("|", 40, 2, ifcond_op_bitwise_or), … … 1331 1484 1332 1485 #endif /* CONFIG_WITH_IF_CONDITIONALS */ 1486
Note:
See TracChangeset
for help on using the changeset viewer.