lib/iec_std_lib.h
changeset 212 8c9ec7d37d3a
parent 200 fde2d08ebaee
child 217 f5dfadf5de54
equal deleted inserted replaced
211:5249d313ff7c 212:8c9ec7d37d3a
   451 static inline __strlen_t __pfind(STRING* IN1, STRING* IN2){
   451 static inline __strlen_t __pfind(STRING* IN1, STRING* IN2){
   452     UINT count1 = 0; /* offset of first matching char in IN1 */
   452     UINT count1 = 0; /* offset of first matching char in IN1 */
   453     UINT count2 = 0; /* count of matching char */
   453     UINT count2 = 0; /* count of matching char */
   454     while(count1 + count2 < IN1->len && count2 < IN2->len)
   454     while(count1 + count2 < IN1->len && count2 < IN2->len)
   455     {
   455     {
   456         if(IN1->body[count1 + count2] != IN2->body[count2++]){
   456         if(IN1->body[count1 + count2] != IN2->body[count2]){
   457             count1 += count2;
   457             count1 += count2 + 1;
   458             count2 = 0;
   458             count2 = 0;
       
   459         }
       
   460         else {
       
   461             count2++;
   459         }
   462         }
   460     }
   463     }
   461     return count2 == IN2->len -1 ? 0 : count1 + 1;
   464     return count2 == IN2->len -1 ? 0 : count1 + 1;
   462 }
   465 }
   463 static inline __strlen_t __find(EN_ENO_PARAMS, STRING IN1, STRING IN2){
   466 static inline __strlen_t __find(EN_ENO_PARAMS, STRING IN1, STRING IN2){
   759     return res;
   762     return res;
   760 }
   763 }
   761     /* BCD */
   764     /* BCD */
   762 #define __bcd_digit(fac)
   765 #define __bcd_digit(fac)
   763 static inline ULINT __bcd_to_uint(EN_ENO_PARAMS, LWORD IN){
   766 static inline ULINT __bcd_to_uint(EN_ENO_PARAMS, LWORD IN){
       
   767     ULINT res;
       
   768     ULINT i;
   764     TEST_EN(ULINT)
   769     TEST_EN(ULINT)
   765     return IN & 0xf +
   770 
   766            !(IN >>= 4) ? 0 : (IN & 0xf * 10ULL) +
   771     res = IN & 0xf;
   767            !(IN >>= 4) ? 0 : (IN & 0xf * 100ULL) +
   772     for(i = 10ULL; i <= 1000000000000000ULL; i *= 10){
   768            !(IN >>= 4) ? 0 : (IN & 0xf * 1000ULL) +
   773         if(!(IN >>= 4))
   769            !(IN >>= 4) ? 0 : (IN & 0xf * 10000ULL) +
   774             break;
   770            !(IN >>= 4) ? 0 : (IN & 0xf * 100000ULL) +
   775         res += (IN & 0xf) * i;
   771            !(IN >>= 4) ? 0 : (IN & 0xf * 1000000ULL) +
   776     }
   772            !(IN >>= 4) ? 0 : (IN & 0xf * 10000000ULL) +
   777     return res;
   773            !(IN >>= 4) ? 0 : (IN & 0xf * 100000000ULL) +
   778 }
   774            !(IN >>= 4) ? 0 : (IN & 0xf * 1000000000ULL) +
   779 
   775            !(IN >>= 4) ? 0 : (IN & 0xf * 10000000000ULL) +
       
   776            !(IN >>= 4) ? 0 : (IN & 0xf * 100000000000ULL) +
       
   777            !(IN >>= 4) ? 0 : (IN & 0xf * 1000000000000ULL) +
       
   778            !(IN >>= 4) ? 0 : (IN & 0xf * 10000000000000ULL) +
       
   779            !(IN >>= 4) ? 0 : (IN & 0xf * 100000000000000ULL) +
       
   780            !(IN >>= 4) ? 0 : (IN & 0xf * 1000000000000000ULL);
       
   781 
       
   782 }
       
   783 static inline LWORD __uint_to_bcd(EN_ENO_PARAMS, ULINT IN){
   780 static inline LWORD __uint_to_bcd(EN_ENO_PARAMS, ULINT IN){
       
   781     LWORD res;
       
   782     USINT i;
   784     TEST_EN(LWORD)
   783     TEST_EN(LWORD)
   785     return (IN - (IN /= 10))|
   784 
   786            (IN - (IN /= 10)) << 4 |
   785     res = IN % 10;
   787            (IN - (IN /= 10)) << 8 |
   786     for(i = 4; i<=60; i += 4){
   788            (IN - (IN /= 10)) << 12 |
   787         if(!(IN /= 10))
   789            (IN - (IN /= 10)) << 16 |
   788             break;
   790            (IN - (IN /= 10)) << 20 |
   789         res |= (IN % 10) << i;
   791            (IN - (IN /= 10)) << 24 |
   790     }
   792            (IN - (IN /= 10)) << 28 |
   791     return res;
   793            (IN - (IN /= 10)) << 32 |
       
   794            (IN - (IN /= 10)) << 36 |
       
   795            (IN - (IN /= 10)) << 40 |
       
   796            (IN - (IN /= 10)) << 44 |
       
   797            (IN - (IN /= 10)) << 48 |
       
   798            (IN - (IN /= 10)) << 52 |
       
   799            (IN - (IN /= 10)) << 56 |
       
   800            (IN - (IN /= 10)) << 60;
       
   801 }
   792 }
   802 
   793 
   803 /* workaround for va-atgs limitation on shorter that int params */
   794 /* workaround for va-atgs limitation on shorter that int params */
   804 #define VA_ARGS_REAL LREAL
   795 #define VA_ARGS_REAL LREAL
   805 #define VA_ARGS_LREAL LREAL
   796 #define VA_ARGS_LREAL LREAL