diff -r b075f28ec081 -r fde2d08ebaee lib/iec_std_lib.h --- a/lib/iec_std_lib.h Tue Sep 01 17:01:08 2009 +0200 +++ b/lib/iec_std_lib.h Wed Sep 02 13:39:05 2009 +0200 @@ -185,6 +185,7 @@ static inline struct timespec __date_to_timespec(int day, int month, int year) { struct timespec ts; struct tm broken_down_time; + time_t epoch_seconds; broken_down_time.tm_sec = 0; broken_down_time.tm_min = 0; @@ -193,7 +194,7 @@ broken_down_time.tm_mon = month - 1; /* month since January, in the range 0 to 11 */ broken_down_time.tm_year = year - 1900; /* number of years since 1900 */ - time_t epoch_seconds = mktime(&broken_down_time); /* determine number of seconds since the epoch, i.e. Jan 1st 1970 */ + epoch_seconds = mktime(&broken_down_time); /* determine number of seconds since the epoch, i.e. Jan 1st 1970 */ if ((time_t)(-1) == epoch_seconds) IEC_error(); @@ -206,12 +207,13 @@ static inline struct timespec __dt_to_timespec(double seconds, double minutes, double hours, int day, int month, int year) { struct timespec ts; + struct tm broken_down_time; + time_t epoch_seconds; long double total_sec = (hours*60 + minutes)*60 + seconds; ts.tv_sec = (long int)total_sec; ts.tv_nsec = (long int)((total_sec - ts.tv_sec)*1e9); - struct tm broken_down_time; broken_down_time.tm_sec = 0; broken_down_time.tm_min = 0; broken_down_time.tm_hour = 0; @@ -219,7 +221,7 @@ broken_down_time.tm_mon = month - 1; /* month since January, in the range 0 to 11 */ broken_down_time.tm_year = year - 1900; /* number of years since 1900 */ - time_t epoch_seconds = mktime(&broken_down_time); /* determine number of seconds since the epoch, i.e. Jan 1st 1970 */ + epoch_seconds = mktime(&broken_down_time); /* determine number of seconds since the epoch, i.e. Jan 1st 1970 */ if ((time_t)(-1) == epoch_seconds) IEC_error(); @@ -323,24 +325,27 @@ return IN.len; } static inline STRING __left(EN_ENO_PARAMS, STRING IN, __strlen_t L){ + STRING res; TEST_EN_COND(STRING, L < 0) - STRING res = __INIT_STRING; + res = __INIT_STRING; L = L < IN.len ? L : IN.len; memcpy(&res.body, &IN.body, L); res.len = L; return res; } static inline STRING __right(EN_ENO_PARAMS, STRING IN, __strlen_t L){ + STRING res; TEST_EN_COND(STRING, L < 0) - STRING res = __INIT_STRING; + res = __INIT_STRING; L = L < IN.len ? L : IN.len; memcpy(&res.body, &IN.body[IN.len - L], L); res.len = L; return res; } static inline STRING __mid(EN_ENO_PARAMS, STRING IN, __strlen_t L, __strlen_t P){ + STRING res; TEST_EN_COND(STRING, L < 0 || P < 0) - STRING res = __INIT_STRING; + res = __INIT_STRING; if(P <= IN.len){ P -= 1; /* now can be used as [index]*/ L = L + P <= IN.len ? L : IN.len - P; @@ -350,11 +355,13 @@ return res; } static inline STRING __concat(EN_ENO_PARAMS, UINT param_count, ...){ + UINT i; + STRING res; + va_list ap; + __strlen_t charcount; TEST_EN(STRING) - va_list ap; - UINT i; - __strlen_t charcount = 0; - STRING res = __INIT_STRING; + charcount = 0; + res = __INIT_STRING; va_start (ap, param_count); /* Initialize the argument list. */ @@ -373,9 +380,10 @@ return res; } static inline STRING __insert(EN_ENO_PARAMS, STRING IN1, STRING IN2, __strlen_t P){ + STRING res; + __strlen_t to_copy; TEST_EN_COND(STRING, P < 0) - STRING res = __INIT_STRING; - __strlen_t to_copy; + res = __INIT_STRING; to_copy = P > IN1.len ? IN1.len : P - 1; memcpy(&res.body, &IN1.body , to_copy); @@ -392,9 +400,10 @@ return res; } static inline STRING __delete(EN_ENO_PARAMS, STRING IN, __strlen_t L, __strlen_t P){ + STRING res; + __strlen_t to_copy; TEST_EN_COND(STRING, L < 0 || P < 0) - STRING res = __INIT_STRING; - __strlen_t to_copy; + res = __INIT_STRING; to_copy = P > IN.len ? IN.len : P-1; memcpy(&res.body, &IN.body , to_copy); @@ -409,9 +418,10 @@ return res; } static inline STRING __replace(EN_ENO_PARAMS, STRING IN1, STRING IN2, __strlen_t L, __strlen_t P){ + STRING res; + __strlen_t to_copy; TEST_EN_COND(STRING, L < 0 || P < 0) - STRING res = __INIT_STRING; - __strlen_t to_copy; + res = __INIT_STRING; to_copy = P > IN1.len ? IN1.len : P-1; memcpy(&res.body, &IN1.body , to_copy); @@ -469,29 +479,33 @@ return (STRING){5,"FALSE"}; } static inline STRING __bit_to_string(EN_ENO_PARAMS, LWORD IN){ + STRING res; TEST_EN(STRING) - STRING res = __INIT_STRING; + res = __INIT_STRING; res.len = snprintf((char*)res.body, STR_MAX_LEN, "16#%llx", IN); if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; } static inline STRING __real_to_string(EN_ENO_PARAMS, LREAL IN){ + STRING res; TEST_EN(STRING) - STRING res = __INIT_STRING; + res = __INIT_STRING; res.len = snprintf((char*)res.body, STR_MAX_LEN, "%.10g", IN); if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; } static inline STRING __sint_to_string(EN_ENO_PARAMS, LINT IN){ + STRING res; TEST_EN(STRING) - STRING res = __INIT_STRING; + res = __INIT_STRING; res.len = snprintf((char*)res.body, STR_MAX_LEN, "%lld", IN); if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; } static inline STRING __uint_to_string(EN_ENO_PARAMS, ULINT IN){ + STRING res; TEST_EN(STRING) - STRING res = __INIT_STRING; + res = __INIT_STRING; res.len = snprintf((char*)res.body, STR_MAX_LEN, "%llu", IN); if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; @@ -578,9 +592,10 @@ return (ULINT)__pstring_to_sint(&IN); } static inline LREAL __string_to_real(EN_ENO_PARAMS, STRING IN){ - TEST_EN(LREAL) + __strlen_t l; + TEST_EN(LREAL) + l = IN.len; /* search the dot */ - __strlen_t l = IN.len; while(--l > 0 && IN.body[l] != '.'); if(l != 0){ return atof((const char *)&IN.body); @@ -602,7 +617,8 @@ return (TIME){IN, (IN - (LINT)IN) * 1000000000}; } static inline TIME __string_to_time(EN_ENO_PARAMS, STRING IN){ - TEST_EN(TIME) + __strlen_t l; + TEST_EN(TIME) /* TODO : * * Duration literals without underlines: T#14ms T#-14ms T#14.7s T#14.7m @@ -625,7 +641,7 @@ */ /* Quick hack : only transform seconds */ /* search the dot */ - __strlen_t l = IN.len; + l = IN.len; while(--l > 0 && IN.body[l] != '.'); if(l != 0){ LREAL IN_val = atof((const char *)&IN.body); @@ -647,10 +663,12 @@ return IN.tv_sec; } static inline STRING __time_to_string(EN_ENO_PARAMS, TIME IN){ + STRING res; + div_t days; TEST_EN(STRING) /*t#5d14h12m18s3.5ms*/ - STRING res = __INIT_STRING; - div_t days = div(IN.tv_sec ,86400); + res = __INIT_STRING; + days = div(IN.tv_sec ,86400); if(!days.rem && IN.tv_nsec == 0){ res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd", days.quot); }else{ @@ -674,11 +692,13 @@ return res; } static inline STRING __date_to_string(EN_ENO_PARAMS, DATE IN){ - TEST_EN(STRING) + STRING res; + struct tm* broken_down_time; + time_t seconds; + TEST_EN(STRING) /* D#1984-06-25 */ - STRING res = __INIT_STRING; - struct tm* broken_down_time; - time_t seconds = IN.tv_sec; + res = __INIT_STRING; + seconds = IN.tv_sec; if (NULL == (broken_down_time = localtime(&seconds))){ /* get the UTC (GMT) broken down time */ IEC_error(); return (STRING){7,"D#ERROR"}; @@ -688,11 +708,13 @@ return res; } static inline STRING __tod_to_string(EN_ENO_PARAMS, TOD IN){ + STRING res; + struct tm* broken_down_time; + time_t seconds; TEST_EN(STRING) /* TOD#15:36:55.36 */ - STRING res = __INIT_STRING; - struct tm* broken_down_time; - time_t seconds = IN.tv_sec; + res = __INIT_STRING; + seconds = IN.tv_sec; if (NULL == (broken_down_time = localtime(&seconds))){ /* get the UTC (GMT) broken down time */ IEC_error(); return (STRING){9,"TOD#ERROR"}; @@ -706,11 +728,12 @@ return res; } static inline STRING __dt_to_string(EN_ENO_PARAMS, DT IN){ + STRING res; + struct tm* broken_down_time; + time_t seconds; TEST_EN(STRING) /* DT#1984-06-25-15:36:55.36 */ - STRING res; - struct tm* broken_down_time; - time_t seconds = IN.tv_sec; + seconds = IN.tv_sec; if (NULL == (broken_down_time = localtime(&seconds))){ /* get the UTC (GMT) broken down time */ IEC_error(); return (STRING){8,"DT#ERROR"}; @@ -805,9 +828,9 @@ /*******************************************/ #define __arith_expand(fname,TYPENAME, OP) \ static inline TYPENAME fname##TYPENAME(EN_ENO_PARAMS, UINT param_count, TYPENAME op1, ...){\ - TEST_EN(TYPENAME)\ va_list ap;\ UINT i;\ + TEST_EN(TYPENAME)\ \ va_start (ap, op1); /* Initialize the argument list. */\ \ @@ -877,9 +900,9 @@ /* XOR */ /**************/ static inline BOOL __xor_BOOL(EN_ENO_PARAMS, UINT param_count, BOOL op1, ...){ - TEST_EN(BOOL) va_list ap; UINT i; + TEST_EN(BOOL) va_start (ap, op1); /* Initialize the argument list. */ @@ -1105,9 +1128,9 @@ #define __extrem_(fname,TYPENAME, COND) \ static inline TYPENAME fname##TYPENAME(EN_ENO_PARAMS, UINT param_count, TYPENAME op1, ...){\ - TEST_EN(TYPENAME)\ va_list ap;\ UINT i;\ + TEST_EN(TYPENAME)\ \ va_start (ap, op1); /* Initialize the argument list. */\ \ @@ -1151,10 +1174,11 @@ /**************/ #define __mux_(TYPENAME) \ static inline TYPENAME __mux_##TYPENAME(EN_ENO_PARAMS, UINT param_count, UINT K, ...){\ - TEST_EN_COND(TYPENAME, K >= param_count)\ va_list ap;\ UINT i;\ - TYPENAME tmp = __INIT_##TYPENAME;\ + TYPENAME tmp;\ + TEST_EN_COND(TYPENAME, K >= param_count)\ + tmp = __INIT_##TYPENAME;\ \ va_start (ap, K); /* Initialize the argument list. */\ \ @@ -1180,9 +1204,9 @@ #define __compare_(fname,TYPENAME, COND) \ static inline BOOL fname##TYPENAME(EN_ENO_PARAMS, UINT param_count, TYPENAME op1, ...){\ - TEST_EN(BOOL)\ va_list ap;\ UINT i;\ + TEST_EN(BOOL)\ \ va_start (ap, op1); /* Initialize the argument list. */\ DBG(#fname #TYPENAME "\n")\