lib/iec_std_lib.h
changeset 200 fde2d08ebaee
parent 199 b075f28ec081
child 212 8c9ec7d37d3a
equal deleted inserted replaced
199:b075f28ec081 200:fde2d08ebaee
   183 }
   183 }
   184 
   184 
   185 static inline struct timespec __date_to_timespec(int day, int month, int year) {
   185 static inline struct timespec __date_to_timespec(int day, int month, int year) {
   186   struct timespec ts;
   186   struct timespec ts;
   187   struct tm broken_down_time;
   187   struct tm broken_down_time;
       
   188   time_t epoch_seconds;
   188 
   189 
   189   broken_down_time.tm_sec = 0;
   190   broken_down_time.tm_sec = 0;
   190   broken_down_time.tm_min = 0;
   191   broken_down_time.tm_min = 0;
   191   broken_down_time.tm_hour = 0;
   192   broken_down_time.tm_hour = 0;
   192   broken_down_time.tm_mday = day;  /* day of month, from 1 to 31 */
   193   broken_down_time.tm_mday = day;  /* day of month, from 1 to 31 */
   193   broken_down_time.tm_mon = month - 1;   /* month since January, in the range 0 to 11 */
   194   broken_down_time.tm_mon = month - 1;   /* month since January, in the range 0 to 11 */
   194   broken_down_time.tm_year = year - 1900;  /* number of years since 1900 */
   195   broken_down_time.tm_year = year - 1900;  /* number of years since 1900 */
   195 
   196 
   196   time_t epoch_seconds = mktime(&broken_down_time); /* determine number of seconds since the epoch, i.e. Jan 1st 1970 */
   197   epoch_seconds = mktime(&broken_down_time); /* determine number of seconds since the epoch, i.e. Jan 1st 1970 */
   197 
   198 
   198   if ((time_t)(-1) == epoch_seconds)
   199   if ((time_t)(-1) == epoch_seconds)
   199     IEC_error();
   200     IEC_error();
   200 
   201 
   201   ts.tv_sec = epoch_seconds;
   202   ts.tv_sec = epoch_seconds;
   204   return ts;
   205   return ts;
   205 }
   206 }
   206 
   207 
   207 static inline struct timespec __dt_to_timespec(double seconds,  double minutes, double hours, int day, int month, int year) {
   208 static inline struct timespec __dt_to_timespec(double seconds,  double minutes, double hours, int day, int month, int year) {
   208   struct timespec ts;
   209   struct timespec ts;
       
   210   struct tm broken_down_time;
       
   211   time_t epoch_seconds;
   209 
   212 
   210   long double total_sec = (hours*60 + minutes)*60 + seconds;
   213   long double total_sec = (hours*60 + minutes)*60 + seconds;
   211   ts.tv_sec = (long int)total_sec;
   214   ts.tv_sec = (long int)total_sec;
   212   ts.tv_nsec = (long int)((total_sec - ts.tv_sec)*1e9);
   215   ts.tv_nsec = (long int)((total_sec - ts.tv_sec)*1e9);
   213 
   216 
   214   struct tm broken_down_time;
       
   215   broken_down_time.tm_sec = 0;
   217   broken_down_time.tm_sec = 0;
   216   broken_down_time.tm_min = 0;
   218   broken_down_time.tm_min = 0;
   217   broken_down_time.tm_hour = 0;
   219   broken_down_time.tm_hour = 0;
   218   broken_down_time.tm_mday = day;  /* day of month, from 1 to 31 */
   220   broken_down_time.tm_mday = day;  /* day of month, from 1 to 31 */
   219   broken_down_time.tm_mon = month - 1;   /* month since January, in the range 0 to 11 */
   221   broken_down_time.tm_mon = month - 1;   /* month since January, in the range 0 to 11 */
   220   broken_down_time.tm_year = year - 1900;  /* number of years since 1900 */
   222   broken_down_time.tm_year = year - 1900;  /* number of years since 1900 */
   221 
   223 
   222   time_t epoch_seconds = mktime(&broken_down_time); /* determine number of seconds since the epoch, i.e. Jan 1st 1970 */
   224   epoch_seconds = mktime(&broken_down_time); /* determine number of seconds since the epoch, i.e. Jan 1st 1970 */
   223   if ((time_t)(-1) == epoch_seconds)
   225   if ((time_t)(-1) == epoch_seconds)
   224     IEC_error();
   226     IEC_error();
   225 
   227 
   226   ts.tv_sec += epoch_seconds;
   228   ts.tv_sec += epoch_seconds;
   227   if (ts.tv_sec < epoch_seconds)
   229   if (ts.tv_sec < epoch_seconds)
   321 static inline __strlen_t __len(EN_ENO_PARAMS, STRING IN){
   323 static inline __strlen_t __len(EN_ENO_PARAMS, STRING IN){
   322     TEST_EN(UINT)
   324     TEST_EN(UINT)
   323     return IN.len;
   325     return IN.len;
   324 }
   326 }
   325 static inline STRING __left(EN_ENO_PARAMS, STRING IN, __strlen_t L){
   327 static inline STRING __left(EN_ENO_PARAMS, STRING IN, __strlen_t L){
       
   328     STRING res;
   326     TEST_EN_COND(STRING, L < 0)
   329     TEST_EN_COND(STRING, L < 0)
   327     STRING res = __INIT_STRING;
   330     res = __INIT_STRING;
   328     L = L < IN.len ? L : IN.len;
   331     L = L < IN.len ? L : IN.len;
   329     memcpy(&res.body, &IN.body, L);
   332     memcpy(&res.body, &IN.body, L);
   330     res.len = L;
   333     res.len = L;
   331     return res;
   334     return res;
   332 }
   335 }
   333 static inline STRING __right(EN_ENO_PARAMS, STRING IN, __strlen_t L){
   336 static inline STRING __right(EN_ENO_PARAMS, STRING IN, __strlen_t L){
       
   337     STRING res;
   334     TEST_EN_COND(STRING, L < 0)
   338     TEST_EN_COND(STRING, L < 0)
   335     STRING res = __INIT_STRING;
   339     res = __INIT_STRING;
   336     L = L < IN.len ? L : IN.len;
   340     L = L < IN.len ? L : IN.len;
   337     memcpy(&res.body, &IN.body[IN.len - L], L);
   341     memcpy(&res.body, &IN.body[IN.len - L], L);
   338     res.len = L;
   342     res.len = L;
   339     return res;
   343     return res;
   340 }
   344 }
   341 static inline STRING __mid(EN_ENO_PARAMS, STRING IN, __strlen_t L, __strlen_t P){
   345 static inline STRING __mid(EN_ENO_PARAMS, STRING IN, __strlen_t L, __strlen_t P){
       
   346     STRING res;
   342     TEST_EN_COND(STRING, L < 0 || P < 0)
   347     TEST_EN_COND(STRING, L < 0 || P < 0)
   343     STRING res = __INIT_STRING;
   348     res = __INIT_STRING;
   344     if(P <= IN.len){
   349     if(P <= IN.len){
   345 	    P -= 1; /* now can be used as [index]*/
   350 	    P -= 1; /* now can be used as [index]*/
   346 	    L = L + P <= IN.len ? L : IN.len - P;
   351 	    L = L + P <= IN.len ? L : IN.len - P;
   347 	    memcpy(&res.body, &IN.body[P] , L);
   352 	    memcpy(&res.body, &IN.body[P] , L);
   348         res.len = L;
   353         res.len = L;
   349     }
   354     }
   350     return res;
   355     return res;
   351 }
   356 }
   352 static inline STRING __concat(EN_ENO_PARAMS, UINT param_count, ...){
   357 static inline STRING __concat(EN_ENO_PARAMS, UINT param_count, ...){
       
   358   UINT i;
       
   359   STRING res;
       
   360   va_list ap;
       
   361   __strlen_t charcount;
   353   TEST_EN(STRING)
   362   TEST_EN(STRING)
   354   va_list ap;
   363   charcount = 0;
   355   UINT i;
   364   res = __INIT_STRING;
   356   __strlen_t charcount = 0;
       
   357   STRING res = __INIT_STRING;
       
   358 
   365 
   359   va_start (ap, param_count);         /* Initialize the argument list.  */
   366   va_start (ap, param_count);         /* Initialize the argument list.  */
   360 
   367 
   361   for (i = 0; i < param_count && charcount < STR_MAX_LEN; i++)
   368   for (i = 0; i < param_count && charcount < STR_MAX_LEN; i++)
   362   {
   369   {
   371 
   378 
   372   va_end (ap);                  /* Clean up.  */
   379   va_end (ap);                  /* Clean up.  */
   373   return res;
   380   return res;
   374 }
   381 }
   375 static inline STRING __insert(EN_ENO_PARAMS, STRING IN1, STRING IN2, __strlen_t P){
   382 static inline STRING __insert(EN_ENO_PARAMS, STRING IN1, STRING IN2, __strlen_t P){
       
   383     STRING res;
       
   384     __strlen_t to_copy;
   376     TEST_EN_COND(STRING, P < 0)
   385     TEST_EN_COND(STRING, P < 0)
   377     STRING res = __INIT_STRING;
   386     res = __INIT_STRING;
   378     __strlen_t to_copy;
       
   379 
   387 
   380     to_copy = P > IN1.len ? IN1.len : P - 1;
   388     to_copy = P > IN1.len ? IN1.len : P - 1;
   381     memcpy(&res.body, &IN1.body , to_copy);
   389     memcpy(&res.body, &IN1.body , to_copy);
   382     P = res.len = to_copy;
   390     P = res.len = to_copy;
   383 
   391 
   390     res.len += to_copy;
   398     res.len += to_copy;
   391 
   399 
   392     return res;
   400     return res;
   393 }
   401 }
   394 static inline STRING __delete(EN_ENO_PARAMS, STRING IN, __strlen_t L, __strlen_t P){
   402 static inline STRING __delete(EN_ENO_PARAMS, STRING IN, __strlen_t L, __strlen_t P){
       
   403     STRING res;
       
   404     __strlen_t to_copy;
   395     TEST_EN_COND(STRING, L < 0 || P < 0)
   405     TEST_EN_COND(STRING, L < 0 || P < 0)
   396     STRING res = __INIT_STRING;
   406     res = __INIT_STRING;
   397     __strlen_t to_copy;
       
   398 
   407 
   399     to_copy = P > IN.len ? IN.len : P-1;
   408     to_copy = P > IN.len ? IN.len : P-1;
   400     memcpy(&res.body, &IN.body , to_copy);
   409     memcpy(&res.body, &IN.body , to_copy);
   401     P = res.len = to_copy;
   410     P = res.len = to_copy;
   402 
   411 
   407     }
   416     }
   408 
   417 
   409     return res;
   418     return res;
   410 }
   419 }
   411 static inline STRING __replace(EN_ENO_PARAMS, STRING IN1, STRING IN2, __strlen_t L, __strlen_t P){
   420 static inline STRING __replace(EN_ENO_PARAMS, STRING IN1, STRING IN2, __strlen_t L, __strlen_t P){
       
   421     STRING res;
       
   422     __strlen_t to_copy;
   412     TEST_EN_COND(STRING, L < 0 || P < 0)
   423     TEST_EN_COND(STRING, L < 0 || P < 0)
   413     STRING res = __INIT_STRING;
   424     res = __INIT_STRING;
   414     __strlen_t to_copy;
       
   415 
   425 
   416     to_copy = P > IN1.len ? IN1.len : P-1;
   426     to_copy = P > IN1.len ? IN1.len : P-1;
   417     memcpy(&res.body, &IN1.body , to_copy);
   427     memcpy(&res.body, &IN1.body , to_copy);
   418     P = res.len = to_copy;
   428     P = res.len = to_copy;
   419 
   429 
   467     if(IN)
   477     if(IN)
   468         return (STRING){4, "TRUE"};
   478         return (STRING){4, "TRUE"};
   469     return (STRING){5,"FALSE"};
   479     return (STRING){5,"FALSE"};
   470 }
   480 }
   471 static inline STRING __bit_to_string(EN_ENO_PARAMS, LWORD IN){
   481 static inline STRING __bit_to_string(EN_ENO_PARAMS, LWORD IN){
       
   482     STRING res;
   472     TEST_EN(STRING)
   483     TEST_EN(STRING)
   473     STRING res = __INIT_STRING;
   484     res = __INIT_STRING;
   474     res.len = snprintf((char*)res.body, STR_MAX_LEN, "16#%llx", IN);
   485     res.len = snprintf((char*)res.body, STR_MAX_LEN, "16#%llx", IN);
   475     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   486     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   476     return res;
   487     return res;
   477 }
   488 }
   478 static inline STRING __real_to_string(EN_ENO_PARAMS, LREAL IN){
   489 static inline STRING __real_to_string(EN_ENO_PARAMS, LREAL IN){
       
   490     STRING res;
   479     TEST_EN(STRING)
   491     TEST_EN(STRING)
   480     STRING res = __INIT_STRING;
   492     res = __INIT_STRING;
   481     res.len = snprintf((char*)res.body, STR_MAX_LEN, "%.10g", IN);
   493     res.len = snprintf((char*)res.body, STR_MAX_LEN, "%.10g", IN);
   482     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   494     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   483     return res;
   495     return res;
   484 }
   496 }
   485 static inline STRING __sint_to_string(EN_ENO_PARAMS, LINT IN){
   497 static inline STRING __sint_to_string(EN_ENO_PARAMS, LINT IN){
       
   498     STRING res;
   486     TEST_EN(STRING)
   499     TEST_EN(STRING)
   487     STRING res = __INIT_STRING;
   500     res = __INIT_STRING;
   488     res.len = snprintf((char*)res.body, STR_MAX_LEN, "%lld", IN);
   501     res.len = snprintf((char*)res.body, STR_MAX_LEN, "%lld", IN);
   489     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   502     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   490     return res;
   503     return res;
   491 }
   504 }
   492 static inline STRING __uint_to_string(EN_ENO_PARAMS, ULINT IN){
   505 static inline STRING __uint_to_string(EN_ENO_PARAMS, ULINT IN){
       
   506     STRING res;
   493     TEST_EN(STRING)
   507     TEST_EN(STRING)
   494     STRING res = __INIT_STRING;
   508     res = __INIT_STRING;
   495     res.len = snprintf((char*)res.body, STR_MAX_LEN, "%llu", IN);
   509     res.len = snprintf((char*)res.body, STR_MAX_LEN, "%llu", IN);
   496     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   510     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   497     return res;
   511     return res;
   498 }
   512 }
   499     /***************/
   513     /***************/
   576 static inline ULINT __string_to_uint(EN_ENO_PARAMS, STRING IN){
   590 static inline ULINT __string_to_uint(EN_ENO_PARAMS, STRING IN){
   577     TEST_EN(ULINT)
   591     TEST_EN(ULINT)
   578     return (ULINT)__pstring_to_sint(&IN);
   592     return (ULINT)__pstring_to_sint(&IN);
   579 }
   593 }
   580 static inline LREAL __string_to_real(EN_ENO_PARAMS, STRING IN){
   594 static inline LREAL __string_to_real(EN_ENO_PARAMS, STRING IN){
   581     TEST_EN(LREAL)
   595 	__strlen_t l;
       
   596 	TEST_EN(LREAL)
       
   597 	l = IN.len;
   582     /* search the dot */
   598     /* search the dot */
   583     __strlen_t l = IN.len;
       
   584     while(--l > 0 && IN.body[l] != '.');
   599     while(--l > 0 && IN.body[l] != '.');
   585     if(l != 0){
   600     if(l != 0){
   586         return atof((const char *)&IN.body);
   601         return atof((const char *)&IN.body);
   587     }else{
   602     }else{
   588         return (LREAL)__pstring_to_sint(&IN);
   603         return (LREAL)__pstring_to_sint(&IN);
   600 static inline TIME __real_to_time(EN_ENO_PARAMS, LREAL IN){
   615 static inline TIME __real_to_time(EN_ENO_PARAMS, LREAL IN){
   601     TEST_EN(TIME)
   616     TEST_EN(TIME)
   602     return (TIME){IN, (IN - (LINT)IN) * 1000000000};
   617     return (TIME){IN, (IN - (LINT)IN) * 1000000000};
   603 }
   618 }
   604 static inline TIME __string_to_time(EN_ENO_PARAMS, STRING IN){
   619 static inline TIME __string_to_time(EN_ENO_PARAMS, STRING IN){
   605     TEST_EN(TIME)
   620 	__strlen_t l;
       
   621 	TEST_EN(TIME)
   606     /* TODO :
   622     /* TODO :
   607      *
   623      *
   608      *  Duration literals without underlines: T#14ms    T#-14ms   T#14.7s   T#14.7m
   624      *  Duration literals without underlines: T#14ms    T#-14ms   T#14.7s   T#14.7m
   609      *                short prefix            T#14.7h    t#14.7d   t#25h15m
   625      *                short prefix            T#14.7h    t#14.7d   t#25h15m
   610      *                                        t#5d14h12m18s3.5ms
   626      *                                        t#5d14h12m18s3.5ms
   623      *  date_and_time#1984-06-25-15:36:55.36 dt#1984-06-25-15:36:55.36
   639      *  date_and_time#1984-06-25-15:36:55.36 dt#1984-06-25-15:36:55.36
   624      *
   640      *
   625      */
   641      */
   626     /* Quick hack : only transform seconds */
   642     /* Quick hack : only transform seconds */
   627     /* search the dot */
   643     /* search the dot */
   628     __strlen_t l = IN.len;
   644 	l = IN.len;
   629     while(--l > 0 && IN.body[l] != '.');
   645     while(--l > 0 && IN.body[l] != '.');
   630     if(l != 0){
   646     if(l != 0){
   631         LREAL IN_val = atof((const char *)&IN.body);
   647         LREAL IN_val = atof((const char *)&IN.body);
   632         return  (TIME){IN_val, (IN_val - (LINT)IN_val)*1000000000};
   648         return  (TIME){IN_val, (IN_val - (LINT)IN_val)*1000000000};
   633     }else{
   649     }else{
   645 static inline LINT __time_to_int(EN_ENO_PARAMS, TIME IN){
   661 static inline LINT __time_to_int(EN_ENO_PARAMS, TIME IN){
   646     TEST_EN(LINT)
   662     TEST_EN(LINT)
   647     return IN.tv_sec;
   663     return IN.tv_sec;
   648 }
   664 }
   649 static inline STRING __time_to_string(EN_ENO_PARAMS, TIME IN){
   665 static inline STRING __time_to_string(EN_ENO_PARAMS, TIME IN){
       
   666     STRING res;
       
   667     div_t days;
   650     TEST_EN(STRING)
   668     TEST_EN(STRING)
   651     /*t#5d14h12m18s3.5ms*/
   669     /*t#5d14h12m18s3.5ms*/
   652     STRING res = __INIT_STRING;
   670     res = __INIT_STRING;
   653     div_t days = div(IN.tv_sec ,86400);
   671     days = div(IN.tv_sec ,86400);
   654     if(!days.rem && IN.tv_nsec == 0){
   672     if(!days.rem && IN.tv_nsec == 0){
   655         res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd", days.quot);
   673         res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd", days.quot);
   656     }else{
   674     }else{
   657         div_t hours = div(days.rem, 3600);
   675         div_t hours = div(days.rem, 3600);
   658         if(!hours.rem && IN.tv_nsec == 0){
   676         if(!hours.rem && IN.tv_nsec == 0){
   672     }
   690     }
   673     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   691     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   674     return res;
   692     return res;
   675 }
   693 }
   676 static inline STRING __date_to_string(EN_ENO_PARAMS, DATE IN){
   694 static inline STRING __date_to_string(EN_ENO_PARAMS, DATE IN){
   677     TEST_EN(STRING)
   695     STRING res;
       
   696     struct tm* broken_down_time;
       
   697     time_t seconds;
       
   698 	TEST_EN(STRING)
   678     /* D#1984-06-25 */
   699     /* D#1984-06-25 */
   679     STRING res = __INIT_STRING;
   700     res = __INIT_STRING;
   680     struct tm* broken_down_time;
   701     seconds = IN.tv_sec;
   681     time_t seconds = IN.tv_sec;
       
   682     if (NULL == (broken_down_time = localtime(&seconds))){ /* get the UTC (GMT) broken down time */
   702     if (NULL == (broken_down_time = localtime(&seconds))){ /* get the UTC (GMT) broken down time */
   683         IEC_error();
   703         IEC_error();
   684         return (STRING){7,"D#ERROR"};
   704         return (STRING){7,"D#ERROR"};
   685     }
   705     }
   686     res.len = snprintf((char*)&res.body, STR_MAX_LEN, "D#%d-%2.2d-%2.2d", broken_down_time->tm_year + 1900, broken_down_time->tm_mon + 1, broken_down_time->tm_mday);
   706     res.len = snprintf((char*)&res.body, STR_MAX_LEN, "D#%d-%2.2d-%2.2d", broken_down_time->tm_year + 1900, broken_down_time->tm_mon + 1, broken_down_time->tm_mday);
   687     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   707     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   688     return res;
   708     return res;
   689 }
   709 }
   690 static inline STRING __tod_to_string(EN_ENO_PARAMS, TOD IN){
   710 static inline STRING __tod_to_string(EN_ENO_PARAMS, TOD IN){
       
   711     STRING res;
       
   712     struct tm* broken_down_time;
       
   713     time_t seconds;
   691     TEST_EN(STRING)
   714     TEST_EN(STRING)
   692     /* TOD#15:36:55.36 */
   715     /* TOD#15:36:55.36 */
   693     STRING res = __INIT_STRING;
   716     res = __INIT_STRING;
   694     struct tm* broken_down_time;
   717     seconds = IN.tv_sec;
   695     time_t seconds = IN.tv_sec;
       
   696     if (NULL == (broken_down_time = localtime(&seconds))){ /* get the UTC (GMT) broken down time */
   718     if (NULL == (broken_down_time = localtime(&seconds))){ /* get the UTC (GMT) broken down time */
   697         IEC_error();
   719         IEC_error();
   698         return (STRING){9,"TOD#ERROR"};
   720         return (STRING){9,"TOD#ERROR"};
   699     }
   721     }
   700     if(IN.tv_nsec == 0){
   722     if(IN.tv_nsec == 0){
   704     }
   726     }
   705     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   727     if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
   706     return res;
   728     return res;
   707 }
   729 }
   708 static inline STRING __dt_to_string(EN_ENO_PARAMS, DT IN){
   730 static inline STRING __dt_to_string(EN_ENO_PARAMS, DT IN){
       
   731     STRING res;
       
   732     struct tm* broken_down_time;
       
   733     time_t seconds;
   709     TEST_EN(STRING)
   734     TEST_EN(STRING)
   710     /* DT#1984-06-25-15:36:55.36 */
   735     /* DT#1984-06-25-15:36:55.36 */
   711     STRING res;
   736     seconds = IN.tv_sec;
   712     struct tm* broken_down_time;
       
   713     time_t seconds = IN.tv_sec;
       
   714     if (NULL == (broken_down_time = localtime(&seconds))){ /* get the UTC (GMT) broken down time */
   737     if (NULL == (broken_down_time = localtime(&seconds))){ /* get the UTC (GMT) broken down time */
   715         IEC_error();
   738         IEC_error();
   716         return (STRING){8,"DT#ERROR"};
   739         return (STRING){8,"DT#ERROR"};
   717     }
   740     }
   718     if(IN.tv_nsec == 0){
   741     if(IN.tv_nsec == 0){
   803 /*******************************************/
   826 /*******************************************/
   804 /*     Arithmetic and bitwise functions    */
   827 /*     Arithmetic and bitwise functions    */
   805 /*******************************************/
   828 /*******************************************/
   806 #define __arith_expand(fname,TYPENAME, OP) \
   829 #define __arith_expand(fname,TYPENAME, OP) \
   807 static inline TYPENAME fname##TYPENAME(EN_ENO_PARAMS, UINT param_count, TYPENAME op1, ...){\
   830 static inline TYPENAME fname##TYPENAME(EN_ENO_PARAMS, UINT param_count, TYPENAME op1, ...){\
   808   TEST_EN(TYPENAME)\
       
   809   va_list ap;\
   831   va_list ap;\
   810   UINT i;\
   832   UINT i;\
       
   833   TEST_EN(TYPENAME)\
   811   \
   834   \
   812   va_start (ap, op1);         /* Initialize the argument list.  */\
   835   va_start (ap, op1);         /* Initialize the argument list.  */\
   813   \
   836   \
   814   for (i = 0; i < param_count - 1; i++){\
   837   for (i = 0; i < param_count - 1; i++){\
   815     op1 = op1 OP va_arg (ap, VA_ARGS_##TYPENAME);\
   838     op1 = op1 OP va_arg (ap, VA_ARGS_##TYPENAME);\
   875 
   898 
   876 /**************/
   899 /**************/
   877 /*     XOR    */
   900 /*     XOR    */
   878 /**************/
   901 /**************/
   879 static inline BOOL __xor_BOOL(EN_ENO_PARAMS, UINT param_count, BOOL op1, ...){
   902 static inline BOOL __xor_BOOL(EN_ENO_PARAMS, UINT param_count, BOOL op1, ...){
   880   TEST_EN(BOOL)
       
   881   va_list ap;
   903   va_list ap;
   882   UINT i;
   904   UINT i;
       
   905   TEST_EN(BOOL)
   883 
   906 
   884   va_start (ap, op1);         /* Initialize the argument list.  */
   907   va_start (ap, op1);         /* Initialize the argument list.  */
   885 
   908 
   886   for (i = 0; i < param_count - 1; i++){
   909   for (i = 0; i < param_count - 1; i++){
   887     BOOL tmp = va_arg (ap, VA_ARGS_BOOL);
   910     BOOL tmp = va_arg (ap, VA_ARGS_BOOL);
  1103     /*     MAX    */
  1126     /*     MAX    */
  1104     /**************/
  1127     /**************/
  1105 
  1128 
  1106 #define __extrem_(fname,TYPENAME, COND) \
  1129 #define __extrem_(fname,TYPENAME, COND) \
  1107 static inline TYPENAME fname##TYPENAME(EN_ENO_PARAMS, UINT param_count, TYPENAME op1, ...){\
  1130 static inline TYPENAME fname##TYPENAME(EN_ENO_PARAMS, UINT param_count, TYPENAME op1, ...){\
  1108   TEST_EN(TYPENAME)\
       
  1109   va_list ap;\
  1131   va_list ap;\
  1110   UINT i;\
  1132   UINT i;\
       
  1133   TEST_EN(TYPENAME)\
  1111   \
  1134   \
  1112   va_start (ap, op1);         /* Initialize the argument list.  */\
  1135   va_start (ap, op1);         /* Initialize the argument list.  */\
  1113   \
  1136   \
  1114   for (i = 0; i < param_count - 1; i++){\
  1137   for (i = 0; i < param_count - 1; i++){\
  1115     TYPENAME tmp = va_arg (ap, VA_ARGS_##TYPENAME);\
  1138     TYPENAME tmp = va_arg (ap, VA_ARGS_##TYPENAME);\
  1149     /**************/
  1172     /**************/
  1150     /*     MUX    */
  1173     /*     MUX    */
  1151     /**************/
  1174     /**************/
  1152 #define __mux_(TYPENAME) \
  1175 #define __mux_(TYPENAME) \
  1153 static inline TYPENAME __mux_##TYPENAME(EN_ENO_PARAMS, UINT param_count, UINT K, ...){\
  1176 static inline TYPENAME __mux_##TYPENAME(EN_ENO_PARAMS, UINT param_count, UINT K, ...){\
  1154   TEST_EN_COND(TYPENAME, K >= param_count)\
       
  1155   va_list ap;\
  1177   va_list ap;\
  1156   UINT i;\
  1178   UINT i;\
  1157   TYPENAME tmp = __INIT_##TYPENAME;\
  1179   TYPENAME tmp;\
       
  1180   TEST_EN_COND(TYPENAME, K >= param_count)\
       
  1181   tmp = __INIT_##TYPENAME;\
  1158   \
  1182   \
  1159   va_start (ap, K);         /* Initialize the argument list.  */\
  1183   va_start (ap, K);         /* Initialize the argument list.  */\
  1160   \
  1184   \
  1161   for (i = 0; i < param_count; i++){\
  1185   for (i = 0; i < param_count; i++){\
  1162     if(K == i){\
  1186     if(K == i){\
  1178 /* Comparison */
  1202 /* Comparison */
  1179 /**************/
  1203 /**************/
  1180 
  1204 
  1181 #define __compare_(fname,TYPENAME, COND) \
  1205 #define __compare_(fname,TYPENAME, COND) \
  1182 static inline BOOL fname##TYPENAME(EN_ENO_PARAMS, UINT param_count, TYPENAME op1, ...){\
  1206 static inline BOOL fname##TYPENAME(EN_ENO_PARAMS, UINT param_count, TYPENAME op1, ...){\
  1183   TEST_EN(BOOL)\
       
  1184   va_list ap;\
  1207   va_list ap;\
  1185   UINT i;\
  1208   UINT i;\
       
  1209   TEST_EN(BOOL)\
  1186   \
  1210   \
  1187   va_start (ap, op1);         /* Initialize the argument list.  */\
  1211   va_start (ap, op1);         /* Initialize the argument list.  */\
  1188   DBG(#fname #TYPENAME "\n")\
  1212   DBG(#fname #TYPENAME "\n")\
  1189   DBG_TYPE(TYPENAME, op1)\
  1213   DBG_TYPE(TYPENAME, op1)\
  1190   \
  1214   \