etisserant@107: /* msousa@350: * copyright 2008 Edouard TISSERANT msousa@350: * copyright 2011 Mario de Sousa (msousa@fe.up.pt) etisserant@107: * etisserant@107: * Offered to the public under the terms of the GNU Lesser General Public etisserant@107: * License as published by the Free Software Foundation; either version 2 etisserant@107: * of the License, or (at your option) any later version. etisserant@107: * etisserant@107: * This program is distributed in the hope that it will be useful, but etisserant@107: * WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@107: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser etisserant@107: * General Public License for more details. etisserant@107: * etisserant@107: * This code is made available on the understanding that it will not be etisserant@107: * used in safety-critical situations without a full and competent review. etisserant@107: */ etisserant@107: etisserant@40: /**** etisserant@107: * IEC 61131-3 standard function library etisserant@40: */ etisserant@40: msousa@350: /* NOTE: This file is full of (what may seem at first) very strange macros. msousa@350: * If you want to know what all these strange macros are doing, msousa@350: * just parse this file through a C preprocessor (e.g. cpp), msousa@350: * and analyse the output! msousa@350: * $gcc -E iec_std_lib.h msousa@350: */ msousa@350: mjsousa@905: #ifndef _IEC_STD_FUNCTIONS_H mjsousa@905: #define _IEC_STD_FUNCTIONS_H msousa@350: msousa@350: msousa@350: /*****************************************************************/ msousa@350: /*****************************************************************/ msousa@350: /***** *****/ msousa@350: /***** IEC 61131-3 *****/ msousa@350: /***** S T A N D A R D F U N C T I O N S *****/ msousa@350: /***** *****/ msousa@350: /*****************************************************************/ msousa@350: /*****************************************************************/ msousa@350: msousa@350: /* NOTE: If you want to know what all these strange macros are doing, msousa@350: * just parse this file through a C preprocessor, and analyse the output! msousa@350: * $gcc -E iec_std_lib.h msousa@350: */ msousa@350: msousa@350: /* NOTE: We only define and declare the explicitly typed standard functions msousa@350: * (e.g., SIN_REAL, SIN_LREAL, ..., ADD_SINT, ADD_INT, ADD_LINT, ...) msousa@350: * We do not declare/define the overloaded functions msousa@350: * (SIN, ADD, ...). msousa@350: * When handling a call to an overloaded function, the iec2c compiler msousa@350: * will determine in stage3 the data type of the parameter being passed, msousa@350: * and in stage4 generate the C code to call the correct msousa@350: * typed standard function. msousa@350: */ msousa@350: msousa@350: /* NOTE on explicit typing of: msousa@350: * - Table 25 - Standard bit shift functions msousa@350: * - Table 29 - Character string Functions msousa@350: * msousa@350: * In section 2.5.1.4 (Typing, overloading, and type conversion) of the IEC 61131-3 (version 2) msousa@350: * of the standard, it is stated: msousa@350: * "A standard function, [...] is said to be overloaded when it msousa@350: * can operate on input data elements of various types within a generic type designator as defined in msousa@350: * 2.3.2. For instance, an overloaded addition function on generic type ANY_NUM can operate on data msousa@350: * of types LREAL, REAL, DINT, INT, and SINT." msousa@350: * [...] msousa@350: * "When a function which normally represents an overloaded operator is to be typed, i.e., the types msousa@350: * of its inputs and outputs restricted to a particular elementary or derived data type as defined in msousa@350: * 2.3, this shall be done by appending an "underline" character followed by the required type, as msousa@350: * shown in table 21." msousa@350: * msousa@350: * However, this explanation (as well as the example in table 21) only refers to functions where the same msousa@350: * generic data type is used for the single input and the output parameter. msousa@350: * How can we create explicitly types functions when this is not the case? msousa@350: * It does not seem to be covered by the standard. msousa@350: * msousa@350: * For this reason, we do not define the LEN_SINT, LEN_INT, LEN_STRING, LEN_[ANY_INT], LEN_[ANY_STRING] functions... msousa@350: */ msousa@350: msousa@350: msousa@350: /********************/ msousa@350: /* EN/ENO PARAMS */ msousa@350: /********************/ mjsousa@1011: #ifdef DISABLE_EN_ENO_PARAMETERS mjsousa@1011: mjsousa@1011: /* Do _not_ generate the EN and ENO parameters! */ mjsousa@1011: #define EN_ENO_PARAMS mjsousa@1011: #define EN_ENO mjsousa@1011: mjsousa@1011: #define TEST_EN(TYPENAME) mjsousa@1011: #define TEST_EN_COND(TYPENAME, COND) mjsousa@1011: mjsousa@1011: #else mjsousa@1011: mjsousa@1011: /* _Do_ generate the EN and ENO parameters! */ mjsousa@1011: #define EN_ENO_PARAMS BOOL EN, BOOL *ENO, mjsousa@1011: #define EN_ENO EN, ENO, mjsousa@1011: mjsousa@1011: #define TEST_EN(TYPENAME)\ mjsousa@1011: if (!EN) {\ mjsousa@1011: if (ENO != NULL)\ mjsousa@1011: *ENO = __BOOL_LITERAL(FALSE);\ mjsousa@1011: return __INIT_##TYPENAME;\ mjsousa@1011: }\ mjsousa@1011: else if (ENO != NULL)\ mjsousa@1011: *ENO = __BOOL_LITERAL(TRUE); mjsousa@1011: mjsousa@1011: #define TEST_EN_COND(TYPENAME, COND)\ mjsousa@1011: if (!EN || (COND)) {\ mjsousa@1011: if (ENO != NULL)\ mjsousa@1011: *ENO = __BOOL_LITERAL(FALSE);\ mjsousa@1011: return __INIT_##TYPENAME;\ mjsousa@1011: }\ mjsousa@1011: else if (ENO != NULL)\ mjsousa@1011: *ENO = __BOOL_LITERAL(TRUE); mjsousa@1011: mjsousa@1011: #endif msousa@350: msousa@350: msousa@350: /*****************************************/ msousa@350: /*****************************************/ msousa@350: /* 2.5.1.5.1 Type Conversion Functions */ msousa@350: /*****************************************/ msousa@350: /*****************************************/ msousa@350: msousa@350: #define __convert_type(from_TYPENAME,to_TYPENAME, oper) \ mjsousa@1011: static inline to_TYPENAME from_TYPENAME##_TO_##to_TYPENAME(EN_ENO_PARAMS from_TYPENAME op){\ msousa@350: TEST_EN(to_TYPENAME)\ msousa@350: return (to_TYPENAME)oper(op);\ msousa@350: } msousa@350: laurent@398: /******** [ANY_NUM | ANY_NBIT]_TO_BOOL ************/ laurent@398: #define __convert_num_to_bool(TYPENAME) \ mjsousa@1011: static inline BOOL TYPENAME##_TO_BOOL(EN_ENO_PARAMS TYPENAME op){\ laurent@398: TEST_EN(BOOL)\ laurent@398: return op == 0 ? 0 : 1;\ laurent@398: } laurent@398: __ANY_NUM(__convert_num_to_bool) laurent@398: __ANY_NBIT(__convert_num_to_bool) laurent@398: laurent@398: /******** [TIME | ANY_DATE]_TO_BOOL ************/ laurent@398: #define __convert_time_to_bool(TYPENAME) \ mjsousa@1011: static inline BOOL TYPENAME##_TO_BOOL(EN_ENO_PARAMS TYPENAME op){\ laurent@398: TEST_EN(BOOL)\ laurent@398: return op.tv_sec == 0 && op.tv_nsec == 0 ? 0 : 1;\ laurent@398: } laurent@398: __convert_time_to_bool(TIME) laurent@398: __ANY_DATE(__convert_time_to_bool) msousa@350: msousa@350: #define __to_anynum_(from_TYPENAME) __ANY_NUM_1(__iec_,from_TYPENAME) msousa@350: #define __to_anyint_(from_TYPENAME) __ANY_INT_1(__iec_,from_TYPENAME) msousa@350: #define __to_anybit_(from_TYPENAME) __ANY_BIT_1(__iec_,from_TYPENAME) msousa@350: #define __to_anynbit_(from_TYPENAME) __ANY_NBIT_1(__iec_,from_TYPENAME) msousa@350: #define __to_anysint_(from_TYPENAME) __ANY_SINT_1(__iec_,from_TYPENAME) msousa@350: #define __to_anyuint_(from_TYPENAME) __ANY_UINT_1(__iec_,from_TYPENAME) msousa@350: #define __to_anyreal_(from_TYPENAME) __ANY_REAL_1(__iec_,from_TYPENAME) msousa@350: #define __to_anydate_(from_TYPENAME) __ANY_DATE_1(__iec_,from_TYPENAME) msousa@350: laurent@398: /******** [ANY_BIT]_TO_[ANY_NUM | ANT_NBIT] ************/ msousa@350: #define __iec_(to_TYPENAME,from_TYPENAME) __convert_type(from_TYPENAME, to_TYPENAME, __move_##to_TYPENAME) msousa@350: __ANY_BIT(__to_anynum_) laurent@398: __ANY_BIT(__to_anynbit_) laurent@398: #undef __iec_ laurent@398: laurent@398: /******** [ANY_INT]_TO_[ANY_NUM | ANT_NBIT] ************/ msousa@350: #define __iec_(to_TYPENAME,from_TYPENAME) __convert_type(from_TYPENAME, to_TYPENAME, __move_##to_TYPENAME) msousa@350: __ANY_INT(__to_anynum_) laurent@398: __ANY_INT(__to_anynbit_) laurent@398: #undef __iec_ laurent@398: laurent@398: /******** [ANY_REAL]_TO_[ANY_NBIT] ************/ msousa@350: #define __iec_(to_TYPENAME,from_TYPENAME) __convert_type(from_TYPENAME, to_TYPENAME, __real_to_bit) laurent@398: __ANY_REAL(__to_anynbit_) laurent@398: #undef __iec_ laurent@398: laurent@398: /******** [ANY_REAL]_TO_[ANY_NINT] ************/ msousa@350: #define __iec_(to_TYPENAME,from_TYPENAME) __convert_type(from_TYPENAME, to_TYPENAME, __real_to_sint) msousa@350: __ANY_REAL(__to_anysint_) msousa@350: #undef __iec_ msousa@350: #define __iec_(to_TYPENAME,from_TYPENAME) __convert_type(from_TYPENAME, to_TYPENAME, __real_to_uint) msousa@350: __ANY_REAL(__to_anyuint_) msousa@350: #undef __iec_ msousa@350: msousa@350: /******** [ANY_REAL]_TO_[ANY_REAL] ************/ msousa@350: #define __iec_(to_TYPENAME,from_TYPENAME) __convert_type(from_TYPENAME, to_TYPENAME, __move_##to_TYPENAME) msousa@350: __ANY_REAL(__to_anyreal_) msousa@350: #undef __iec_ msousa@350: msousa@350: /******** [ANY_BIT | ANY_INT]_TO_[TIME | ANY_DATE] ************/ msousa@350: #define __iec_(from_TYPENAME) __convert_type(from_TYPENAME, TIME, __int_to_time) msousa@350: __ANY_BIT(__iec_) msousa@350: __ANY_INT(__iec_) msousa@350: #undef __iec_ msousa@350: #define __iec_(to_TYPENAME,from_TYPENAME) __convert_type(from_TYPENAME, to_TYPENAME, __int_to_time) msousa@350: __ANY_BIT(__to_anydate_) msousa@350: __ANY_INT(__to_anydate_) msousa@350: #undef __iec_ msousa@350: msousa@350: /******** [ANY_REAL]_TO_[TIME | ANY_DATE] ************/ msousa@350: #define __iec_(from_TYPENAME) __convert_type(from_TYPENAME, TIME, __real_to_time) msousa@350: __ANY_REAL(__iec_) msousa@350: #undef __iec_ msousa@350: #define __iec_(to_TYPENAME,from_TYPENAME) __convert_type(from_TYPENAME, to_TYPENAME, __real_to_time) msousa@350: __ANY_REAL(__to_anydate_) msousa@350: #undef __iec_ msousa@350: msousa@350: /******** [TIME | ANY_DATE]_TO_[ANY_BIT | ANY_INT] ************/ msousa@350: #define __iec_(to_TYPENAME,from_TYPENAME) __convert_type(from_TYPENAME, to_TYPENAME, __time_to_int) msousa@350: __to_anyint_(TIME) laurent@398: __to_anynbit_(TIME) msousa@350: __ANY_DATE(__to_anyint_) laurent@398: __ANY_DATE(__to_anynbit_) msousa@350: #undef __iec_ msousa@350: msousa@350: /******** [TIME | ANY_DATE]_TO_[ANY_REAL] ************/ msousa@350: #define __iec_(to_TYPENAME,from_TYPENAME) __convert_type(from_TYPENAME, to_TYPENAME, __time_to_real) msousa@350: __to_anyreal_(TIME) msousa@350: __ANY_DATE(__to_anyreal_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: /******** [ANY_DATE]_TO_[ANY_DATE | TIME] ************/ msousa@350: /* Not supported: DT_TO_TIME */ msousa@350: __convert_type(DT, DATE, __date_and_time_to_date) mjsousa@1011: static inline DATE DATE_AND_TIME_TO_DATE(EN_ENO_PARAMS DT op){ mjsousa@1011: return DT_TO_DATE(EN_ENO op); Laurent@705: } msousa@350: __convert_type(DT, DT, __move_DT) msousa@350: __convert_type(DT, TOD, __date_and_time_to_time_of_day) mjsousa@1011: static inline DATE DATE_AND_TIME_TO_TIME_OF_DAY(EN_ENO_PARAMS DT op){ mjsousa@1011: return DT_TO_TOD(EN_ENO op); Laurent@705: } msousa@350: /* Not supported: DATE_TO_TIME */ msousa@350: __convert_type(DATE, DATE, __move_DATE) msousa@350: /* Not supported: DATE_TO_DT */ msousa@350: /* Not supported: DATE_TO_TOD */ msousa@350: /* Not supported: TOD_TO_TIME */ msousa@350: /* Not supported: TOD_TO_DATE */ msousa@350: /* Not supported: TOD_TO_DT */ msousa@350: __convert_type(TOD, TOD, __move_TOD) msousa@350: msousa@350: msousa@350: /******** TIME_TO_[ANY_DATE] ************/ msousa@350: /* Not supported: TIME_TO_DATE */ msousa@350: /* Not supported: TIME_TO_DT */ msousa@350: /* Not supported: TIME_TO_TOD */ msousa@350: msousa@350: /******** TIME_TO_TIME ************/ msousa@350: __convert_type(TIME, TIME, __move_TIME) msousa@350: msousa@350: msousa@350: /******** [ANY_BIT]_TO_STRING ************/ msousa@350: __convert_type(BOOL, STRING, __bool_to_string) msousa@350: #define __iec_(from_TYPENAME) __convert_type(from_TYPENAME, STRING, __bit_to_string) msousa@350: __ANY_NBIT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /******** [ANY_INT]_TO_STRING ************/ msousa@350: #define __iec_(from_TYPENAME) __convert_type(from_TYPENAME, STRING, __sint_to_string) msousa@350: __ANY_SINT(__iec_) msousa@350: #undef __iec_ msousa@350: #define __iec_(from_TYPENAME) __convert_type(from_TYPENAME, STRING, __uint_to_string) msousa@350: __ANY_UINT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /******** [ANY_REAL]_TO_STRING ************/ msousa@350: #define __iec_(from_TYPENAME) __convert_type(from_TYPENAME, STRING, __real_to_string) msousa@350: __ANY_REAL(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /******** [ANY_DATE]_TO_STRING ************/ msousa@350: __convert_type(DATE, STRING, __date_to_string) msousa@350: __convert_type(DT, STRING, __dt_to_string) msousa@350: __convert_type(TOD, STRING, __tod_to_string) msousa@350: msousa@350: /******** TIME_TO_STRING ************/ msousa@350: __convert_type(TIME, STRING, __time_to_string) msousa@350: msousa@350: msousa@350: /******** STRING_TO_[ANY_BIT] ************/ msousa@350: __convert_type(STRING, BOOL, __string_to_bool) msousa@350: #define __iec_(to_TYPENAME) __convert_type(STRING, to_TYPENAME, __string_to_bit) msousa@350: __ANY_NBIT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /******** STRING_TO_[ANY_INT] ************/ msousa@350: #define __iec_(to_TYPENAME) __convert_type(STRING, to_TYPENAME, __string_to_sint) msousa@350: __ANY_SINT(__iec_) msousa@350: #undef __iec_ msousa@350: #define __iec_(to_TYPENAME) __convert_type(STRING, to_TYPENAME, __string_to_uint) msousa@350: __ANY_UINT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /******** STRING_TO_[ANY_REAL] ************/ msousa@350: #define __iec_(to_TYPENAME) __convert_type(STRING, to_TYPENAME, __string_to_real) msousa@350: __ANY_REAL(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /******** STRING_TO_[ANY_DATE] ************/ msousa@350: #define __iec_(to_TYPENAME) __convert_type(STRING, to_TYPENAME, __string_to_time) msousa@350: __ANY_DATE(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /******** STRING_TO_TIME ************/ msousa@350: __convert_type(STRING, TIME, __string_to_time) msousa@350: msousa@350: msousa@350: /******** TRUNC ************/ msousa@350: #define __iec_(to_TYPENAME,from_TYPENAME) \ mjsousa@1011: static inline to_TYPENAME TRUNC__##to_TYPENAME##__##from_TYPENAME(EN_ENO_PARAMS from_TYPENAME op){\ msousa@350: TEST_EN(to_TYPENAME)\ msousa@350: return (to_TYPENAME)__move_##to_TYPENAME(op);\ msousa@350: } msousa@350: __ANY_REAL(__to_anyint_) msousa@350: #undef __iec_ msousa@350: msousa@350: Laurent@704: /******** _TO_BCD ************/ msousa@350: #define __iec_(to_TYPENAME,from_TYPENAME) \ mjsousa@1011: static inline to_TYPENAME from_TYPENAME##_TO_BCD_##to_TYPENAME(EN_ENO_PARAMS from_TYPENAME op){\ msousa@350: TEST_EN(to_TYPENAME)\ msousa@350: return (to_TYPENAME)__uint_to_bcd(op);\ Laurent@704: }\ mjsousa@1011: static inline to_TYPENAME from_TYPENAME##_TO_BCD__##to_TYPENAME##__##from_TYPENAME(EN_ENO_PARAMS from_TYPENAME op){\ mjsousa@1011: return from_TYPENAME##_TO_BCD_##to_TYPENAME(EN_ENO op);\ msousa@350: } msousa@350: __ANY_UINT(__to_anynbit_) msousa@350: #undef __iec_ msousa@350: msousa@350: Laurent@704: /******** BCD_TO_ ************/ msousa@350: #define __iec_(to_TYPENAME,from_TYPENAME) \ mjsousa@1011: static inline to_TYPENAME from_TYPENAME##_BCD_TO_##to_TYPENAME(EN_ENO_PARAMS from_TYPENAME op){\ Laurent@715: TEST_EN_COND(to_TYPENAME, __test_bcd(op))\ msousa@350: return (to_TYPENAME)__bcd_to_uint(op);\ Laurent@704: }\ mjsousa@1011: static inline to_TYPENAME BCD_TO_##to_TYPENAME##__##to_TYPENAME##__##from_TYPENAME(EN_ENO_PARAMS from_TYPENAME op){\ mjsousa@1011: return from_TYPENAME##_BCD_TO_##to_TYPENAME(EN_ENO op);\ msousa@350: } msousa@350: __ANY_NBIT(__to_anyuint_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: /***********************************/ msousa@350: /***********************************/ msousa@350: /* 2.5.1.5.2 Numerical Functions */ msousa@350: /***********************************/ msousa@350: /***********************************/ msousa@350: Edouard@271: /* workaround for va-args limitation on shorter than int params */ etisserant@40: #define VA_ARGS_REAL LREAL etisserant@40: #define VA_ARGS_LREAL LREAL etisserant@40: #define VA_ARGS_SINT DINT etisserant@40: #define VA_ARGS_INT DINT etisserant@40: #define VA_ARGS_DINT DINT etisserant@40: #define VA_ARGS_LINT LINT etisserant@40: #define VA_ARGS_USINT UDINT etisserant@40: #define VA_ARGS_UINT UDINT etisserant@40: #define VA_ARGS_UDINT UDINT etisserant@40: #define VA_ARGS_ULINT ULINT etisserant@40: #define VA_ARGS_TIME TIME etisserant@40: #define VA_ARGS_BOOL DWORD etisserant@40: #define VA_ARGS_BYTE DWORD etisserant@40: #define VA_ARGS_WORD DWORD etisserant@40: #define VA_ARGS_DWORD DWORD etisserant@40: #define VA_ARGS_LWORD LWORD etisserant@40: #define VA_ARGS_STRING STRING etisserant@40: #define VA_ARGS_WSTRING WSTRING etisserant@40: #define VA_ARGS_DATE DATE etisserant@40: #define VA_ARGS_TOD TOD etisserant@40: #define VA_ARGS_DT DT etisserant@40: msousa@350: msousa@350: #define __numeric(fname,TYPENAME, FUNC) \ laurent@393: /* explicitly typed function */\ mjsousa@1011: static inline TYPENAME fname##TYPENAME(EN_ENO_PARAMS TYPENAME op){\ msousa@350: TEST_EN(TYPENAME)\ msousa@350: return FUNC(op);\ laurent@393: }\ laurent@393: /* overloaded function */\ mjsousa@1011: static inline TYPENAME fname##_##TYPENAME##__##TYPENAME(EN_ENO_PARAMS TYPENAME op) {\ mjsousa@1011: return fname##TYPENAME(EN_ENO op);\ msousa@350: } msousa@350: msousa@350: /******************************************************************/ msousa@350: /*** Table 23 - Standard functions of one numeric variable ***/ msousa@350: /******************************************************************/ msousa@350: msousa@350: /**************/ msousa@350: /* ABS */ msousa@350: /**************/ laurent@393: #define __abs_signed(TYPENAME) \ laurent@393: /* explicitly typed function */\ mjsousa@1011: static inline TYPENAME ABS_##TYPENAME(EN_ENO_PARAMS TYPENAME op){\ msousa@350: TEST_EN(TYPENAME)\ msousa@350: if (op < 0)\ msousa@350: return -op;\ msousa@350: return op;\ laurent@393: }\ laurent@393: /* overloaded function */\ mjsousa@1011: static inline TYPENAME ABS__##TYPENAME##__##TYPENAME(EN_ENO_PARAMS TYPENAME op) {\ mjsousa@1011: return ABS_##TYPENAME(EN_ENO op);\ laurent@393: } laurent@393: laurent@393: #define __abs_unsigned(TYPENAME) \ laurent@393: /* explicitly typed function */\ mjsousa@1011: static inline TYPENAME ABS_##TYPENAME(EN_ENO_PARAMS TYPENAME op){\ msousa@350: TEST_EN(TYPENAME)\ msousa@350: return op;\ laurent@393: }\ laurent@393: /* overloaded function */\ mjsousa@1011: static inline TYPENAME ABS__##TYPENAME##__##TYPENAME(EN_ENO_PARAMS TYPENAME op) {\ mjsousa@1011: return ABS_##TYPENAME(EN_ENO op);\ laurent@393: } laurent@393: laurent@393: __ANY_REAL(__abs_signed) laurent@393: __ANY_SINT(__abs_signed) laurent@393: __ANY_UINT(__abs_unsigned) msousa@350: msousa@350: msousa@350: /**************/ msousa@350: /* SQRT */ msousa@350: /**************/ laurent@393: #define __sqrt(TYPENAME) __numeric(SQRT_, TYPENAME, sqrt) laurent@393: __ANY_REAL(__sqrt) laurent@393: laurent@393: laurent@393: /**************/ msousa@350: /* LN */ msousa@350: /**************/ laurent@393: #define __ln(TYPENAME) __numeric(LN_, TYPENAME, log) laurent@393: __ANY_REAL(__ln) msousa@350: msousa@350: msousa@350: /**************/ msousa@350: /* LOG */ msousa@350: /**************/ laurent@393: #define __log(TYPENAME) __numeric(LOG_, TYPENAME, log10) laurent@393: __ANY_REAL(__log) laurent@393: msousa@350: msousa@350: /**************/ msousa@350: /* EXP */ msousa@350: /**************/ laurent@393: #define __exp(TYPENAME) __numeric(EXP_, TYPENAME, exp) laurent@393: __ANY_REAL(__exp) msousa@350: msousa@350: msousa@350: /**************/ msousa@350: /* SIN */ msousa@350: /**************/ laurent@393: #define __sin(TYPENAME) __numeric(SIN_, TYPENAME, sin) laurent@393: __ANY_REAL(__sin) msousa@350: msousa@350: msousa@350: /**************/ msousa@350: /* COS */ msousa@350: /**************/ laurent@393: #define __cos(TYPENAME) __numeric(COS_, TYPENAME, cos) laurent@393: __ANY_REAL(__cos) msousa@350: msousa@350: /**************/ msousa@350: /* TAN */ msousa@350: /**************/ laurent@393: #define __tan(TYPENAME) __numeric(TAN_, TYPENAME, tan) laurent@393: __ANY_REAL(__tan) msousa@350: msousa@350: msousa@350: /**************/ msousa@350: /* ASIN */ msousa@350: /**************/ laurent@393: #define __asin(TYPENAME) __numeric(ASIN_, TYPENAME, asin) laurent@393: __ANY_REAL(__asin) msousa@350: msousa@350: /**************/ msousa@350: /* ACOS */ msousa@350: /**************/ laurent@393: #define __acos(TYPENAME) __numeric(ACOS_, TYPENAME, acos) laurent@393: __ANY_REAL(__acos) msousa@350: msousa@350: /**************/ msousa@350: /* ATAN */ msousa@350: /**************/ laurent@393: #define __atan(TYPENAME) __numeric(ATAN_, TYPENAME, atan) laurent@393: __ANY_REAL(__atan) msousa@350: msousa@350: msousa@350: msousa@350: /*****************************************************/ msousa@350: /*** Table 24 - Standard arithmetic functions ***/ msousa@350: /*****************************************************/ laurent@393: laurent@393: #define __arith_expand(fname,TYPENAME, OP)\ mjsousa@1011: static inline TYPENAME fname(EN_ENO_PARAMS UINT param_count, TYPENAME op1, ...){\ lbessard@149: va_list ap;\ lbessard@149: UINT i;\ laurent@200: TEST_EN(TYPENAME)\ lbessard@149: \ lbessard@149: va_start (ap, op1); /* Initialize the argument list. */\ lbessard@149: \ lbessard@149: for (i = 0; i < param_count - 1; i++){\ lbessard@149: op1 = op1 OP va_arg (ap, VA_ARGS_##TYPENAME);\ lbessard@149: }\ lbessard@149: \ lbessard@149: va_end (ap); /* Clean up. */\ lbessard@149: return op1;\ lbessard@149: } lbessard@149: laurent@393: #define __arith_static(fname,TYPENAME, OP)\ laurent@393: /* explicitly typed function */\ mjsousa@1011: static inline TYPENAME fname##TYPENAME(EN_ENO_PARAMS TYPENAME op1, TYPENAME op2){\ lbessard@149: TEST_EN(TYPENAME)\ lbessard@149: return op1 OP op2;\ laurent@393: }\ laurent@393: /* overloaded function */\ mjsousa@1011: static inline TYPENAME fname##_##TYPENAME##__##TYPENAME##__##TYPENAME(EN_ENO_PARAMS TYPENAME op1, TYPENAME op2){\ mjsousa@1011: return fname##TYPENAME(EN_ENO op1, op2);\ lbessard@149: } lbessard@149: msousa@350: /**************/ msousa@350: /* ADD */ msousa@350: /**************/ laurent@393: #define __add(TYPENAME) \ msousa@350: __arith_expand(ADD_##TYPENAME, TYPENAME, +) /* explicitly typed function */\ msousa@350: __arith_expand(ADD__##TYPENAME##__##TYPENAME, TYPENAME, +) /* overloaded function */ laurent@393: __ANY_NUM(__add) laurent@393: msousa@350: msousa@350: /**************/ msousa@350: /* MUL */ msousa@350: /**************/ laurent@393: #define __mul(TYPENAME) \ msousa@350: __arith_expand(MUL_##TYPENAME, TYPENAME, *) /* explicitly typed function */\ msousa@350: __arith_expand(MUL__##TYPENAME##__##TYPENAME, TYPENAME, *) /* overloaded function */ laurent@393: __ANY_NUM(__mul) laurent@393: msousa@350: msousa@350: /**************/ msousa@350: /* SUB */ msousa@350: /**************/ laurent@393: #define __sub(TYPENAME) __arith_static(SUB_, TYPENAME, -) laurent@393: __ANY_NUM(__sub) laurent@393: msousa@350: msousa@350: /**************/ msousa@350: /* DIV */ msousa@350: /**************/ laurent@393: #define __div(TYPENAME)\ laurent@393: /* The explicitly typed standard functions */\ mjsousa@1011: static inline TYPENAME DIV_##TYPENAME(EN_ENO_PARAMS TYPENAME op1, TYPENAME op2){\ lbessard@149: TEST_EN_COND(TYPENAME, op2 == 0)\ lbessard@149: return op1 / op2;\ laurent@393: }\ laurent@393: /* The overloaded standard functions */\ mjsousa@1011: static inline TYPENAME DIV__##TYPENAME##__##TYPENAME##__##TYPENAME(EN_ENO_PARAMS TYPENAME op1, TYPENAME op2){\ mjsousa@1011: return DIV_##TYPENAME(EN_ENO op1, op2);\ laurent@393: } laurent@393: __ANY_NUM(__div) laurent@393: laurent@393: laurent@393: /**************/ laurent@393: /* MOD */ laurent@393: /**************/ laurent@393: #define __mod(TYPENAME)\ laurent@393: /* The explicitly typed standard functions */\ mjsousa@1011: static inline TYPENAME MOD_##TYPENAME(EN_ENO_PARAMS TYPENAME op1, TYPENAME op2){\ laurent@398: TEST_EN(TYPENAME)\ laurent@398: if (op2 == 0) return 0;\ laurent@393: return op1 % op2;\ laurent@393: }\ laurent@393: /* The overloaded standard functions */\ mjsousa@1011: static inline TYPENAME MOD__##TYPENAME##__##TYPENAME##__##TYPENAME(EN_ENO_PARAMS TYPENAME op1, TYPENAME op2){\ mjsousa@1011: return MOD_##TYPENAME(EN_ENO op1, op2);\ laurent@393: } laurent@393: __ANY_INT(__mod) msousa@350: msousa@350: /**************/ msousa@350: /* EXPT */ msousa@350: /**************/ msousa@350: /* overloaded function */ msousa@350: #define __iec_(in1_TYPENAME,in2_TYPENAME) \ msousa@350: static inline in1_TYPENAME EXPT__##in1_TYPENAME##__##in1_TYPENAME##__##in2_TYPENAME\ mjsousa@1011: (EN_ENO_PARAMS in1_TYPENAME IN1, in2_TYPENAME IN2){\ msousa@350: TEST_EN(in1_TYPENAME)\ mjsousa@1011: return __expt(IN1, IN2);\ msousa@350: } msousa@350: #define __in1_anyreal_(in2_TYPENAME) __ANY_REAL_1(__iec_,in2_TYPENAME) msousa@350: __ANY_NUM(__in1_anyreal_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: msousa@350: /***************/ msousa@350: /* MOVE */ msousa@350: /***************/ msousa@350: /* The explicitly typed standard functions */ msousa@350: #define __iec_(TYPENAME)\ mjsousa@1011: static inline TYPENAME MOVE_##TYPENAME(EN_ENO_PARAMS TYPENAME op1){\ msousa@350: TEST_EN(TYPENAME)\ msousa@350: return op1;\ msousa@350: } msousa@350: __ANY(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Overloaded function */ msousa@350: #define __iec_(TYPENAME)\ mjsousa@1011: static inline TYPENAME MOVE__##TYPENAME##__##TYPENAME(EN_ENO_PARAMS TYPENAME op1){\ msousa@350: TEST_EN(TYPENAME)\ msousa@350: return op1;\ msousa@350: } msousa@350: __ANY(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: msousa@350: msousa@350: msousa@350: msousa@350: /***********************************/ msousa@350: /***********************************/ msousa@350: /* 2.5.1.5.3 Bit String Functions */ msousa@350: /***********************************/ msousa@350: /***********************************/ msousa@350: msousa@350: /****************************************************/ msousa@350: /*** Table 25 - Standard bit shift functions ***/ msousa@350: /****************************************************/ msousa@350: msousa@350: /* We do not delcare explcitly typed versions of the functions in table 25. msousa@350: * See note above regarding explicitly typed functions for more details. msousa@350: */ msousa@350: #define __in1_anynbit_(in2_TYPENAME) __ANY_NBIT_1(__iec_,in2_TYPENAME) msousa@350: msousa@350: #define __shift_(fname, in1_TYPENAME, in2_TYPENAME, OP)\ mjsousa@1011: static inline in1_TYPENAME fname(EN_ENO_PARAMS in1_TYPENAME IN, in2_TYPENAME N) {\ msousa@350: TEST_EN(in1_TYPENAME)\ msousa@350: return IN OP N;\ msousa@350: } msousa@350: msousa@350: /**************/ msousa@350: /* SHL */ msousa@350: /**************/ msousa@350: #define __iec_(TYPENAME) \ msousa@350: /* Overloaded function */\ mjsousa@1011: static inline BOOL SHL__BOOL__##TYPENAME(EN_ENO_PARAMS BOOL IN, TYPENAME N) { \ msousa@350: TEST_EN(BOOL);\ msousa@350: return (N==0)? IN : __INIT_BOOL; /* shifting by N>1 will always introduce a 0 */\ msousa@350: } msousa@350: __ANY_INT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: #define __iec_(in1_TYPENAME,in2_TYPENAME) \ msousa@350: __shift_(SHL__##in1_TYPENAME##__##in1_TYPENAME##__##in2_TYPENAME, in1_TYPENAME, in2_TYPENAME, << )/* Overloaded function */ msousa@350: __ANY_INT(__in1_anynbit_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: /**************/ msousa@350: /* SHR */ msousa@350: /**************/ msousa@350: #define __iec_(TYPENAME) \ msousa@350: /* Overloaded function */\ mjsousa@1011: static inline BOOL SHR__BOOL__##TYPENAME(EN_ENO_PARAMS BOOL IN, TYPENAME N) { \ msousa@350: TEST_EN(BOOL);\ msousa@350: return (N==0)? IN : __INIT_BOOL; /* shifting by N>1 will always introduce a 0 */\ msousa@350: } msousa@350: __ANY_INT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: #define __iec_(in1_TYPENAME,in2_TYPENAME) \ msousa@350: __shift_(SHR__##in1_TYPENAME##__##in1_TYPENAME##__##in2_TYPENAME, in1_TYPENAME, in2_TYPENAME, >> )/* Overloaded function */ msousa@350: __ANY_INT(__in1_anynbit_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: /**************/ msousa@350: /* ROR */ msousa@350: /**************/ msousa@350: #define __iec_(TYPENAME) \ msousa@350: /* Overloaded function */\ mjsousa@1011: static inline BOOL ROR__BOOL__##TYPENAME(EN_ENO_PARAMS BOOL IN, TYPENAME N) { \ msousa@350: TEST_EN(BOOL);\ msousa@350: return IN; /* rotating a single bit by any value N will not change that bit! */\ msousa@350: } msousa@350: __ANY_INT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: #define __iec_(in1_TYPENAME,in2_TYPENAME) \ mjsousa@1011: static inline in1_TYPENAME ROR__##in1_TYPENAME##__##in1_TYPENAME##__##in2_TYPENAME(EN_ENO_PARAMS in1_TYPENAME IN, in2_TYPENAME N){\ msousa@350: TEST_EN(in1_TYPENAME)\ msousa@350: N %= 8*sizeof(in1_TYPENAME);\ msousa@350: return (IN >> N) | (IN << (8*sizeof(in1_TYPENAME)-N));\ msousa@350: } msousa@350: __ANY_INT(__in1_anynbit_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: /**************/ msousa@350: /* ROL */ msousa@350: /**************/ msousa@350: #define __iec_(TYPENAME) \ msousa@350: /* Overloaded function */\ mjsousa@1011: static inline BOOL ROL__BOOL__##TYPENAME(EN_ENO_PARAMS BOOL IN, TYPENAME N) { \ msousa@350: TEST_EN(BOOL);\ msousa@350: return IN; /* rotating a single bit by any value N will not change that bit! */\ msousa@350: } msousa@350: __ANY_INT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: #define __iec_(in1_TYPENAME,in2_TYPENAME) \ mjsousa@1011: static inline in1_TYPENAME ROL__##in1_TYPENAME##__##in1_TYPENAME##__##in2_TYPENAME(EN_ENO_PARAMS in1_TYPENAME IN, in2_TYPENAME N){\ msousa@350: TEST_EN(in1_TYPENAME)\ msousa@350: N %= 8*sizeof(in1_TYPENAME);\ msousa@350: return (IN << N) | (IN >> (8*sizeof(in1_TYPENAME)-N));\ msousa@350: } msousa@350: __ANY_INT(__in1_anynbit_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: msousa@350: /*********************/ msousa@350: /*** Table 26 ***/ msousa@350: /*********************/ msousa@350: msousa@350: /**************/ msousa@350: /* AND */ msousa@350: /**************/ msousa@350: __arith_expand(AND_BOOL, BOOL, && ) /* The explicitly typed standard functions */ msousa@350: __arith_expand(AND__BOOL__BOOL, BOOL, && ) /* Overloaded function */ msousa@350: msousa@350: #define __iec_(TYPENAME) \ msousa@350: __arith_expand(AND_##TYPENAME, TYPENAME, &) /* The explicitly typed standard functions */\ msousa@350: __arith_expand(AND__##TYPENAME##__##TYPENAME, TYPENAME, &) /* Overloaded function */ msousa@350: __ANY_NBIT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /*************/ msousa@350: /* OR */ msousa@350: /*************/ msousa@350: __arith_expand(OR_BOOL, BOOL, || ) /* The explicitly typed standard functions */ msousa@350: __arith_expand(OR__BOOL__BOOL, BOOL, || ) /* Overloaded function */ msousa@350: msousa@350: #define __iec_(TYPENAME) \ msousa@350: __arith_expand(OR_##TYPENAME, TYPENAME, |) /* The explicitly typed standard functions */\ msousa@350: __arith_expand(OR__##TYPENAME##__##TYPENAME, TYPENAME, |) /* Overloaded function */ msousa@350: __ANY_NBIT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /**************/ msousa@350: /* XOR */ msousa@350: /**************/ msousa@350: #define __xorbool_expand(fname) \ mjsousa@1011: static inline BOOL fname(EN_ENO_PARAMS UINT param_count, BOOL op1, ...){ \ msousa@350: va_list ap; \ msousa@350: UINT i; \ msousa@350: TEST_EN(BOOL) \ msousa@350: \ msousa@350: va_start (ap, op1); /* Initialize the argument list. */ \ msousa@350: \ msousa@350: for (i = 0; i < param_count - 1; i++){ \ msousa@350: BOOL tmp = va_arg (ap, VA_ARGS_BOOL); \ msousa@350: op1 = (op1 && !tmp) || (!op1 && tmp); \ msousa@350: } \ msousa@350: \ msousa@350: va_end (ap); /* Clean up. */ \ msousa@350: return op1; \ msousa@350: } msousa@350: msousa@350: __xorbool_expand(XOR_BOOL) /* The explicitly typed standard functions */ msousa@350: __xorbool_expand(XOR__BOOL__BOOL) /* Overloaded function */ msousa@350: msousa@350: #define __iec_(TYPENAME) \ msousa@350: __arith_expand(XOR_##TYPENAME, TYPENAME, ^) /* The explicitly typed standard functions */\ msousa@350: __arith_expand(XOR__##TYPENAME##__##TYPENAME, TYPENAME, ^) /* Overloaded function */\ msousa@350: __ANY_NBIT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: /**************/ msousa@350: /* NOT */ msousa@350: /**************/ msousa@350: /* The explicitly typed standard functions */ mjsousa@1011: static inline BOOL NOT_BOOL(EN_ENO_PARAMS BOOL op1){ lbessard@149: TEST_EN(BOOL) lbessard@149: return !op1; lbessard@149: } lbessard@149: msousa@350: /* Overloaded function */ mjsousa@1011: static inline BOOL NOT__BOOL__BOOL(EN_ENO_PARAMS BOOL op1){ msousa@350: TEST_EN(BOOL) msousa@350: return !op1; msousa@350: } msousa@350: msousa@350: /* The explicitly typed standard functions */ msousa@350: #define __iec_(TYPENAME)\ mjsousa@1011: static inline TYPENAME NOT_##TYPENAME(EN_ENO_PARAMS TYPENAME op1){\ lbessard@149: TEST_EN(TYPENAME)\ lbessard@149: return ~op1;\ lbessard@149: } msousa@350: __ANY_NBIT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Overloaded function */ msousa@350: #define __iec_(TYPENAME)\ mjsousa@1011: static inline TYPENAME NOT__##TYPENAME##__##TYPENAME(EN_ENO_PARAMS TYPENAME op1){\ lbessard@149: TEST_EN(TYPENAME)\ msousa@350: return ~op1;\ msousa@350: } msousa@350: __ANY_NBIT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: msousa@350: msousa@350: msousa@350: msousa@350: /***************************************************/ msousa@350: /***************************************************/ msousa@350: /* 2.5.1.5.4 Selection and comparison Functions */ msousa@350: /***************************************************/ msousa@350: /***************************************************/ msousa@350: msousa@350: /*********************/ msousa@350: /*** Table 27 ***/ msousa@350: /*********************/ msousa@350: msousa@350: msousa@350: /**************/ msousa@350: /* SEL */ msousa@350: /**************/ msousa@350: msousa@350: /* The explicitly typed standard functions */ msousa@350: #define __iec_(TYPENAME)\ mjsousa@1011: static inline TYPENAME SEL_##TYPENAME(EN_ENO_PARAMS BOOL G, TYPENAME op0, TYPENAME op1){\ lbessard@149: TEST_EN(TYPENAME)\ lbessard@149: return G ? op1 : op0;\ lbessard@149: } msousa@350: __ANY(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Overloaded function */ msousa@350: #define __iec_(TYPENAME)\ mjsousa@1011: static inline TYPENAME SEL__##TYPENAME##__BOOL__##TYPENAME##__##TYPENAME(EN_ENO_PARAMS BOOL G, TYPENAME op0, TYPENAME op1){\ lbessard@149: TEST_EN(TYPENAME)\ msousa@350: return G ? op1 : op0;\ msousa@350: } msousa@350: __ANY(__iec_) msousa@350: #undef __iec_ msousa@350: lbessard@149: lbessard@149: /**************/ lbessard@149: /* MAX */ lbessard@149: /**************/ lbessard@149: etisserant@40: #define __extrem_(fname,TYPENAME, COND) \ mjsousa@1011: static inline TYPENAME fname(EN_ENO_PARAMS UINT param_count, TYPENAME op1, ...){\ etisserant@40: va_list ap;\ etisserant@40: UINT i;\ laurent@200: TEST_EN(TYPENAME)\ etisserant@40: \ etisserant@40: va_start (ap, op1); /* Initialize the argument list. */\ etisserant@40: \ lbessard@165: for (i = 0; i < param_count - 1; i++){\ etisserant@40: TYPENAME tmp = va_arg (ap, VA_ARGS_##TYPENAME);\ etisserant@40: op1 = COND ? tmp : op1;\ etisserant@40: }\ etisserant@40: \ etisserant@40: va_end (ap); /* Clean up. */\ etisserant@40: return op1;\ etisserant@40: } etisserant@40: msousa@350: /* Max for numerical data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __extrem_(MAX_##TYPENAME,TYPENAME, op1 < tmp) /* The explicitly typed standard functions */\ msousa@350: __extrem_(MAX__##TYPENAME##__##TYPENAME,TYPENAME, op1 < tmp) /* Overloaded function */ msousa@350: __ANY_BIT(__iec_) msousa@350: __ANY_NUM(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Max for time data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __extrem_(MAX_##TYPENAME, TYPENAME, __time_cmp(op1, tmp) < 0) /* The explicitly typed standard functions */\ msousa@350: __extrem_(MAX__##TYPENAME##__##TYPENAME, TYPENAME, __time_cmp(op1, tmp) < 0) /* Overloaded function */ msousa@350: __ANY_DATE(__iec_) msousa@350: __iec_(TIME) msousa@350: #undef __iec_ msousa@350: Edouard@378: #define __STR_CMP(str1, str2) memcmp((char*)&str1.body,(char*)&str2.body, str1.len < str2.len ? str1.len : str2.len) Edouard@378: msousa@350: /* Max for string data types */ msousa@350: __extrem_(MAX_STRING, STRING, __STR_CMP(op1,tmp) < 0) /* The explicitly typed standard functions */ msousa@350: __extrem_(MAX__STRING__STRING, STRING, __STR_CMP(op1,tmp) < 0) /* Overloaded function */ etisserant@40: etisserant@40: /**************/ etisserant@40: /* MIN */ etisserant@40: /**************/ msousa@350: /* Min for numerical data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __extrem_(MIN_##TYPENAME, TYPENAME, op1 > tmp) /* The explicitly typed standard functions */\ msousa@350: __extrem_(MIN__##TYPENAME##__##TYPENAME, TYPENAME, op1 > tmp) /* Overloaded function */ msousa@350: __ANY_NBIT(__iec_) msousa@350: __ANY_NUM(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Min for time data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __extrem_(MIN_##TYPENAME, TYPENAME, __time_cmp(op1, tmp) > 0) /* The explicitly typed standard functions */\ msousa@350: __extrem_(MIN__##TYPENAME##__##TYPENAME, TYPENAME, __time_cmp(op1, tmp) > 0) /* Overloaded function */ msousa@350: __ANY_DATE(__iec_) msousa@350: __iec_(TIME) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Min for string data types */ msousa@350: __extrem_(MIN_STRING, STRING, __STR_CMP(op1,tmp) > 0) /* The explicitly typed standard functions */ msousa@350: __extrem_(MIN__STRING__STRING, STRING, __STR_CMP(op1,tmp) > 0) /* Overloaded function */ msousa@350: msousa@350: /**************/ msousa@350: /* LIMIT */ msousa@350: /**************/ msousa@350: msousa@350: /* Limit for numerical data types */ msousa@350: #define __iec_(TYPENAME)\ msousa@350: /* The explicitly typed standard functions */\ mjsousa@1011: static inline TYPENAME LIMIT_##TYPENAME(EN_ENO_PARAMS TYPENAME MN, TYPENAME IN, TYPENAME MX){\ msousa@350: TEST_EN(TYPENAME)\ msousa@350: return IN > MN ? IN < MX ? IN : MX : MN;\ msousa@350: }\ msousa@350: /* Overloaded function */\ mjsousa@1011: static inline TYPENAME LIMIT__##TYPENAME##__##TYPENAME##__##TYPENAME##__##TYPENAME(EN_ENO_PARAMS TYPENAME MN, TYPENAME IN, TYPENAME MX){\ msousa@350: TEST_EN(TYPENAME)\ msousa@350: return IN > MN ? IN < MX ? IN : MX : MN;\ msousa@350: } msousa@350: __ANY_NBIT(__iec_) msousa@350: __ANY_NUM(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: /* Limit for time data types */ msousa@350: #define __iec_(TYPENAME)\ msousa@350: /* The explicitly typed standard functions */\ mjsousa@1011: static inline TYPENAME LIMIT_##TYPENAME(EN_ENO_PARAMS TYPENAME MN, TYPENAME IN, TYPENAME MX){\ msousa@350: TEST_EN(TYPENAME)\ msousa@350: return __time_cmp(IN, MN) > 0 ? /* IN>MN ?*/\ msousa@350: __time_cmp(IN, MX) < 0 ? /* IN 0 ? /* IN>MN ?*/\ msousa@350: __time_cmp(IN, MX) < 0 ? /* IN 0 ? __STR_CMP(IN, MX) < 0 ? IN : MX : MN; msousa@350: } msousa@350: msousa@350: /* Overloaded function */ mjsousa@1011: static inline STRING LIMIT__STRING__STRING__STRING__STRING(EN_ENO_PARAMS STRING MN, STRING IN, STRING MX){ msousa@350: TEST_EN(STRING) msousa@350: return __STR_CMP(IN, MN) > 0 ? __STR_CMP(IN, MX) < 0 ? IN : MX : MN; msousa@350: } msousa@350: etisserant@40: etisserant@40: /**************/ etisserant@40: /* MUX */ etisserant@40: /**************/ msousa@350: /* The standard states that the inputs for SEL and MUX must be named starting off from 0, msousa@350: * unlike remaining functions, that start off at 1. msousa@350: */ msousa@350: /* The explicitly typed standard functions */ msousa@350: #define __in1_anyint_(in2_TYPENAME) __ANY_INT_1(__iec_,in2_TYPENAME) msousa@350: #define __iec_(in1_TYPENAME,in2_TYPENAME) \ mjsousa@1011: static inline in2_TYPENAME MUX__##in2_TYPENAME##__##in1_TYPENAME##__##in2_TYPENAME(EN_ENO_PARAMS in1_TYPENAME K, UINT param_count, ...){\ etisserant@40: va_list ap;\ etisserant@40: UINT i;\ msousa@350: in2_TYPENAME tmp;\ msousa@350: TEST_EN_COND(in2_TYPENAME, K >= param_count)\ msousa@350: tmp = __INIT_##in2_TYPENAME;\ etisserant@40: \ laurent@398: va_start (ap, param_count); /* Initialize the argument list. */\ etisserant@40: \ etisserant@40: for (i = 0; i < param_count; i++){\ etisserant@40: if(K == i){\ msousa@350: tmp = va_arg (ap, VA_ARGS_##in2_TYPENAME);\ etisserant@40: va_end (ap); /* Clean up. */\ etisserant@40: return tmp;\ etisserant@40: }else{\ msousa@350: va_arg (ap, VA_ARGS_##in2_TYPENAME);\ etisserant@40: }\ etisserant@40: }\ etisserant@40: \ etisserant@40: va_end (ap); /* Clean up. */\ etisserant@41: return tmp;\ etisserant@40: } etisserant@40: msousa@350: __ANY(__in1_anyint_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: /******************************************/ msousa@350: /*** Table 28 ***/ msousa@350: /*** Standard comparison functions ***/ msousa@350: /******************************************/ etisserant@40: etisserant@40: #define __compare_(fname,TYPENAME, COND) \ mjsousa@1011: static inline BOOL fname(EN_ENO_PARAMS UINT param_count, TYPENAME op1, ...){\ etisserant@40: va_list ap;\ etisserant@40: UINT i;\ laurent@200: TEST_EN(BOOL)\ etisserant@40: \ etisserant@40: va_start (ap, op1); /* Initialize the argument list. */\ etisserant@43: DBG(#fname #TYPENAME "\n")\ etisserant@43: DBG_TYPE(TYPENAME, op1)\ etisserant@40: \ etisserant@43: for (i = 0; i < param_count - 1; i++){\ etisserant@40: TYPENAME tmp = va_arg (ap, VA_ARGS_##TYPENAME);\ etisserant@43: DBG_TYPE(TYPENAME, tmp)\ etisserant@40: if(COND){\ etisserant@40: op1 = tmp;\ etisserant@40: }else{\ etisserant@40: va_end (ap); /* Clean up. */\ etisserant@40: return 0;\ etisserant@40: }\ etisserant@40: }\ etisserant@40: \ etisserant@40: va_end (ap); /* Clean up. */\ etisserant@40: return 1;\ etisserant@40: } etisserant@40: etisserant@40: #define __compare_num(fname, TYPENAME, TEST) __compare_(fname, TYPENAME, op1 TEST tmp ) msousa@350: #define __compare_time(fname, TYPENAME, TEST) __compare_(fname, TYPENAME, __time_cmp(op1, tmp) TEST 0) etisserant@40: #define __compare_string(fname, TEST) __compare_(fname, STRING, __STR_CMP(op1, tmp) TEST 0 ) etisserant@40: lbessard@149: etisserant@40: /**************/ etisserant@40: /* GT */ etisserant@40: /**************/ msousa@350: /* Comparison for numerical data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __compare_num(GT_##TYPENAME, TYPENAME, > ) /* The explicitly typed standard functions */\ msousa@350: __compare_num(GT__BOOL__##TYPENAME, TYPENAME, > ) /* Overloaded function */ msousa@350: __ANY_NBIT(__iec_) msousa@350: __ANY_NUM(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Comparison for time data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __compare_time(GT_##TYPENAME, TYPENAME, > ) /* The explicitly typed standard functions */\ msousa@350: __compare_time(GT__BOOL__##TYPENAME, TYPENAME, > ) /* Overloaded function */ msousa@350: __ANY_DATE(__iec_) msousa@350: __iec_(TIME) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Comparison for string data types */ msousa@350: __compare_string(GT_STRING, > ) /* The explicitly typed standard functions */ msousa@350: __compare_string(GT__BOOL__STRING, > ) /* Overloaded function */ etisserant@40: etisserant@40: /**************/ etisserant@40: /* GE */ etisserant@40: /**************/ msousa@350: /* Comparison for numerical data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __compare_num(GE_##TYPENAME, TYPENAME, >= ) /* The explicitly typed standard functions */\ msousa@350: __compare_num(GE__BOOL__##TYPENAME, TYPENAME, >= ) /* Overloaded function */ msousa@350: __ANY_NBIT(__iec_) msousa@350: __ANY_NUM(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Comparison for time data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __compare_time(GE_##TYPENAME, TYPENAME, >= ) /* The explicitly typed standard functions */\ msousa@350: __compare_time(GE__BOOL__##TYPENAME, TYPENAME, >= ) /* Overloaded function */ msousa@350: __ANY_DATE(__iec_) msousa@350: __iec_(TIME) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Comparison for string data types */ msousa@350: __compare_string(GE_STRING, >= ) /* The explicitly typed standard functions */ msousa@350: __compare_string(GE__BOOL__STRING, >= ) /* Overloaded function */ msousa@350: msousa@350: etisserant@40: etisserant@40: /**************/ etisserant@40: /* EQ */ etisserant@40: /**************/ msousa@350: /* Comparison for numerical data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __compare_num(EQ_##TYPENAME, TYPENAME, == ) /* The explicitly typed standard functions */\ msousa@350: __compare_num(EQ__BOOL__##TYPENAME, TYPENAME, == ) /* Overloaded function */ msousa@350: __ANY_NBIT(__iec_) msousa@350: __ANY_NUM(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Comparison for time data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __compare_time(EQ_##TYPENAME, TYPENAME, == ) /* The explicitly typed standard functions */\ msousa@350: __compare_time(EQ__BOOL__##TYPENAME, TYPENAME, == ) /* Overloaded function */ msousa@350: __ANY_DATE(__iec_) msousa@350: __iec_(TIME) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Comparison for string data types */ msousa@350: __compare_string(EQ_STRING, == ) /* The explicitly typed standard functions */ msousa@350: __compare_string(EQ__BOOL__STRING, == ) /* Overloaded function */ msousa@350: etisserant@40: etisserant@40: /**************/ etisserant@40: /* LT */ etisserant@40: /**************/ msousa@350: /* Comparison for numerical data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __compare_num(LT_##TYPENAME, TYPENAME, < ) /* The explicitly typed standard functions */\ msousa@350: __compare_num(LT__BOOL__##TYPENAME, TYPENAME, < ) /* Overloaded function */ msousa@350: __ANY_NBIT(__iec_) msousa@350: __ANY_NUM(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Comparison for time data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __compare_time(LT_##TYPENAME, TYPENAME, < ) /* The explicitly typed standard functions */\ msousa@350: __compare_time(LT__BOOL__##TYPENAME, TYPENAME, < ) /* Overloaded function */ msousa@350: __ANY_DATE(__iec_) msousa@350: __iec_(TIME) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Comparison for string data types */ msousa@350: __compare_string(LT_STRING, < ) /* The explicitly typed standard functions */ msousa@350: __compare_string(LT__BOOL__STRING, < ) /* Overloaded function */ msousa@350: etisserant@40: etisserant@40: /**************/ etisserant@40: /* LE */ etisserant@40: /**************/ msousa@350: /* Comparison for numerical data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __compare_num(LE_##TYPENAME, TYPENAME, <= ) /* The explicitly typed standard functions */\ msousa@350: __compare_num(LE__BOOL__##TYPENAME, TYPENAME, <= ) /* Overloaded function */ msousa@350: __ANY_NBIT(__iec_) msousa@350: __ANY_NUM(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Comparison for time data types */ msousa@350: #define __iec_(TYPENAME) \ msousa@350: __compare_time(LE_##TYPENAME, TYPENAME, <= ) /* The explicitly typed standard functions */\ msousa@350: __compare_time(LE__BOOL__##TYPENAME, TYPENAME, <= ) /* Overloaded function */ msousa@350: __ANY_DATE(__iec_) msousa@350: __iec_(TIME) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Comparison for string data types */ msousa@350: __compare_string(LE_STRING, <= ) /* The explicitly typed standard functions */ msousa@350: __compare_string(LE__BOOL__STRING, <= ) /* Overloaded function */ msousa@350: etisserant@40: etisserant@40: /**************/ etisserant@40: /* NE */ etisserant@40: /**************/ laurent@398: #define __ne_num(fname, TYPENAME) \ mjsousa@1011: static inline BOOL fname(EN_ENO_PARAMS TYPENAME op1, TYPENAME op2){\ laurent@398: TEST_EN(BOOL)\ laurent@398: return op1 != op2 ? 1 : 0;\ laurent@398: } laurent@398: laurent@398: #define __ne_time(fname, TYPENAME) \ mjsousa@1011: static inline BOOL fname(EN_ENO_PARAMS TYPENAME op1, TYPENAME op2){\ laurent@398: TEST_EN(BOOL)\ laurent@398: return __time_cmp(op1, op2) != 0 ? 1 : 0;\ laurent@398: } laurent@398: Laurent@638: #define __ne_string(fname, TYPENAME) \ mjsousa@1011: static inline BOOL fname(EN_ENO_PARAMS TYPENAME op1, TYPENAME op2){\ Laurent@638: TEST_EN(BOOL)\ Laurent@638: return __STR_CMP(op1, op2) != 0 ? 1 : 0;\ Laurent@638: } laurent@398: msousa@350: /* Comparison for numerical data types */ msousa@350: #define __iec_(TYPENAME) \ laurent@398: __ne_num(NE_##TYPENAME, TYPENAME) /* The explicitly typed standard functions */\ laurent@398: __ne_num(NE__BOOL__##TYPENAME##__##TYPENAME, TYPENAME) /* Overloaded function */ msousa@350: __ANY_NBIT(__iec_) msousa@350: __ANY_NUM(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Comparison for time data types */ msousa@350: #define __iec_(TYPENAME) \ laurent@398: __ne_time(NE_##TYPENAME, TYPENAME) /* The explicitly typed standard functions */\ laurent@398: __ne_time(NE__BOOL__##TYPENAME##__##TYPENAME, TYPENAME) /* Overloaded function */ msousa@350: __ANY_DATE(__iec_) msousa@350: __iec_(TIME) msousa@350: #undef __iec_ msousa@350: msousa@350: /* Comparison for string data types */ Laurent@638: __ne_string(NE_STRING, STRING) /* The explicitly typed standard functions */ Laurent@638: __ne_string(NE__BOOL__STRING__STRING, STRING) /* Overloaded function */ msousa@350: msousa@350: msousa@350: msousa@350: msousa@350: msousa@350: msousa@350: /*********************************************/ msousa@350: /*********************************************/ msousa@350: /* 2.5.1.5.5 Character string Functions */ msousa@350: /*********************************************/ msousa@350: /*********************************************/ msousa@350: msousa@350: /*************************************/ msousa@350: /*** Table 29 ***/ msousa@350: /*** Character string Functions ***/ msousa@350: /*************************************/ msousa@350: msousa@350: /* We do not delcare explcitly typed versions of the functions in table 29. msousa@350: * See note above regarding explicitly typed functions for more details. msousa@350: */ msousa@350: msousa@350: msousa@350: msousa@350: msousa@350: /***************/ msousa@350: /* LEN */ msousa@350: /***************/ msousa@350: static inline __strlen_t __len(STRING IN) {return IN.len;} msousa@350: msousa@350: /* A function, with 1 input paramter, implementing a generic OPERATION */ msousa@350: #define __genoper_1p_(fname,ret_TYPENAME, par_TYPENAME, OPERATION) \ mjsousa@1011: static inline ret_TYPENAME fname(EN_ENO_PARAMS par_TYPENAME par1){\ msousa@350: TEST_EN(ret_TYPENAME)\ msousa@350: return (ret_TYPENAME)OPERATION(par1);\ msousa@350: } msousa@350: msousa@350: #define __iec_(TYPENAME) __genoper_1p_(LEN__##TYPENAME##__STRING, TYPENAME, STRING, __len) msousa@350: __ANY_INT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: /****************/ msousa@350: /* LEFT */ msousa@350: /****************/ msousa@350: Edouard@384: #define __left(TYPENAME) \ mjsousa@1011: static inline STRING LEFT__STRING__STRING__##TYPENAME(EN_ENO_PARAMS STRING IN, TYPENAME L){\ Edouard@384: STRING res;\ Edouard@384: TEST_EN_COND(STRING, L < 0)\ Edouard@384: res = __INIT_STRING;\ Edouard@384: L = L < (TYPENAME)IN.len ? L : (TYPENAME)IN.len;\ conti@696: memcpy(&res.body, &IN.body, (size_t)L);\ conti@696: res.len = (__strlen_t)L;\ Edouard@384: return res;\ Edouard@384: } Edouard@384: __ANY_INT(__left) msousa@350: msousa@350: msousa@350: /*****************/ msousa@350: /* RIGHT */ msousa@350: /*****************/ msousa@350: laurent@379: #define __right(TYPENAME) \ mjsousa@1011: static inline STRING RIGHT__STRING__STRING__##TYPENAME(EN_ENO_PARAMS STRING IN, TYPENAME L){\ laurent@379: STRING res;\ msousa@350: TEST_EN_COND(STRING, L < 0)\ laurent@379: res = __INIT_STRING;\ Edouard@384: L = L < (TYPENAME)IN.len ? L : (TYPENAME)IN.len;\ conti@696: memcpy(&res.body, &IN.body[(TYPENAME)IN.len - L], (size_t)L);\ conti@696: res.len = (__strlen_t)L;\ laurent@379: return res;\ laurent@379: } laurent@379: __ANY_INT(__right) msousa@350: msousa@350: msousa@350: /***************/ msousa@350: /* MID */ msousa@350: /***************/ msousa@350: laurent@379: #define __mid(TYPENAME) \ mjsousa@1011: static inline STRING MID__STRING__STRING__##TYPENAME##__##TYPENAME(EN_ENO_PARAMS STRING IN, TYPENAME L, TYPENAME P){\ laurent@379: STRING res;\ msousa@350: TEST_EN_COND(STRING, L < 0 || P < 0)\ laurent@379: res = __INIT_STRING;\ Edouard@384: if(P <= (TYPENAME)IN.len){\ laurent@379: P -= 1; /* now can be used as [index]*/\ Edouard@384: L = L + P <= (TYPENAME)IN.len ? L : (TYPENAME)IN.len - P;\ conti@696: memcpy(&res.body, &IN.body[P] , (size_t)L);\ conti@696: res.len = (__strlen_t)L;\ laurent@379: }\ laurent@379: return res;\ laurent@379: } laurent@379: __ANY_INT(__mid) msousa@350: msousa@350: msousa@350: /******************/ msousa@350: /* CONCAT */ msousa@350: /******************/ msousa@350: mjsousa@1011: static inline STRING CONCAT(EN_ENO_PARAMS UINT param_count, ...){ msousa@350: UINT i; msousa@350: STRING res; msousa@350: va_list ap; msousa@350: __strlen_t charcount; laurent@379: TEST_EN(STRING) msousa@350: charcount = 0; msousa@350: res = __INIT_STRING; msousa@350: msousa@350: va_start (ap, param_count); /* Initialize the argument list. */ msousa@350: msousa@350: for (i = 0; i < param_count && charcount < STR_MAX_LEN; i++) msousa@350: { msousa@350: STRING tmp = va_arg(ap, STRING); msousa@350: __strlen_t charrem = STR_MAX_LEN - charcount; msousa@350: __strlen_t to_write = tmp.len > charrem ? charrem : tmp.len; msousa@350: memcpy(&res.body[charcount], &tmp.body , to_write); msousa@350: charcount += to_write; msousa@350: } msousa@350: msousa@350: res.len = charcount; msousa@350: msousa@350: va_end (ap); /* Clean up. */ msousa@350: return res; msousa@350: } msousa@350: msousa@350: /******************/ msousa@350: /* INSERT */ msousa@350: /******************/ msousa@350: msousa@350: static inline STRING __insert(STRING IN1, STRING IN2, __strlen_t P){ msousa@350: STRING res; msousa@350: __strlen_t to_copy; msousa@350: res = __INIT_STRING; msousa@350: msousa@350: to_copy = P > IN1.len ? IN1.len : P; msousa@350: memcpy(&res.body, &IN1.body , to_copy); msousa@350: P = res.len = to_copy; msousa@350: msousa@350: to_copy = IN2.len + res.len > STR_MAX_LEN ? STR_MAX_LEN - res.len : IN2.len; msousa@350: memcpy(&res.body[res.len], &IN2.body , to_copy); msousa@350: res.len += to_copy; msousa@350: msousa@350: to_copy = IN1.len - P < STR_MAX_LEN - res.len ? IN1.len - P : STR_MAX_LEN - res.len ; msousa@350: memcpy(&res.body[res.len], &IN1.body[P] , to_copy); msousa@350: res.len += to_copy; msousa@350: msousa@350: return res; msousa@350: } msousa@350: msousa@350: #define __iec_(TYPENAME) \ mjsousa@1011: static inline STRING INSERT__STRING__STRING__STRING__##TYPENAME(EN_ENO_PARAMS STRING str1, STRING str2, TYPENAME P){\ msousa@350: TEST_EN_COND(STRING, P < 0)\ conti@696: return (STRING)__insert(str1,str2,(__strlen_t)P);\ msousa@350: } msousa@350: __ANY_INT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: /******************/ msousa@350: /* DELETE */ msousa@350: /******************/ msousa@350: msousa@350: static inline STRING __delete(STRING IN, __strlen_t L, __strlen_t P){ msousa@350: STRING res; msousa@350: __strlen_t to_copy; msousa@350: res = __INIT_STRING; msousa@350: msousa@350: to_copy = P > IN.len ? IN.len : P-1; msousa@350: memcpy(&res.body, &IN.body , to_copy); msousa@350: P = res.len = to_copy; msousa@350: msousa@350: if( IN.len > P + L ){ msousa@350: to_copy = IN.len - P - L; msousa@350: memcpy(&res.body[res.len], &IN.body[P + L], to_copy); msousa@350: res.len += to_copy; msousa@350: } msousa@350: msousa@350: return res; msousa@350: } msousa@350: msousa@350: #define __iec_(TYPENAME) \ mjsousa@1011: static inline STRING DELETE__STRING__STRING__##TYPENAME##__##TYPENAME(EN_ENO_PARAMS STRING str, TYPENAME L, TYPENAME P){\ msousa@350: TEST_EN_COND(STRING, L < 0 || P < 0)\ conti@696: return (STRING)__delete(str,(__strlen_t)L,(__strlen_t)P);\ msousa@350: } msousa@350: __ANY_INT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: /*******************/ msousa@350: /* REPLACE */ msousa@350: /*******************/ msousa@350: msousa@350: static inline STRING __replace(STRING IN1, STRING IN2, __strlen_t L, __strlen_t P){ msousa@350: STRING res; msousa@350: __strlen_t to_copy; msousa@350: res = __INIT_STRING; msousa@350: msousa@350: to_copy = P > IN1.len ? IN1.len : P-1; msousa@350: memcpy(&res.body, &IN1.body , to_copy); msousa@350: P = res.len = to_copy; msousa@350: msousa@350: to_copy = IN2.len < L ? IN2.len : L; msousa@350: msousa@350: if( to_copy + res.len > STR_MAX_LEN ) msousa@350: to_copy = STR_MAX_LEN - res.len; msousa@350: msousa@350: memcpy(&res.body[res.len], &IN2.body , to_copy); msousa@350: res.len += to_copy; msousa@350: msousa@350: P += L; msousa@350: if( res.len < STR_MAX_LEN && P < IN1.len) msousa@350: { msousa@350: to_copy = IN1.len - P; msousa@350: memcpy(&res.body[res.len], &IN1.body[P] , to_copy); msousa@350: res.len += to_copy; msousa@350: } msousa@350: msousa@350: return res; msousa@350: } msousa@350: msousa@350: #define __iec_(TYPENAME) \ mjsousa@1011: static inline STRING REPLACE__STRING__STRING__STRING__##TYPENAME##__##TYPENAME(EN_ENO_PARAMS STRING str1, STRING str2, TYPENAME L, TYPENAME P){\ msousa@350: TEST_EN_COND(STRING, L < 0 || P < 0)\ conti@696: return (STRING)__replace(str1,str2,(__strlen_t)L,(__strlen_t)P);\ msousa@350: } msousa@350: __ANY_INT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /****************/ msousa@350: /* FIND */ msousa@350: /****************/ msousa@350: msousa@350: static inline __strlen_t __pfind(STRING* IN1, STRING* IN2){ msousa@350: UINT count1 = 0; /* offset of first matching char in IN1 */ msousa@350: UINT count2 = 0; /* count of matching char */ msousa@350: while(count1 + count2 < IN1->len && count2 < IN2->len) msousa@350: { msousa@350: if(IN1->body[count1 + count2] != IN2->body[count2]){ msousa@350: count1 += count2 + 1; msousa@350: count2 = 0; msousa@350: } msousa@350: else { msousa@350: count2++; msousa@350: } msousa@350: } msousa@350: return count2 == IN2->len -1 ? 0 : count1 + 1; msousa@350: } msousa@350: msousa@350: #define __iec_(TYPENAME) \ mjsousa@1011: static inline TYPENAME FIND__##TYPENAME##__STRING__STRING(EN_ENO_PARAMS STRING str1, STRING str2){\ msousa@350: TEST_EN(TYPENAME)\ msousa@350: return (TYPENAME)__pfind(&str1,&str2);\ msousa@350: } msousa@350: __ANY_INT(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: msousa@350: /*********************************************/ msousa@350: /*********************************************/ msousa@350: /* 2.5.1.5.6 Functions of time data types */ msousa@350: /*********************************************/ msousa@350: /*********************************************/ msousa@350: msousa@350: /**************************************/ msousa@350: /*** Table 30 ***/ msousa@350: /*** Functions of time data types ***/ msousa@350: /**************************************/ msousa@350: msousa@350: mjsousa@1011: static inline TIME ADD_TIME(EN_ENO_PARAMS TIME IN1, TIME IN2){ msousa@350: TEST_EN(TIME) msousa@350: return __time_add(IN1, IN2); msousa@350: } msousa@350: mjsousa@1011: static inline TOD ADD_TOD_TIME(EN_ENO_PARAMS TOD IN1, TIME IN2){ msousa@350: TEST_EN(TOD) msousa@350: return __time_add(IN1, IN2); msousa@350: } msousa@350: mjsousa@1011: static inline DT ADD_DT_TIME(EN_ENO_PARAMS DT IN1, TIME IN2){ msousa@350: TEST_EN(DT) msousa@350: return __time_add(IN1, IN2); msousa@350: } msousa@350: mjsousa@1011: static inline TIME SUB_TIME(EN_ENO_PARAMS TIME IN1, TIME IN2){ msousa@350: TEST_EN(TIME) msousa@350: return __time_sub(IN1, IN2); msousa@350: } msousa@350: mjsousa@1011: static inline TIME SUB_DATE_DATE(EN_ENO_PARAMS DATE IN1, DATE IN2){ msousa@350: TEST_EN(TIME) msousa@350: return __time_sub(IN1, IN2); msousa@350: } msousa@350: mjsousa@1011: static inline TOD SUB_TOD_TIME(EN_ENO_PARAMS TOD IN1, TIME IN2){ msousa@350: TEST_EN(TOD) msousa@350: return __time_sub(IN1, IN2); msousa@350: } msousa@350: mjsousa@1011: static inline TIME SUB_TOD_TOD(EN_ENO_PARAMS TOD IN1, TOD IN2){ msousa@350: TEST_EN(TIME) msousa@350: return __time_sub(IN1, IN2); msousa@350: } msousa@350: mjsousa@1011: static inline DT SUB_DT_TIME(EN_ENO_PARAMS DT IN1, TIME IN2){ msousa@350: TEST_EN(DT) msousa@350: return __time_sub(IN1, IN2); msousa@350: } msousa@350: mjsousa@1011: static inline TIME SUB_DT_DT(EN_ENO_PARAMS DT IN1, DT IN2){ msousa@350: TEST_EN(TIME) msousa@350: return __time_sub(IN1, IN2); msousa@350: } msousa@350: msousa@350: msousa@350: /*** MULTIME ***/ msousa@350: #define __iec_(TYPENAME)\ mjsousa@1011: static inline TIME MULTIME__TIME__TIME__##TYPENAME(EN_ENO_PARAMS TIME IN1, TYPENAME IN2){\ msousa@350: TEST_EN(TIME)\ conti@696: return __time_mul(IN1, (LREAL)IN2);\ msousa@350: } msousa@350: __ANY_NUM(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /*** MUL ***/ msousa@350: #define __iec_(TYPENAME)\ mjsousa@1011: static inline TIME MUL__TIME__TIME__##TYPENAME(EN_ENO_PARAMS TIME IN1, TYPENAME IN2){\ msousa@350: TEST_EN(TIME)\ conti@696: return __time_mul(IN1, (LREAL)IN2);\ msousa@350: } msousa@350: __ANY_NUM(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /*** DIVTIME ***/ msousa@350: #define __iec_(TYPENAME)\ mjsousa@1011: static inline TIME DIVTIME__TIME__TIME__##TYPENAME(EN_ENO_PARAMS TIME IN1, TYPENAME IN2){\ msousa@350: TEST_EN(TIME)\ conti@696: return __time_div(IN1, (LREAL)IN2);\ msousa@350: } msousa@350: __ANY_NUM(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /*** DIV ***/ msousa@350: #define __iec_(TYPENAME)\ mjsousa@1011: static inline TIME DIV__TIME__TIME__##TYPENAME(EN_ENO_PARAMS TIME IN1, TYPENAME IN2){\ msousa@350: TEST_EN(TIME)\ conti@696: return __time_div(IN1, (LREAL)IN2);\ msousa@350: } msousa@350: __ANY_NUM(__iec_) msousa@350: #undef __iec_ msousa@350: msousa@350: /*** CONCAT_DATE_TOD ***/ mjsousa@1011: static inline DT CONCAT_DATE_TOD(EN_ENO_PARAMS DATE IN1, TOD IN2){ msousa@350: TEST_EN(DT) msousa@350: return __time_add(IN1, IN2); msousa@350: } msousa@350: msousa@350: msousa@350: msousa@350: /****************************************************/ msousa@350: /****************************************************/ msousa@350: /* 2.5.1.5.6 Functions of enumerated data types */ msousa@350: /****************************************************/ msousa@350: /****************************************************/ msousa@350: msousa@350: /********************************************/ msousa@350: /*** Table 31 ***/ msousa@350: /*** Functions of enumerated data types ***/ msousa@350: /********************************************/ msousa@350: msousa@350: /* Do we support this? */ msousa@739: mjsousa@905: mjsousa@905: mjsousa@905: mjsousa@905: mjsousa@905: mjsousa@905: mjsousa@905: mjsousa@905: #endif /* _IEC_STD_FUNCTIONS_H */