From d22f9e7c7cb7b27da5638c6eda11cf82280258c6 Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周六, 16 3月 2013 02:48:36 +0800
Subject: [PATCH] Make library more C++ friendly

---
 libscpi/src/utils.c |   33 +++++++++++++++++----------------
 1 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/libscpi/src/utils.c b/libscpi/src/utils.c
index 583b5f7..0c54ed3 100644
--- a/libscpi/src/utils.c
+++ b/libscpi/src/utils.c
@@ -154,7 +154,7 @@
     return FALSE;
 }
 
-enum locate_text_states {
+enum _locate_text_states {
     STATE_FIRST_WHITESPACE,
     STATE_TEXT_QUOTED,
     STATE_TEXT,
@@ -162,18 +162,20 @@
     STATE_COMMA,
     STATE_ERROR,
 };
+typedef enum _locate_text_states locate_text_states;
 
-struct locate_text_nfa {
-    enum locate_text_states state;
+struct _locate_text_nfa {
+    locate_text_states state;
     int32_t startIdx;
     int32_t stopIdx;
     size_t i;
 };
+typedef struct _locate_text_nfa locate_text_nfa;
 
 /**
  * Test locate text state, if it is correct final state
  */
-static inline bool_t isFinalState(enum locate_text_states state) {
+static inline bool_t isFinalState(locate_text_states state) {
     return (
         ((state) == STATE_COMMA)
         || ((state) == STATE_LAST_WHITESPACE)
@@ -187,7 +189,7 @@
  * @param nfa stores automaton state
  * @param c current char processed
  */
-static inline bool_t locateTextAutomaton(struct locate_text_nfa * nfa, unsigned char c) {
+static inline bool_t locateTextAutomaton(locate_text_nfa * nfa, unsigned char c) {
     switch(nfa->state) {
         /* first state locating only white spaces */
         case STATE_FIRST_WHITESPACE:
@@ -249,11 +251,10 @@
  * @return string str1 contains text and str2 was set
  */
 bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) {
-    struct locate_text_nfa nfa = {
-        .startIdx = 0,
-        .stopIdx = 0,
-        .state = STATE_FIRST_WHITESPACE,
-    };
+    locate_text_nfa nfa;
+    nfa.state = STATE_FIRST_WHITESPACE;
+    nfa.startIdx = 0;
+    nfa.stopIdx = 0;
 
     for (nfa.i = 0; nfa.i < len1; nfa.i++) {
         if(FALSE == locateTextAutomaton(&nfa, str1[nfa.i])) {
@@ -280,7 +281,7 @@
  * @param nfa stores automaton state
  * @param c current char processed
  */
-static inline bool_t locateStrAutomaton(struct locate_text_nfa * nfa, unsigned char c) {
+static inline bool_t locateStrAutomaton(locate_text_nfa * nfa, unsigned char c) {
     switch(nfa->state) {
         /* first state locating only white spaces */
         case STATE_FIRST_WHITESPACE:
@@ -322,11 +323,11 @@
  * @return string str1 contains text and str2 was set
  */
 bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) {
-    struct locate_text_nfa nfa = {
-        .startIdx = 0,
-        .stopIdx = 0,
-        .state = STATE_FIRST_WHITESPACE,
-    };
+    locate_text_nfa nfa;
+    nfa.state = STATE_FIRST_WHITESPACE;
+    nfa.startIdx = 0;
+    nfa.stopIdx = 0;
+
 
     for (nfa.i = 0; nfa.i < len1; nfa.i++) {
         if(FALSE == locateStrAutomaton(&nfa, str1[nfa.i])) {

--
Gitblit v1.9.1