STRING max size and length type can now be overloaded (define STR_MAX_LEN and STR_LEN_TYPE before including iec_types.h)
authoretisserant
Tue, 23 Dec 2008 13:21:19 +0100
changeset 161 a27957e13d42
parent 160 59d58f5e6caa
child 162 60a124678842
STRING max size and length type can now be overloaded (define STR_MAX_LEN and STR_LEN_TYPE before including iec_types.h)
lib/iec_std_lib.h
lib/iec_types.h
--- a/lib/iec_std_lib.h	Fri Dec 19 15:09:29 2008 +0100
+++ b/lib/iec_std_lib.h	Tue Dec 23 13:21:19 2008 +0100
@@ -318,11 +318,11 @@
 /***************/
 #define __STR_CMP(str1, str2) memcmp((char*)&str1.body,(char*)&str2.body, str1.len < str2.len ? str1.len : str2.len)
 
-static inline UINT __len(EN_ENO_PARAMS, STRING IN){
+static inline __strlen_t __len(EN_ENO_PARAMS, STRING IN){
     TEST_EN(UINT)
     return IN.len;
 }
-static inline STRING __left(EN_ENO_PARAMS, STRING IN, SINT L){
+static inline STRING __left(EN_ENO_PARAMS, STRING IN, __strlen_t L){
     TEST_EN_COND(STRING, L < 0)
     STRING res = __INIT_STRING;
     L = L < IN.len ? L : IN.len;
@@ -330,7 +330,7 @@
     res.len = L;
     return res;
 }
-static inline STRING __right(EN_ENO_PARAMS, STRING IN, SINT L){
+static inline STRING __right(EN_ENO_PARAMS, STRING IN, __strlen_t L){
     TEST_EN_COND(STRING, L < 0)
     STRING res = __INIT_STRING;
     L = L < IN.len ? L : IN.len;
@@ -338,7 +338,7 @@
     res.len = L;
     return res;
 }
-static inline STRING __mid(EN_ENO_PARAMS, STRING IN, SINT L, SINT P){
+static inline STRING __mid(EN_ENO_PARAMS, STRING IN, __strlen_t L, __strlen_t P){
     TEST_EN_COND(STRING, L < 0 || P < 0)
     STRING res = __INIT_STRING;
     if(P <= IN.len){
@@ -349,7 +349,7 @@
     }
     return res;
 }
-static inline STRING __concat(EN_ENO_PARAMS, SINT param_count, ...){
+static inline STRING __concat(EN_ENO_PARAMS, UINT param_count, ...){
   TEST_EN(STRING)
   va_list ap;
   UINT i;
@@ -372,7 +372,7 @@
   va_end (ap);                  /* Clean up.  */
   return res;
 }
-static inline STRING __insert(EN_ENO_PARAMS, STRING IN1, STRING IN2, SINT P){
+static inline STRING __insert(EN_ENO_PARAMS, STRING IN1, STRING IN2, __strlen_t P){
     TEST_EN_COND(STRING, P < 0)
     STRING res = __INIT_STRING;
     __strlen_t to_copy;
@@ -391,7 +391,7 @@
 
     return res;
 }
-static inline STRING __delete(EN_ENO_PARAMS, STRING IN, SINT L, SINT P){
+static inline STRING __delete(EN_ENO_PARAMS, STRING IN, __strlen_t L, __strlen_t P){
     TEST_EN_COND(STRING, L < 0 || P < 0)
     STRING res = __INIT_STRING;
     __strlen_t to_copy;
@@ -408,7 +408,7 @@
 
     return res;
 }
-static inline STRING __replace(EN_ENO_PARAMS, STRING IN1, STRING IN2, SINT L, SINT P){
+static inline STRING __replace(EN_ENO_PARAMS, STRING IN1, STRING IN2, __strlen_t L, __strlen_t P){
     TEST_EN_COND(STRING, L < 0 || P < 0)
     STRING res = __INIT_STRING;
     __strlen_t to_copy;
@@ -438,7 +438,7 @@
 
 
 
-static inline UINT __pfind(STRING* IN1, STRING* IN2){
+static inline __strlen_t __pfind(STRING* IN1, STRING* IN2){
     UINT count1 = 0; /* offset of first matching char in IN1 */
     UINT count2 = 0; /* count of matching char */
     while(count1 + count2 < IN1->len && count2 < IN2->len)
@@ -450,7 +450,7 @@
     }
     return count2 == IN2->len -1 ? 0 : count1 + 1;
 }
-static inline UINT __find(EN_ENO_PARAMS, STRING IN1, STRING IN2){
+static inline __strlen_t __find(EN_ENO_PARAMS, STRING IN1, STRING IN2){
     TEST_EN(UINT)
     return __pfind(&IN1, &IN2);
 }
--- a/lib/iec_types.h	Fri Dec 19 15:09:29 2008 +0100
+++ b/lib/iec_types.h	Tue Dec 23 13:21:19 2008 +0100
@@ -47,8 +47,15 @@
 typedef struct timespec IEC_DT;
 typedef struct timespec IEC_TOD;
 
+#ifndef STR_MAX_LEN
 #define STR_MAX_LEN 40
-typedef int8_t __strlen_t;
+#endif
+
+#ifndef STR_LEN_TYPE
+#define STR_LEN_TYPE uint8_t
+#endif
+
+typedef STR_LEN_TYPE __strlen_t;
 typedef struct {
     __strlen_t len;
     uint8_t body[STR_MAX_LEN];