Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_XmlParser.cpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017  *
00018  */
00019 
00020 #include "C_XmlParser.hpp"
00021 #include "GeneratorTrace.hpp"
00022 #include "GeneratorError.h"
00023 
00024 #include "Utils.hpp"
00025 
00026 extern int parser_start (FILE *P_fd, C_XmlParser* P_parser);
00027 
00028 C_XmlParser::C_XmlParser() {
00029 
00030   GEN_DEBUG(1, "C_XmlParser::C_XmlParser() start") ;
00031 
00032   m_lex_string_value = NULL ;
00033   m_lex_string_index = 0 ;
00034   m_lex_max_string_size = 0 ;
00035 
00036   m_pCurrentXmlData = NULL ; 
00037   m_pXmldata = NULL ;
00038   m_vector.clear () ; 
00039   m_pXmlfield = NULL ;  
00040 
00041   GEN_DEBUG(1, "C_XmlParser::C_XmlParser() end") ;
00042 
00043 }
00044 
00045 C_XmlParser::~C_XmlParser() {
00046   GEN_DEBUG(1, "C_XmlParser::~C_XmlParser() start") ;
00047   GEN_DEBUG(1, "C_XmlParser::~C_XmlParser() end") ;
00048 }
00049 
00050 int C_XmlParser::lex_string_value_update (char P_char) {
00051   int L_result = 0 ;
00052 
00053   if (m_lex_string_index > m_lex_max_string_size) {
00054     printf("error, max reached\n");
00055     L_result = 1 ;
00056   } else {
00057     m_lex_string_value [ m_lex_string_index ] = P_char ;
00058     m_lex_string_index++ ;
00059     L_result = 0 ;
00060   }
00061   return (L_result);
00062 
00063 }
00064 
00065 void  C_XmlParser::lex_integer_update (char* P_value) {
00066   GEN_DEBUG(1, "C_XmlParser::lex_integer_update(" << P_value << ") start");
00067   m_lex_integer = atoi (P_value);
00068   GEN_DEBUG(1, "C_XmlParser::lex_integer_update() end");
00069 }
00070 
00071 int   C_XmlParser::get_lex_integer () {
00072   GEN_DEBUG(1, "C_XmlParser::get_lex_integer() start");
00073   GEN_DEBUG(1, "C_XmlParser::get_lex_integer() end");
00074   return (m_lex_integer);
00075 }
00076 
00077 
00078 char* C_XmlParser::get_lex_string_value () {
00079   GEN_DEBUG(1, "C_XmlParser::get_lex_string_value() start");
00080   GEN_DEBUG(1, "C_XmlParser::get_lex_string_value() end");
00081   return (m_lex_string_value) ;
00082 }
00083 
00084 void C_XmlParser::lex_string_value_reset () {
00085   GEN_DEBUG(1, "C_XmlParser::lex_string_value_reset() start");
00086   m_lex_string_index = 0 ;
00087   GEN_DEBUG(1, "C_XmlParser::lex_string_value_reset() end");
00088 }
00089 
00090 void C_XmlParser::new_xml_data (char *P_name) {
00091   GEN_DEBUG(1, "C_XmlParser::new_xml_data(" << P_name << ") start");
00092   NEW_VAR(m_pCurrentXmlData, C_XmlData(P_name));
00093   GEN_DEBUG(1, "C_XmlParser::new_xml_data() end");
00094 }
00095 
00096 void C_XmlParser::new_xml_field (char *P_name) {
00097   GEN_DEBUG(1, "C_XmlParser::new_xml_field(" << P_name << ") start");
00098   NEW_VAR(m_pXmlfield, C_XmlData::C_XmlField(P_name));
00099   GEN_DEBUG(1, "C_XmlParser::new_xml_field() end");
00100 }
00101 
00102 void C_XmlParser::add_xml_field (char *P_value) {
00103   GEN_DEBUG(1, "C_XmlParser::add_xml_field(" << P_value << ") start");
00104   m_pXmlfield->set_value(P_value); 
00105   m_pCurrentXmlData->add_field(m_pXmlfield) ;
00106   GEN_DEBUG(1, "C_XmlParser::add_xml_field() end");
00107 }
00108 
00109 void C_XmlParser::save_xml_data () {
00110   GEN_DEBUG(1, "C_XmlParser::save_xml_data() start");
00111   m_vector.push_back(m_pXmldata) ;
00112   m_vector.push_back(m_pCurrentXmlData) ;
00113   m_pXmldata = m_pCurrentXmlData ;
00114   GEN_DEBUG(1, "C_XmlParser::save_xml_data() end");
00115 }
00116 
00117 void C_XmlParser::retrieve_xml_data () {
00118   GEN_DEBUG(1, "C_XmlParser::retrieve_xml_data() start");
00119   m_vector_rit = m_vector.rbegin() ;
00120   m_pCurrentXmlData = *m_vector_rit ;
00121   m_vector.pop_back() ;
00122   m_vector_rit = m_vector.rbegin() ;
00123   m_pXmldata = *m_vector_rit ; 
00124   m_vector.pop_back() ;
00125   GEN_DEBUG(1, "C_XmlParser::retrieve_xml_data() end");
00126 }
00127 
00128 void C_XmlParser::add_sub_xml_data () {
00129   GEN_DEBUG(1, "C_XmlParser::add_sub_xml_data() start");
00130   GEN_DEBUG(1, "C_XmlParser::add_sub_xml_data() end");
00131   m_pXmldata -> add_sub_data (m_pCurrentXmlData);
00132 }
00133 
00134 
00135 void C_XmlParser::init () {
00136   GEN_DEBUG(1, "C_XmlParser::init() start");
00137 
00138   // m_lex_string_value = (char*) malloc (1024) ;
00139   // m_lex_max_string_size = 1024 ;
00140 
00141   m_lex_string_value = (char*) malloc (2048) ;
00142   m_lex_max_string_size = 2048 ;
00143   NEW_VAR(m_pXmldata, C_XmlData((char*)""));
00144   GEN_DEBUG(1, "C_XmlParser::init() end");
00145 }
00146 
00147 FILE* C_XmlParser::next_file() {
00148   
00149   FILE *L_fd = NULL ;
00150   GEN_DEBUG(1, "C_XmlParser::next_file() start");
00151   m_current_file++ ;
00152   if (m_current_file < m_nb_file) {
00153 
00154     if ((L_fd = fopen (m_file_name_table[m_current_file].c_str(), "r")) == NULL) {
00155       GEN_FATAL(E_GEN_FATAL_ERROR, "Unable to open file [" 
00156             << m_file_name_table[m_current_file] << "]");
00157     } 
00158   } else {
00159     if (m_current_file) m_current_file -- ;
00160   }
00161   GEN_DEBUG(1, "C_XmlParser::next_file() end");
00162   return (L_fd) ;
00163 }
00164 
00165 string_t& C_XmlParser::get_current_file_name() {
00166   GEN_DEBUG(1, "C_XmlParser::get_current_file_name() start");
00167   GEN_DEBUG(1, "C_XmlParser::get_current_file_name() end");
00168   return (m_file_name_table[m_current_file]) ;
00169 }
00170 
00171 C_XmlData* C_XmlParser::parse (int P_nb, 
00172                                string_t* P_fileName, 
00173                                int *P_error) {
00174 
00175   FILE      *L_fd = NULL ;
00176   C_XmlData *L_pData = NULL ;
00177 
00178   GEN_DEBUG(1, "C_XmlParser::parse() start");
00179 
00180   m_nb_file = P_nb ;
00181   m_file_name_table = P_fileName ;
00182   m_current_file = 0 ;
00183 
00184   if ((L_fd = fopen (m_file_name_table[m_current_file].c_str(), "r")) == NULL) {
00185     GEN_FATAL(E_GEN_FATAL_ERROR, "Unable to open file [" 
00186           << m_file_name_table[m_current_file] << "]");
00187     *P_error = -1 ;
00188     return (NULL) ;
00189   } 
00190   
00191   init();
00192 
00193   *P_error = parser_start (L_fd, this) ;
00194   if (*P_error == 0) {
00195     L_pData = m_pXmldata ;
00196   } 
00197   
00198   GEN_DEBUG(1, "C_XmlParser::parse() end");
00199   return (L_pData);
00200 }
00201 
00202 
00203 bool C_XmlParser::check_xml_data_name(char *P_name, int P_line) {
00204   bool L_ret = false ;
00205   GEN_DEBUG(1, "C_XmlParser::xml_data_name() start");
00206   if (m_pCurrentXmlData != NULL) {
00207     L_ret 
00208       = (strcmp(m_pCurrentXmlData->get_name(), P_name) == 0) ? true : false ;
00209     if (L_ret == false) {
00210       GEN_ERROR(E_GEN_FATAL_ERROR, 
00211             "Keyword [" 
00212             << m_pCurrentXmlData->get_name() 
00213             << "] expected near line ["
00214             << P_line << "]");
00215     }
00216   } 
00217   
00218   GEN_DEBUG(1, "C_XmlParser::xml_data_name() end");
00219   return (L_ret);
00220 }

Generated on Wed Mar 7 14:44:59 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002