Main Page   Class Hierarchy   Compound List   File List   Compound Members  

ProtocolData.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 "ProtocolData.hpp"
00021 #include "string_t.hpp"
00022 #include "integer_t.hpp"
00023 
00024 #include "GeneratorTrace.hpp"
00025 #include "GeneratorError.h"
00026 #include "BufferUtils.hpp"
00027 #include "Utils.hpp"
00028 
00029 const char* type_type_table[] = {
00030   "number",
00031   "signed",
00032   //  "real",
00033   "string",
00034   "composed",
00035   "grouped",
00036   "number64",
00037   "signed64" } ;
00038 
00039 static const char* default_value_table[] = {
00040   "0",
00041   "0",
00042   "" } ;
00043 
00044 iostream_output& operator<<(iostream_output&           P_ostream, 
00045                             T_TypeType&                P_value) {
00046   switch (P_value) {
00047   case E_TYPE_NUMBER:
00048   case E_TYPE_SIGNED:
00049   case E_TYPE_STRING:
00050   case E_TYPE_STRUCT:
00051   case E_TYPE_GROUPED:
00052   case E_TYPE_NUMBER_64:
00053   case E_TYPE_SIGNED_64:
00054     P_ostream << type_type_table[(int)P_value] ;
00055     break ;
00056   default:
00057     P_ostream << "UNSUPPORTED_TYPE" ;
00058     break ;
00059   }
00060   return (P_ostream);
00061 }
00062 
00063 iostream_output& operator<< (iostream_output&         P_ostream, 
00064                              T_ValueData& P_valueData){
00065 
00066   switch (P_valueData.m_type) {
00067 
00068   case E_TYPE_NUMBER:
00069     P_ostream << P_valueData.m_value.m_val_number ;
00070     break ;
00071   case E_TYPE_SIGNED:
00072     P_ostream << P_valueData.m_value.m_val_signed ;
00073     break ;
00074   case E_TYPE_STRING: {
00075 //      string_t L_value ;
00076 //      L_value.append((char*)P_valueData.m_value.m_val_binary.m_value,
00077 //                 P_valueData.m_value.m_val_binary.m_size);
00078 //      P_ostream << L_value ;
00079 
00080 
00081     if (P_valueData.m_value.m_val_binary.m_value != NULL) {
00082       static char L_hexa_buf [50] ;
00083       const  size_t L_cNum = 16 ;
00084       size_t L_i, L_nb ;
00085       unsigned char*L_cur ;
00086       size_t L_buffer_size = P_valueData.m_value.m_val_binary.m_size ;
00087 
00088       L_nb = L_buffer_size / L_cNum ;
00089       L_cur = P_valueData.m_value.m_val_binary.m_value ;
00090       P_ostream << " " ;        
00091       for (L_i = 0 ; L_i < L_nb; L_i++) {
00092         pretty_binary_buffer(L_cur, L_cNum, L_hexa_buf);
00093         P_ostream << L_hexa_buf ;
00094         L_cur += L_cNum ;
00095       }
00096       L_nb = L_buffer_size % L_cNum ;
00097       if (L_nb != 0) {
00098         pretty_binary_buffer(L_cur, L_nb, L_hexa_buf);
00099         P_ostream << L_hexa_buf ;
00100       }
00101     }
00102 
00103 
00104   }
00105     break ;
00106 
00107 
00108 
00109 
00110   case E_TYPE_STRUCT:
00111     P_ostream << P_valueData.m_value.m_val_struct.m_id_1 << ";" 
00112               << P_valueData.m_value.m_val_struct.m_id_2 ;
00113     break ;
00114 
00115   case E_TYPE_NUMBER_64:
00116     P_ostream << P_valueData.m_value.m_val_number_64 ;
00117     break ;
00118   case E_TYPE_SIGNED_64:
00119     P_ostream << P_valueData.m_value.m_val_signed_64 ;
00120     break ;
00121 
00122   default:
00123     GEN_FATAL(E_GEN_FATAL_ERROR, "operator << not implemented");
00124     break ;
00125   }
00126 
00127   return (P_ostream) ;
00128 }
00129 
00130 bool operator< 
00131   (const T_ValueData & P_left, 
00132    const T_ValueData & P_rigth) {
00133   bool   L_ret = false;
00134   int    L_i ;
00135   size_t L_min ;
00136   bool   L_left_min = false ;
00137   
00138 
00139   if (P_left.m_type == P_rigth.m_type) {
00140 
00141     switch (P_left.m_type) {
00142       
00143     case E_TYPE_NUMBER:
00144       L_ret = P_left.m_value.m_val_number < P_rigth.m_value.m_val_number ;
00145       break ;
00146     case E_TYPE_SIGNED:
00147       L_ret = P_left.m_value.m_val_signed < P_rigth.m_value.m_val_signed ;
00148       break ;
00149     case E_TYPE_STRING: 
00150       
00151       L_i = 0 ;
00152       
00153       if (P_left.m_value.m_val_binary.m_size 
00154           != P_rigth.m_value.m_val_binary.m_size) {
00155         
00156         if (P_left.m_value.m_val_binary.m_size 
00157             < P_rigth.m_value.m_val_binary.m_size) {
00158           L_min = P_left.m_value.m_val_binary.m_size  ;
00159           L_left_min = true ;
00160         } else {
00161           L_min = P_rigth.m_value.m_val_binary.m_size ;
00162         }
00163         
00164         while (P_left.m_value.m_val_binary.m_value[L_i] 
00165                == P_rigth.m_value.m_val_binary.m_value[L_i]) {
00166           L_i ++ ;
00167           if (L_i == (int) L_min) break ;
00168         }
00169         if (L_i == (int) L_min) {
00170           L_ret = L_left_min ;
00171         } else {
00172           L_ret = P_left.m_value.m_val_binary.m_value[L_i] 
00173             < P_rigth.m_value.m_val_binary.m_value[L_i];
00174         }
00175         
00176       } else {
00177         
00178         while (P_left.m_value.m_val_binary.m_value[L_i] 
00179                == P_rigth.m_value.m_val_binary.m_value[L_i]) {
00180           L_i ++ ;
00181           if (L_i == (int)P_left.m_value.m_val_binary.m_size) {
00182             break ;
00183           }
00184         }
00185         if (L_i == (int)P_left.m_value.m_val_binary.m_size) {
00186           L_ret = false ;
00187         } else {
00188           L_ret = P_left.m_value.m_val_binary.m_value[L_i] 
00189             < P_rigth.m_value.m_val_binary.m_value[L_i];
00190         }
00191       }
00192       break ;
00193       
00194     case E_TYPE_STRUCT:
00195       L_ret = P_left.m_value.m_val_struct.m_id_1 < P_rigth.m_value.m_val_struct.m_id_1 ;
00196       if (!L_ret) { L_ret = P_left.m_value.m_val_struct.m_id_2 < P_rigth.m_value.m_val_struct.m_id_2 ; }
00197       break ;
00198       
00199     case E_TYPE_NUMBER_64:
00200       L_ret = P_left.m_value.m_val_number_64 < P_rigth.m_value.m_val_number_64 ;
00201       break ;
00202     case E_TYPE_SIGNED_64:
00203       L_ret = P_left.m_value.m_val_signed_64 < P_rigth.m_value.m_val_signed_64 ;
00204       break ;
00205 
00206     default:
00207       GEN_FATAL(E_GEN_FATAL_ERROR, "operator < not implemented");
00208       break ;
00209     }
00210     
00211   } else {
00212 
00213     L_ret = (P_left.m_type < P_rigth.m_type) ;
00214 
00215   }
00216 
00217 
00218   return (L_ret);
00219 }
00220 
00221 
00222 bool operator==
00223   (const T_ValueData & P_left, 
00224    const T_ValueData & P_rigth) {
00225   bool   L_ret = false;
00226   int    L_i ;
00227   
00228   if (P_left.m_type == P_rigth.m_type) {
00229 
00230     switch (P_left.m_type) {
00231       
00232     case E_TYPE_NUMBER:
00233       L_ret = P_left.m_value.m_val_number == P_rigth.m_value.m_val_number ;
00234       break ;
00235     case E_TYPE_SIGNED:
00236       L_ret = P_left.m_value.m_val_signed == P_rigth.m_value.m_val_signed ;
00237       break ;
00238     case E_TYPE_STRING: 
00239       
00240       L_i = 0 ;
00241       
00242       if (P_left.m_value.m_val_binary.m_size 
00243           != P_rigth.m_value.m_val_binary.m_size) {
00244         L_ret = false;
00245       } else {
00246         
00247         while (P_left.m_value.m_val_binary.m_value[L_i] 
00248                == P_rigth.m_value.m_val_binary.m_value[L_i]) {
00249           L_i ++ ;
00250           if (L_i == (int)P_left.m_value.m_val_binary.m_size) {
00251             break ;
00252           }
00253         }
00254         if (L_i == (int)P_left.m_value.m_val_binary.m_size) {
00255           L_ret = true ;
00256         } else {
00257           L_ret = false ;
00258         }
00259       }
00260       break ;
00261       
00262     case E_TYPE_STRUCT:
00263       L_ret = P_left.m_value.m_val_struct.m_id_1 == P_rigth.m_value.m_val_struct.m_id_1 ;
00264       if (!L_ret) { L_ret = P_left.m_value.m_val_struct.m_id_2 == P_rigth.m_value.m_val_struct.m_id_2 ; }
00265       break ;
00266       
00267     case E_TYPE_NUMBER_64:
00268       L_ret = P_left.m_value.m_val_number_64 == P_rigth.m_value.m_val_number_64 ;
00269       break ;
00270     case E_TYPE_SIGNED_64:
00271       L_ret = P_left.m_value.m_val_signed_64 == P_rigth.m_value.m_val_signed_64 ;
00272       break ;
00273 
00274     default:
00275       GEN_FATAL(E_GEN_FATAL_ERROR, "operator == not implemented");
00276       break ;
00277     }
00278     
00279   } else {
00280 
00281     L_ret = (P_left.m_type == P_rigth.m_type) ;
00282 
00283   }
00284 
00285 
00286   return (L_ret);
00287 }
00288 
00289 
00290 
00291 T_TypeType typeFromString (char *P_type) {
00292   T_TypeType L_type = E_UNSUPPORTED_TYPE ;
00293   int        L_i ;
00294 
00295   for (L_i=0; L_i < (int)E_UNSUPPORTED_TYPE; L_i++) {
00296     if (strcmp(P_type, type_type_table[L_i])==0) {
00297       L_type = (T_TypeType) L_i ;
00298       break ;
00299     }
00300   }
00301   
00302   return (L_type);
00303 }
00304 
00305 T_ValueData valueFromString (char *P_value, T_TypeType P_type, int &P_result) {
00306   
00307   T_ValueData  L_value         ;
00308   char        *L_field_value   ;
00309   size_t       L_size          ;
00310 
00311 
00312   GEN_DEBUG(1, "ProtocolData::valueFromString() start");
00313   
00314 
00315   L_value.m_type = P_type ;
00316   L_field_value = P_value ;
00317 
00318   if (L_field_value == NULL) { P_result = -1 ; return (L_value); }
00319   L_size = strlen(L_field_value); 
00320   P_result = 0 ;
00321 
00322   GEN_DEBUG(1, "ProtocolData::valueFromString() "
00323             << "L_field_value [" << L_field_value << "]");
00324   
00325   GEN_DEBUG(1, "ProtocolData::valueFromString() "
00326             << " L_value.m_type  [" <<  L_value.m_type  << "]");
00327 
00328   switch (L_value.m_type) {
00329   
00330   case E_TYPE_SIGNED: {
00331     
00332     T_Integer32 L_signed_value ;
00333     char *L_endstr ;
00334     if (L_size > 0) {
00335       if ((L_size>2) 
00336           && (L_field_value[0] == '0') 
00337           && (L_field_value[1] == 'x')) { // hexa buffer value
00338         L_signed_value = strtol_f (L_field_value, &L_endstr,16) ; 
00339       } else {
00340         L_signed_value = strtol_f (L_field_value, &L_endstr,10) ;
00341       }
00342       
00343       if (L_endstr[0] != '\0') {
00344         GEN_ERROR(E_GEN_FATAL_ERROR, "field value ["
00345                   << L_field_value << "] bad format");
00346         P_result = -1 ;
00347       } else {
00348         GEN_DEBUG(1, "C_ExternalDataControl::analyze_data() "
00349                   << "signed value = " << L_signed_value);
00350         L_value.m_value.m_val_signed = L_signed_value ;
00351       }
00352     } else {
00353       GEN_ERROR(E_GEN_FATAL_ERROR, "Field empty where a signed number is expected");
00354       P_result = -1 ;
00355     }
00356   } 
00357   break ;
00358 
00359   case E_TYPE_NUMBER: {
00360     
00361     T_UnsignedInteger32 L_unsigned_value ;
00362     char *L_endstr ;
00363     if (L_size > 0) {
00364       if ((L_size>2) 
00365           && (L_field_value[0] == '0') 
00366           && (L_field_value[1] == 'x')) { // hexa buffer value
00367         L_unsigned_value = strtoul_f (L_field_value, &L_endstr,16) ; 
00368       } else {
00369         L_unsigned_value = strtoul_f (L_field_value, &L_endstr,10) ;
00370       }
00371       
00372       if (L_endstr[0] != '\0') {
00373         GEN_ERROR(E_GEN_FATAL_ERROR, "field value ["
00374                   << L_field_value << "] bad format");
00375         P_result = -1  ;
00376       } else {
00377         GEN_DEBUG(1, "C_ExternalDataControl::analyze_data() "
00378                   << "unsigned value =" << L_unsigned_value);
00379         L_value.m_value.m_val_number = L_unsigned_value ;
00380       }
00381     } else {
00382       GEN_ERROR(E_GEN_FATAL_ERROR, "Field empty where a number is expected");
00383       P_result = -1 ; 
00384     }
00385   }
00386   break ;
00387   
00388   case E_TYPE_STRING: {
00389     if ((L_size>2) 
00390         && (L_field_value[0] == '0') 
00391         && (L_field_value[1] == 'x')) { // hexa buffer value
00392       
00393       char  *L_ptr = L_field_value+2 ;
00394       size_t L_res_size ;
00395       
00396       L_value.m_value.m_val_binary.m_value  
00397         = convert_hexa_char_to_bin(L_ptr, &L_res_size);
00398 
00399       if (L_value.m_value.m_val_binary.m_value == NULL ) {
00400         GEN_ERROR(E_GEN_FATAL_ERROR, 
00401                   "Bad buffer size for hexadecimal buffer ["
00402                   << L_field_value << "]" ); 
00403         P_result = -1 ;
00404       } else {
00405         L_value.m_value.m_val_binary.m_size = L_res_size ;        
00406       }
00407       
00408     } else { // direct string value
00409       
00410       L_value.m_value.m_val_binary.m_size = L_size ;
00411       
00412       if (L_size != 0) {
00413         ALLOC_TABLE(L_value.m_value.m_val_binary.m_value,
00414                     unsigned char*,
00415                     sizeof(unsigned char),
00416                     L_size);
00417         memcpy(L_value.m_value.m_val_binary.m_value,
00418                L_field_value,
00419                L_size);
00420       } else {
00421         L_value.m_value.m_val_binary.m_value = NULL ;
00422       }
00423     }
00424     
00425     GEN_DEBUG(1, "C_ExternalDataControl::analyze_data() "
00426               << "string value size=" 
00427               << L_value.m_value.m_val_binary.m_size) ;
00428   }
00429   break ;
00430 
00431   case E_TYPE_SIGNED_64: {
00432     
00433     T_Integer64  L_signed_value ;
00434     char *L_endstr ;
00435     if (L_size > 0) {
00436       if ((L_size>2) 
00437           && (L_field_value[0] == '0') 
00438           && (L_field_value[1] == 'x')) { // hexa buffer value
00439         L_signed_value = strtoll_f (L_field_value, &L_endstr,16) ; 
00440       } else {
00441         L_signed_value = strtoll_f (L_field_value, &L_endstr,10) ;
00442       }
00443       
00444       if (L_endstr[0] != '\0') {
00445         GEN_ERROR(E_GEN_FATAL_ERROR, "field value ["
00446                   << L_field_value << "] bad format");
00447         P_result = -1 ;
00448       } else {
00449         GEN_DEBUG(1, "C_ExternalDataControl::analyze_data() "
00450                   << "signed64 value = " << L_signed_value);
00451         L_value.m_value.m_val_signed_64 = L_signed_value ;
00452       }
00453     } else {
00454       GEN_ERROR(E_GEN_FATAL_ERROR, "Field empty where a signed number64 is expected");
00455       P_result = -1 ;
00456     }
00457   } 
00458   break ;
00459 
00460   case E_TYPE_NUMBER_64: {
00461     
00462     T_UnsignedInteger64 L_unsigned_value ;
00463     char *L_endstr ;
00464     if (L_size > 0) {
00465       if ((L_size>2) 
00466           && (L_field_value[0] == '0') 
00467           && (L_field_value[1] == 'x')) { // hexa buffer value
00468         L_unsigned_value = strtoull_f (L_field_value, &L_endstr,16) ; 
00469       } else {
00470         L_unsigned_value = strtoull_f (L_field_value, &L_endstr,10) ;
00471       }
00472       
00473       if (L_endstr[0] != '\0') {
00474         GEN_ERROR(E_GEN_FATAL_ERROR, "field value ["
00475                   << L_field_value << "] bad format");
00476         P_result = -1  ;
00477       } else {
00478         GEN_DEBUG(1, "C_ExternalDataControl::analyze_data() "
00479                   << "unsigned64 value =" << L_unsigned_value);
00480         L_value.m_value.m_val_number_64 = L_unsigned_value ;
00481       }
00482     } else {
00483       GEN_ERROR(E_GEN_FATAL_ERROR, "Field empty where a number64 is expected");
00484       P_result = -1 ; 
00485     }
00486   }
00487   break ;
00488   
00489   default:
00490     GEN_FATAL(E_GEN_FATAL_ERROR,
00491               "Unsupported type for external data");
00492     P_result = -1 ;
00493     break ;
00494   }
00495 
00496   GEN_DEBUG(1, "ProtocolData::valueFromString() end");
00497 
00498   return (L_value);
00499 }
00500 
00501 const char* defaultStringValue(T_TypeType P_type) {
00502   if (P_type <= E_TYPE_STRING) {
00503     return(default_value_table[(int)P_type]);
00504   } else {
00505     return (NULL);
00506   }
00507 }
00508 
00509 void copyValue(T_ValueData& P_dest, 
00510                T_ValueData& P_source, 
00511                bool P_reset) {
00512   if (P_reset) {
00513     if (P_dest.m_type == E_TYPE_STRING) {
00514       FREE_TABLE(P_dest.m_value.m_val_binary.m_value);
00515       P_dest.m_value.m_val_binary.m_size = 0 ;
00516     }
00517   }
00518   P_dest = P_source ;
00519   if (P_dest.m_type == E_TYPE_STRING) {
00520     ALLOC_TABLE(P_dest.m_value.m_val_binary.m_value,
00521                 unsigned char*,
00522                 sizeof(unsigned char),
00523                 P_dest.m_value.m_val_binary.m_size);
00524     memcpy(P_dest.m_value.m_val_binary.m_value,
00525            P_source.m_value.m_val_binary.m_value,
00526            P_dest.m_value.m_val_binary.m_size);
00527   }
00528 }
00529 
00530 void resetMemory(T_ValueData &P_value) {
00531   if (P_value.m_type == E_TYPE_STRING) {
00532     FREE_TABLE(P_value.m_value.m_val_binary.m_value);
00533     P_value.m_value.m_val_binary.m_size = 0 ;
00534     //P_value.m_type = E_TYPE_NUMBER ;
00535   }
00536 }
00537 
00538 
00539 void resetValue(T_Value& P_value) {
00540     FREE_TABLE(P_value.m_val_binary.m_value);
00541     P_value.m_val_binary.m_size = 0 ;
00542 }
00543 
00544 
00545 bool copyBinaryVal(T_Value& P_dest, int P_begin, int P_size,
00546                    T_Value& P_source){
00547 
00548   int                    L_size ;
00549   unsigned char         *L_new_value ;
00550 
00551   L_size = P_dest.m_val_binary.m_size - P_begin - P_size ;
00552 
00553   if (L_size < 0) {
00554     P_dest.m_val_binary.m_size -= L_size ;
00555     ALLOC_TABLE(L_new_value,
00556                 unsigned char*,
00557                 sizeof(unsigned char),
00558                 P_dest.m_val_binary.m_size);
00559     memset(L_new_value, 0, P_dest.m_val_binary.m_size);
00560     //    memcpy(L_new_value, P_dest.m_val_binary.m_value,
00561     //     P_dest.m_val_binary.m_size+L_size);
00562     if (P_dest.m_val_binary.m_value) FREE_TABLE(P_dest.m_val_binary.m_value);
00563     P_dest.m_val_binary.m_value = L_new_value ;
00564 
00565   }
00566 
00567   memcpy(P_dest.m_val_binary.m_value+P_begin,
00568          P_source.m_val_binary.m_value,
00569          P_size);
00570 
00571   return (true);
00572 }
00573 
00574 
00575 bool copyBinaryVal(T_ValueData& P_dest, int P_begin, int P_size,
00576                    T_ValueData& P_source){
00577 
00578   int                    L_size ;
00579   unsigned char         *L_new_value ;
00580 
00581   L_size = P_dest.m_value.m_val_binary.m_size - P_begin - P_size ;
00582 
00583   if (L_size < 0) {
00584     P_dest.m_value.m_val_binary.m_size -= L_size ;
00585     ALLOC_TABLE(L_new_value,
00586                 unsigned char*,
00587                 sizeof(unsigned char),
00588                 P_dest.m_value.m_val_binary.m_size);
00589     memset(L_new_value, 0, P_dest.m_value.m_val_binary.m_size);
00590     memcpy(L_new_value, P_dest.m_value.m_val_binary.m_value,
00591            P_dest.m_value.m_val_binary.m_size+L_size);
00592     FREE_TABLE(P_dest.m_value.m_val_binary.m_value);
00593     P_dest.m_value.m_val_binary.m_value = L_new_value ;
00594 
00595   }
00596 
00597   memcpy(P_dest.m_value.m_val_binary.m_value+P_begin,
00598          P_source.m_value.m_val_binary.m_value,
00599          P_size);
00600 
00601   return (true);
00602 }
00603 
00604 
00605 bool extractBinaryVal(T_ValueData& P_dest, int P_begin, int P_size,
00606                       T_ValueData& P_source){
00607 
00608   unsigned char         *L_ptr  ;
00609 
00610   // TO DO ctrl P_source NULL
00611   L_ptr =  P_source.m_value.m_val_binary.m_value;
00612   
00613   L_ptr += P_begin ;
00614   
00615   memcpy(P_dest.m_value.m_val_binary.m_value, 
00616          L_ptr, P_size);
00617 
00618   return (true);
00619 }
00620 
00621 bool extractBinaryVal(T_Value& P_dest, int P_begin, int P_size,
00622                       T_Value& P_source){
00623 
00624   unsigned char         *L_ptr  ;
00625 
00626   // TO DO ctrl P_source NULL
00627   L_ptr =  P_source.m_val_binary.m_value;
00628   
00629   L_ptr += P_begin ;
00630   
00631   memcpy(P_dest.m_val_binary.m_value, 
00632          L_ptr, P_size);
00633 
00634   return (true);
00635 }
00636 
00637 char* create_string(T_ValueData& P_src) {
00638 
00639   char *L_result = NULL ;
00640 
00641   if ((P_src.m_type == E_TYPE_STRING) && 
00642       (P_src.m_value.m_val_binary.m_size > 0)) {
00643     ALLOC_TABLE(L_result,
00644                 char*,
00645                 sizeof(char),
00646                 P_src.m_value.m_val_binary.m_size+1);
00647     memcpy(L_result, 
00648            (char*)P_src.m_value.m_val_binary.m_value,
00649            P_src.m_value.m_val_binary.m_size);
00650     
00651     L_result[P_src.m_value.m_val_binary.m_size] = 0 ;
00652   }
00653   return (L_result);
00654 }
00655 
00656 bool compare_value(T_Value& P_left, 
00657                    T_Value& P_rigth) {
00658   bool   L_ret = false;
00659   int    L_i ;
00660   L_i = 0 ;
00661   
00662   if (P_left.m_val_binary.m_size 
00663       != P_rigth.m_val_binary.m_size) {
00664     L_ret = false;
00665   } else {
00666     while (P_left.m_val_binary.m_value[L_i] 
00667            == P_rigth.m_val_binary.m_value[L_i]) {
00668       L_i ++ ;
00669       if (L_i == (int)P_left.m_val_binary.m_size) {
00670         break ;
00671       }
00672     }
00673     if (L_i == (int)P_left.m_val_binary.m_size) {
00674       L_ret = true ;
00675     } else {
00676       L_ret = false ;
00677     }
00678   }
00679   return (L_ret);
00680 }
00681 
00682 void valueToString (T_ValueData& P_value, char *P_result, size_t& P_size) {
00683   size_t L_size = 1 ;
00684   static char L_tmp[250] ;
00685   
00686   L_tmp[0] = '\0' ;
00687   
00688   switch (P_value.m_type) {
00689   case E_TYPE_NUMBER:
00690     sprintf(L_tmp, "%ld",
00691             P_value.m_value.m_val_number);
00692     L_size = strlen(L_tmp);
00693     memcpy (P_result, L_tmp, L_size);
00694     P_size = L_size ;
00695     break ;
00696     
00697   case E_TYPE_SIGNED:
00698     sprintf(L_tmp, "%ld",
00699             P_value.m_value.m_val_signed);
00700     L_size = strlen(L_tmp);
00701     memcpy (P_result, L_tmp, L_size);
00702     P_size = L_size ;
00703     break ;
00704     
00705   case E_TYPE_NUMBER_64:
00706     sprintf(L_tmp, "%lld",
00707             P_value.m_value.m_val_number_64);
00708     L_size = strlen(L_tmp);
00709     memcpy (P_result, L_tmp, L_size);
00710     P_size = L_size ;
00711     break ;
00712     
00713   case E_TYPE_SIGNED_64:
00714     sprintf(L_tmp, "%lld",
00715             P_value.m_value.m_val_signed_64);
00716     L_size = strlen(L_tmp);
00717     memcpy (P_result, L_tmp, L_size);
00718     P_size = L_size ;
00719     break ;
00720     
00721   case E_TYPE_STRING:
00722     memcpy(P_result,
00723            (char*)P_value.m_value.m_val_binary.m_value,
00724            P_value.m_value.m_val_binary.m_size);
00725     P_result[P_value.m_value.m_val_binary.m_size] = 0 ;
00726     P_size = strlen(P_result);
00727     break ;
00728     
00729   case E_TYPE_STRUCT:
00730   case E_TYPE_GROUPED:
00731   case E_UNSUPPORTED_TYPE:
00732     GEN_FATAL(E_GEN_FATAL_ERROR,
00733               "Unsupported type for string conversion ["
00734               << P_value.m_type << "]");
00735     break ;
00736     
00737   }
00738 }

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