Explorar o código

Fix compile errors (original LuaXML_lib.c is not strict C)

There are many compile errors in the original LuaXML_lib.c file,
when using a MSVC C compiler. It does not define variables at the
beginning of a function, which is allowed in C++ but not in C.
This seems to be a non-standard gcc extention, which must not be
used within civetweb.
These changes might be required for all new versions of this
third party component. Maybe on the long term this library should
be replaced or rewritten.
bel %!s(int64=10) %!d(string=hai) anos
pai
achega
37b1879d1f
Modificáronse 1 ficheiros con 35 adicións e 18 borrados
  1. 35 18
      src/third_party/LuaXML_lib.c

+ 35 - 18
src/third_party/LuaXML_lib.c

@@ -133,7 +133,8 @@ const char* Tokenizer_next(Tokenizer* tok) {
     const char* ESC_str = "\033";
     const char* OPEN_str = "\034";
     const char* CLOSE_str = "\035";
-
+    int quotMode=0;
+    int tokenComplete = 0;
 
     if(tok->m_token) {
         free(tok->m_token);
@@ -141,8 +142,6 @@ const char* Tokenizer_next(Tokenizer* tok) {
         tok->m_token_size=tok->m_token_capacity = 0;
     }
 
-    int quotMode=0;
-    int tokenComplete = 0;
     while(tok->m_next_size || (tok->i < tok->s_size)) {
 
         if(tok->m_next_size) {
@@ -247,12 +246,18 @@ static char** sv_code=0;
 //--- public methods -----------------------------------------------
 
 static void Xml_pushDecode(lua_State* L, const char* s, size_t s_size) {
+
+    luaL_Buffer b;
+    const char* found = strstr(s, "&#");
+    size_t start=0, pos, i;
+
     if(!s_size)
         s_size=strlen(s);
-    luaL_Buffer b;
+
     luaL_buffinit(L, &b);
-    const char* found = strstr(s, "&#");
-    size_t start=0, pos = found ? found-s : s_size;
+    found = strstr(s, "&#");
+    pos = found ? found-s : s_size;
+
     while(found) {
         char ch = 0;
         size_t i=0;
@@ -272,7 +277,7 @@ static void Xml_pushDecode(lua_State* L, const char* s, size_t s_size) {
     if(pos>start)
         luaL_addlstring(&b,s+start, pos-start);
     luaL_pushresult(&b);
-    size_t i;
+
     for(i=sv_code_size-1; i<sv_code_size; i-=2) {
         luaL_gsub(L, lua_tostring(L,-1), sv_code[i], sv_code[i-1]);
         lua_remove(L,-2);
@@ -282,6 +287,10 @@ static void Xml_pushDecode(lua_State* L, const char* s, size_t s_size) {
 int Xml_eval(lua_State *L) {
     char* str = 0;
     size_t str_size=0;
+    Tokenizer* tok;
+    const char* token=0;
+    int firstStatement = 1;
+
     if(lua_isuserdata(L,1))
         str = (char*)lua_touserdata(L,1);
     else {
@@ -290,10 +299,9 @@ int Xml_eval(lua_State *L) {
         memcpy(str, sTmp, str_size);
         str[str_size]=0;
     }
-    Tokenizer* tok = Tokenizer_new(str, str_size ? str_size : strlen(str));
+    tok = Tokenizer_new(str, str_size ? str_size : strlen(str));
     lua_settop(L,0);
-    const char* token=0;
-    int firstStatement = 1;
+
     while((token=Tokenizer_next(tok))!=0) if(token[0]==OPN) { // new tag found
         if(lua_gettop(L)) {
             int newIndex=lua_rawlen(L,-1)+1;
@@ -333,8 +341,10 @@ int Xml_eval(lua_State *L) {
             size_t sepPos=find(token, "=", 0);
             if(token[sepPos]) { // regular attribute
                 const char* aVal =token+sepPos+2;
+                size_t lenVal;
+
                 lua_pushlstring(L, token, sepPos);
-                size_t lenVal = strlen(aVal)-1;
+                lenVal = strlen(aVal)-1;
                 if(!lenVal) Xml_pushDecode(L, "", 0);
                 else Xml_pushDecode(L, aVal, lenVal);
                 lua_settable(L, -3);
@@ -362,13 +372,16 @@ int Xml_eval(lua_State *L) {
 int Xml_load (lua_State *L) {
     const char * filename = luaL_checkstring(L,1);
     FILE * file=fopen(filename,"r");
+    char* buffer;
+    size_t sz;
+
     if(!file)
         return luaL_error(L,"LuaXml ERROR: \"%s\" file error or file not found!",filename);
 
     fseek (file , 0 , SEEK_END);
-    size_t sz = ftell (file);
+    sz = ftell (file);
     rewind (file);
-    char* buffer = (char*)malloc(sz+1);
+    buffer = (char*)malloc(sz+1);
     sz = fread (buffer,1,sz,file);
     fclose(file);
     buffer[sz]=0;
@@ -397,18 +410,22 @@ int Xml_registerCode(lua_State *L) {
 }
 
 int Xml_encode(lua_State *L) {
+
+    char buf[8];
+    size_t start, pos;
+    luaL_Buffer b;
+    const char* s;
+    size_t i;
+
     if(lua_gettop(L)!=1)
         return 0;
     luaL_checkstring(L,-1);
-    size_t i;
+
     for(i=0; i<sv_code_size; i+=2) {
         luaL_gsub(L, lua_tostring(L,-1), sv_code[i], sv_code[i+1]);
         lua_remove(L,-2);
     }
-    char buf[8];
-    const char* s=lua_tostring(L,1);
-    size_t start, pos;
-    luaL_Buffer b;
+    s=lua_tostring(L,1);
     luaL_buffinit(L, &b);
     for(start=pos=0; s[pos]!=0; ++pos) if(s[pos]<0) {
         if(pos>start) luaL_addlstring(&b,s+start, pos-start);