]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add enum helpers
authorMichael Jerris <mike@jerris.com>
Mon, 11 Jun 2007 22:11:58 +0000 (22:11 +0000)
committerMichael Jerris <mike@jerris.com>
Mon, 11 Jun 2007 22:11:58 +0000 (22:11 +0000)
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@245 a93c3328-9c30-0410-af19-c9cd2b2d52af

libs/openzap/src/isdn/Q931api.c
libs/openzap/src/isdn/include/Q931.h

index 7930fa53db83515cc662740f9b2684c568c454df..641f34a7ce5dfd14c2ff4b752c98ee24c4816b51 100644 (file)
@@ -556,3 +556,6 @@ L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf)
 
     return RetCode;
 }
+
+Q931_ENUM_NAMES(DIALECT_TYPE_NAMES, DIALECT_STRINGS)
+Q931_STR2ENUM(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, Q931Dialect_t, DIALECT_TYPE_NAMES, Q931_Dialect_Count)
index 10a2e6e5ddc3add23693e3e5897a7e040baa9c7c..b230c96e35906807a1ddd49bd920af0a46dd3fcb 100644 (file)
 
 #ifdef _MSC_VER
 #pragma warning(disable:4100)
+#ifndef strcasecmp
+#define strcasecmp(s1, s2) _stricmp(s1, s2)
 #endif
+#endif
+#include <string.h>
+
+
+/*****************************************************************************
+
+  Enum helper macros
+
+*****************************************************************************/
+#define Q931_ENUM_NAMES(_NAME, _STRINGS) static char * _NAME [] = { _STRINGS , NULL };
+#define Q931_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (char *name); char * _FUNC2 (_TYPE type);
+#define Q931_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX)   \
+       _TYPE _FUNC1 (char *name)                                                               \
+       {                                                                                                               \
+               int i;                                                                                          \
+               _TYPE t = _MAX ;                                                                        \
+                                                                                                                       \
+               for (i = 0; i < _MAX ; i++) {                                           \
+                       if (!strcasecmp(name, _STRINGS[i])) {                   \
+                               t = (_TYPE) i;                                                          \
+                               break;                                                                          \
+                       }                                                                                               \
+               }                                                                                                       \
+                                                                                                                       \
+               return t;                                                                                       \
+       }                                                                                                               \
+       char * _FUNC2 (_TYPE type)                                                              \
+       {                                                                                                               \
+               if (type > _MAX) {                                                                      \
+                       type = _MAX;                                                                    \
+               }                                                                                                       \
+               return _STRINGS[(int)type];                                                     \
+       }                                                                                                               \
 
 /*****************************************************************************
 
@@ -454,6 +489,8 @@ typedef enum                                                /* Dialect enum                         */
 
        Q931_Dialect_Count
 } Q931Dialect_t;
+#define DIALECT_STRINGS "q931", "", "national"
+Q931_STR2ENUM_P(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, Q931Dialect_t)
 
 typedef enum                                           /* Trunk Line Type.                     */
 {