lib/iec_std_lib.h
author laurent
Mon, 06 Jun 2011 16:28:41 +0200
changeset 314 41d4ac0b4821
parent 313 90c3772e6547
child 348 990ecb883731
child 350 2c3c4dc34979
permissions -rwxr-xr-x
Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
107
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
     1
/*
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
     2
 * (c) 2008 Edouard TISSERANT
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
     3
 *
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
     4
 * Offered to the public under the terms of the GNU Lesser General Public
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
     5
 * License as published by the Free Software Foundation; either version 2
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
     6
 * of the License, or (at your option) any later version.
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
     7
 *
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
     8
 * This program is distributed in the hope that it will be useful, but
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
     9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
    10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
    11
 * General Public License for more details.
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
    12
 *
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
    13
 * This code is made available on the understanding that it will not be
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
    14
 * used in safety-critical situations without a full and competent review.
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
    15
 */
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
    16
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    17
/****
107
ff5c92df0c78 Fixed headers of generated code
etisserant
parents: 66
diff changeset
    18
 * IEC 61131-3 standard function library
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    19
 */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    20
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    21
#include <limits.h>
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    22
#include <float.h>
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    23
#include <math.h>
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    24
#include <time.h>
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    25
#include <stdint.h>
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    26
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
    27
#include <stdio.h>
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    28
#include <stdlib.h>
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    29
#include <string.h>
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    30
#include <stdarg.h>
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    31
43
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
    32
#ifdef DEBUG_IEC
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
    33
#define DBG(...) printf(__VA_ARGS__);
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
    34
#define DBG_TYPE(TYPENAME, name) __print_##TYPENAME(name);
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
    35
#else
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
    36
#define DBG(...)
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
    37
#define DBG_TYPE(TYPENAME, name)
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
    38
#endif
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
    39
137
9ceda59abd27 Re-organized types headers, to ease debug code generation
etisserant
parents: 129
diff changeset
    40
/*
9ceda59abd27 Re-organized types headers, to ease debug code generation
etisserant
parents: 129
diff changeset
    41
 * Include type defs.
9ceda59abd27 Re-organized types headers, to ease debug code generation
etisserant
parents: 129
diff changeset
    42
 */
9ceda59abd27 Re-organized types headers, to ease debug code generation
etisserant
parents: 129
diff changeset
    43
#include "iec_types_all.h"
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    44
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
    45
extern TIME __CURRENT_TIME;
140
8c0366d41e84 Added __DEBUG global var to eventually change PLC code execution
etisserant
parents: 137
diff changeset
    46
extern BOOL __DEBUG;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    47
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    48
/* TODO
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    49
typedef struct {
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    50
    __strlen_t len;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    51
    u_int16_t body[STR_MAX_LEN];
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    52
} WSTRING;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    53
*/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
    54
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    55
# if __WORDSIZE == 64
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    56
#define __32b_sufix
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    57
#define __64b_sufix L
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    58
#else
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    59
#define __32b_sufix L
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
    60
#define __64b_sufix LL
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
    61
#endif
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    62
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    63
#define __lit(type,value,sfx) (type)value##sfx
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
    64
// Keep this macro expention step to let sfx change into L or LL
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    65
#define __literal(type,value,sfx) __lit(type,value,sfx)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    66
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    67
#define __BOOL_LITERAL(value) __literal(BOOL,value,)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    68
#define __SINT_LITERAL(value) __literal(SINT,value,)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    69
#define __INT_LITERAL(value) __literal(INT,value,)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    70
#define __DINT_LITERAL(value) __literal(DINT,value,__32b_sufix)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    71
#define __LINT_LITERAL(value) __literal(LINT,value,__64b_sufix)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    72
#define __USINT_LITERAL(value) __literal(USINT,value,)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    73
#define __UINT_LITERAL(value) __literal(UINT,value,)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    74
#define __UDINT_LITERAL(value) __literal(UDINT,value,__32b_sufix)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    75
#define __ULINT_LITERAL(value) __literal(ULINT,value,__64b_sufix)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    76
#define __REAL_LITERAL(value) __literal(REAL,value,__32b_sufix)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    77
#define __LREAL_LITERAL(value) __literal(LREAL,value,__64b_sufix)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    78
#define __TIME_LITERAL(value) __literal(TIME,value,)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    79
#define __DATE_LITERAL(value) __literal(DATE,value,)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    80
#define __TOD_LITERAL(value) __literal(TOD,value,)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    81
#define __DT_LITERAL(value) __literal(DT,value,)
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 212
diff changeset
    82
#define __STRING_LITERAL(count,value) (STRING){count,value}
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    83
#define __BYTE_LITERAL(value) __literal(BYTE,value,)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    84
#define __WORD_LITERAL(value) __literal(WORD,value,)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    85
#define __DWORD_LITERAL(value) __literal(DWORD,value,__32b_sufix)
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
    86
#define __LWORD_LITERAL(value) __literal(LWORD,value,__32b_sufix)
55
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 48
diff changeset
    87
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 48
diff changeset
    88
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 48
diff changeset
    89
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
    90
#define __INIT_REAL 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
    91
#define __INIT_LREAL 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
    92
#define __INIT_SINT 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
    93
#define __INIT_INT 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
    94
#define __INIT_DINT 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
    95
#define __INIT_LINT 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
    96
#define __INIT_USINT 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
    97
#define __INIT_UINT 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
    98
#define __INIT_UDINT 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
    99
#define __INIT_ULINT 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   100
#define __INIT_TIME (TIME){0,0}
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   101
#define __INIT_BOOL 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   102
#define __INIT_BYTE 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   103
#define __INIT_WORD 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   104
#define __INIT_DWORD 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   105
#define __INIT_LWORD 0
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   106
#define __INIT_STRING (STRING){0,""}
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   107
//#define __INIT_WSTRING
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   108
#define __INIT_DATE (DATE){0,0}
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   109
#define __INIT_TOD (TOD){0,0}
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   110
#define __INIT_DT (DT){0,0}
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   111
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   112
typedef union __IL_DEFVAR_T {
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   113
    BOOL    BOOLvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   114
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   115
    SINT    SINTvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   116
    INT     INTvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   117
    DINT    DINTvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   118
    LINT    LINTvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   119
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   120
    USINT   USINTvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   121
    UINT    UINTvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   122
    UDINT   UDINTvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   123
    ULINT   ULINTvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   124
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   125
    BYTE    BYTEvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   126
    WORD    WORDvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   127
    DWORD   DWORDvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   128
    LWORD   LWORDvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   129
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   130
    REAL    REALvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   131
    LREAL   LREALvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   132
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   133
    TIME    TIMEvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   134
    TOD TODvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   135
    DT  DTvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   136
    DATE    DATEvar;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   137
} __IL_DEFVAR_T;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   138
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   139
/*****************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   140
/* Misc internal */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   141
/*****************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   142
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   143
/* function that generates an IEC runtime error */
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   144
static inline void IEC_error(void) {
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   145
  /* TODO... */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   146
  fprintf(stderr, "IEC 61131-3 runtime error.\n");
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   147
  /*exit(1);*/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   148
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   149
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   150
254
28bd86c56793 Initial TIME support in debugger
Edouard Tisserant
parents: 217
diff changeset
   151
static inline void __normalize_timespec (IEC_TIMESPEC *ts) {
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   152
  if( ts->tv_nsec < -1000000000 || (( ts->tv_sec > 0 ) && ( ts->tv_nsec < 0 ))){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   153
    ts->tv_sec--;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   154
    ts->tv_nsec += 1000000000;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   155
  }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   156
  if( ts->tv_nsec > 1000000000 || (( ts->tv_sec < 0 ) && ( ts->tv_nsec > 0 ))){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   157
    ts->tv_sec++;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   158
    ts->tv_nsec -= 1000000000;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   159
  }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   160
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   161
254
28bd86c56793 Initial TIME support in debugger
Edouard Tisserant
parents: 217
diff changeset
   162
static inline IEC_TIMESPEC __time_to_timespec(int sign, double mseconds, double seconds, double minutes, double hours, double days) {
28bd86c56793 Initial TIME support in debugger
Edouard Tisserant
parents: 217
diff changeset
   163
  IEC_TIMESPEC ts;
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   164
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   165
  /* sign is 1 for positive values, -1 for negative time... */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   166
  long double total_sec = ((days*24 + hours)*60 + minutes)*60 + seconds + mseconds/1e3;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   167
  if (sign >= 0) sign = 1; else sign = -1;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   168
  ts.tv_sec = sign * (long int)total_sec;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   169
  ts.tv_nsec = sign * (long int)((total_sec - ts.tv_sec)*1e9);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   170
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   171
  return ts;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   172
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   173
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   174
254
28bd86c56793 Initial TIME support in debugger
Edouard Tisserant
parents: 217
diff changeset
   175
static inline IEC_TIMESPEC __tod_to_timespec(double seconds, double minutes, double hours) {
28bd86c56793 Initial TIME support in debugger
Edouard Tisserant
parents: 217
diff changeset
   176
  IEC_TIMESPEC ts;
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   177
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   178
  long double total_sec = (hours*60 + minutes)*60 + seconds;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   179
  ts.tv_sec = (long int)total_sec;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   180
  ts.tv_nsec = (long int)((total_sec - ts.tv_sec)*1e9);
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   181
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   182
  return ts;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   183
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   184
254
28bd86c56793 Initial TIME support in debugger
Edouard Tisserant
parents: 217
diff changeset
   185
static inline IEC_TIMESPEC __date_to_timespec(int day, int month, int year) {
28bd86c56793 Initial TIME support in debugger
Edouard Tisserant
parents: 217
diff changeset
   186
  IEC_TIMESPEC ts;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   187
  struct tm broken_down_time;
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   188
  time_t epoch_seconds;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   189
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   190
  broken_down_time.tm_sec = 0;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   191
  broken_down_time.tm_min = 0;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   192
  broken_down_time.tm_hour = 0;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   193
  broken_down_time.tm_mday = day;  /* day of month, from 1 to 31 */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   194
  broken_down_time.tm_mon = month - 1;   /* month since January, in the range 0 to 11 */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   195
  broken_down_time.tm_year = year - 1900;  /* number of years since 1900 */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   196
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   197
  epoch_seconds = mktime(&broken_down_time); /* determine number of seconds since the epoch, i.e. Jan 1st 1970 */
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   198
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   199
  if ((time_t)(-1) == epoch_seconds)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   200
    IEC_error();
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   201
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   202
  ts.tv_sec = epoch_seconds;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   203
  ts.tv_nsec = 0;
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   204
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   205
  return ts;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   206
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   207
254
28bd86c56793 Initial TIME support in debugger
Edouard Tisserant
parents: 217
diff changeset
   208
static inline IEC_TIMESPEC __dt_to_timespec(double seconds,  double minutes, double hours, int day, int month, int year) {
28bd86c56793 Initial TIME support in debugger
Edouard Tisserant
parents: 217
diff changeset
   209
  IEC_TIMESPEC ts;
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   210
  struct tm broken_down_time;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   211
  time_t epoch_seconds;
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   212
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   213
  long double total_sec = (hours*60 + minutes)*60 + seconds;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   214
  ts.tv_sec = (long int)total_sec;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   215
  ts.tv_nsec = (long int)((total_sec - ts.tv_sec)*1e9);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   216
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   217
  broken_down_time.tm_sec = 0;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   218
  broken_down_time.tm_min = 0;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   219
  broken_down_time.tm_hour = 0;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   220
  broken_down_time.tm_mday = day;  /* day of month, from 1 to 31 */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   221
  broken_down_time.tm_mon = month - 1;   /* month since January, in the range 0 to 11 */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   222
  broken_down_time.tm_year = year - 1900;  /* number of years since 1900 */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   223
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   224
  epoch_seconds = mktime(&broken_down_time); /* determine number of seconds since the epoch, i.e. Jan 1st 1970 */
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   225
  if ((time_t)(-1) == epoch_seconds)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   226
    IEC_error();
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   227
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   228
  ts.tv_sec += epoch_seconds;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   229
  if (ts.tv_sec < epoch_seconds)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   230
    /* since the TOD is always positive, if the above happens then we had an overflow */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   231
    IEC_error();
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   232
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   233
  return ts;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   234
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   235
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   236
/********************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   237
/*   EN/ENO PARAMS  */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   238
/********************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   239
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   240
#define EN_ENO_PARAMS BOOL EN, BOOL *ENO
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   241
#define TEST_EN(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   242
  if (!EN) {\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   243
    if (ENO != NULL)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   244
      *ENO = __BOOL_LITERAL(FALSE);\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   245
    return __INIT_##TYPENAME;\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   246
  }\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   247
  else if (ENO != NULL)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   248
    *ENO = __BOOL_LITERAL(TRUE);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   249
#define TEST_EN_COND(TYPENAME, COND)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   250
  if (!EN || (COND)) {\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   251
    if (ENO != NULL)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   252
      *ENO = __BOOL_LITERAL(FALSE);\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   253
    return __INIT_##TYPENAME;\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   254
  }\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   255
  else if (ENO != NULL)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   256
    *ENO = __BOOL_LITERAL(TRUE);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   257
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   258
/***************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   259
/*   Time ops  */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   260
/***************/
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   261
#define __TIME_CMP(t1, t2) (t2.tv_sec == t1.tv_sec ? t1.tv_nsec - t2.tv_nsec : t1.tv_sec - t2.tv_sec)
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   262
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   263
static inline TIME __TIME_ADD(TIME IN1, TIME IN2){
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   264
  TIME res ={IN1.tv_sec + IN2.tv_sec,
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   265
             IN1.tv_nsec + IN2.tv_nsec };
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   266
  __normalize_timespec(&res);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   267
  return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   268
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   269
static inline TIME __TIME_SUB(TIME IN1, TIME IN2){
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   270
  TIME res ={IN1.tv_sec - IN2.tv_sec,
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   271
             IN1.tv_nsec - IN2.tv_nsec };
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   272
  __normalize_timespec(&res);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   273
  return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   274
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   275
static inline TIME __TIME_MUL(TIME IN1, LREAL IN2){
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   276
  LREAL s_f = IN1.tv_sec * IN2;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   277
  time_t s = s_f;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   278
  div_t ns = div((LREAL)IN1.tv_nsec * IN2, 1000000000);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   279
  TIME res = {s + ns.quot,
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   280
              ns.rem + (s_f - s) * 1000000000 };
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   281
  __normalize_timespec(&res);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   282
  return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   283
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   284
static inline TIME __TIME_DIV(TIME IN1, LREAL IN2){
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   285
  LREAL s_f = IN1.tv_sec / IN2;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   286
  time_t s = s_f;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   287
  TIME res = {s,
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   288
              IN1.tv_nsec / IN2 + (s_f - s) * 1000000000 };
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   289
  __normalize_timespec(&res);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   290
  return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   291
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   292
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   293
static inline TIME __date_and_time_to_time_of_day(EN_ENO_PARAMS, TIME IN){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   294
  TEST_EN(TIME)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   295
  return (TIME){IN.tv_sec % 86400, IN.tv_nsec};
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   296
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   297
static inline TIME __date_and_time_to_date(EN_ENO_PARAMS, TIME IN){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   298
  TEST_EN(TIME)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   299
  return (TIME){IN.tv_sec - (IN.tv_sec % (24*60*60)), 0};
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   300
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   301
static inline TIME __time_add(EN_ENO_PARAMS, TIME IN1, TIME IN2){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   302
  TEST_EN(TIME)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   303
  return __TIME_ADD(IN1, IN2);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   304
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   305
static inline TIME __time_sub(EN_ENO_PARAMS, TIME IN1, TIME IN2){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   306
  TEST_EN(TIME)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   307
  return __TIME_SUB(IN1, IN2);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   308
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   309
static inline TIME __time_mul(EN_ENO_PARAMS, TIME IN1, LREAL IN2){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   310
  TEST_EN(TIME)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   311
  return __TIME_MUL(IN1, IN2);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   312
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   313
static inline TIME __time_div(EN_ENO_PARAMS, TIME IN1, LREAL IN2){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   314
  TEST_EN(TIME)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   315
  return __TIME_DIV(IN1, IN2);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   316
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   317
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   318
/***************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   319
/* String ops  */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   320
/***************/
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   321
#define __STR_CMP(str1, str2) memcmp((char*)&str1.body,(char*)&str2.body, str1.len < str2.len ? str1.len : str2.len)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   322
161
a27957e13d42 STRING max size and length type can now be overloaded (define STR_MAX_LEN and STR_LEN_TYPE before including iec_types.h)
etisserant
parents: 156
diff changeset
   323
static inline __strlen_t __len(EN_ENO_PARAMS, STRING IN){
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   324
    TEST_EN(UINT)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   325
    return IN.len;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   326
}
161
a27957e13d42 STRING max size and length type can now be overloaded (define STR_MAX_LEN and STR_LEN_TYPE before including iec_types.h)
etisserant
parents: 156
diff changeset
   327
static inline STRING __left(EN_ENO_PARAMS, STRING IN, __strlen_t L){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   328
    STRING res;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   329
    TEST_EN_COND(STRING, L < 0)
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   330
    res = __INIT_STRING;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   331
    L = L < IN.len ? L : IN.len;
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   332
    memcpy(&res.body, &IN.body, L);
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   333
    res.len = L;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   334
    return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   335
}
161
a27957e13d42 STRING max size and length type can now be overloaded (define STR_MAX_LEN and STR_LEN_TYPE before including iec_types.h)
etisserant
parents: 156
diff changeset
   336
static inline STRING __right(EN_ENO_PARAMS, STRING IN, __strlen_t L){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   337
    STRING res;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   338
    TEST_EN_COND(STRING, L < 0)
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   339
    res = __INIT_STRING;
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   340
    L = L < IN.len ? L : IN.len;
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   341
    memcpy(&res.body, &IN.body[IN.len - L], L);
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   342
    res.len = L;
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   343
    return res;
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   344
}
161
a27957e13d42 STRING max size and length type can now be overloaded (define STR_MAX_LEN and STR_LEN_TYPE before including iec_types.h)
etisserant
parents: 156
diff changeset
   345
static inline STRING __mid(EN_ENO_PARAMS, STRING IN, __strlen_t L, __strlen_t P){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   346
    STRING res;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   347
    TEST_EN_COND(STRING, L < 0 || P < 0)
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   348
    res = __INIT_STRING;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   349
    if(P <= IN.len){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   350
	    P -= 1; /* now can be used as [index]*/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   351
	    L = L + P <= IN.len ? L : IN.len - P;
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   352
	    memcpy(&res.body, &IN.body[P] , L);
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   353
        res.len = L;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   354
    }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   355
    return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   356
}
161
a27957e13d42 STRING max size and length type can now be overloaded (define STR_MAX_LEN and STR_LEN_TYPE before including iec_types.h)
etisserant
parents: 156
diff changeset
   357
static inline STRING __concat(EN_ENO_PARAMS, UINT param_count, ...){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   358
  UINT i;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   359
  STRING res;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   360
  va_list ap;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   361
  __strlen_t charcount;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   362
  TEST_EN(STRING)
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   363
  charcount = 0;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   364
  res = __INIT_STRING;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   365
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   366
  va_start (ap, param_count);         /* Initialize the argument list.  */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   367
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   368
  for (i = 0; i < param_count && charcount < STR_MAX_LEN; i++)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   369
  {
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   370
    STRING tmp = va_arg(ap, STRING);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   371
    __strlen_t charrem = STR_MAX_LEN - charcount;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   372
    __strlen_t to_write = tmp.len > charrem ? charrem : tmp.len;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   373
    memcpy(&res.body[charcount], &tmp.body , to_write);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   374
    charcount += to_write;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   375
  }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   376
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   377
  res.len = charcount;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   378
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   379
  va_end (ap);                  /* Clean up.  */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   380
  return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   381
}
161
a27957e13d42 STRING max size and length type can now be overloaded (define STR_MAX_LEN and STR_LEN_TYPE before including iec_types.h)
etisserant
parents: 156
diff changeset
   382
static inline STRING __insert(EN_ENO_PARAMS, STRING IN1, STRING IN2, __strlen_t P){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   383
    STRING res;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   384
    __strlen_t to_copy;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   385
    TEST_EN_COND(STRING, P < 0)
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   386
    res = __INIT_STRING;
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   387
313
90c3772e6547 fixing INSERT function: was inserting into incorrect position. (submitted by Manuele)
Mario de Sousa <msousa@fe.up.pt>
parents: 291
diff changeset
   388
    to_copy = P > IN1.len ? IN1.len : P;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   389
    memcpy(&res.body, &IN1.body , to_copy);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   390
    P = res.len = to_copy;
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   391
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   392
    to_copy = IN2.len + res.len > STR_MAX_LEN ? STR_MAX_LEN - res.len : IN2.len;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   393
    memcpy(&res.body[res.len], &IN2.body , to_copy);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   394
    res.len += to_copy;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   395
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   396
    to_copy = IN1.len - P < STR_MAX_LEN - res.len ? IN1.len - P : STR_MAX_LEN - res.len ;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   397
    memcpy(&res.body[res.len], &IN1.body[P] , to_copy);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   398
    res.len += to_copy;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   399
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   400
    return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   401
}
161
a27957e13d42 STRING max size and length type can now be overloaded (define STR_MAX_LEN and STR_LEN_TYPE before including iec_types.h)
etisserant
parents: 156
diff changeset
   402
static inline STRING __delete(EN_ENO_PARAMS, STRING IN, __strlen_t L, __strlen_t P){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   403
    STRING res;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   404
    __strlen_t to_copy;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   405
    TEST_EN_COND(STRING, L < 0 || P < 0)
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   406
    res = __INIT_STRING;
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   407
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   408
    to_copy = P > IN.len ? IN.len : P-1;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   409
    memcpy(&res.body, &IN.body , to_copy);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   410
    P = res.len = to_copy;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   411
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   412
    if( IN.len > P + L ){
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   413
        to_copy = IN.len - P - L;
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   414
        memcpy(&res.body[res.len], &IN.body[P + L], to_copy);
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   415
        res.len += to_copy;
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   416
    }
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   417
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   418
    return res;
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   419
}
161
a27957e13d42 STRING max size and length type can now be overloaded (define STR_MAX_LEN and STR_LEN_TYPE before including iec_types.h)
etisserant
parents: 156
diff changeset
   420
static inline STRING __replace(EN_ENO_PARAMS, STRING IN1, STRING IN2, __strlen_t L, __strlen_t P){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   421
    STRING res;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   422
    __strlen_t to_copy;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   423
    TEST_EN_COND(STRING, L < 0 || P < 0)
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   424
    res = __INIT_STRING;
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   425
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   426
    to_copy = P > IN1.len ? IN1.len : P-1;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   427
    memcpy(&res.body, &IN1.body , to_copy);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   428
    P = res.len = to_copy;
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   429
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   430
    to_copy = IN2.len < L ? IN2.len : L;
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   431
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   432
    if( to_copy + res.len > STR_MAX_LEN )
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   433
       to_copy = STR_MAX_LEN - res.len;
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   434
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   435
    memcpy(&res.body[res.len], &IN2.body , to_copy);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   436
    res.len += to_copy;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   437
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   438
    P += L;
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   439
    if( res.len <  STR_MAX_LEN && P < IN1.len)
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   440
    {
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   441
        to_copy = IN1.len - P;
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   442
        memcpy(&res.body[res.len], &IN1.body[P] , to_copy);
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   443
        res.len += to_copy;
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   444
    }
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   445
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   446
    return res;
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   447
}
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   448
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   449
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   450
161
a27957e13d42 STRING max size and length type can now be overloaded (define STR_MAX_LEN and STR_LEN_TYPE before including iec_types.h)
etisserant
parents: 156
diff changeset
   451
static inline __strlen_t __pfind(STRING* IN1, STRING* IN2){
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   452
    UINT count1 = 0; /* offset of first matching char in IN1 */
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   453
    UINT count2 = 0; /* count of matching char */
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   454
    while(count1 + count2 < IN1->len && count2 < IN2->len)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   455
    {
212
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   456
        if(IN1->body[count1 + count2] != IN2->body[count2]){
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   457
            count1 += count2 + 1;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   458
            count2 = 0;
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   459
        }
212
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   460
        else {
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   461
            count2++;
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   462
        }
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   463
    }
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   464
    return count2 == IN2->len -1 ? 0 : count1 + 1;
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   465
}
161
a27957e13d42 STRING max size and length type can now be overloaded (define STR_MAX_LEN and STR_LEN_TYPE before including iec_types.h)
etisserant
parents: 156
diff changeset
   466
static inline __strlen_t __find(EN_ENO_PARAMS, STRING IN1, STRING IN2){
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   467
    TEST_EN(UINT)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   468
    return __pfind(&IN1, &IN2);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   469
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   470
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   471
/***************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   472
/* Convertions */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   473
/***************/
314
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   474
    /*****************/
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   475
    /*  REAL_TO_INT  */
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   476
    /*****************/
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   477
static inline LINT __real_round(LREAL IN)
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   478
{
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   479
	return fmod(IN, 1) == 0 ? ((LINT)IN / 2) * 2 : (LINT)IN;
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   480
}
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   481
static inline LINT __preal_to_sint(LREAL IN)
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   482
{
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   483
   return IN >= 0 ? __real_round(IN + 0.5) : __real_round(IN - 0.5);
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   484
}
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   485
static inline LINT __preal_to_uint(LREAL IN)
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   486
{
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   487
   return IN >= 0 ? __real_round(IN + 0.5) : 0;
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   488
}
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   489
static inline LINT __real_to_sint(EN_ENO_PARAMS, LREAL IN){
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   490
    TEST_EN(LINT)
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   491
    return (LINT)__preal_to_sint(IN);
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   492
}
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   493
static inline LWORD __real_to_bit(EN_ENO_PARAMS, LREAL IN){
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   494
    TEST_EN(LWORD)
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   495
    return (LWORD)__preal_to_uint(IN);
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   496
}
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   497
static inline ULINT __real_to_uint(EN_ENO_PARAMS, LREAL IN){
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   498
    TEST_EN(ULINT)
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   499
    return (ULINT)__preal_to_uint(IN);
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   500
}
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   501
    /***************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   502
    /*  TO_STRING  */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   503
    /***************/
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   504
static inline STRING __bool_to_string(EN_ENO_PARAMS, BOOL IN)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   505
{
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   506
    TEST_EN(STRING)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   507
    if(IN)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   508
        return (STRING){4, "TRUE"};
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   509
    return (STRING){5,"FALSE"};
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   510
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   511
static inline STRING __bit_to_string(EN_ENO_PARAMS, LWORD IN){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   512
    STRING res;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   513
    TEST_EN(STRING)
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   514
    res = __INIT_STRING;
114
28cf5bddeb9f cast fir gcc4 fix in lib
etisserant
parents: 107
diff changeset
   515
    res.len = snprintf((char*)res.body, STR_MAX_LEN, "16#%llx", IN);
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   516
    if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   517
    return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   518
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   519
static inline STRING __real_to_string(EN_ENO_PARAMS, LREAL IN){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   520
    STRING res;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   521
    TEST_EN(STRING)
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   522
    res = __INIT_STRING;
114
28cf5bddeb9f cast fir gcc4 fix in lib
etisserant
parents: 107
diff changeset
   523
    res.len = snprintf((char*)res.body, STR_MAX_LEN, "%.10g", IN);
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   524
    if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   525
    return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   526
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   527
static inline STRING __sint_to_string(EN_ENO_PARAMS, LINT IN){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   528
    STRING res;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   529
    TEST_EN(STRING)
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   530
    res = __INIT_STRING;
114
28cf5bddeb9f cast fir gcc4 fix in lib
etisserant
parents: 107
diff changeset
   531
    res.len = snprintf((char*)res.body, STR_MAX_LEN, "%lld", IN);
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   532
    if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   533
    return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   534
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   535
static inline STRING __uint_to_string(EN_ENO_PARAMS, ULINT IN){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   536
    STRING res;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   537
    TEST_EN(STRING)
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   538
    res = __INIT_STRING;
114
28cf5bddeb9f cast fir gcc4 fix in lib
etisserant
parents: 107
diff changeset
   539
    res.len = snprintf((char*)res.body, STR_MAX_LEN, "%llu", IN);
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   540
    if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   541
    return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   542
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   543
    /***************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   544
    /* FROM_STRING */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   545
    /***************/
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   546
static inline BOOL __string_to_bool(EN_ENO_PARAMS, STRING IN){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   547
    TEST_EN(BOOL)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   548
    return IN.len == 5 ? !memcmp(&IN.body,"TRUE", IN.len) : 0;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   549
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   550
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   551
static inline LINT __pstring_to_sint(STRING* IN){
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   552
    LINT res = 0;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   553
    __strlen_t l;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   554
    unsigned int shift = 0;
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   555
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   556
    if(IN->body[0]=='2' && IN->body[1]=='#'){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   557
        /* 2#0101_1010_1011_1111 */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   558
        for(l = IN->len - 1; l >= 2 && shift < 64; l--)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   559
        {
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   560
            char c = IN->body[l];
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   561
            if( c >= '0' && c <= '1'){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   562
                res |= ( c - '0') << shift;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   563
                shift += 1;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   564
            }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   565
        }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   566
    }else if(IN->body[0]=='8' && IN->body[1]=='#'){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   567
        /* 8#1234_5665_4321 */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   568
        for(l = IN->len - 1; l >= 2 && shift < 64; l--)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   569
        {
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   570
            char c = IN->body[l];
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   571
            if( c >= '0' && c <= '7'){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   572
                res |= ( c - '0') << shift;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   573
                shift += 3;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   574
            }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   575
        }
43
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
   576
    }else if(IN->body[0]=='1' && IN->body[1]=='6' && IN->body[2]=='#'){
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   577
        /* 16#1234_5678_9abc_DEFG */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   578
        for(l = IN->len - 1; l >= 3 && shift < 64; l--)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   579
        {
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   580
            char c = IN->body[l];
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   581
            if( c >= '0' && c <= '9'){
43
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
   582
                res |= (LWORD)( c - '0') << shift;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   583
                shift += 4;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   584
            }else if( c >= 'a' && c <= 'f'){
43
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
   585
                res |= (LWORD)( c - 'a' + 10 ) << shift;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   586
                shift += 4;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   587
            }else if( c >= 'A' && c <= 'F'){
43
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
   588
                res |= (LWORD)( c - 'A' + 10 ) << shift;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   589
                shift += 4;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   590
            }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   591
        }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   592
    }else{
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   593
        /* -123456789 */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   594
        LINT fac = IN->body[0] == '-' ? -1 : 1;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   595
        for(l = IN->len - 1; l >= 0 && shift < 20; l--)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   596
        {
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   597
            char c = IN->body[l];
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   598
            if( c >= '0' && c <= '9'){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   599
                res += ( c - '0') * fac;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   600
                fac *= 10;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   601
                shift += 1;
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   602
            }else if( c >= '.' ){ /* reset value */
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   603
                res = 0;
163
61f65dd6eeb9 Fixed errors in string_to_int.
etisserant
parents: 161
diff changeset
   604
                fac = IN->body[0] == '-' ? -1 : 1;
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
   605
                shift = 0;
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   606
            }
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   607
        }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   608
    }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   609
    return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   610
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   611
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   612
static inline LINT __string_to_sint(EN_ENO_PARAMS, STRING IN){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   613
    TEST_EN(LINT)
314
41d4ac0b4821 Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents: 313
diff changeset
   614
    return (LINT)__pstring_to_sint(&IN);
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   615
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   616
static inline LWORD __string_to_bit(EN_ENO_PARAMS, STRING IN){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   617
    TEST_EN(LWORD)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   618
    return (LWORD)__pstring_to_sint(&IN);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   619
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   620
static inline ULINT __string_to_uint(EN_ENO_PARAMS, STRING IN){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   621
    TEST_EN(ULINT)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   622
    return (ULINT)__pstring_to_sint(&IN);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   623
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   624
static inline LREAL __string_to_real(EN_ENO_PARAMS, STRING IN){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   625
	__strlen_t l;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   626
	TEST_EN(LREAL)
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   627
	l = IN.len;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   628
    /* search the dot */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   629
    while(--l > 0 && IN.body[l] != '.');
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   630
    if(l != 0){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   631
        return atof((const char *)&IN.body);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   632
    }else{
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   633
        return (LREAL)__pstring_to_sint(&IN);
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   634
    }
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   635
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   636
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   637
    /***************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   638
    /*   TO_TIME   */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   639
    /***************/
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   640
static inline TIME __int_to_time(EN_ENO_PARAMS, LINT IN){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   641
    TEST_EN(TIME)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   642
    return (TIME){IN, 0};
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   643
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   644
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   645
static inline TIME __real_to_time(EN_ENO_PARAMS, LREAL IN){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   646
    TEST_EN(TIME)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   647
    return (TIME){IN, (IN - (LINT)IN) * 1000000000};
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   648
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   649
static inline TIME __string_to_time(EN_ENO_PARAMS, STRING IN){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   650
	__strlen_t l;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   651
	TEST_EN(TIME)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   652
    /* TODO :
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   653
     *
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   654
     *  Duration literals without underlines: T#14ms    T#-14ms   T#14.7s   T#14.7m
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   655
     *                short prefix            T#14.7h    t#14.7d   t#25h15m
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   656
     *                                        t#5d14h12m18s3.5ms
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   657
     *                long prefix             TIME#14ms    TIME#-14ms   time#14.7s
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   658
     *  Duration literals with underlines:
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   659
     *                short prefix            t#25h_15m t#5d_14h_12m_18s_3.5ms
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   660
     *                long prefix             TIME#25h_15m
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   661
     *                                        time#5d_14h_12m_18s_3.5ms
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   662
     *
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   663
     *  Long prefix notation                 Short prefix notation
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   664
     *  DATE#1984-06-25                      D#1984-06-25
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   665
     *  date#1984-06-25                      d#1984-06-25
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   666
     *  TIME_OF_DAY#15:36:55.36              TOD#15:36:55.36
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   667
     *  time_of_day#15:36:55.36              tod#15:36:55.36
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   668
     *  DATE_AND_TIME#1984-06-25-15:36:55.36 DT#1984-06-25-15:36:55.36
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   669
     *  date_and_time#1984-06-25-15:36:55.36 dt#1984-06-25-15:36:55.36
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   670
     *
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   671
     */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   672
    /* Quick hack : only transform seconds */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   673
    /* search the dot */
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   674
	l = IN.len;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   675
    while(--l > 0 && IN.body[l] != '.');
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   676
    if(l != 0){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   677
        LREAL IN_val = atof((const char *)&IN.body);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   678
        return  (TIME){IN_val, (IN_val - (LINT)IN_val)*1000000000};
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   679
    }else{
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   680
        return  (TIME){__pstring_to_sint(&IN), 0};
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   681
    }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   682
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   683
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   684
    /***************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   685
    /*  FROM_TIME  */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   686
    /***************/
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   687
static inline LREAL __time_to_real(EN_ENO_PARAMS, TIME IN){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   688
    TEST_EN(LREAL)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   689
    return (LREAL)IN.tv_sec + ((LREAL)IN.tv_nsec/1000000000);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   690
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   691
static inline LINT __time_to_int(EN_ENO_PARAMS, TIME IN){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   692
    TEST_EN(LINT)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   693
    return IN.tv_sec;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   694
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   695
static inline STRING __time_to_string(EN_ENO_PARAMS, TIME IN){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   696
    STRING res;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   697
    div_t days;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   698
    TEST_EN(STRING)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   699
    /*t#5d14h12m18s3.5ms*/
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   700
    res = __INIT_STRING;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   701
    days = div(IN.tv_sec ,86400);
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   702
    if(!days.rem && IN.tv_nsec == 0){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   703
        res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd", days.quot);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   704
    }else{
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   705
        div_t hours = div(days.rem, 3600);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   706
        if(!hours.rem && IN.tv_nsec == 0){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   707
            res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd%dh", days.quot, hours.quot);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   708
        }else{
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   709
            div_t minuts = div(hours.rem, 60);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   710
            if(!minuts.rem && IN.tv_nsec == 0){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   711
                res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd%dh%dm", days.quot, hours.quot, minuts.quot);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   712
            }else{
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   713
                if(IN.tv_nsec == 0){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   714
                    res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd%dh%dm%ds", days.quot, hours.quot, minuts.quot, minuts.rem);
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   715
                }else{
42
b45c7f34dec1 IEC std lib test enhanced string ops, from string and to string conv.
etisserant
parents: 41
diff changeset
   716
                    res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd%dh%dm%ds%gms", days.quot, hours.quot, minuts.quot, minuts.rem, (LREAL)IN.tv_nsec / 1000000);
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   717
                }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   718
            }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   719
        }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   720
    }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   721
    if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   722
    return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   723
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   724
static inline STRING __date_to_string(EN_ENO_PARAMS, DATE IN){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   725
    STRING res;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   726
    struct tm* broken_down_time;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   727
    time_t seconds;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   728
	TEST_EN(STRING)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   729
    /* D#1984-06-25 */
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   730
    res = __INIT_STRING;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   731
    seconds = IN.tv_sec;
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   732
    if (NULL == (broken_down_time = localtime(&seconds))){ /* get the UTC (GMT) broken down time */
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   733
        IEC_error();
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   734
        return (STRING){7,"D#ERROR"};
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   735
    }
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   736
    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);
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   737
    if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   738
    return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   739
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   740
static inline STRING __tod_to_string(EN_ENO_PARAMS, TOD IN){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   741
    STRING res;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   742
    struct tm* broken_down_time;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   743
    time_t seconds;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   744
    TEST_EN(STRING)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   745
    /* TOD#15:36:55.36 */
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   746
    res = __INIT_STRING;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   747
    seconds = IN.tv_sec;
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   748
    if (NULL == (broken_down_time = localtime(&seconds))){ /* get the UTC (GMT) broken down time */
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   749
        IEC_error();
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   750
        return (STRING){9,"TOD#ERROR"};
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   751
    }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   752
    if(IN.tv_nsec == 0){
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   753
        res.len = snprintf((char*)&res.body, STR_MAX_LEN, "TOD#%2.2d:%2.2d:%d", broken_down_time->tm_hour, broken_down_time->tm_min, broken_down_time->tm_sec);
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   754
    }else{
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   755
        res.len = snprintf((char*)&res.body, STR_MAX_LEN, "TOD#%2.2d:%2.2d:%g", broken_down_time->tm_hour, broken_down_time->tm_min, (LREAL)broken_down_time->tm_sec + (LREAL)IN.tv_nsec / 1e9);
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   756
    }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   757
    if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   758
    return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   759
}
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   760
static inline STRING __dt_to_string(EN_ENO_PARAMS, DT IN){
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   761
    STRING res;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   762
    struct tm* broken_down_time;
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   763
    time_t seconds;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   764
    TEST_EN(STRING)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   765
    /* DT#1984-06-25-15:36:55.36 */
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   766
    seconds = IN.tv_sec;
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   767
    if (NULL == (broken_down_time = localtime(&seconds))){ /* get the UTC (GMT) broken down time */
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   768
        IEC_error();
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   769
        return (STRING){8,"DT#ERROR"};
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   770
    }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   771
    if(IN.tv_nsec == 0){
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   772
        res.len = snprintf((char*)&res.body, STR_MAX_LEN, "DT#%d-%2.2d-%2.2d-%2.2d:%2.2d:%d",
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   773
                 broken_down_time->tm_year,
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   774
                 broken_down_time->tm_mon,
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   775
                 broken_down_time->tm_mday,
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   776
                 broken_down_time->tm_hour,
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   777
                 broken_down_time->tm_min,
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   778
                 broken_down_time->tm_sec);
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   779
    }else{
42
b45c7f34dec1 IEC std lib test enhanced string ops, from string and to string conv.
etisserant
parents: 41
diff changeset
   780
        res.len = snprintf((char*)&res.body, STR_MAX_LEN, "DT#%d-%2.2d-%2.2d-%2.2d:%2.2d:%g",
57
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   781
                 broken_down_time->tm_year,
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   782
                 broken_down_time->tm_mon,
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   783
                 broken_down_time->tm_mday,
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   784
                 broken_down_time->tm_hour,
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   785
                 broken_down_time->tm_min,
db9cadaab2ea Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents: 55
diff changeset
   786
                 (LREAL)broken_down_time->tm_sec + ((LREAL)IN.tv_nsec / 1e9));
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   787
    }
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   788
    if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   789
    return res;
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   790
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   791
    /* BCD */
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   792
#define __bcd_digit(fac)
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   793
static inline ULINT __bcd_to_uint(EN_ENO_PARAMS, LWORD IN){
212
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   794
    ULINT res;
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   795
    ULINT i;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   796
    TEST_EN(ULINT)
212
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   797
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   798
    res = IN & 0xf;
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   799
    for(i = 10ULL; i <= 1000000000000000ULL; i *= 10){
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   800
        if(!(IN >>= 4))
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   801
            break;
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   802
        res += (IN & 0xf) * i;
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   803
    }
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   804
    return res;
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   805
}
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   806
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   807
static inline LWORD __uint_to_bcd(EN_ENO_PARAMS, ULINT IN){
212
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   808
    LWORD res;
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   809
    USINT i;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   810
    TEST_EN(LWORD)
212
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   811
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   812
    res = IN % 10;
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   813
    for(i = 4; i<=60; i += 4){
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   814
        if(!(IN /= 10))
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   815
            break;
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   816
        res |= (IN % 10) << i;
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   817
    }
8c9ec7d37d3a Fix some warnings on compilation
greg
parents: 200
diff changeset
   818
    return res;
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   819
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   820
271
4f281513277f Fixes to make handling of standard functions in Semantic analyser compatible with code generation of standard functions
Edouard Tisserant
parents: 254
diff changeset
   821
/* workaround for va-args limitation on shorter than int params */
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   822
#define VA_ARGS_REAL LREAL
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   823
#define VA_ARGS_LREAL LREAL
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   824
#define VA_ARGS_SINT DINT
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   825
#define VA_ARGS_INT DINT
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   826
#define VA_ARGS_DINT DINT
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   827
#define VA_ARGS_LINT LINT
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   828
#define VA_ARGS_USINT UDINT
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   829
#define VA_ARGS_UINT UDINT
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   830
#define VA_ARGS_UDINT UDINT
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   831
#define VA_ARGS_ULINT ULINT
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   832
#define VA_ARGS_TIME TIME
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   833
#define VA_ARGS_BOOL DWORD
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   834
#define VA_ARGS_BYTE DWORD
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   835
#define VA_ARGS_WORD DWORD
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   836
#define VA_ARGS_DWORD DWORD
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   837
#define VA_ARGS_LWORD LWORD
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   838
#define VA_ARGS_STRING STRING
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   839
#define VA_ARGS_WSTRING WSTRING
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   840
#define VA_ARGS_DATE DATE
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   841
#define VA_ARGS_TOD TOD
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   842
#define VA_ARGS_DT DT
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
   843
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   844
/*******************************************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   845
/*     Arithmetic and bitwise functions    */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   846
/*******************************************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   847
#define __arith_expand(fname,TYPENAME, OP) \
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   848
static inline TYPENAME fname##TYPENAME(EN_ENO_PARAMS, UINT param_count, TYPENAME op1, ...){\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   849
  va_list ap;\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   850
  UINT i;\
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   851
  TEST_EN(TYPENAME)\
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   852
  \
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   853
  va_start (ap, op1);         /* Initialize the argument list.  */\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   854
  \
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   855
  for (i = 0; i < param_count - 1; i++){\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   856
    op1 = op1 OP va_arg (ap, VA_ARGS_##TYPENAME);\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   857
  }\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   858
  \
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   859
  va_end (ap);                  /* Clean up.  */\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   860
  return op1;\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   861
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   862
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   863
#define __arith_static(fname,TYPENAME, OP) \
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   864
static inline TYPENAME fname##TYPENAME(EN_ENO_PARAMS, TYPENAME op1, TYPENAME op2){\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   865
  TEST_EN(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   866
  return op1 OP op2;\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   867
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   868
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   869
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   870
/*     ADD    */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   871
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   872
#define __add_(TYPENAME) __arith_expand(__add_, TYPENAME, + )
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   873
ANY_NUM(__add_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   874
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   875
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   876
/*     MUL    */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   877
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   878
#define __mul_(TYPENAME) __arith_expand(__mul_, TYPENAME, * )
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   879
ANY_NUM(__mul_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   880
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   881
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   882
/*     SUB    */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   883
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   884
#define __sub_(TYPENAME) __arith_static(__sub_, TYPENAME, - )
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   885
ANY_NUM(__sub_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   886
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   887
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   888
/*     DIV    */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   889
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   890
#define __div_(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   891
static inline TYPENAME __div_##TYPENAME(EN_ENO_PARAMS, TYPENAME op1, TYPENAME op2){\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   892
  TEST_EN_COND(TYPENAME, op2 == 0)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   893
  return op1 / op2;\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   894
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   895
ANY_NUM(__div_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   896
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   897
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   898
/*     MOD    */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   899
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   900
#define __mod_(TYPENAME) __arith_static(__mod_, TYPENAME, % )
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   901
ANY_INT(__mod_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   902
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   903
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   904
/*     AND    */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   905
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   906
__arith_expand(__and_, BOOL, && )
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   907
#define __and_(TYPENAME) __arith_expand(__and_, TYPENAME, & )
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   908
ANY_NBIT(__and_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   909
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   910
/*************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   911
/*     OR    */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   912
/*************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   913
__arith_expand(__or_, BOOL, || )
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   914
#define __or_(TYPENAME) __arith_expand(__or_, TYPENAME, |)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   915
ANY_NBIT(__or_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   916
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   917
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   918
/*     XOR    */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   919
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   920
static inline BOOL __xor_BOOL(EN_ENO_PARAMS, UINT param_count, BOOL op1, ...){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   921
  va_list ap;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   922
  UINT i;
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
   923
  TEST_EN(BOOL)
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   924
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   925
  va_start (ap, op1);         /* Initialize the argument list.  */
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   926
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   927
  for (i = 0; i < param_count - 1; i++){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   928
    BOOL tmp = va_arg (ap, VA_ARGS_BOOL);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   929
    op1 = (op1 && !tmp) || (!op1 && tmp);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   930
  }
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
   931
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   932
  va_end (ap);                  /* Clean up.  */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   933
  return op1;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   934
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   935
#define __xor_(TYPENAME) __arith_expand(__xor_, TYPENAME, ^)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   936
ANY_NBIT(__xor_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   937
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   938
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   939
/*     NOT    */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   940
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   941
static inline BOOL __not_BOOL(EN_ENO_PARAMS, BOOL op1){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   942
  TEST_EN(BOOL)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   943
  return !op1;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   944
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   945
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   946
#define __not_(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   947
static inline TYPENAME __not_##TYPENAME(EN_ENO_PARAMS, TYPENAME op1){\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   948
  TEST_EN(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   949
  return ~op1;\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   950
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   951
ANY_NBIT(__not_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   952
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   953
/***************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   954
/*     MOVE    */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   955
/***************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   956
#define __move_(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   957
static inline TYPENAME __move_##TYPENAME(EN_ENO_PARAMS, TYPENAME op1){\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   958
  TEST_EN(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   959
  return op1;\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   960
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   961
ANY(__move_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   962
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   963
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   964
/* Binary ops */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   965
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   966
#define __shift_(fname, TYPENAME, OP)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   967
static inline TYPENAME fname##TYPENAME(EN_ENO_PARAMS, TYPENAME IN, USINT N) {\
156
6b16b7f8b527 Warning conditions on win32 fixed
greg
parents: 149
diff changeset
   968
  TEST_EN(TYPENAME)\
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   969
  return IN OP N;\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   970
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   971
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   972
#define __shl_(TYPENAME) __shift_(__shl_, TYPENAME, << )
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   973
/* Call previously defined macro for each ANY_NBIT */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   974
ANY_NBIT(__shl_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   975
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   976
#define __shr_(TYPENAME) __shift_(__shr_, TYPENAME, >> )
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   977
/* Call previously defined macro for each ANY_NBIT */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   978
ANY_NBIT(__shr_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   979
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   980
#define __ror_(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   981
static inline TYPENAME __ror_##TYPENAME(EN_ENO_PARAMS, TYPENAME IN, USINT N){\
156
6b16b7f8b527 Warning conditions on win32 fixed
greg
parents: 149
diff changeset
   982
  TEST_EN(TYPENAME)\
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   983
  N %= 8*sizeof(TYPENAME);\
199
b075f28ec081 Bug with type conversion EN/ENO not evaluated fixed
laurent
parents: 187
diff changeset
   984
  return (IN >> N) | (IN << (8*sizeof(TYPENAME)-N));\
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   985
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   986
/* Call previously defined macro for each ANY_NBIT */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   987
ANY_NBIT(__ror_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   988
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   989
#define __rol_(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   990
static inline TYPENAME __rol_##TYPENAME(EN_ENO_PARAMS, TYPENAME IN, USINT N){\
156
6b16b7f8b527 Warning conditions on win32 fixed
greg
parents: 149
diff changeset
   991
  TEST_EN(TYPENAME)\
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   992
  N %= 8*sizeof(TYPENAME);\
199
b075f28ec081 Bug with type conversion EN/ENO not evaluated fixed
laurent
parents: 187
diff changeset
   993
  return (IN << N) | (IN >> (8*sizeof(TYPENAME)-N));\
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   994
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   995
/* Call previously defined macro for each ANY_NBIT */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   996
ANY_NBIT(__rol_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
   997
165
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
   998
/*******************************************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
   999
/*     Arithmetic and bitwise functions    */
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1000
/*******************************************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1001
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1002
#define __numeric(fname,TYPENAME, FUNC) \
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1003
static inline TYPENAME fname##TYPENAME(EN_ENO_PARAMS, TYPENAME op){\
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1004
  TEST_EN(TYPENAME)\
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1005
  return FUNC(op);\
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1006
}
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1007
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1008
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1009
  /*    ABS     */
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1010
  /**************/
187
f2cd0b5236f7 Warning when compiling abs functions for unsigned integer fixed
lbessard
parents: 180
diff changeset
  1011
#define __abs_signed(TYPENAME) \
180
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
  1012
static inline TYPENAME __abs_##TYPENAME(EN_ENO_PARAMS, TYPENAME op){\
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
  1013
  TEST_EN(TYPENAME)\
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
  1014
  if (op < 0)\
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
  1015
    return -op;\
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
  1016
  return op;\
64334c5a00b1 Bug on "abs" not working with float fixed
greg
parents: 165
diff changeset
  1017
}
187
f2cd0b5236f7 Warning when compiling abs functions for unsigned integer fixed
lbessard
parents: 180
diff changeset
  1018
ANY_REAL(__abs_signed)
f2cd0b5236f7 Warning when compiling abs functions for unsigned integer fixed
lbessard
parents: 180
diff changeset
  1019
ANY_SINT(__abs_signed)
f2cd0b5236f7 Warning when compiling abs functions for unsigned integer fixed
lbessard
parents: 180
diff changeset
  1020
f2cd0b5236f7 Warning when compiling abs functions for unsigned integer fixed
lbessard
parents: 180
diff changeset
  1021
#define __abs_unsigned(TYPENAME) \
f2cd0b5236f7 Warning when compiling abs functions for unsigned integer fixed
lbessard
parents: 180
diff changeset
  1022
static inline TYPENAME __abs_##TYPENAME(EN_ENO_PARAMS, TYPENAME op){\
f2cd0b5236f7 Warning when compiling abs functions for unsigned integer fixed
lbessard
parents: 180
diff changeset
  1023
  TEST_EN(TYPENAME)\
f2cd0b5236f7 Warning when compiling abs functions for unsigned integer fixed
lbessard
parents: 180
diff changeset
  1024
  return op;\
f2cd0b5236f7 Warning when compiling abs functions for unsigned integer fixed
lbessard
parents: 180
diff changeset
  1025
}
f2cd0b5236f7 Warning when compiling abs functions for unsigned integer fixed
lbessard
parents: 180
diff changeset
  1026
ANY_UINT(__abs_unsigned)
165
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1027
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1028
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1029
  /*    SQRT    */
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1030
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1031
#define __sqrt_(TYPENAME) __numeric(__sqrt_, TYPENAME, sqrt)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1032
ANY_REAL(__sqrt_)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1033
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1034
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1035
  /*     LN     */
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1036
  /**************/
199
b075f28ec081 Bug with type conversion EN/ENO not evaluated fixed
laurent
parents: 187
diff changeset
  1037
#define __ln_(TYPENAME) __numeric(__ln_, TYPENAME, log)
165
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1038
ANY_REAL(__ln_)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1039
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1040
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1041
  /*     LOG    */
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1042
  /**************/
199
b075f28ec081 Bug with type conversion EN/ENO not evaluated fixed
laurent
parents: 187
diff changeset
  1043
#define __log_(TYPENAME) __numeric(__log_, TYPENAME, log10)
165
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1044
ANY_REAL(__log_)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1045
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1046
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1047
  /*     EXP    */
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1048
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1049
#define __exp_(TYPENAME) __numeric(__exp_, TYPENAME, exp)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1050
ANY_REAL(__exp_)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1051
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1052
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1053
  /*     SIN    */
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1054
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1055
#define __sin_(TYPENAME) __numeric(__sin_, TYPENAME, sin)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1056
ANY_REAL(__sin_)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1057
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1058
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1059
  /*     COS    */
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1060
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1061
#define __cos_(TYPENAME) __numeric(__cos_, TYPENAME, cos)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1062
ANY_REAL(__cos_)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1063
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1064
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1065
  /*     TAN    */
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1066
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1067
#define __tan_(TYPENAME) __numeric(__tan_, TYPENAME, tan)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1068
ANY_REAL(__tan_)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1069
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1070
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1071
  /*    ASIN    */
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1072
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1073
#define __asin_(TYPENAME) __numeric(__asin_, TYPENAME, asin)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1074
ANY_REAL(__asin_)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1075
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1076
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1077
  /*    ACOS    */
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1078
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1079
#define __acos_(TYPENAME) __numeric(__acos_, TYPENAME, acos)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1080
ANY_REAL(__acos_)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1081
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1082
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1083
  /*    ATAN    */
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1084
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1085
#define __atan_(TYPENAME) __numeric(__atan_, TYPENAME, atan)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1086
ANY_REAL(__atan_)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1087
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1088
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1089
  /*    EXPT    */
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1090
  /**************/
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1091
#define __expt_(TYPENAME)\
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1092
static inline TYPENAME __expt_##TYPENAME(EN_ENO_PARAMS, TYPENAME IN1, REAL IN2){\
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1093
  TEST_EN(TYPENAME)\
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1094
  return pow(IN1, IN2);\
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1095
}ANY_REAL(__expt_)
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1096
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1097
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1098
/* Selection  */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1099
/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1100
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1101
  /**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1102
  /*    SEL     */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1103
  /**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1104
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1105
#define __sel_(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1106
static inline TYPENAME __sel_##TYPENAME(EN_ENO_PARAMS, BOOL G, TYPENAME op0, TYPENAME op1){\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1107
  TEST_EN(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1108
  return G ? op1 : op0;\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1109
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1110
ANY(__sel_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1111
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1112
	/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1113
	/*   limit    */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1114
	/**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1115
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1116
#define __limit_(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1117
static inline TYPENAME __limit_##TYPENAME(EN_ENO_PARAMS, TYPENAME MN, TYPENAME IN, TYPENAME MX){\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1118
  TEST_EN(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1119
  return IN > MN ? IN < MX ? IN : MX : MN;\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1120
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1121
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1122
/* Call previously defined macro for each concerned type */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1123
ANY_NBIT(__limit_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1124
ANY_NUM(__limit_)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1125
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1126
#define __limit_time(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1127
static inline TYPENAME __limit_##TYPENAME(EN_ENO_PARAMS, TYPENAME MN, TYPENAME IN, TYPENAME MX){\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1128
    TEST_EN(TYPENAME)\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1129
    return __TIME_CMP(IN, MN) > 0 ? /* IN>MN ?*/\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1130
           __TIME_CMP(IN, MX) < 0 ? /* IN<MX ?*/\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1131
           IN : MX : MN;\
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1132
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1133
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1134
/* Call previously defined macro for each concerned type */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1135
ANY_DATE(__limit_time)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1136
__limit_time(TIME)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1137
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1138
static inline STRING __limit_STRING(EN_ENO_PARAMS, STRING MN, STRING IN, STRING MX){
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1139
    TEST_EN(STRING)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1140
    return __STR_CMP(IN, MN) > 0 ? __STR_CMP(IN, MX) < 0 ? IN : MX : MN;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1141
}
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1142
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1143
    /**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1144
    /*     MAX    */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1145
    /**************/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1146
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1147
#define __extrem_(fname,TYPENAME, COND) \
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1148
static inline TYPENAME fname##TYPENAME(EN_ENO_PARAMS, UINT param_count, TYPENAME op1, ...){\
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1149
  va_list ap;\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1150
  UINT i;\
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
  1151
  TEST_EN(TYPENAME)\
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1152
  \
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1153
  va_start (ap, op1);         /* Initialize the argument list.  */\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1154
  \
165
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1155
  for (i = 0; i < param_count - 1; i++){\
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1156
    TYPENAME tmp = va_arg (ap, VA_ARGS_##TYPENAME);\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1157
    op1 = COND ? tmp : op1;\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1158
  }\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1159
  \
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1160
  va_end (ap);                  /* Clean up.  */\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1161
  return op1;\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1162
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1163
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1164
#define __max_num(TYPENAME) __extrem_(__max_,TYPENAME, op1 < tmp)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1165
ANY_NBIT(__max_num)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1166
ANY_NUM(__max_num)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1167
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1168
__extrem_(__max_, STRING, __STR_CMP(op1,tmp) < 0)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1169
#define __max_time(TYPENAME) __extrem_(__max_, TYPENAME, __TIME_CMP(op1, tmp) < 0)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1170
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1171
/* Call previously defined macro for each concerned type */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1172
ANY_DATE(__max_time)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1173
__max_time(TIME)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1174
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1175
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1176
    /*     MIN    */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1177
    /**************/
165
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1178
#define __min_num(TYPENAME) __extrem_(__min_, TYPENAME, op1 > tmp)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1179
ANY_NBIT(__min_num)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1180
ANY_NUM(__min_num)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1181
165
83963465b773 Bug on standard function not defined with EN/ENO fixed
lbessard
parents: 163
diff changeset
  1182
__extrem_(__min_, STRING, __STR_CMP(op1,tmp) > 0)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1183
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1184
#define __min_time(TYPENAME) __extrem_(__min_, TYPENAME, __TIME_CMP(op1, tmp) > 0)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1185
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1186
/* Call previously defined macro for each concerned type */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1187
ANY_DATE(__min_time)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1188
__min_time(TIME)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1189
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1190
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1191
    /*     MUX    */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1192
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1193
#define __mux_(TYPENAME) \
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1194
static inline TYPENAME __mux_##TYPENAME(EN_ENO_PARAMS, UINT param_count, UINT K, ...){\
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1195
  va_list ap;\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1196
  UINT i;\
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
  1197
  TYPENAME tmp;\
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
  1198
  TEST_EN_COND(TYPENAME, K >= param_count)\
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
  1199
  tmp = __INIT_##TYPENAME;\
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1200
  \
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1201
  va_start (ap, K);         /* Initialize the argument list.  */\
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1202
  \
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1203
  for (i = 0; i < param_count; i++){\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1204
    if(K == i){\
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1205
        tmp = va_arg (ap, VA_ARGS_##TYPENAME);\
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1206
        va_end (ap);                  /* Clean up.  */\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1207
        return tmp;\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1208
    }else{\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1209
        va_arg (ap, VA_ARGS_##TYPENAME);\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1210
    }\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1211
  }\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1212
  \
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1213
  va_end (ap);                  /* Clean up.  */\
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1214
  return tmp;\
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1215
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1216
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1217
ANY(__mux_)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1218
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1219
/**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1220
/* Comparison */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1221
/**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1222
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1223
#define __compare_(fname,TYPENAME, COND) \
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1224
static inline BOOL fname##TYPENAME(EN_ENO_PARAMS, UINT param_count, TYPENAME op1, ...){\
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1225
  va_list ap;\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1226
  UINT i;\
200
fde2d08ebaee Applying patch from Iztok for old gcc versions
laurent
parents: 199
diff changeset
  1227
  TEST_EN(BOOL)\
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1228
  \
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1229
  va_start (ap, op1);         /* Initialize the argument list.  */\
43
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
  1230
  DBG(#fname #TYPENAME "\n")\
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
  1231
  DBG_TYPE(TYPENAME, op1)\
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1232
  \
43
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
  1233
  for (i = 0; i < param_count - 1; i++){\
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1234
    TYPENAME tmp = va_arg (ap, VA_ARGS_##TYPENAME);\
43
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
  1235
    DBG_TYPE(TYPENAME, tmp)\
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1236
    if(COND){\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1237
        op1 = tmp;\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1238
    }else{\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1239
        va_end (ap);                  /* Clean up.  */\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1240
        return 0;\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1241
    }\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1242
  }\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1243
  \
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1244
  va_end (ap);                  /* Clean up.  */\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1245
  return 1;\
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1246
}
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1247
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1248
#define __compare_num(fname, TYPENAME, TEST) __compare_(fname, TYPENAME, op1 TEST tmp )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1249
#define __compare_time(fname, TYPENAME, TEST) __compare_(fname, TYPENAME, __TIME_CMP(op1, tmp) TEST 0)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1250
#define __compare_string(fname, TEST) __compare_(fname, STRING, __STR_CMP(op1, tmp) TEST 0 )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1251
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 140
diff changeset
  1252
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1253
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1254
    /*     GT     */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1255
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1256
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1257
#define __gt_num(TYPENAME) __compare_num(__gt_, TYPENAME, > )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1258
ANY_NBIT(__gt_num)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1259
ANY_NUM(__gt_num)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1260
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1261
#define __gt_time(TYPENAME) __compare_time(__gt_, TYPENAME, > )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1262
ANY_DATE(__gt_time)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1263
__gt_time(TIME)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1264
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1265
__compare_string(__gt_, > )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1266
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1267
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1268
    /*     GE     */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1269
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1270
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1271
#define __ge_num(TYPENAME) __compare_num(__ge_, TYPENAME, >= )
43
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
  1272
ANY_BIT(__ge_num)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1273
ANY_NUM(__ge_num)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1274
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1275
#define __ge_time(TYPENAME) __compare_time(__ge_, TYPENAME, >= )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1276
ANY_DATE(__ge_time)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1277
__ge_time(TIME)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1278
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1279
__compare_string(__ge_, >=)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1280
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1281
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1282
    /*     EQ     */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1283
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1284
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1285
#define __eq_num(TYPENAME) __compare_num(__eq_, TYPENAME, == )
43
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
  1286
ANY_BIT(__eq_num)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1287
ANY_NUM(__eq_num)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1288
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1289
#define __eq_time(TYPENAME) __compare_time(__eq_, TYPENAME, == )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1290
ANY_DATE(__eq_time)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1291
__eq_time(TIME)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1292
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1293
__compare_string(__eq_, == )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1294
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1295
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1296
    /*     LT     */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1297
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1298
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1299
#define __lt_num(TYPENAME) __compare_num(__lt_, TYPENAME, < )
43
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
  1300
ANY_BIT(__lt_num)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1301
ANY_NUM(__lt_num)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1302
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1303
#define __lt_time(TYPENAME) __compare_time(__lt_, TYPENAME, < )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1304
ANY_DATE(__lt_time)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1305
__lt_time(TIME)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1306
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1307
__compare_string(__lt_, < )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1308
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1309
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1310
    /*     LE     */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1311
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1312
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1313
#define __le_num(TYPENAME) __compare_num(__le_, TYPENAME, <= )
43
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
  1314
ANY_BIT(__le_num)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1315
ANY_NUM(__le_num)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1316
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1317
#define __le_time(TYPENAME) __compare_time(__le_, TYPENAME, <= )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1318
ANY_DATE(__le_time)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1319
__le_time(TIME)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1320
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1321
__compare_string(__le_, <= )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1322
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1323
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1324
    /*     NE     */
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1325
    /**************/
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1326
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1327
#define __ne_num(TYPENAME) __compare_num(__ne_, TYPENAME, != )
43
37dd4e2fd2ec Test IEC_LIB and fix bugs (EQ, GT et all)
etisserant
parents: 42
diff changeset
  1328
ANY_BIT(__ne_num)
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1329
ANY_NUM(__ne_num)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1330
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1331
#define __ne_time(TYPENAME) __compare_time(__ne_, TYPENAME, != )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1332
ANY_DATE(__ne_time)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1333
__ne_time(TIME)
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1334
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1335
__compare_string(__ne_, != )
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents:
diff changeset
  1336