00001 #include "cmlfile.h"
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <string.h>
00005
00006 #define BufferLength 1024
00007 #define KeywordLength 64
00008 #define MaxFiles 16
00009 #define DefaultDoubleFormat "%10.10E"
00010
00011 #define KeywordSection "SECTION"
00012 #define KeywordEndSection "END"
00013 #define KeywordFile "FILE"
00014
00015 #define OK 1
00016
00017 #define None -1
00018 #define Comment -2
00019 #define File -3
00020 #define Section -4
00021 #define EndSection -5
00022
00023 #define Required 1
00024 #define Optional 0
00025 #define Refused -1
00026
00027 long read_to_eoln ( FILE *ofile , char *obuffer )
00028 {
00029 if ( !fgets( obuffer,BufferLength,ofile ))
00030 {
00031 return None ;
00032 }
00033 long i=0 ;
00034 while ( obuffer[i] )
00035 {
00036 i++ ;
00037 }
00038 obuffer[i-1]=0 ;
00039 return OK ;
00040 }
00041
00042 long str_equal ( char *opattern , char *ostring )
00043 {
00044 long i=0 ;
00045 while ( opattern[i] )
00046 {
00047 if ( opattern[i]!=ostring[i] )
00048 {
00049 return 0 ;
00050 }
00051 i++ ;
00052 }
00053 return 1 ;
00054 }
00055
00056 long read_string ( FILE *ofile , char *obuffer )
00057 {
00058 long i,j ;
00059 j=fscanf( ofile,"%s",obuffer ) ;
00060
00061 if ( j!=1 )
00062 {
00063 return j ;
00064 }
00065 if ( obuffer[0]!='"' )
00066 {
00067 return 1 ;
00068 }
00069 i=0 ;
00070 while ( obuffer[i] )
00071 {
00072 i++ ;
00073 }
00074 if ( obuffer[i-1]=='"' )
00075 {
00076 obuffer[i-1]=0 ;
00077 memcpy( obuffer,obuffer+1,i ) ;
00078 return 1 ;
00079 }
00080 char c ;
00081 do
00082 {
00083 c=fgetc( ofile ) ;
00084 if ( c==EOF )
00085 {
00086 return -1 ;
00087 }
00088 obuffer[i]=c ;
00089 i++ ;
00090 }
00091 while ( c!='"' ) ;
00092 obuffer[i-1]=0 ;
00093 memcpy( obuffer,obuffer+1,i ) ;
00094 return 1 ;
00095 }
00096
00097 struct keyword
00098 {
00099 long *file,*position ;
00100 long i,n,req ;
00101 char *word ;
00102 keyword ( void ) ;
00103 ~keyword ( void ) ;
00104 void copy ( keyword &ok ) ;
00105 } ;
00106
00107 keyword::keyword ( void )
00108 {
00109 file=NULL ;
00110 position=NULL ;
00111 word=new char[KeywordLength] ;
00112 i=0 ;
00113 n=0 ;
00114 req=Optional ;
00115 }
00116
00117 keyword::~keyword ( void )
00118 {
00119 if ( file )
00120 {
00121 delete [] file ;
00122 }
00123 if ( position )
00124 {
00125 delete [] position ;
00126 }
00127 if ( word )
00128 {
00129 delete [] word ;
00130 }
00131 }
00132
00133 void keyword::copy ( keyword &ok )
00134 {
00135 req=ok.req ;
00136 memcpy( word,ok.word,KeywordLength ) ;
00137 }
00138
00139 struct section
00140 {
00141 char *word ;
00142 long *pos,*rows,*file,*end ;
00143 long files,rows_all,actual,i,req ;
00144 section ( void ) ;
00145 ~section ( void ) ;
00146 void copy ( section &os ) ;
00147 } ;
00148
00149 section::section ( void )
00150 {
00151 pos=new long[MaxFiles] ;
00152 rows=new long[MaxFiles] ;
00153 file=new long[MaxFiles] ;
00154 end=new long[MaxFiles] ;
00155 word=new char[KeywordLength] ;
00156 files=0 ;
00157 rows_all=0 ;
00158 actual=0 ;
00159 i=0 ;
00160 req=0 ;
00161 }
00162
00163 section::~section ( void )
00164 {
00165 if ( pos )
00166 {
00167 delete [] pos ;
00168 }
00169 if ( rows )
00170 {
00171 delete [] rows ;
00172 }
00173 if ( file )
00174 {
00175 delete [] file ;
00176 }
00177 if ( end )
00178 {
00179 delete [] end ;
00180 }
00181 if ( word )
00182 {
00183 delete [] word ;
00184 }
00185 }
00186
00187 void section::copy ( section &os )
00188 {
00189 req=os.req ;
00190 memcpy( word,os.word,KeywordLength ) ;
00191 }
00192
00193 cmlfile::cmlfile ( void )
00194 {
00195 input=new PFILE[MaxFiles] ;
00196 long i ;
00197 for ( i=0 ; i<MaxFiles ; i++ )
00198 {
00199 input[i]=NULL ;
00200 }
00201 files=0 ;
00202 labels=0 ;
00203
00204 names=0 ;
00205 get_name=NULL ;
00206
00207 sections=0 ;
00208 stop=NULL ;
00209 block=NULL ;
00210 output=NULL ;
00211
00212 buffer=new char[BufferLength] ;
00213 double_format=new char[16] ;
00214 strcpy( double_format,DefaultDoubleFormat ) ;
00215
00216 clear_errors() ;
00217 normal_read_disable=0 ;
00218 requirement_insufficient=0 ;
00219 compiled=0 ;
00220 }
00221
00222 cmlfile::cmlfile ( char *ofname )
00223 {
00224 input=new PFILE[MaxFiles] ;
00225 long i ;
00226 for ( i=0 ; i<MaxFiles ; i++ )
00227 {
00228 input[i]=NULL ;
00229 }
00230
00231 names=0 ;
00232 get_name=NULL ;
00233
00234 labels=0 ;
00235 sections=0 ;
00236 stop=NULL ;
00237 block=NULL ;
00238 output=NULL ;
00239
00240 buffer=new char[BufferLength] ;
00241 double_format=new char[16] ;
00242 strcpy( double_format,DefaultDoubleFormat ) ;
00243
00244 clear_errors() ;
00245 normal_read_disable=0 ;
00246 requirement_insufficient=0 ;
00247 compiled=0 ;
00248
00249 input[0]=fopen( ofname,"rt" ) ;
00250 if ( !input[0] )
00251 {
00252 printf( "Cannot open file %s.\n",ofname ) ;
00253 open_error=1 ;
00254 return ;
00255 }
00256 files=1 ;
00257 }
00258
00259 cmlfile::~cmlfile ( void )
00260 {
00261 long i ;
00262 for ( i=0 ; i<files ; i++ )
00263 {
00264 fclose( input[i] ) ;
00265 }
00266 delete [] input ;
00267 if ( output )
00268 {
00269 fclose( output ) ;
00270 }
00271 if ( buffer )
00272 {
00273 delete [] buffer ;
00274 }
00275 if ( double_format )
00276 {
00277 delete [] double_format ;
00278 }
00279 if ( stop )
00280 {
00281 delete [] stop ;
00282 }
00283 if ( block )
00284 {
00285 delete [] block ;
00286 }
00287
00288 if ( get_name )
00289 {
00290 delete [] get_name ;
00291 }
00292
00293 }
00294
00295
00296 void cmlfile::set_names ( long onames )
00297 {
00298 names=onames ;
00299 get_name=new keyword[onames] ;
00300 }
00301
00302 void cmlfile::set_name_string ( long oname , char *oname_string )
00303 {
00304 strcpy( get_name[oname].word,oname_string ) ;
00305 }
00306
00307 void cmlfile::get_value_from_name ( long olabel , long &ovalue )
00308 {
00309 char s[KeywordLength] ;
00310
00311 get_value( olabel,s ) ;
00312 ovalue=name( s ) ;
00313 }
00314
00315 void cmlfile::get_value_from_name ( long olabel , long oorder , long &ovalue )
00316 {
00317 char s[KeywordLength] ;
00318
00319 get_value( olabel,oorder,s ) ;
00320 ovalue=name( s ) ;
00321 }
00322
00323 void cmlfile::get_value_with_index_from_name ( long olabel , long oindex , long &ovalue )
00324 {
00325 char s[KeywordLength] ;
00326
00327 get_value_with_index( olabel, oindex, s ) ;
00328 ovalue=name( s ) ;
00329 }
00330
00331 void cmlfile::get_value_with_index_from_name ( long olabel , long oindex , long oorder , long &ovalue )
00332 {
00333 char s[KeywordLength] ;
00334
00335 get_value_with_index( olabel, oindex, oorder, s ) ;
00336 ovalue=name( s ) ;
00337 }
00338
00339 void cmlfile::get_section_value ( long olabel, long oline, long oorder, long &ovalue )
00340 {
00341 if ( !compiled )
00342 {
00343 compile() ;
00344 }
00345
00346 actual=block[olabel].file[0] ;
00347 fseek( input[actual],block[olabel].pos[0],SEEK_SET ) ;
00348 read_to_eoln( input[actual],buffer ) ;
00349
00350 long i, j ;
00351 for ( i=0 ; ( i<oline ) && ( i<block[olabel].rows_all ) ; i++ )
00352 {
00353 read_to_eoln( input[actual],buffer ) ;
00354 }
00355
00356 for ( i=0 ; i<oorder ; i++ )
00357 {
00358 read_string( input[actual],buffer ) ;
00359 }
00360 j=fscanf( input[actual],"%ld",&ovalue ) ;
00361
00362 if ( j!=1 )
00363 {
00364 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
00365 read_error=1 ;
00366 }
00367 }
00368
00369 void cmlfile::get_section_value ( long olabel, long oline, long oorder, double &ovalue )
00370 {
00371 if ( !compiled )
00372 {
00373 compile() ;
00374 }
00375
00376 actual=block[olabel].file[0] ;
00377 fseek( input[actual],block[olabel].pos[0],SEEK_SET ) ;
00378 read_to_eoln( input[actual],buffer ) ;
00379
00380 long i, j ;
00381 for ( i=0 ; ( i<oline ) && ( i<block[olabel].rows_all ) ; i++ )
00382 {
00383 read_to_eoln( input[actual],buffer ) ;
00384 }
00385
00386 for ( i=0 ; i<oorder ; i++ )
00387 {
00388 read_string( input[actual],buffer ) ;
00389 }
00390 j=fscanf( input[actual],"%lf",&ovalue ) ;
00391
00392 if ( j!=1 )
00393 {
00394 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
00395 read_error=1 ;
00396 }
00397 }
00398
00399 void cmlfile::get_section_value ( long olabel, long oline, long oorder, char *ovalue )
00400 {
00401 if ( !compiled )
00402 {
00403 compile() ;
00404 }
00405
00406 actual=block[olabel].file[0] ;
00407 fseek( input[actual],block[olabel].pos[0],SEEK_SET ) ;
00408 read_to_eoln( input[actual],buffer ) ;
00409
00410 long i, j ;
00411 for ( i=0 ; ( i<oline ) && ( i<block[olabel].rows_all ) ; i++ )
00412 {
00413 read_to_eoln( input[actual],buffer ) ;
00414 }
00415
00416 for ( i=0 ; i<oorder ; i++ )
00417 {
00418 read_string( input[actual],buffer ) ;
00419 }
00420 j=read_string( input[actual],ovalue ) ;
00421
00422 if ( j!=1 )
00423 {
00424 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
00425 read_error=1 ;
00426 }
00427 }
00428
00429 long cmlfile::name ( char *obuffer )
00430 {
00431 long i ;
00432 for ( i=0 ; i<names ; i++ )
00433 {
00434 if ( str_equal( obuffer,get_name[i].word ))
00435 {
00436 return i ;
00437 }
00438 }
00439 return None ;
00440 }
00441
00442
00443 void cmlfile::open ( char *ofname )
00444 {
00445 long i ;
00446 for ( i=0 ; i<files ; i++ )
00447 {
00448 fclose( input[i] ) ;
00449 }
00450 input[0]=fopen( ofname,"rt" ) ;
00451 if ( !input[0] )
00452 {
00453 printf( "Cannot open file %s.\n",ofname ) ;
00454 open_error=1 ;
00455 return ;
00456 }
00457 files=1 ;
00458 compiled=0 ;
00459 }
00460
00461 void cmlfile::open_for_output ( char *ofname )
00462 {
00463 output=fopen( ofname,"wt" ) ;
00464 if ( !output )
00465 {
00466 printf( "For some reason cannot open file %s.\n",ofname ) ;
00467 open_error=1 ;
00468 }
00469 }
00470
00471 void cmlfile::close ( void )
00472 {
00473 long i ;
00474 for ( i=0 ; i<files ; i++ )
00475 {
00476 fclose( input[i] ) ;
00477 input[i]=NULL ;
00478 }
00479 files=0 ;
00480 if ( output )
00481 {
00482 fclose( output ) ;
00483 output=NULL ;
00484 }
00485 }
00486
00487 void cmlfile::set_labels ( long olabels )
00488 {
00489 labels=olabels ;
00490 stop=new keyword[olabels] ;
00491 compiled=0 ;
00492 }
00493 void cmlfile::set_sections ( long osections )
00494 {
00495 sections=osections ;
00496 block=new section[osections] ;
00497 compiled=0 ;
00498 }
00499
00500 void cmlfile::set_label_string ( long olabel , char *olabel_string )
00501 {
00502 strcpy( stop[olabel].word,olabel_string ) ;
00503 compiled=0 ;
00504 }
00505
00506 void cmlfile::set_section_string ( long olabel , char *osection_string )
00507 {
00508 strcpy( block[olabel].word,osection_string ) ;
00509 compiled=0 ;
00510 }
00511
00512 void cmlfile::set_double_format ( char *odouble_format )
00513 {
00514 strcpy( double_format,odouble_format ) ;
00515 }
00516
00517 void cmlfile::compile ( void )
00518 {
00519 requirement_insufficient=0 ;
00520 if ( !input[0] )
00521 {
00522 printf( "Nothing to compile.\n" ) ;
00523 return ;
00524 }
00525 long i,j ;
00526
00527 actual=0 ;
00528
00529 do
00530 {
00531 while ( !feof( input[actual] ))
00532 {
00533 fscanf( input[actual],"%s",buffer ) ;
00534 j=label( buffer ) ;
00535 switch ( j )
00536 {
00537 case None:
00538 break ;
00539 case Comment:
00540 break ;
00541 case File:
00542 fscanf( input[actual],"%s",buffer ) ;
00543 open_next_input( buffer ) ;
00544 break ;
00545 case Section:
00546 stat_section() ;
00547 break ;
00548 case EndSection:
00549 break ;
00550 default:
00551 stop[j].n++ ;
00552 break ;
00553 }
00554 }
00555 actual++ ;
00556 }
00557 while ( input[actual] ) ;
00558
00559 for ( i=0 ; i<labels ; i++ )
00560 {
00561 stop[i].file=new long[stop[i].n] ;
00562 stop[i].position=new long[stop[i].n] ;
00563 }
00564
00565 for ( actual=0 ; actual<files ; actual++ )
00566 {
00567 rewind( input[actual] ) ;
00568 while ( !feof( input[actual] ))
00569 {
00570 fscanf( input[actual],"%s",buffer ) ;
00571 j=label( buffer ) ;
00572 switch ( j )
00573 {
00574 case None:
00575 break ;
00576 case Comment:
00577 break ;
00578 case File:
00579 read_to_eoln( input[actual],buffer ) ;
00580 break ;
00581 case Section:
00582 jump_over_section() ;
00583 break ;
00584 case EndSection:
00585 break ;
00586 default:
00587 stop[j].file[stop[j].i]=actual ;
00588 stop[j].position[stop[j].i]=ftell( input[actual] ) ;
00589 stop[j].i++ ;
00590 break ;
00591 }
00592 }
00593 }
00594 compiled=1 ;
00595 }
00596
00597 void cmlfile::check_requirements ( void )
00598 {
00599 if ( !compiled )
00600 {
00601 compile() ;
00602 }
00603 long i ;
00604 for ( i=0 ; i<labels ; i++ )
00605 {
00606 if ( stop[i].n<stop[i].req )
00607 {
00608 printf( "Insufficient input for label %s. This means fatal error.\n",stop[i].word ) ;
00609 requirement_insufficient=1 ;
00610 }
00611 }
00612 for ( i=0 ; i<sections ; i++ )
00613 {
00614 if ( block[i].rows_all<block[i].req )
00615 {
00616 printf( "Insufficient input for section %s. This means fatal error.\n",block[i].word ) ;
00617 requirement_insufficient=1 ;
00618 }
00619 }
00620 }
00621
00622 void cmlfile::require ( long olabel )
00623 {
00624 stop[olabel].req=Required ;
00625 }
00626
00627 void cmlfile::minimal ( long olabel , long ominimal )
00628 {
00629 stop[olabel].req=ominimal ;
00630 }
00631
00632 void cmlfile::optionalize ( long olabel )
00633 {
00634 stop[olabel].req=Optional ;
00635 }
00636
00637 void cmlfile::refuse ( long olabel )
00638 {
00639 stop[olabel].req=Refused ;
00640 }
00641
00642 void cmlfile::check_label ( long olabel )
00643 {
00644 if ( !compiled )
00645 {
00646 compile() ;
00647 }
00648 if ( stop[olabel].n<stop[olabel].req )
00649 {
00650 printf( "Insufficient input for label %s. This means fatal error.\n",stop[olabel].word ) ;
00651 requirement_insufficient=1 ;
00652 }
00653 }
00654
00655 void cmlfile::set_minimal_rows ( long osection , long ominimal )
00656 {
00657 block[osection].req=ominimal ;
00658 }
00659
00660 void cmlfile::check_section ( long osection )
00661 {
00662 if ( !compiled )
00663 {
00664 compile() ;
00665 }
00666 if ( block[osection].rows_all<block[osection].req )
00667 {
00668 printf( "Insufficient input for section %s. This means fatal error.\n",block[osection].word ) ;
00669 requirement_insufficient=1 ;
00670 }
00671 }
00672
00673 void cmlfile::load_labels ( char *orcname )
00674 {
00675 FILE *rc ;
00676 rc=fopen( orcname,"rt" ) ;
00677 if ( !rc )
00678 {
00679 printf( "Cannot open rc file %s.\n",orcname ) ;
00680 open_error=1 ;
00681 return ;
00682 }
00683 long j,l=0,s=0 ;
00684 while ( !feof( rc ))
00685 {
00686 fscanf( rc,"%s",buffer ) ;
00687 if ( str_equal( KeywordSection,buffer ))
00688 {
00689 s++ ;
00690 read_to_eoln( rc,buffer ) ;
00691 }
00692 else
00693 {
00694 if (( buffer[0]>='A' ) && ( buffer[0]<='z' ))
00695 {
00696 l++ ;
00697 read_to_eoln( rc,buffer ) ;
00698 }
00699 }
00700 }
00701 rewind( rc ) ;
00702 set_labels( l ) ;
00703 set_sections( s ) ;
00704
00705 l=0 ; s=0 ;
00706
00707 while ( !feof( rc ))
00708 {
00709 j=fscanf( rc,"%s",buffer ) ;
00710 if ( j!=1 )
00711 {
00712 break ;
00713 }
00714 if ( str_equal( KeywordSection,buffer ))
00715 {
00716 fscanf( rc,"%s",buffer ) ;
00717 fscanf( rc,"%ld",&j ) ;
00718 set_section_string( s,buffer ) ;
00719 set_minimal_rows( s,j ) ;
00720 s++ ;
00721 }
00722 else
00723 {
00724 if (( buffer[0]>='A' ) && ( buffer[0]<='z' ))
00725 {
00726 fscanf( rc,"%ld",&j ) ;
00727 set_label_string( l,buffer ) ;
00728 minimal( l,j ) ;
00729 l++ ;
00730 }
00731 }
00732 }
00733 compiled=0 ;
00734 }
00735
00736 void cmlfile::inherit_labels ( cmlfile &of )
00737 {
00738 if ( stop )
00739 {
00740 delete [] stop ;
00741 }
00742 if ( block )
00743 {
00744 delete [] block ;
00745 }
00746 labels=of.labels ;
00747 sections=of.sections ;
00748
00749 stop=new keyword[labels] ;
00750 block=new section[sections] ;
00751
00752 long i ;
00753 for ( i=0 ; i<labels ; i++ )
00754 {
00755 stop[i].copy( of.stop[i] ) ;
00756 }
00757 for ( i=0 ; i<sections ; i++ )
00758 {
00759 block[i].copy( of.block[i] ) ;
00760 }
00761 compiled=0 ;
00762 }
00763
00764 void cmlfile::get_value_count ( long olabel , long &ocount )
00765 {
00766 if ( !compiled )
00767 {
00768 compile() ;
00769 }
00770 ocount=stop[olabel].n ;
00771 }
00772
00773 void cmlfile::get_value ( long olabel , long &ovalue )
00774 {
00775 if ( !compiled )
00776 {
00777 compile() ;
00778 }
00779 if ( !stop[olabel].n )
00780 {
00781 ovalue=NoInt ;
00782 return ;
00783 }
00784 if ( normal_read_disable )
00785 {
00786 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
00787 ovalue=NoInt ;
00788 read_error=1 ;
00789 return ;
00790 }
00791 actual=stop[olabel].file[0] ;
00792 fseek( input[actual],stop[olabel].position[0],SEEK_SET ) ;
00793 long j ;
00794 j=fscanf( input[actual],"%ld",&ovalue ) ;
00795
00796 if ( j!=1 )
00797 {
00798 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
00799 read_error=1 ;
00800 }
00801 }
00802
00803 void cmlfile::get_value ( long olabel , double &ovalue )
00804 {
00805 if ( !compiled )
00806 {
00807 compile() ;
00808 }
00809 if ( !stop[olabel].n )
00810 {
00811 ovalue=NoDouble ;
00812 return ;
00813 }
00814 if ( normal_read_disable )
00815 {
00816 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
00817 ovalue=NoDouble ;
00818 read_error=1 ;
00819 return ;
00820 }
00821 actual=stop[olabel].file[0] ;
00822 fseek( input[actual],stop[olabel].position[0],SEEK_SET ) ;
00823 long j ;
00824 j=fscanf( input[actual],"%lf",&ovalue ) ;
00825
00826 if ( j!=1 )
00827 {
00828 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
00829 read_error=1 ;
00830 }
00831 }
00832
00833 void cmlfile::get_value ( long olabel , char *ovalue )
00834 {
00835 if ( !compiled )
00836 {
00837 compile() ;
00838 }
00839 if ( !stop[olabel].n )
00840 {
00841 ovalue[0]=0 ;
00842 return ;
00843 }
00844 if ( normal_read_disable )
00845 {
00846 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
00847 ovalue[0]=0 ;
00848 read_error=1 ;
00849 return ;
00850 }
00851 actual=stop[olabel].file[0] ;
00852 fseek( input[actual],stop[olabel].position[0],SEEK_SET ) ;
00853 long j ;
00854 j=read_string( input[actual],ovalue ) ;
00855
00856 if ( j!=1 )
00857 {
00858 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
00859 read_error=1 ;
00860 }
00861 }
00862
00863 void cmlfile::get_value ( long olabel , long oorder , long &ovalue )
00864 {
00865 if ( !compiled )
00866 {
00867 compile() ;
00868 }
00869 if ( !stop[olabel].n )
00870 {
00871 ovalue=NoInt ;
00872 return ;
00873 }
00874 if ( normal_read_disable )
00875 {
00876 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
00877 ovalue=NoInt ;
00878 read_error=1 ;
00879 return ;
00880 }
00881 actual=stop[olabel].file[0] ;
00882 fseek( input[actual],stop[olabel].position[0],SEEK_SET ) ;
00883 long i,j ;
00884 for ( i=0 ; i<oorder ; i++ )
00885 {
00886 read_string( input[actual],buffer ) ;
00887 }
00888 j=fscanf( input[actual],"%ld",&ovalue ) ;
00889
00890 if ( j!=1 )
00891 {
00892 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
00893 read_error=1 ;
00894 }
00895 }
00896
00897 void cmlfile::get_value ( long olabel , long oorder , double &ovalue )
00898 {
00899 if ( !compiled )
00900 {
00901 compile() ;
00902 }
00903 if ( !stop[olabel].n )
00904 {
00905 ovalue=NoDouble ;
00906 return ;
00907 }
00908 if ( normal_read_disable )
00909 {
00910 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
00911 ovalue=NoDouble ;
00912 read_error=1 ;
00913 return ;
00914 }
00915 actual=stop[olabel].file[0] ;
00916 fseek( input[actual],stop[olabel].position[0],SEEK_SET ) ;
00917 long i,j ;
00918 for ( i=0 ; i<oorder ; i++ )
00919 {
00920 read_string( input[actual],buffer ) ;
00921 }
00922 j=fscanf( input[actual],"%lf",&ovalue ) ;
00923
00924 if ( j!=1 )
00925 {
00926 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
00927 read_error=1 ;
00928 }
00929 }
00930
00931 void cmlfile::get_value ( long olabel , long oorder , char *ovalue )
00932 {
00933 if ( !compiled )
00934 {
00935 compile() ;
00936 }
00937 if ( !stop[olabel].n )
00938 {
00939 ovalue[0]=0 ;
00940 return ;
00941 }
00942 if ( normal_read_disable )
00943 {
00944 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
00945 ovalue[0]=0 ;
00946 read_error=1 ;
00947 return ;
00948 }
00949 actual=stop[olabel].file[0] ;
00950 fseek( input[actual],stop[olabel].position[0],SEEK_SET ) ;
00951 long i,j ;
00952 for ( i=0 ; i<oorder ; i++ )
00953 {
00954 read_string( input[actual],ovalue ) ;
00955 }
00956 j=read_string( input[actual],ovalue ) ;
00957
00958 if ( j!=1 )
00959 {
00960 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
00961 read_error=1 ;
00962 }
00963 }
00964
00965 void cmlfile::get_value_with_key ( long olabel , long okey , long &ovalue )
00966 {
00967 if ( !compiled )
00968 {
00969 compile() ;
00970 }
00971 if ( !stop[olabel].n )
00972 {
00973 ovalue=NoInt ;
00974 return ;
00975 }
00976 if ( normal_read_disable )
00977 {
00978 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
00979 ovalue=NoInt ;
00980 read_error=1 ;
00981 return ;
00982 }
00983 long i=0,pos,key ;
00984 do
00985 {
00986 actual=stop[olabel].file[i] ;
00987 pos=stop[olabel].position[i] ;
00988 fseek( input[actual],pos,SEEK_SET ) ;
00989 fscanf( input[actual],"%ld",&key ) ;
00990 if ( key!=okey )
00991 {
00992 i++ ;
00993 }
00994 }
00995 while (( key!=okey ) && ( i<stop[olabel].n )) ;
00996 if ( i==stop[olabel].n )
00997 {
00998 printf( "Key value %ld does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
00999 ovalue=NoInt ;
01000 return ;
01001 }
01002 long j ;
01003 j=fscanf( input[actual],"%ld",&ovalue ) ;
01004
01005 if ( j!=1 )
01006 {
01007 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01008 read_error=1 ;
01009 }
01010 }
01011
01012 void cmlfile::get_value_with_key ( long olabel , long okey , double &ovalue )
01013 {
01014 if ( !compiled )
01015 {
01016 compile() ;
01017 }
01018 if ( !stop[olabel].n )
01019 {
01020 ovalue=NoDouble ;
01021 return ;
01022 }
01023 if ( normal_read_disable )
01024 {
01025 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01026 ovalue=NoDouble ;
01027 read_error=1 ;
01028 return ;
01029 }
01030 long i=0,pos,key ;
01031 do
01032 {
01033 actual=stop[olabel].file[i] ;
01034 pos=stop[olabel].position[i] ;
01035 fseek( input[actual],pos,SEEK_SET ) ;
01036 fscanf( input[actual],"%ld",&key ) ;
01037 if ( key!=okey )
01038 {
01039 i++ ;
01040 }
01041 }
01042 while (( key!=okey ) && ( i<stop[olabel].n )) ;
01043 if ( i==stop[olabel].n )
01044 {
01045 printf( "Key value %ld does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
01046 ovalue=NoDouble ;
01047 return ;
01048 }
01049 long j ;
01050 j=fscanf( input[actual],"%lf",&ovalue ) ;
01051
01052 if ( j!=1 )
01053 {
01054 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01055 read_error=1 ;
01056 }
01057 }
01058
01059 void cmlfile::get_value_with_key ( long olabel , long okey , char *ovalue )
01060 {
01061 if ( !compiled )
01062 {
01063 compile() ;
01064 }
01065 if ( !stop[olabel].n )
01066 {
01067 ovalue[0]=0 ;
01068 return ;
01069 }
01070 if ( normal_read_disable )
01071 {
01072 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01073 ovalue[0]=0 ;
01074 read_error=1 ;
01075 return ;
01076 }
01077 long i=0,pos,key ;
01078 do
01079 {
01080 actual=stop[olabel].file[i] ;
01081 pos=stop[olabel].position[i] ;
01082 fseek( input[actual],pos,SEEK_SET ) ;
01083 fscanf( input[actual],"%ld",&key ) ;
01084 if ( key!=okey )
01085 {
01086 i++ ;
01087 }
01088 }
01089 while (( key!=okey ) && ( i<stop[olabel].n )) ;
01090 if ( i==stop[olabel].n )
01091 {
01092 printf( "Key value %ld does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
01093 ovalue[0]=0 ;
01094 return ;
01095 }
01096 long j ;
01097 j=read_string( input[actual],ovalue ) ;
01098
01099 if ( j!=1 )
01100 {
01101 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01102 read_error=1 ;
01103 }
01104 }
01105
01106 void cmlfile::get_value_with_key ( long olabel , long okey , long oorder , long &ovalue )
01107 {
01108 if ( !compiled )
01109 {
01110 compile() ;
01111 }
01112 if ( !stop[olabel].n )
01113 {
01114 ovalue=NoInt ;
01115 return ;
01116 }
01117 if ( normal_read_disable )
01118 {
01119 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01120 ovalue=NoInt ;
01121 read_error=1 ;
01122 return ;
01123 }
01124 long i=0,pos,key ;
01125 do
01126 {
01127 actual=stop[olabel].file[i] ;
01128 pos=stop[olabel].position[i] ;
01129 fseek( input[actual],pos,SEEK_SET ) ;
01130 fscanf( input[actual],"%ld",&key ) ;
01131 if ( key!=okey )
01132 {
01133 i++ ;
01134 }
01135 }
01136 while (( key!=okey ) && ( i<stop[olabel].n )) ;
01137 if ( i==stop[olabel].n )
01138 {
01139 printf( "Key value %ld does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
01140 ovalue=NoInt ;
01141 return ;
01142 }
01143 long j ;
01144 for ( i=0 ; i<oorder ; i++ )
01145 {
01146 read_string( input[actual],buffer ) ;
01147 }
01148 j=fscanf( input[actual],"%ld",&ovalue ) ;
01149
01150 if ( j!=1 )
01151 {
01152 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01153 read_error=1 ;
01154 }
01155 }
01156
01157 void cmlfile::get_value_with_key ( long olabel , long okey , long oorder , double &ovalue )
01158 {
01159 if ( !compiled )
01160 {
01161 compile() ;
01162 }
01163 if ( !stop[olabel].n )
01164 {
01165 ovalue=NoDouble ;
01166 return ;
01167 }
01168 if ( normal_read_disable )
01169 {
01170 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01171 ovalue=NoDouble ;
01172 read_error=1 ;
01173 return ;
01174 }
01175 long i=0,pos,key ;
01176 do
01177 {
01178 actual=stop[olabel].file[i] ;
01179 pos=stop[olabel].position[i] ;
01180 fseek( input[actual],pos,SEEK_SET ) ;
01181 fscanf( input[actual],"%ld",&key ) ;
01182 if ( key!=okey )
01183 {
01184 i++ ;
01185 }
01186 }
01187 while (( key!=okey ) && ( i<stop[olabel].n )) ;
01188 if ( i==stop[olabel].n )
01189 {
01190 printf( "Key value %ld does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
01191 ovalue=NoDouble ;
01192 return ;
01193 }
01194 for ( i=0 ; i<oorder ; i++ )
01195 {
01196 read_string( input[actual],buffer ) ;
01197 }
01198 long j ;
01199 j=fscanf( input[actual],"%lf",&ovalue ) ;
01200
01201 if ( j!=1 )
01202 {
01203 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01204 read_error=1 ;
01205 }
01206 }
01207
01208 void cmlfile::get_value_with_key ( long olabel , long okey , long oorder , char *ovalue )
01209 {
01210 if ( !compiled )
01211 {
01212 compile() ;
01213 }
01214 if ( !stop[olabel].n )
01215 {
01216 ovalue[0]=0 ;
01217 return ;
01218 }
01219 if ( normal_read_disable )
01220 {
01221 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01222 ovalue[0]=0 ;
01223 read_error=1 ;
01224 return ;
01225 }
01226 long i=0,pos,key ;
01227 do
01228 {
01229 actual=stop[olabel].file[i] ;
01230 pos=stop[olabel].position[i] ;
01231 fseek( input[actual],pos,SEEK_SET ) ;
01232 fscanf( input[actual],"%ld",&key ) ;
01233 if ( key!=okey )
01234 {
01235 i++ ;
01236 }
01237 }
01238 while (( key!=okey ) && ( i<stop[olabel].n )) ;
01239 if ( i==stop[olabel].n )
01240 {
01241 printf( "Key value %ld does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
01242 ovalue[0]=0 ;
01243 return ;
01244 }
01245 for ( i=0 ; i<oorder ; i++ )
01246 {
01247 read_string( input[actual],ovalue ) ;
01248 }
01249 long j ;
01250 j=read_string( input[actual],ovalue ) ;
01251
01252 if ( j!=1 )
01253 {
01254 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01255 read_error=1 ;
01256 }
01257 }
01258
01259 void cmlfile::get_value_with_key ( long olabel , char *okey , long &ovalue )
01260 {
01261 if ( !compiled )
01262 {
01263 compile() ;
01264 }
01265 if ( !stop[olabel].n )
01266 {
01267 ovalue=NoInt ;
01268 return ;
01269 }
01270 if ( normal_read_disable )
01271 {
01272 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01273 ovalue=NoInt ;
01274 read_error=1 ;
01275 return ;
01276 }
01277 long i=0,pos ;
01278 do
01279 {
01280 actual=stop[olabel].file[i] ;
01281 pos=stop[olabel].position[i] ;
01282 fseek( input[actual],pos,SEEK_SET ) ;
01283 read_string( input[actual],buffer ) ;
01284 if ( !str_equal( okey,buffer ))
01285 {
01286 i++ ;
01287 }
01288 }
01289 while (( !str_equal( okey,buffer )) && ( i<stop[olabel].n )) ;
01290 if ( i==stop[olabel].n )
01291 {
01292 printf( "Key value %s does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
01293 ovalue=NoInt ;
01294 return ;
01295 }
01296 long j ;
01297 j=fscanf( input[actual],"%ld",&ovalue ) ;
01298
01299 if ( j!=1 )
01300 {
01301 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01302 read_error=1 ;
01303 }
01304 }
01305
01306 void cmlfile::get_value_with_key ( long olabel , char *okey , double &ovalue )
01307 {
01308 if ( !compiled )
01309 {
01310 compile() ;
01311 }
01312 if ( !stop[olabel].n )
01313 {
01314 ovalue=NoDouble ;
01315 return ;
01316 }
01317 if ( normal_read_disable )
01318 {
01319 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01320 ovalue=NoDouble ;
01321 read_error=1 ;
01322 return ;
01323 }
01324 long i=0,pos ;
01325 do
01326 {
01327 actual=stop[olabel].file[i] ;
01328 pos=stop[olabel].position[i] ;
01329 fseek( input[actual],pos,SEEK_SET ) ;
01330 read_string( input[actual],buffer ) ;
01331 if ( !str_equal( okey,buffer ))
01332 {
01333 i++ ;
01334 }
01335 }
01336 while (( !str_equal( okey,buffer )) && ( i<stop[olabel].n )) ;
01337 if ( i==stop[olabel].n )
01338 {
01339 printf( "Key value %s does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
01340 ovalue=NoDouble ;
01341 return ;
01342 }
01343 long j ;
01344 j=fscanf( input[actual],"%lf",&ovalue ) ;
01345
01346 if ( j!=1 )
01347 {
01348 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01349 read_error=1 ;
01350 }
01351 }
01352
01353 void cmlfile::get_value_with_key ( long olabel , char *okey , char *ovalue )
01354 {
01355 if ( !compiled )
01356 {
01357 compile() ;
01358 }
01359 if ( !stop[olabel].n )
01360 {
01361 ovalue[0]=0 ;
01362 return ;
01363 }
01364 if ( normal_read_disable )
01365 {
01366 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01367 ovalue[0]=0 ;
01368 read_error=1 ;
01369 return ;
01370 }
01371 long i=0,pos ;
01372 do
01373 {
01374 actual=stop[olabel].file[i] ;
01375 pos=stop[olabel].position[i] ;
01376 fseek( input[actual],pos,SEEK_SET ) ;
01377 read_string( input[actual],buffer ) ;
01378 if ( !str_equal( okey,buffer ))
01379 {
01380 i++ ;
01381 }
01382 }
01383 while (( !str_equal( okey,buffer )) && ( i<stop[olabel].n )) ;
01384 if ( i==stop[olabel].n )
01385 {
01386 printf( "Key value %s does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
01387 ovalue[0]=0 ;
01388 return ;
01389 }
01390 long j ;
01391 j=read_string( input[actual],ovalue ) ;
01392
01393 if ( j!=1 )
01394 {
01395 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01396 read_error=1 ;
01397 }
01398 }
01399
01400 void cmlfile::get_value_with_key ( long olabel , char *okey , long oorder , long &ovalue )
01401 {
01402 if ( !compiled )
01403 {
01404 compile() ;
01405 }
01406 if ( !stop[olabel].n )
01407 {
01408 ovalue=NoInt ;
01409 return ;
01410 }
01411 if ( normal_read_disable )
01412 {
01413 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01414 ovalue=NoInt ;
01415 read_error=1 ;
01416 return ;
01417 }
01418 long i=0,pos ;
01419 do
01420 {
01421 actual=stop[olabel].file[i] ;
01422 pos=stop[olabel].position[i] ;
01423 fseek( input[actual],pos,SEEK_SET ) ;
01424 read_string( input[actual],buffer ) ;
01425 if ( !str_equal( okey,buffer ))
01426 {
01427 i++ ;
01428 }
01429 }
01430 while (( !str_equal( okey,buffer )) && ( i<stop[olabel].n )) ;
01431 if ( i==stop[olabel].n )
01432 {
01433 printf( "Key value %s does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
01434 ovalue=NoInt ;
01435 return ;
01436 }
01437 long j ;
01438 for ( i=0 ; i<oorder ; i++ )
01439 {
01440 read_string( input[actual],buffer ) ;
01441 }
01442 j=fscanf( input[actual],"%ld",&ovalue ) ;
01443
01444 if ( j!=1 )
01445 {
01446 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01447 read_error=1 ;
01448 }
01449 }
01450
01451 void cmlfile::get_value_with_key ( long olabel , char *okey , long oorder , double &ovalue )
01452 {
01453 if ( !compiled )
01454 {
01455 compile() ;
01456 }
01457 if ( !stop[olabel].n )
01458 {
01459 ovalue=NoDouble ;
01460 return ;
01461 }
01462 if ( normal_read_disable )
01463 {
01464 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01465 ovalue=NoDouble ;
01466 read_error=1 ;
01467 return ;
01468 }
01469 long i=0,pos ;
01470 do
01471 {
01472 actual=stop[olabel].file[i] ;
01473 pos=stop[olabel].position[i] ;
01474 fseek( input[actual],pos,SEEK_SET ) ;
01475 read_string( input[actual],buffer ) ;
01476 if ( !str_equal( okey,buffer ))
01477 {
01478 i++ ;
01479 }
01480 }
01481 while (( !str_equal( okey,buffer )) && ( i<stop[olabel].n )) ;
01482 if ( i==stop[olabel].n )
01483 {
01484 printf( "Key value %s does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
01485 ovalue=NoDouble ;
01486 return ;
01487 }
01488 for ( i=0 ; i<oorder ; i++ )
01489 {
01490 read_string( input[actual],buffer ) ;
01491 }
01492 long j ;
01493 j=fscanf( input[actual],"%lf",&ovalue ) ;
01494
01495 if ( j!=1 )
01496 {
01497 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01498 read_error=1 ;
01499 }
01500 }
01501
01502 void cmlfile::get_value_with_key ( long olabel , char *okey , long oorder , char *ovalue )
01503 {
01504 if ( !compiled )
01505 {
01506 compile() ;
01507 }
01508 if ( !stop[olabel].n )
01509 {
01510 ovalue[0]=0 ;
01511 return ;
01512 }
01513 if ( normal_read_disable )
01514 {
01515 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01516 ovalue[0]=0 ;
01517 read_error=1 ;
01518 return ;
01519 }
01520 long i=0,pos ;
01521 do
01522 {
01523 actual=stop[olabel].file[i] ;
01524 pos=stop[olabel].position[i] ;
01525 fseek( input[actual],pos,SEEK_SET ) ;
01526 read_string( input[actual],buffer ) ;
01527 if ( !str_equal( okey,buffer ))
01528 {
01529 i++ ;
01530 }
01531 }
01532 while (( !str_equal( okey,buffer )) && ( i<stop[olabel].n )) ;
01533 if ( i==stop[olabel].n )
01534 {
01535 printf( "Key value %s does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
01536 ovalue[0]=0 ;
01537 return ;
01538 }
01539 for ( i=0 ; i<oorder ; i++ )
01540 {
01541 read_string( input[actual],ovalue ) ;
01542 }
01543 long j ;
01544 j=read_string( input[actual],ovalue ) ;
01545
01546 if ( j!=1 )
01547 {
01548 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01549 read_error=1 ;
01550 }
01551 }
01552
01553 void cmlfile::get_value_with_index ( long olabel , long oindex , long &ovalue )
01554 {
01555 if ( !compiled )
01556 {
01557 compile() ;
01558 }
01559 if ( !stop[olabel].n )
01560 {
01561 ovalue=NoInt ;
01562 return ;
01563 }
01564 if ( normal_read_disable )
01565 {
01566 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01567 ovalue=NoInt ;
01568 read_error=1 ;
01569 return ;
01570 }
01571 if ( oindex>=stop[olabel].n )
01572 {
01573 printf( "Index over possible value.\n" ) ;
01574 ovalue=NoInt ;
01575 read_error=1 ;
01576 return ;
01577 }
01578
01579 actual=stop[olabel].file[oindex] ;
01580 fseek( input[actual],stop[olabel].position[oindex],SEEK_SET ) ;
01581
01582 long j ;
01583 j=fscanf( input[actual],"%ld",&ovalue ) ;
01584
01585 if ( j!=1 )
01586 {
01587 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01588 read_error=1 ;
01589 }
01590 }
01591
01592 void cmlfile::get_value_with_index ( long olabel , long oindex , double &ovalue )
01593 {
01594 if ( !compiled )
01595 {
01596 compile() ;
01597 }
01598 if ( !stop[olabel].n )
01599 {
01600 ovalue=NoDouble ;
01601 return ;
01602 }
01603 if ( normal_read_disable )
01604 {
01605 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01606 ovalue=NoDouble ;
01607 read_error=1 ;
01608 return ;
01609 }
01610 if ( oindex>=stop[olabel].n )
01611 {
01612 printf( "Index over possible value.\n" ) ;
01613 ovalue=NoDouble ;
01614 read_error=1 ;
01615 return ;
01616 }
01617
01618 actual=stop[olabel].file[oindex] ;
01619 fseek( input[actual],stop[olabel].position[oindex],SEEK_SET ) ;
01620
01621 long j ;
01622 j=fscanf( input[actual],"%lf",&ovalue ) ;
01623
01624 if ( j!=1 )
01625 {
01626 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01627 read_error=1 ;
01628 }
01629 }
01630
01631 void cmlfile::get_value_with_index ( long olabel , long oindex , char *ovalue )
01632 {
01633 if ( !compiled )
01634 {
01635 compile() ;
01636 }
01637 if ( !stop[olabel].n )
01638 {
01639 ovalue[0]=0 ;
01640 return ;
01641 }
01642 if ( normal_read_disable )
01643 {
01644 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01645 ovalue[0]=0 ;
01646 read_error=1 ;
01647 return ;
01648 }
01649 if ( oindex>=stop[olabel].n )
01650 {
01651 printf( "Index over possible value.\n" ) ;
01652 ovalue[0]=0 ;
01653 read_error=1 ;
01654 return ;
01655 }
01656
01657 actual=stop[olabel].file[oindex] ;
01658 fseek( input[actual],stop[olabel].position[oindex],SEEK_SET ) ;
01659
01660 long j ;
01661 j=read_string( input[actual],ovalue ) ;
01662
01663 if ( j!=1 )
01664 {
01665 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01666 read_error=1 ;
01667 }
01668 }
01669
01670 void cmlfile::get_value_with_index ( long olabel , long oindex , long oorder , long &ovalue )
01671 {
01672 if ( !compiled )
01673 {
01674 compile() ;
01675 }
01676 if ( !stop[olabel].n )
01677 {
01678 ovalue=NoInt ;
01679 return ;
01680 }
01681 if ( normal_read_disable )
01682 {
01683 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01684 ovalue=NoInt ;
01685 read_error=1 ;
01686 return ;
01687 }
01688 if ( oindex>=stop[olabel].n )
01689 {
01690 printf( "Index over possible value.\n" ) ;
01691 ovalue=NoInt ;
01692 read_error=1 ;
01693 return ;
01694 }
01695
01696 actual=stop[olabel].file[oindex] ;
01697 fseek( input[actual],stop[olabel].position[oindex],SEEK_SET ) ;
01698
01699 long i,j ;
01700 for ( i=0 ; i<oorder ; i++ )
01701 {
01702 read_string( input[actual],buffer ) ;
01703 }
01704 j=fscanf( input[actual],"%ld",&ovalue ) ;
01705
01706 if ( j!=1 )
01707 {
01708 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01709 read_error=1 ;
01710 }
01711 }
01712
01713 void cmlfile::get_value_with_index ( long olabel , long oindex , long oorder , double &ovalue )
01714 {
01715 if ( !compiled )
01716 {
01717 compile() ;
01718 }
01719 if ( !stop[olabel].n )
01720 {
01721 ovalue=NoDouble ;
01722 return ;
01723 }
01724 if ( normal_read_disable )
01725 {
01726 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01727 ovalue=NoDouble ;
01728 read_error=1 ;
01729 return ;
01730 }
01731 if ( oindex>=stop[olabel].n )
01732 {
01733 printf( "Index over possible value.\n" ) ;
01734 ovalue=NoDouble ;
01735 read_error=1 ;
01736 return ;
01737 }
01738
01739 actual=stop[olabel].file[oindex] ;
01740 fseek( input[actual],stop[olabel].position[oindex],SEEK_SET ) ;
01741
01742 long i,j ;
01743 for ( i=0 ; i<oorder ; i++ )
01744 {
01745 read_string( input[actual],buffer ) ;
01746 }
01747 j=fscanf( input[actual],"%lf",&ovalue ) ;
01748
01749 if ( j!=1 )
01750 {
01751 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01752 read_error=1 ;
01753 }
01754 }
01755
01756 void cmlfile::get_value_with_index ( long olabel , long oindex , long oorder , char *ovalue )
01757 {
01758 if ( !compiled )
01759 {
01760 compile() ;
01761 }
01762 if ( !stop[olabel].n )
01763 {
01764 ovalue[0]=0 ;
01765 return ;
01766 }
01767 if ( normal_read_disable )
01768 {
01769 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01770 ovalue[0]=0 ;
01771 read_error=1 ;
01772 return ;
01773 }
01774 if ( oindex>=stop[olabel].n )
01775 {
01776 printf( "Index over possible value.\n" ) ;
01777 ovalue[0]=0 ;
01778 read_error=1 ;
01779 return ;
01780 }
01781
01782 actual=stop[olabel].file[oindex] ;
01783 fseek( input[actual],stop[olabel].position[oindex],SEEK_SET ) ;
01784
01785 long i,j ;
01786 for ( i=0 ; i<oorder ; i++ )
01787 {
01788 read_string( input[actual],ovalue ) ;
01789 }
01790 j=read_string( input[actual],ovalue ) ;
01791
01792 if ( j!=1 )
01793 {
01794 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01795 read_error=1 ;
01796 }
01797 }
01798
01799 void cmlfile::get_percentage ( long olabel , double &ovalue )
01800 {
01801 if ( !compiled )
01802 {
01803 compile() ;
01804 }
01805 if ( !stop[olabel].n )
01806 {
01807 ovalue=NoDouble ;
01808 return ;
01809 }
01810 if ( normal_read_disable )
01811 {
01812 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01813 read_error=1 ;
01814 return ;
01815 }
01816 actual=stop[olabel].file[0] ;
01817 fseek( input[actual],stop[olabel].position[0],SEEK_SET ) ;
01818 long j ;
01819 j=fscanf( input[actual],"%s",buffer ) ;
01820
01821 if ( j!=1 )
01822 {
01823 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01824 read_error=1 ;
01825 }
01826 sscanf( buffer,"%lf",&ovalue ) ;
01827 j=0 ;
01828 while ( buffer[j] )
01829 {
01830 if ( buffer[j]=='%' )
01831 {
01832 ovalue/=100.0 ;
01833 return ;
01834 }
01835 j++ ;
01836 }
01837 }
01838
01839 void cmlfile::get_percentage ( long olabel , long oorder , double &ovalue )
01840 {
01841 if ( !compiled )
01842 {
01843 compile() ;
01844 }
01845 if ( !stop[olabel].n )
01846 {
01847 ovalue=NoDouble ;
01848 return ;
01849 }
01850 if ( normal_read_disable )
01851 {
01852 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01853 ovalue=NoDouble ;
01854 read_error=1 ;
01855 return ;
01856 }
01857 actual=stop[olabel].file[0] ;
01858 fseek( input[actual],stop[olabel].position[0],SEEK_SET ) ;
01859 long i,j ;
01860 for ( i=0 ; i<oorder ; i++ )
01861 {
01862 read_string( input[actual],buffer ) ;
01863 }
01864 j=fscanf( input[actual],"%s",buffer ) ;
01865
01866 if ( j!=1 )
01867 {
01868 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01869 read_error=1 ;
01870 }
01871 sscanf( buffer,"%lf",&ovalue ) ;
01872 j=0 ;
01873 while ( buffer[j] )
01874 {
01875 if ( buffer[j]=='%' )
01876 {
01877 ovalue/=100.0 ;
01878 return ;
01879 }
01880 j++ ;
01881 }
01882 }
01883
01884 void cmlfile::get_percentage_with_key ( long olabel , long okey , double &ovalue )
01885 {
01886 if ( !compiled )
01887 {
01888 compile() ;
01889 }
01890 if ( !stop[olabel].n )
01891 {
01892 ovalue=NoDouble ;
01893 return ;
01894 }
01895 if ( normal_read_disable )
01896 {
01897 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01898 ovalue=NoDouble ;
01899 read_error=1 ;
01900 return ;
01901 }
01902 long i=0,pos,key ;
01903 do
01904 {
01905 actual=stop[olabel].file[i] ;
01906 pos=stop[olabel].position[i] ;
01907 fseek( input[actual],pos,SEEK_SET ) ;
01908 fscanf( input[actual],"%ld",&key ) ;
01909 if ( key!=okey )
01910 {
01911 i++ ;
01912 }
01913 }
01914 while (( key!=okey ) && ( i<stop[olabel].n )) ;
01915 if ( i==stop[olabel].n )
01916 {
01917 printf( "Key value %ld does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
01918 ovalue=NoDouble ;
01919 return ;
01920 }
01921 long j ;
01922 j=fscanf( input[actual],"%s",buffer ) ;
01923
01924 if ( j!=1 )
01925 {
01926 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01927 read_error=1 ;
01928 }
01929 sscanf( buffer,"%lf",&ovalue ) ;
01930 j=0 ;
01931 while ( buffer[j] )
01932 {
01933 if ( buffer[j]=='%' )
01934 {
01935 ovalue/=100.0 ;
01936 return ;
01937 }
01938 j++ ;
01939 }
01940 }
01941
01942 void cmlfile::get_percentage_with_key ( long olabel , long okey , long oorder , double &ovalue )
01943 {
01944 if ( !compiled )
01945 {
01946 compile() ;
01947 }
01948 if ( !stop[olabel].n )
01949 {
01950 ovalue=NoDouble ;
01951 return ;
01952 }
01953 if ( normal_read_disable )
01954 {
01955 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
01956 ovalue=NoDouble ;
01957 read_error=1 ;
01958 return ;
01959 }
01960 long i=0,pos,key ;
01961 do
01962 {
01963 actual=stop[olabel].file[i] ;
01964 pos=stop[olabel].position[i] ;
01965 fseek( input[actual],pos,SEEK_SET ) ;
01966 fscanf( input[actual],"%ld",&key ) ;
01967 if ( key!=okey )
01968 {
01969 i++ ;
01970 }
01971 }
01972 while (( key!=okey ) && ( i<stop[olabel].n )) ;
01973 if ( i==stop[olabel].n )
01974 {
01975 printf( "Key value %ld does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
01976 ovalue=NoDouble ;
01977 return ;
01978 }
01979 for ( i=0 ; i<oorder ; i++ )
01980 {
01981 read_string( input[actual],buffer ) ;
01982 }
01983 long j ;
01984 j=fscanf( input[actual],"%s",buffer ) ;
01985
01986 if ( j!=1 )
01987 {
01988 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
01989 read_error=1 ;
01990 }
01991 sscanf( buffer,"%lf",&ovalue ) ;
01992 j=0 ;
01993 while ( buffer[j] )
01994 {
01995 if ( buffer[j]=='%' )
01996 {
01997 ovalue/=100.0 ;
01998 return ;
01999 }
02000 j++ ;
02001 }
02002 }
02003
02004 void cmlfile::get_percentage_with_key ( long olabel , char *okey , double &ovalue )
02005 {
02006 if ( !compiled )
02007 {
02008 compile() ;
02009 }
02010 if ( !stop[olabel].n )
02011 {
02012 ovalue=NoDouble ;
02013 return ;
02014 }
02015 if ( normal_read_disable )
02016 {
02017 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
02018 ovalue=NoDouble ;
02019 read_error=1 ;
02020 return ;
02021 }
02022 long i=0,pos ;
02023 do
02024 {
02025 actual=stop[olabel].file[i] ;
02026 pos=stop[olabel].position[i] ;
02027 fseek( input[actual],pos,SEEK_SET ) ;
02028 fscanf( input[actual],"%s",buffer ) ;
02029 if ( !str_equal( okey,buffer ))
02030 {
02031 i++ ;
02032 }
02033 }
02034 while (( !str_equal( okey,buffer )) && ( i<stop[olabel].n )) ;
02035 if ( i==stop[olabel].n )
02036 {
02037 printf( "Key value %s does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
02038 ovalue=NoDouble ;
02039 }
02040 long j ;
02041 j=fscanf( input[actual],"%s",buffer ) ;
02042
02043 if ( j!=1 )
02044 {
02045 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
02046 read_error=1 ;
02047 }
02048 sscanf( buffer,"%lf",&ovalue ) ;
02049 j=0 ;
02050 while ( buffer[j] )
02051 {
02052 if ( buffer[j]=='%' )
02053 {
02054 ovalue/=100.0 ;
02055 return ;
02056 }
02057 j++ ;
02058 }
02059 }
02060
02061 void cmlfile::get_percentage_with_key ( long olabel , char *okey , long oorder , double &ovalue )
02062 {
02063 if ( !compiled )
02064 {
02065 compile() ;
02066 }
02067 if ( !stop[olabel].n )
02068 {
02069 ovalue=NoDouble ;
02070 return ;
02071 }
02072 if ( normal_read_disable )
02073 {
02074 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
02075 ovalue=NoDouble ;
02076 read_error=1 ;
02077 return ;
02078 }
02079 long i=0,pos ;
02080 do
02081 {
02082 actual=stop[olabel].file[i] ;
02083 pos=stop[olabel].position[i] ;
02084 fseek( input[actual],pos,SEEK_SET ) ;
02085 fscanf( input[actual],"%s",buffer ) ;
02086 if ( !str_equal( okey,buffer ))
02087 {
02088 i++ ;
02089 }
02090 }
02091 while (( !str_equal( okey,buffer )) && ( i<stop[olabel].n )) ;
02092 if ( i==stop[olabel].n )
02093 {
02094 printf( "Key value %s does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
02095 ovalue=NoDouble ;
02096 }
02097 for ( i=0 ; i<oorder ; i++ )
02098 {
02099 read_string( input[actual],buffer ) ;
02100 }
02101 long j ;
02102 j=fscanf( input[actual],"%s",buffer ) ;
02103
02104 if ( j!=1 )
02105 {
02106 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
02107 read_error=1 ;
02108 }
02109 sscanf( buffer,"%lf",&ovalue ) ;
02110 j=0 ;
02111 while ( buffer[j] )
02112 {
02113 if ( buffer[j]=='%' )
02114 {
02115 ovalue/=100.0 ;
02116 return ;
02117 }
02118 j++ ;
02119 }
02120 }
02121
02122 void cmlfile::get_percentage_with_index ( long olabel , long oindex , double &ovalue )
02123 {
02124 if ( !compiled )
02125 {
02126 compile() ;
02127 }
02128 if ( !stop[olabel].n )
02129 {
02130 ovalue=NoDouble ;
02131 return ;
02132 }
02133 if ( normal_read_disable )
02134 {
02135 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
02136 ovalue=NoDouble ;
02137 read_error=1 ;
02138 return ;
02139 }
02140 if ( oindex>=stop[olabel].n )
02141 {
02142 printf( "Index over possible value.\n" ) ;
02143 ovalue=NoDouble ;
02144 read_error=1 ;
02145 return ;
02146 }
02147
02148 actual=stop[olabel].file[oindex] ;
02149 fseek( input[actual],stop[olabel].position[oindex],SEEK_SET ) ;
02150
02151 long j ;
02152 j=fscanf( input[actual],"%s",buffer ) ;
02153
02154 if ( j!=1 )
02155 {
02156 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
02157 read_error=1 ;
02158 }
02159 sscanf( buffer,"%lf",&ovalue ) ;
02160 j=0 ;
02161 while ( buffer[j] )
02162 {
02163 if ( buffer[j]=='%' )
02164 {
02165 ovalue/=100.0 ;
02166 return ;
02167 }
02168 j++ ;
02169 }
02170 }
02171
02172 void cmlfile::get_percentage_with_index ( long olabel , long oindex , long oorder , double &ovalue )
02173 {
02174 if ( !compiled )
02175 {
02176 compile() ;
02177 }
02178 if ( !stop[olabel].n )
02179 {
02180 ovalue=NoDouble ;
02181 return ;
02182 }
02183 if ( normal_read_disable )
02184 {
02185 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
02186 ovalue=NoDouble ;
02187 read_error=1 ;
02188 return ;
02189 }
02190 if ( oindex>=stop[olabel].n )
02191 {
02192 printf( "Index over possible value.\n" ) ;
02193 ovalue=NoDouble ;
02194 read_error=1 ;
02195 return ;
02196 }
02197
02198 actual=stop[olabel].file[oindex] ;
02199 fseek( input[actual],stop[olabel].position[oindex],SEEK_SET ) ;
02200
02201 long i,j ;
02202 for ( i=0 ; i<oorder ; i++ )
02203 {
02204 read_string( input[actual],buffer ) ;
02205 }
02206 j=fscanf( input[actual],"%s",buffer ) ;
02207
02208 if ( j!=1 )
02209 {
02210 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
02211 read_error=1 ;
02212 }
02213 sscanf( buffer,"%lf",&ovalue ) ;
02214 j=0 ;
02215 while ( buffer[j] )
02216 {
02217 if ( buffer[j]=='%' )
02218 {
02219 ovalue/=100.0 ;
02220 return ;
02221 }
02222 j++ ;
02223 }
02224 }
02225
02226 void cmlfile::get_line ( long olabel , char *oline )
02227 {
02228 if ( !compiled )
02229 {
02230 compile() ;
02231 }
02232 if ( !stop[olabel].n )
02233 {
02234 oline[0]=0 ;
02235 return ;
02236 }
02237 if ( normal_read_disable )
02238 {
02239 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
02240 oline[0]=0 ;
02241 read_error=1 ;
02242 return ;
02243 }
02244 actual=stop[olabel].file[0] ;
02245 fseek( input[actual],stop[olabel].position[0],SEEK_SET ) ;
02246 long j ;
02247 j=read_to_eoln( input[actual],oline ) ;
02248 if ( j==None )
02249 {
02250 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
02251 read_error=1 ;
02252 }
02253 }
02254
02255 void cmlfile::get_line_with_key ( long olabel , long okey , char *oline )
02256 {
02257 if ( !compiled )
02258 {
02259 compile() ;
02260 }
02261 if ( !stop[olabel].n )
02262 {
02263 oline[0]=0 ;
02264 return ;
02265 }
02266 if ( normal_read_disable )
02267 {
02268 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
02269 oline[0]=0 ;
02270 read_error=1 ;
02271 return ;
02272 }
02273 long i=0,pos,key ;
02274 do
02275 {
02276 actual=stop[olabel].file[i] ;
02277 pos=stop[olabel].position[i] ;
02278 fseek( input[actual],pos,SEEK_SET ) ;
02279 fscanf( input[actual],"%ld",&key ) ;
02280 if ( key!=okey )
02281 {
02282 i++ ;
02283 }
02284 }
02285 while (( key!=okey ) && ( i<stop[olabel].n )) ;
02286 if ( i==stop[olabel].n )
02287 {
02288 printf( "Key value %ld does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
02289 oline[0]=0 ;
02290 return ;
02291 }
02292 long j ;
02293 j=read_to_eoln( input[actual],oline ) ;
02294
02295 if ( j==None )
02296 {
02297 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
02298 read_error=1 ;
02299 }
02300 }
02301
02302 void cmlfile::get_line_with_key ( long olabel , char *okey , char *oline )
02303 {
02304 if ( !compiled )
02305 {
02306 compile() ;
02307 }
02308 if ( !stop[olabel].n )
02309 {
02310 oline[0]=0 ;
02311 return ;
02312 }
02313 if ( normal_read_disable )
02314 {
02315 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
02316 oline[0]=0 ;
02317 read_error=1 ;
02318 return ;
02319 }
02320 long i=0,pos ;
02321 do
02322 {
02323 actual=stop[olabel].file[i] ;
02324 pos=stop[olabel].position[i] ;
02325 fseek( input[actual],pos,SEEK_SET ) ;
02326 fscanf( input[actual],"%s",buffer ) ;
02327 if ( !str_equal( okey,buffer ))
02328 {
02329 i++ ;
02330 }
02331 }
02332 while (( !str_equal( okey,buffer )) && ( i<stop[olabel].n )) ;
02333 if ( i==stop[olabel].n )
02334 {
02335 printf( "Key value %s does not occur in data for label %s.\n",okey,stop[olabel].word ) ;
02336 oline[0]=0 ;
02337 return ;
02338 }
02339 long j ;
02340 j=read_to_eoln( input[actual],oline ) ;
02341
02342 if ( j==None )
02343 {
02344 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
02345 read_error=1 ;
02346 }
02347 }
02348
02349 void cmlfile::get_line_with_index ( long olabel , long oindex , char *oline )
02350 {
02351 if ( !compiled )
02352 {
02353 compile() ;
02354 }
02355 if ( !stop[olabel].n )
02356 {
02357 oline[0]=0 ;
02358 return ;
02359 }
02360 if ( normal_read_disable )
02361 {
02362 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
02363 oline[0]=0 ;
02364 read_error=1 ;
02365 return ;
02366 }
02367 if ( oindex>=stop[olabel].n )
02368 {
02369 printf( "Index over possible value.\n" ) ;
02370 oline[0]=0 ;
02371 read_error=1 ;
02372 return ;
02373 }
02374
02375 actual=stop[olabel].file[oindex] ;
02376 fseek( input[actual],stop[olabel].position[oindex],SEEK_SET ) ;
02377
02378 long j ;
02379 j=read_to_eoln( input[actual],oline ) ;
02380
02381 if ( j==None )
02382 {
02383 printf( "Seems that some error occured reading data for label %s.\n",stop[olabel].word ) ;
02384 read_error=1 ;
02385 }
02386 }
02387
02388 void cmlfile::find_section ( long olabel , long &osection_rows )
02389 {
02390 if ( !compiled )
02391 {
02392 compile() ;
02393 }
02394 if ( block[olabel].files==0 )
02395 {
02396 osection_rows=0 ;
02397 return ;
02398 }
02399 if ( normal_read_disable )
02400 {
02401 printf( "Cannot read line input now because now reading SECTION data.\n" ) ;
02402 read_error=1 ;
02403 }
02404 block[olabel].actual=0 ;
02405 block[olabel].i=0 ;
02406 actual=block[olabel].file[0] ;
02407 osection_rows=block[olabel].rows_all ;
02408 fseek( input[actual],block[olabel].pos[0],SEEK_SET ) ;
02409 read_to_eoln( input[actual],buffer ) ;
02410 normal_read_disable=1 ;
02411 }
02412
02413 void cmlfile::get_section_line ( long olabel , char *oline )
02414 {
02415 if ( !compiled )
02416 {
02417 compile() ;
02418 }
02419 long i=block[olabel].actual ;
02420 if ( block[olabel].i>=block[olabel].rows[i] )
02421 {
02422 i++ ;
02423 if ( i>=files )
02424 {
02425 normal_read_disable=0 ;
02426 return ;
02427 }
02428 block[olabel].actual=i ;
02429 block[olabel].i=0 ;
02430 actual=block[olabel].file[i] ;
02431 fseek( input[actual],block[olabel].pos[i],SEEK_SET ) ;
02432 read_to_eoln( input[actual],buffer ) ;
02433 }
02434 long j ;
02435 j=read_to_eoln( input[actual],oline ) ;
02436 block[olabel].i++ ;
02437
02438 if ( j==None )
02439 {
02440 printf( "Seems that some error occured reading data for label %s.\n",block[olabel].word ) ;
02441 read_error=1 ;
02442 }
02443 }
02444
02445 void cmlfile::end_reading_section ( void )
02446 {
02447 normal_read_disable=0 ;
02448 }
02449
02450 void cmlfile::out ( long olabel , long ovalue )
02451 {
02452 if ( !output )
02453 {
02454 printf( "Cannot write to output file.\n" ) ;
02455 write_error=1 ;
02456 }
02457 fprintf( output,"%s %ld\n",stop[olabel].word,ovalue ) ;
02458 }
02459
02460 void cmlfile::out ( long olabel , double ovalue )
02461 {
02462 if ( !output )
02463 {
02464 printf( "Cannot write to output file.\n" ) ;
02465 write_error=1 ;
02466 }
02467 fprintf( output,"%s ",stop[olabel].word ) ;
02468 fprintf( output,double_format,ovalue ) ;
02469 fprintf( output,"\n" ) ;
02470 }
02471
02472
02473 void cmlfile::out ( long olabel , char *ovalue )
02474 {
02475 if ( !output )
02476 {
02477 printf( "Cannot write to output file.\n" ) ;
02478 write_error=1 ;
02479 }
02480 fprintf( output,"%s ",stop[olabel].word ) ;
02481 long i=0,k=0 ;
02482 while ( ovalue[i] )
02483 {
02484 if ( ovalue[i]==' ' )
02485 {
02486 k=1 ;
02487 break ;
02488 }
02489 i++ ;
02490 }
02491 if ( k )
02492 {
02493 fputc( 34,output ) ;
02494 }
02495 fprintf( output,"%s",ovalue ) ;
02496 if ( k )
02497 {
02498 fputc( 34,output ) ;
02499 }
02500 fprintf( output,"%c",' ' ) ;
02501 fprintf( output,"\n" ) ;
02502 }
02503
02504 void cmlfile::out_label ( long olabel )
02505 {
02506 if ( !output )
02507 {
02508 printf( "Cannot write to output file.\n" ) ;
02509 write_error=1 ;
02510 }
02511 fprintf( output,"%s ",stop[olabel].word ) ;
02512 }
02513
02514 void cmlfile::out_long ( long ovalue )
02515 {
02516 if ( !output )
02517 {
02518 printf( "Cannot write to output file.\n" ) ;
02519 write_error=1 ;
02520 }
02521 fprintf( output,"%ld ",ovalue ) ;
02522 }
02523
02524 void cmlfile::out_double ( double ovalue )
02525 {
02526 if ( !output )
02527 {
02528 printf( "Cannot write to output file.\n" ) ;
02529 write_error=1 ;
02530 }
02531 fprintf( output,double_format,ovalue ) ;
02532 fprintf( output," " ) ;
02533 }
02534
02535 void cmlfile::out_string ( char *ovalue )
02536 {
02537 if ( !output )
02538 {
02539 printf( "Cannot write to output file.\n" ) ;
02540 write_error=1 ;
02541 }
02542 long i=0,k=0 ;
02543 while ( ovalue[i] )
02544 {
02545 if ( ovalue[i]==' ' )
02546 {
02547 k=1 ;
02548 break ;
02549 }
02550 i++ ;
02551 }
02552 if ( k )
02553 {
02554 fputc( 34,output ) ;
02555 }
02556 fprintf( output,"%s",ovalue ) ;
02557 if ( k )
02558 {
02559 fputc( 34,output ) ;
02560 }
02561 fprintf( output,"%c",' ' ) ;
02562 }
02563
02564 void cmlfile::out_free_string ( char *ovalue )
02565 {
02566 if ( !output )
02567 {
02568 printf( "Cannot write to output file.\n" ) ;
02569 write_error=1 ;
02570 }
02571 fprintf( output,"%s",ovalue ) ;
02572 }
02573
02574 void cmlfile::out_eoln ( void )
02575 {
02576 if ( !output )
02577 {
02578 printf( "Cannot write to output file.\n" ) ;
02579 write_error=1 ;
02580 }
02581 fprintf( output,"\n" ) ;
02582 }
02583
02584 void cmlfile::out_section ( long olabel )
02585 {
02586 if ( !output )
02587 {
02588 printf( "Cannot write to output file.\n" ) ;
02589 write_error=1 ;
02590 }
02591 fprintf( output,"%s %s\n",KeywordSection,block[olabel].word ) ;
02592 }
02593
02594 void cmlfile::out_data ( char *oline )
02595 {
02596 if ( !output )
02597 {
02598 printf( "Cannot write to output file.\n" ) ;
02599 write_error=1 ;
02600 }
02601 fprintf( output,"%s\n",oline ) ;
02602 }
02603
02604 void cmlfile::out_section_end ( void )
02605 {
02606 if ( !output )
02607 {
02608 printf( "Cannot write to output file.\n" ) ;
02609 write_error=1 ;
02610 }
02611 fprintf( output,"%s\n",KeywordEndSection ) ;
02612 }
02613
02614 void cmlfile::clear_errors ( void )
02615 {
02616 open_error=0 ;
02617 read_error=0 ;
02618 write_error=0 ;
02619 }
02620
02621 long cmlfile::error_opening_file ( void )
02622 {
02623 return open_error ;
02624 }
02625
02626 long cmlfile::error_reading_file ( void )
02627 {
02628 return read_error ;
02629 }
02630
02631 long cmlfile::error_writing_file ( void )
02632 {
02633 return write_error ;
02634 }
02635
02636 long cmlfile::error_in_requirements ( void )
02637 {
02638 return requirement_insufficient ;
02639 }
02640
02641 long cmlfile::any_error ( void )
02642 {
02643 if ( open_error | read_error | write_error | requirement_insufficient )
02644 {
02645 return 1 ;
02646 }
02647 return 0 ;
02648 }
02649
02650 void cmlfile::open_next_input ( char *ofname )
02651 {
02652 input[files]=fopen( ofname,"rt" ) ;
02653 if ( !input[files] )
02654 {
02655 printf( "Cannot open file %s.\n",ofname ) ;
02656 open_error=1 ;
02657 return ;
02658 }
02659 files++ ;
02660 }
02661
02662 void cmlfile::stat_section ( void )
02663 {
02664 fscanf( input[actual],"%s",buffer ) ;
02665 long i,j,b ;
02666 j=section_name( buffer ) ;
02667 if ( j==None )
02668 {
02669 printf( "Invalid section %s.\n",buffer ) ;
02670 return ;
02671 }
02672 i=block[j].files ;
02673 block[j].pos[i]=ftell( input[actual] ) ;
02674 block[j].end[i]=ftell( input[actual] ) ;
02675 block[j].file[i]=actual ;
02676 block[j].rows[i]=0 ;
02677
02678 b=read_to_eoln( input[actual],buffer ) ;
02679 b=read_to_eoln( input[actual],buffer ) ;
02680 if ( b==None )
02681 {
02682 printf( "Seems that some error occured reading data for section %s.\n",block[j].word ) ;
02683 read_error=1 ;
02684 return ;
02685 }
02686
02687 while ( !str_equal( KeywordEndSection,buffer ))
02688 {
02689 block[j].end[i]=ftell( input[actual] ) ;
02690 block[j].rows[i]++ ;
02691 read_to_eoln( input[actual],buffer ) ;
02692 if ( b==None )
02693 {
02694 printf( "Seems that some error occured reading data for section %s.\n",block[j].word ) ;
02695 read_error=1 ;
02696 return ;
02697 }
02698
02699 }
02700 block[j].rows_all+=block[j].rows[i] ;
02701 block[j].files++ ;
02702 }
02703
02704 void cmlfile::jump_over_section ( void )
02705 {
02706 fscanf( input[actual],"%s",buffer ) ;
02707 long j ;
02708 j=section_name( buffer ) ;
02709 if ( j==None )
02710 {
02711 printf( "Invalid section %s.\n",buffer ) ;
02712 return ;
02713 }
02714 long i=0 ;
02715 while ( block[j].file[i]!=actual )
02716 {
02717 i++ ;
02718 }
02719 fseek( input[actual],block[j].end[i],SEEK_SET ) ;
02720 }
02721
02722 long cmlfile::label ( char *obuffer )
02723 {
02724 if ( obuffer[0]=='#' )
02725 {
02726 return Comment ;
02727 }
02728 if ( str_equal( KeywordSection,obuffer ))
02729 {
02730 return Section ;
02731 }
02732 if ( str_equal( KeywordEndSection,obuffer ))
02733 {
02734 return EndSection ;
02735 }
02736 if ( str_equal( KeywordFile,obuffer ))
02737 {
02738 return File ;
02739 }
02740 long i ;
02741 for ( i=0 ; i<labels ; i++ )
02742 {
02743 if ( str_equal( obuffer,stop[i].word ))
02744 {
02745 return i ;
02746 }
02747 }
02748 return None ;
02749 }
02750
02751 long cmlfile::section_name ( char *obuffer )
02752 {
02753 long i ;
02754 for ( i=0 ; i<sections ; i++ )
02755 {
02756 if ( str_equal( block[i].word,obuffer ))
02757 {
02758 return i ;
02759 }
02760 }
02761 return None ;
02762 }