00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "C_ExternalDataControl.hpp"
00021 #include "GeneratorTrace.hpp"
00022 #include "GeneratorError.h"
00023 #include "Utils.hpp"
00024 #include "BufferUtils.hpp"
00025 #include "list_t.hpp"
00026 #include "integer_t.hpp"
00027
00028 #define START_FIELD '"'
00029 #define STOP_FIELD '"'
00030 #define NEXT_FIELD ';'
00031
00032 C_ExternalDataControl::C_ExternalDataControl() {
00033 GEN_DEBUG(1, "C_ExternalDataControl::C_ExternalDataControl() start");
00034 m_number_line = 0 ;
00035 m_allocted_nb_line = 0 ;
00036 m_max_size_line = 0 ;
00037 m_nb_field = 0 ;
00038
00039 m_line_selected = 0 ;
00040 m_line_selected_max = 0 ;
00041
00042 m_file = NULL ;
00043 m_data_table = NULL ;
00044 m_regExpr1 = NULL ;
00045 m_regExpr2 = NULL ;
00046 m_regExpr3 = NULL ;
00047 m_regExpr4 = NULL ;
00048 m_field_type_table = NULL ;
00049 GEN_DEBUG(1, "C_ExternalDataControl::C_ExternalDataControl() end");
00050 }
00051
00052 C_ExternalDataControl::~C_ExternalDataControl() {
00053
00054 size_t L_i, L_j ;
00055 T_pValueData L_value = NULL;
00056
00057 GEN_DEBUG(1, "C_ExternalDataControl::~C_ExternalDataControl() start");
00058 m_file = NULL ;
00059
00060 GEN_DEBUG(1, "C_ExternalDataControl::~C_ExternalDataControl() "
00061 << "m_allocted_nb_line = " << m_allocted_nb_line
00062 << " m_nb_field = " << m_nb_field);
00063
00064 for (L_i = 0; L_i < m_allocted_nb_line ; L_i ++) {
00065 for (L_j = 0; L_j < m_nb_field; L_j++) {
00066 L_value = m_data_table[L_i][L_j] ;
00067 if (L_value != NULL) {
00068 if(L_value->m_type == E_TYPE_STRING) {
00069 FREE_TABLE(L_value->m_value.m_val_binary.m_value);
00070 }
00071 FREE_VAR(L_value);
00072 m_data_table[L_i][L_j] = NULL;
00073 }
00074 }
00075 FREE_TABLE (m_data_table[L_i]);
00076 m_data_table[L_i] = NULL;
00077 }
00078 FREE_TABLE (m_data_table);
00079 FREE_TABLE(m_field_type_table);
00080
00081 GEN_DEBUG(1, "C_ExternalDataControl::~C_ExternalDataControl() end");
00082 }
00083
00084 bool C_ExternalDataControl::init (char * P_file_name) {
00085
00086 bool L_result = false ;
00087
00088 GEN_DEBUG(1, "C_ExternalDataControl::init() start");
00089
00090 m_file_name = P_file_name ;
00091
00092
00093 L_result = max_buffer_size();
00094
00095 if(L_result == false ) {
00096 GEN_ERROR(E_GEN_FATAL_ERROR,
00097 "Unable to determine max buffer size in file ["
00098 << P_file_name << "]");
00099 return (L_result);
00100 }
00101
00102
00103 L_result = create_regexp() ;
00104 if (L_result == false) {
00105 GEN_ERROR(E_GEN_FATAL_ERROR, "Regular expression building is failed");
00106 return (L_result);
00107 }
00108
00109 L_result = analyze();
00110
00111 delete_regexp();
00112
00113 if (L_result == false) {
00114 GEN_ERROR(E_GEN_FATAL_ERROR, "External data analysis failed");
00115 return (L_result);
00116 }
00117
00118 L_result = true ;
00119 GEN_DEBUG(1, "C_ExternalDataControl::init() end");
00120 return (L_result);
00121 }
00122
00123 T_pValueData C_ExternalDataControl::get_value (int P_line, int P_field) {
00124 return (m_data_table[P_line][P_field]);
00125 }
00126
00127 size_t C_ExternalDataControl::get_nb_field () {
00128 return (m_nb_field);
00129 }
00130
00131 T_TypeType& C_ExternalDataControl::get_field_type (int P_field_id) {
00132 return ( m_field_type_table[P_field_id]);
00133 }
00134
00135 bool C_ExternalDataControl::max_buffer_size () {
00136
00137 bool L_result = false ;
00138 size_t L_max = 0 ;
00139 size_t L_char_line = 0 ;
00140 char L_char ;
00141 bool L_line_with_data = false ;
00142
00143 m_allocted_nb_line = 0 ;
00144
00145 GEN_DEBUG(1, "C_ExternalDataControl::max_buffer_size() start on file ["
00146 << m_file_name << "]");
00147
00148 NEW_VAR(m_file, fstream_input(m_file_name));
00149
00150 if (!m_file->good()) {
00151 DELETE_VAR(m_file);
00152 GEN_ERROR(E_GEN_FATAL_ERROR,
00153 "Unable to open file [" << m_file_name << "]");
00154 return (L_result) ;
00155 }
00156
00157
00158 while (!m_file->eof()) {
00159 m_file->get(L_char);
00160 L_char_line ++ ;
00161 if (L_char == '\n') {
00162 if (L_max < L_char_line) {
00163 L_max = L_char_line ;
00164 }
00165 L_char_line = 0 ;
00166 L_line_with_data = false ;
00167 }
00168 if (L_line_with_data == false) {
00169 if (L_char == ';') {
00170 L_line_with_data = true ;
00171 m_allocted_nb_line ++ ;
00172 }
00173 }
00174 }
00175 m_file->close();
00176 DELETE_VAR(m_file);
00177
00178 if (L_max) {
00179 m_max_size_line = L_max ;
00180 L_result = true ;
00181 }
00182
00183 GEN_DEBUG(1, "m_allocted_nb_line is ["
00184 << m_allocted_nb_line << "]");
00185
00186 GEN_DEBUG(1, "max_char_buffer_size is ["
00187 << m_max_size_line << "]");
00188 GEN_DEBUG(1, "C_ExternalDataControl::max_char_buffer_size() end with "
00189 << L_result);
00190 return (L_result) ;
00191
00192 }
00193
00194 bool C_ExternalDataControl::analyze () {
00195
00196 char *L_line = NULL ;
00197 bool L_result = false ;
00198 bool L_first_line = true ;
00199 int L_pos = 0 ;
00200
00201 GEN_DEBUG(1, "C_ExternalDataControl::analyze() start");
00202
00203 ALLOC_TABLE(L_line, char*, sizeof(char), m_max_size_line);
00204
00205 GEN_DEBUG(1, "C_ExternalDataControl::analyze() m_file_name="
00206 << m_file_name) ;
00207
00208 NEW_VAR(m_file, fstream_input(m_file_name));
00209
00210 if (!m_file->good()) {
00211 DELETE_VAR(m_file);
00212 GEN_ERROR(E_GEN_FATAL_ERROR,
00213 "Unable to open file [" << m_file_name << "]");
00214 return (L_result) ;
00215 }
00216
00217 m_line_selected = 0 ;
00218
00219 do {
00220
00221 L_pos = get_line (L_line) ;
00222 GEN_DEBUG(1, "C_ExternalDataControl::analyze() get_line() L_pos="
00223 << L_pos) ;
00224 if (L_pos == -1) break ;
00225
00226
00227 GEN_DEBUG(1, "data: pos=" << L_pos << " line=" << L_line+L_pos) ;
00228
00229 if (L_first_line == true) {
00230 L_result = analyze_first_data (L_line+L_pos);
00231 L_first_line = false ;
00232 } else {
00233 L_result = analyze_data (L_line+L_pos);
00234 if (L_result == true) { m_line_selected ++ ; }
00235 }
00236 if (L_result == false) break ;
00237
00238 } while (!m_file->eof()) ;
00239
00240
00241 if (L_result == true) {
00242 m_number_line = m_line_selected ;
00243 if (m_number_line > 1) {
00244 m_line_selected = (m_number_line - 1) ;
00245 m_line_selected_max = (m_number_line - 1) ;
00246 }
00247
00248 if (m_number_line == 0){
00249 GEN_ERROR(E_GEN_FATAL_ERROR,
00250 "The file [" << m_file_name << "] doesn't contain any valid lines");
00251 L_result = false ;
00252 }
00253 }
00254
00255 FREE_TABLE(L_line);
00256
00257 m_file->close();
00258 DELETE_VAR(m_file);
00259
00260 GEN_DEBUG(1, "C_ExternalDataControl::analyze() end");
00261 return (L_result);
00262 }
00263
00264 int C_ExternalDataControl::get_line(char *P_line) {
00265
00266 int L_ret = -1 ;
00267 int L_line_size ;
00268
00269 char *L_search = NULL ;
00270 regmatch_t L_pmatch ;
00271 int L_status ;
00272
00273 GEN_DEBUG(1, "C_ExternalDataControl::get_line() start");
00274 P_line[0] = '\0' ;
00275
00276 while (!m_file->eof()) {
00277
00278 m_file->getline(P_line, m_max_size_line);
00279 L_line_size = strlen (P_line);
00280
00281 GEN_DEBUG(1, "C_ExternalDataControl::get_line() P_line="
00282 << P_line << " size=" << L_line_size);
00283
00284 if (L_line_size == 0) continue ;
00285
00286
00287 L_search = P_line ;
00288 L_status = regexec (m_regExpr1, L_search, 1, &L_pmatch, 0) ;
00289
00290
00291 if (L_status == 0) {
00292
00293 if (L_pmatch.rm_eo == L_line_size) { L_ret = -1 ; continue ; }
00294 L_ret = L_pmatch.rm_eo ;
00295 L_search += L_ret ;
00296
00297 } else {
00298
00299 L_ret = 0 ;
00300 }
00301
00302
00303 L_status = regexec (m_regExpr2, L_search, 1, &L_pmatch, 0) ;
00304
00305 if (L_status == 0) {
00306 L_ret = -1 ;
00307 continue ;
00308 }
00309
00310
00311 L_status = regexec (m_regExpr3, L_search, 1, &L_pmatch, 0) ;
00312
00313 if (L_status == 0) {
00314 L_ret = -1 ;
00315 continue ;
00316 }
00317
00318 break ;
00319
00320 }
00321
00322 GEN_DEBUG(1, "C_ExternalDataControl::get_line() return " << L_ret);
00323 return (L_ret);
00324
00325 }
00326
00327
00328 bool C_ExternalDataControl::create_regexp() {
00329
00330 int L_status ;
00331 char L_buffer[100] ;
00332
00333
00334 GEN_DEBUG(1, "C_ExternalDataControl::create_regexp() start ");
00335
00336 ALLOC_VAR(m_regExpr1, regex_t*, sizeof(regex_t));
00337 ALLOC_VAR(m_regExpr2, regex_t*, sizeof(regex_t));
00338 ALLOC_VAR(m_regExpr3, regex_t*, sizeof(regex_t));
00339 ALLOC_VAR(m_regExpr4, regex_t*, sizeof(regex_t));
00340
00341 L_status = regcomp (m_regExpr1, "^[[:blank:]]+", REG_EXTENDED) ;
00342 if (L_status != 0) {
00343 regerror(L_status, m_regExpr1, L_buffer, 100);
00344 regfree (m_regExpr1) ;
00345 GEN_ERROR(E_GEN_FATAL_ERROR, "regcomp error: [" << L_buffer << "]");
00346
00347 GEN_DEBUG(1, "C_ExternalDataControl::create_regexp() end Error ");
00348
00349 return (false);
00350 }
00351
00352 L_status = regcomp (m_regExpr2, "^#.*$", REG_EXTENDED) ;
00353 if (L_status != 0) {
00354 regerror(L_status, m_regExpr2, L_buffer, 100);
00355 regfree (m_regExpr2) ;
00356 GEN_ERROR(E_GEN_FATAL_ERROR, "regcomp error: [" << L_buffer << "]");
00357
00358 GEN_DEBUG(1, "C_ExternalDataControl::create_regexp() end Error ");
00359
00360 return (false);
00361 }
00362
00363 L_status = regcomp (m_regExpr3, "^//.*$", REG_EXTENDED) ;
00364 if (L_status != 0) {
00365 regerror(L_status, m_regExpr3, L_buffer, 100);
00366 regfree (m_regExpr3) ;
00367 GEN_ERROR(E_GEN_FATAL_ERROR, "regcomp error: [" << L_buffer << "]");
00368
00369 GEN_DEBUG(1, "C_ExternalDataControl::create_regexp() end Error ");
00370
00371 return (false);
00372 }
00373
00374 L_status = regcomp (m_regExpr4, "[[:blank:]]*;[[:blank:]]*", REG_EXTENDED) ;
00375 if (L_status != 0) {
00376 regerror(L_status, m_regExpr4, L_buffer, 100);
00377 regfree (m_regExpr4) ;
00378 GEN_ERROR(E_GEN_FATAL_ERROR, "regcomp error: [" << L_buffer << "]");
00379
00380 GEN_DEBUG(1, "C_ExternalDataControl::create_regexp() end Error ");
00381 return (false);
00382 }
00383
00384
00385
00386 GEN_DEBUG(1, "C_ExternalDataControl::create_regexp() end Ok ");
00387
00388 return (true);
00389
00390 }
00391
00392 void C_ExternalDataControl::delete_regexp() {
00393
00394 if (m_regExpr1) {
00395 regfree (m_regExpr1);
00396 FREE_VAR(m_regExpr1);
00397 }
00398 if (m_regExpr2) {
00399 regfree (m_regExpr2);
00400 FREE_VAR(m_regExpr2);
00401 }
00402 if (m_regExpr3) {
00403 regfree (m_regExpr3);
00404 FREE_VAR(m_regExpr3);
00405 }
00406 if (m_regExpr4) {
00407 regfree (m_regExpr4);
00408 FREE_VAR(m_regExpr4);
00409 }
00410 }
00411
00412 bool C_ExternalDataControl::analyze_first_data (char*P_line) {
00413
00414 char *L_ptr = P_line ;
00415 char *L_ptrField = NULL ;
00416 size_t L_size = 0 ;
00417 size_t L_next = 0 ;
00418 size_t L_i, L_j ;
00419 bool L_ret = true ;
00420
00421 char *L_type_name ;
00422 T_TypeType L_type = E_UNSUPPORTED_TYPE ;
00423 int L_k = 0 ;
00424
00425 list_t<T_TypeType> L_type_list ;
00426 list_t<T_TypeType>::iterator L_it ;
00427
00428
00429 m_nb_field = 0 ;
00430 while ((L_ptrField = get_field (L_ptr, &L_size, &L_next)) != NULL) {
00431 GEN_DEBUG(1, "found: field="
00432 << L_ptrField << " size="
00433 << L_size << " next=" << L_next) ;
00434
00435 L_ptr = L_ptrField + L_next ;
00436 L_next = 0 ;
00437
00438 m_nb_field ++ ;
00439 ALLOC_TABLE(L_type_name, char*, sizeof(char), L_size+1);
00440 memcpy(L_type_name, L_ptrField, L_size);
00441 L_type_name[L_size]= '\0';
00442
00443
00444 L_type = E_UNSUPPORTED_TYPE ;
00445 for(L_k=0; L_k < (int) E_UNSUPPORTED_TYPE; L_k++) {
00446 if (strcmp(L_type_name, type_type_table[L_k])==0) {
00447 L_type = (T_TypeType) L_k ;
00448 }
00449 }
00450
00451 if (L_type == E_UNSUPPORTED_TYPE) {
00452 GEN_ERROR(E_GEN_FATAL_ERROR, "typedef type value ["
00453 << L_type_name << "] unsupported");
00454 L_ret = false ;
00455 break ;
00456 }
00457
00458 switch (L_type) {
00459 case E_TYPE_NUMBER:
00460 case E_TYPE_SIGNED:
00461 case E_TYPE_STRING:
00462 case E_TYPE_NUMBER_64:
00463 case E_TYPE_SIGNED_64:
00464 break ;
00465 default:
00466 GEN_ERROR(E_GEN_FATAL_ERROR, "type ["
00467 << L_type_name << "] unsupported for external data file");
00468 L_ret = false ;
00469 break ;
00470 }
00471
00472 L_type_list.push_back(L_type);
00473
00474 FREE_TABLE(L_type_name);
00475
00476 }
00477
00478 if (!L_type_list.empty()) {
00479
00480 ALLOC_TABLE(m_field_type_table, T_TypeType*,
00481 sizeof(T_TypeType), m_nb_field);
00482
00483 L_i = 0 ;
00484 for (L_it = L_type_list.begin();
00485 L_it != L_type_list.end();
00486 L_it++) {
00487 m_field_type_table[L_i] = *L_it ;
00488 L_i ++ ;
00489 }
00490 L_type_list.erase(L_type_list.begin(), L_type_list.end());
00491
00492 GEN_DEBUG(1, "m_data_table: m_allocted_nb_line = "
00493 << m_allocted_nb_line << " m_nb_field ="
00494 << m_nb_field ) ;
00495
00496
00497 ALLOC_TABLE(m_data_table, T_pValueData**,
00498 sizeof(T_pValueData*), m_allocted_nb_line);
00499
00500 for (L_i = 0 ; L_i < m_allocted_nb_line ; L_i ++) {
00501 ALLOC_TABLE(m_data_table[L_i], T_pValueData*,
00502 sizeof(T_pValueData), m_nb_field);
00503 }
00504
00505
00506 for (L_i = 0; L_i < m_allocted_nb_line ; L_i++) {
00507 for (L_j = 0; L_j < m_nb_field; L_j++) {
00508 m_data_table[L_i][L_j] = NULL ;
00509 }
00510 }
00511 } else {
00512 GEN_ERROR(E_GEN_FATAL_ERROR, "No field definition (first line) found in file ["
00513 << m_file_name << "]");
00514 L_ret = false ;
00515 }
00516
00517 return (L_ret);
00518
00519 }
00520
00521 char* C_ExternalDataControl::field_filtered(char *P_char, size_t P_size) {
00522 char *L_result = NULL ;
00523 char *L_tmp = NULL ;
00524
00525 size_t L_i, L_j, L_size ;
00526
00527 ALLOC_TABLE(L_tmp, char*, sizeof(char), P_size+1);
00528 L_i = 0 ;
00529 L_j = 0 ;
00530 while (L_j < P_size) {
00531 if ((L_j) && (P_char[L_j] == STOP_FIELD)) {
00532 if (P_char[L_j-1] == '\\') {
00533 L_tmp[L_i-1] = P_char[L_j] ;
00534 } else {
00535 L_tmp[L_i] = P_char[L_j] ;
00536 L_i++ ;
00537 }
00538 } else {
00539 L_tmp[L_i] = P_char[L_j] ;
00540 L_i++ ;
00541 }
00542 L_j ++ ;
00543 }
00544 L_tmp[L_i] = '\0' ;
00545 L_size = L_i ;
00546
00547 ALLOC_TABLE(L_result, char*, sizeof(char), L_size+1);
00548 strcpy(L_result, L_tmp);
00549 FREE_TABLE(L_tmp);
00550
00551 return (L_result);
00552 }
00553
00554 bool C_ExternalDataControl::analyze_data (char*P_line) {
00555
00556 bool L_ret = true ;
00557 char *L_ptr = P_line ;
00558 char *L_ptrField = NULL ;
00559 size_t L_size = 0 ;
00560 size_t L_next = 0 ;
00561 char *L_field_value ;
00562 size_t L_nb_field = 0 ;
00563
00564 T_TypeType L_field_type ;
00565 T_pValueData L_value ;
00566
00567 while ((L_ptrField = get_field (L_ptr, &L_size, &L_next)) != NULL) {
00568
00569
00570 L_field_value = field_filtered (L_ptrField, L_size) ;
00571
00572 GEN_DEBUG(1, "C_ExternalDataControl::analyze_data() "
00573 << "found: field = " << L_field_value);
00574
00575
00576 L_field_type = m_field_type_table[L_nb_field];
00577 ALLOC_VAR(L_value, T_pValueData, sizeof(T_ValueData));
00578 L_value->m_type = L_field_type ;
00579
00580 GEN_DEBUG(1, "C_ExternalDataControl::analyze_data() "
00581 << "type of value = " << L_value->m_type);
00582
00583 switch (L_field_type) {
00584 case E_TYPE_SIGNED: {
00585
00586 T_Integer32 L_signed_value ;
00587 char *L_endstr ;
00588
00589 if (strlen(L_field_value) > 0) {
00590 if ((strlen(L_field_value)>2)
00591 && (L_field_value[0] == '0')
00592 && (L_field_value[1] == 'x')) {
00593 L_signed_value = strtol_f (L_field_value, &L_endstr,16) ;
00594 } else {
00595 L_signed_value = strtol_f (L_field_value, &L_endstr,10) ;
00596 }
00597
00598 if (L_endstr[0] != '\0') {
00599 GEN_ERROR(E_GEN_FATAL_ERROR, "field value ["
00600 << L_field_value << "] bad format in file ["
00601 << m_file_name << "]");
00602 L_ret = false ;
00603 }
00604 GEN_DEBUG(1, "C_ExternalDataControl::analyze_data() "
00605 << "signed value = " << L_signed_value);
00606 L_value->m_value.m_val_signed = L_signed_value ;
00607 } else {
00608 GEN_ERROR(E_GEN_FATAL_ERROR, "Field empty where number value was expected"
00609 << " in file ["
00610 << m_file_name << "]");
00611 L_ret = false ;
00612 }
00613
00614 }
00615 break ;
00616 case E_TYPE_NUMBER: {
00617
00618 T_UnsignedInteger32 L_unsigned_value ;
00619 char *L_endstr ;
00620 if (strlen(L_field_value) > 0) {
00621 if ((strlen(L_field_value)>2)
00622 && (L_field_value[0] == '0')
00623 && (L_field_value[1] == 'x')) {
00624 L_unsigned_value = strtoul_f (L_field_value, &L_endstr,16) ;
00625 } else {
00626 L_unsigned_value = strtoul_f (L_field_value, &L_endstr,10) ;
00627 }
00628
00629
00630 if (L_endstr[0] != '\0') {
00631 GEN_ERROR(E_GEN_FATAL_ERROR, "field value ["
00632 << L_field_value << "] bad format in file ["
00633 << m_file_name << "]");
00634 L_ret = false ;
00635 }
00636 GEN_DEBUG(1, "C_ExternalDataControl::analyze_data() "
00637 << "unsigned value =" << L_unsigned_value);
00638 L_value->m_value.m_val_number = L_unsigned_value ;
00639 } else {
00640 GEN_ERROR(E_GEN_FATAL_ERROR, "Field empty where number value was expected"
00641 << " in file ["
00642 << m_file_name << "]");
00643 }
00644 }
00645 break ;
00646
00647 case E_TYPE_STRING: {
00648
00649 if ((strlen(L_field_value)>2)
00650 && (L_field_value[0] == '0')
00651 && (L_field_value[1] == 'x')) {
00652
00653 char *L_ptr = L_field_value+2 ;
00654 size_t L_res_size ;
00655
00656 L_value -> m_value.m_val_binary.m_value
00657 = convert_hexa_char_to_bin(L_ptr, &L_res_size);
00658
00659 if (L_value -> m_value.m_val_binary.m_value == NULL ) {
00660 GEN_ERROR(E_GEN_FATAL_ERROR,
00661 "Bad buffer size for hexadecimal buffer ["
00662 << L_field_value << "]" );
00663 L_ret = false ;
00664 } else {
00665 L_value -> m_value.m_val_binary.m_size = L_res_size ;
00666 }
00667
00668 } else {
00669
00670 L_value -> m_value.m_val_binary.m_size = L_size ;
00671
00672 if (L_size != 0) {
00673 ALLOC_TABLE(L_value -> m_value.m_val_binary.m_value,
00674 unsigned char*,
00675 sizeof(unsigned char),
00676 L_size);
00677 memcpy(L_value -> m_value.m_val_binary.m_value,
00678 L_field_value,
00679 L_size);
00680 } else {
00681 L_value -> m_value.m_val_binary.m_value = NULL ;
00682 }
00683 }
00684
00685 GEN_DEBUG(1, "C_ExternalDataControl::analyze_data() "
00686 << "string value size="
00687 << L_value -> m_value.m_val_binary.m_size) ;
00688 }
00689 break ;
00690
00691 case E_TYPE_SIGNED_64: {
00692
00693 T_Integer64 L_signed_value ;
00694 char *L_endstr ;
00695
00696 if (strlen(L_field_value) > 0) {
00697 if ((strlen(L_field_value)>2)
00698 && (L_field_value[0] == '0')
00699 && (L_field_value[1] == 'x')) {
00700 L_signed_value = strtoll_f (L_field_value, &L_endstr,16) ;
00701 } else {
00702 L_signed_value = strtoll_f (L_field_value, &L_endstr,10) ;
00703 }
00704
00705 if (L_endstr[0] != '\0') {
00706 GEN_ERROR(E_GEN_FATAL_ERROR, "field value ["
00707 << L_field_value << "] bad format in file ["
00708 << m_file_name << "]");
00709 L_ret = false ;
00710 }
00711 GEN_DEBUG(1, "C_ExternalDataControl::analyze_data() "
00712 << "signed64 value = " << L_signed_value);
00713 L_value->m_value.m_val_signed_64 = L_signed_value ;
00714 } else {
00715 GEN_ERROR(E_GEN_FATAL_ERROR, "empty field for number64 expected"
00716 << " in file ["
00717 << m_file_name << "]");
00718 L_ret = false ;
00719 }
00720
00721 }
00722 break ;
00723 case E_TYPE_NUMBER_64: {
00724
00725 T_UnsignedInteger64 L_unsigned_value ;
00726 char *L_endstr ;
00727 if (strlen(L_field_value) > 0) {
00728 if ((strlen(L_field_value)>2)
00729 && (L_field_value[0] == '0')
00730 && (L_field_value[1] == 'x')) {
00731 L_unsigned_value = strtoull_f (L_field_value, &L_endstr,16) ;
00732 } else {
00733 L_unsigned_value = strtoull_f (L_field_value, &L_endstr,10) ;
00734 }
00735
00736
00737 if (L_endstr[0] != '\0') {
00738 GEN_ERROR(E_GEN_FATAL_ERROR, "field value ["
00739 << L_field_value << "] bad format in file ["
00740 << m_file_name << "]");
00741 L_ret = false ;
00742 }
00743 GEN_DEBUG(1, "C_ExternalDataControl::analyze_data() "
00744 << "unsigned64 value =" << L_unsigned_value);
00745 L_value->m_value.m_val_number_64 = L_unsigned_value ;
00746 } else {
00747 GEN_ERROR(E_GEN_FATAL_ERROR, "empty field for number64 expected"
00748 << " in file ["
00749 << m_file_name << "]");
00750 }
00751 }
00752 break ;
00753
00754 default:
00755 GEN_FATAL(E_GEN_FATAL_ERROR,
00756 "Unsupported type for external data");
00757 break ;
00758 }
00759
00760 m_data_table[m_line_selected][L_nb_field] = L_value ;
00761
00762 FREE_TABLE(L_field_value);
00763
00764 if (L_ret == false) break ;
00765
00766 L_ptr = L_ptrField + L_next ;
00767 L_next = 0 ;
00768
00769 L_nb_field ++ ;
00770 if (L_nb_field > m_nb_field) break ;
00771
00772 }
00773
00774 if (L_nb_field != m_nb_field) {
00775 GEN_ERROR(E_GEN_FATAL_ERROR,
00776 "Illegal number of field for line ["
00777 << P_line << "] expected ["
00778 << m_nb_field << "] found [" << L_nb_field
00779 << "] in texternal data file ["
00780 << m_file_name << "]");
00781 L_ret = false ;
00782 }
00783
00784 return (L_ret);
00785
00786 }
00787
00788 char* C_ExternalDataControl::get_field(char *P_line, size_t *P_size, size_t *P_next) {
00789
00790 char *L_ptr = P_line ;
00791 char *L_ptr_end ;
00792 char *L_init = NULL ;
00793 char *L_search = NULL ;
00794 size_t L_size ;
00795 int L_status = 0 ;
00796 regmatch_t L_pmatch ;
00797
00798
00799 L_size = strlen(L_ptr);
00800 if (L_size == 0) return (NULL);
00801
00802
00803 if (L_ptr[0] == START_FIELD) {
00804 L_search = L_ptr + 1 ;
00805 L_init = L_search ;
00806 if (*L_search != '\0') {
00807 while ((L_ptr_end = strchr(L_search, STOP_FIELD)) != NULL) {
00808 if (*(L_ptr_end-1) != '\\') break ;
00809 L_search = L_ptr_end + 1 ;
00810 if (*L_search == '\0') { return (NULL) ; }
00811 }
00812 if (L_ptr_end == NULL) {
00813 return (NULL);
00814 } else {
00815 *P_size = L_ptr_end - L_init ;
00816 }
00817 } else {
00818 return (NULL);
00819 }
00820 } else {
00821 return (NULL);
00822 }
00823
00824
00825 L_search = L_ptr_end + 1 ;
00826
00827 if ((*L_search) == '\0') { return (NULL); }
00828
00829 L_status = regexec (m_regExpr4, L_search, 1, &L_pmatch, 0) ;
00830
00831 if (L_status == 0) {
00832 *P_next = *P_size + (L_pmatch.rm_eo - L_pmatch.rm_so) + 1 ;
00833 } else {
00834 return (NULL);
00835 }
00836
00837 return (L_ptr+1);
00838
00839 }
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850