Re-apply r40728 and fix Coverity CID 1371 UNINIT again.
[obnox/wireshark/wip.git] / epan / dtd_parse.l
index c29040ca6235056c8cd67372a254be1d1776cef0..29a3c5f4e4b4e210ce28ade8bfd9405a94eb5080 100644 (file)
@@ -1,12 +1,7 @@
-/*
- * We want to stop processing when we get to the end of the input.
- */
-%option noyywrap
-
 /*
  * We don't use unput, so don't generate code for it.
  */
-%option nounput 
+%option nounput
 
 /*
  * We don't read from the terminal.
 %{
 
        /* dtd_parse.l
-       * an XML dissector for Wireshark 
+       * an XML dissector for Wireshark
        * lexical analyzer for DTDs
        *
-       * Copyright 2004, Luis E. Garcia Ontanon <luis.ontanon@gmail.com>
+       * Copyright 2004, Luis E. Garcia Ontanon <luis@ontanon.org>
        *
        * $Id$
        *
        * modify it under the terms of the GNU General Public License
        * as published by the Free Software Foundation; either version 2
        * of the License, or (at your option) any later version.
-       * 
+       *
        * This program is distributed in the hope that it will be useful,
        * but WITHOUT ANY WARRANTY; without even the implied warranty of
        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        * GNU General Public License for more details.
-       * 
+       *
        * You should have received a copy of the GNU General Public License
        * along with this program; if not, write to the Free Software
        * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
        */
-       
+
 #include <glib.h>
 #include <string.h>
-       
+
 #include "dtd.h"
 #include "dtd_grammar.h"
 #include "dtd_parse.h"
 #include "dtd_parse_lex.h"
-       
+
        struct _proto_xmlpi_attr {
                gchar* name;
                void (*act)(gchar*);
        };
 
        static void* pParser;
-       static GString* input_string;   
+       static GString* input_string;
        static guint offset;
        static guint len;
        static gchar* location;
        static gchar* attr_name;
-       
+
        static int my_yyinput(char* buff,guint size);
-       
+
        static dtd_token_data_t* new_token(gchar*);
 
        static dtd_build_data_t* build_data;
-       
+
        static void set_proto_name (gchar* val) { if(build_data->proto_name) g_free(build_data->proto_name); build_data->proto_name = g_strdup(val); }
        static void set_media_type (gchar* val) { if(build_data->media_type) g_free(build_data->media_type); build_data->media_type = g_strdup(val); }
        static void set_proto_root (gchar* val) { if(build_data->proto_root) g_free(build_data->proto_root); build_data->proto_root = g_strdup(val); }
        static void set_description (gchar* val) { if(build_data->description) g_free(build_data->description); build_data->description = g_strdup(val); }
-       static void set_recursive (gchar* val) { build_data->recursion = ( g_strcasecmp(val,"yes") == 0 ) ? TRUE : FALSE; }
+       static void set_recursive (gchar* val) { build_data->recursion = ( g_ascii_strcasecmp(val,"yes") == 0 ) ? TRUE : FALSE; }
 
        static struct _proto_xmlpi_attr proto_attrs[] =
        {
                { "hierarchy", set_recursive },
                {NULL,NULL}
        };
-       
+
 #ifdef DEBUG_DTD_PARSER
 #define DEBUG_DTD_TOKEN fprintf(stderr,"->%s (%i)%s\n",location,token_type,yytext)
 #else
 #define DEBUG_DTD_TOKEN
 #endif
-    
+
 #define DTD_PARSE(token_type) \
        {   DEBUG_DTD_TOKEN; \
                DtdParse(pParser, (token_type), new_token(yytext), build_data); \
 
 #define YY_INPUT(buff,result,max_size) ( (result) = my_yyinput((buff),(max_size)) )
 
+/*
+ * Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
+ */
+#ifdef _WIN32
+#define YY_NO_UNISTD_H
+#endif
+
 %}
 
 comment_start "<!--"
@@ -169,7 +171,7 @@ name           [A-Za-z0-9][-a-zA-Z0-9_]*
 dquoted        ["][^\"]*["]
 squoted        ['][^\']*[']
 
-%START DTD XMLPI LOCATION DONE PROTOCOL GET_ATTR_QUOTE GET_ATTR_VAL GET_ATTR_CLOSE_QUOTE IN_COMMENT IN_NOTATION 
+%START DTD XMLPI LOCATION DONE PROTOCOL GET_ATTR_QUOTE GET_ATTR_VAL GET_ATTR_CLOSE_QUOTE IN_COMMENT IN_NOTATION
 %%
 
 {whitespace}            ;
@@ -208,15 +210,14 @@ squoted        ['][^\']*[']
 <DONE>{stop_xmlpi}  BEGIN DTD;
 
 <PROTOCOL>{name} {
-       attr_name = g_strdup(yytext);
-       g_strdown(attr_name);
+       attr_name = g_ascii_strdown(yytext, -1);
        BEGIN GET_ATTR_QUOTE;
 }
 
 <GET_ATTR_QUOTE>{get_attr_quote} { BEGIN GET_ATTR_VAL; }
 
 <GET_ATTR_QUOTE>. {
-       g_string_sprintfa(build_data->error,
+       g_string_append_printf(build_data->error,
                                        "error in wireshark:protocol xmpli at %s : could not find attribute value!",
                                        location);
        yyterminate();
@@ -226,25 +227,25 @@ squoted        ['][^\']*[']
        /*"*/
        struct _proto_xmlpi_attr* pa;
        gboolean got_it = FALSE;
-       
+
        for(pa = proto_attrs; pa->name; pa++) {
-               if (g_strcasecmp(attr_name,pa->name) == 0) {
+               if (g_ascii_strcasecmp(attr_name,pa->name) == 0) {
                        pa->act(yytext);
                        got_it = TRUE;
                        break;
                }
        }
-       
+
        if (! got_it) {
-               g_string_sprintfa(build_data->error,
+               g_string_append_printf(build_data->error,
                                                "error in wireshark:protocol xmpli at %s : no such parameter %s!",
                                                location, attr_name);
                g_free(attr_name);
                yyterminate();
        }
-       
+
        g_free(attr_name);
-               
+
        BEGIN GET_ATTR_CLOSE_QUOTE;
 }
 
@@ -259,7 +260,7 @@ squoted        ['][^\']*[']
 <DTD>{element_kw}            { DTD_PARSE(TOKEN_ELEMENT_KW); }
 <DTD>{doctype_kw}            { DTD_PARSE(TOKEN_DOCTYPE_KW); }
 
-<DTD>{pcdata}                { DTD_PARSE(TOKEN_ELEM_DATA); } 
+<DTD>{pcdata}                { DTD_PARSE(TOKEN_ELEM_DATA); }
 <DTD>{any}                   { DTD_PARSE(TOKEN_ELEM_DATA); }
 <DTD>{cdata}                 { DTD_PARSE(TOKEN_ELEM_DATA); }
 <DTD>{empty}                            { DTD_PARSE(TOKEN_EMPTY_KW); }
@@ -296,10 +297,10 @@ squoted        ['][^\']*[']
 
 static dtd_token_data_t* new_token(gchar* text) {
        dtd_token_data_t* t = g_malloc(sizeof(dtd_token_data_t));
-       
+
        t->text = g_strdup(text);
        t->location = g_strdup(location);
-       
+
        return t;
 }
 
@@ -324,14 +325,14 @@ extern dtd_build_data_t* dtd_parse(GString* s) {
 
        input_string = s;
        offset = 0;
-       len = input_string->len;
-       
+       len = (guint) input_string->len;
+
        pParser = DtdParseAlloc(g_malloc);
 
 #ifdef DEBUG_DTD_PARSER
        DtdParseTrace(stderr, ">>");
 #endif
-    
+
        build_data = g_malloc(sizeof(dtd_build_data_t));
 
        build_data->proto_name = NULL;
@@ -339,27 +340,38 @@ extern dtd_build_data_t* dtd_parse(GString* s) {
        build_data->description = NULL;
        build_data->proto_root = NULL;
        build_data->recursion = FALSE;
-    
+
        build_data->elements = g_ptr_array_new();
        build_data->attributes = g_ptr_array_new();
 
        build_data->error = g_string_new("");
-       
+
        location = NULL;
-    
+
        BEGIN DTD;
-       
+
        yylex();
 
        DtdParse(pParser, 0, NULL,build_data);
 
        yyrestart(NULL);
-       
+
        if (location) g_free(location);
-       
+
        location = NULL;
-    
+
        DtdParseFree(pParser, g_free );
-       
+
        return build_data;
 }
+
+/*
+ * We want to stop processing when we get to the end of the input.
+ * (%option noyywrap is not used because if used then
+ * some flex versions (eg: 2.5.35) generate code which causes
+ * warnings by the Windows VC compiler).
+ */
+
+int yywrap(void) {
+    return 1;
+}