Repository navigation
Expand file tree
/
Copy pathintecplot.cpp
More file actions
1136 lines (922 loc) · 28.2 KB
/
Copy pathintecplot.cpp
File metadata and controls
1136 lines (922 loc) · 28.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <utils.h>
#include "intecplot.h"
#ifdef __cplusplus
extern "C" {
enum inTecFile_Component {
Unknown = 0,
Title = 11,
Filetype = 12,
FiletypeFull = 12001,
FiletypeGrid = 12002,
FiletypeSolution = 12003,
Variables = 13,
Zone = 21,
Text = 31,
Geometry = 41,
Custom_Label = 51,
Dataset_Auxilary = 61,
Variable_Auxilary = 71,
Comment = 100
};
//
// the zone object methods
//
inTec_Zone::inTec_Zone( inTec_File* file_ )
{
#ifdef _DEBUG_
printf(" i Zone object instantiated\n");
#endif
ipos = 0;
ipos_data = 0;
InitKeywords();
file = file_;
}
inTec_Zone::~inTec_Zone( )
{
#ifdef _DEBUG_
printf(" i Zone object deconstructed\n");
#endif
keywords.clear();
}
void inTec_Zone::InitKeywords()
{
// add TecPlot keywords with default values
// keywords["T"] = "";
keywords["ZONETYPE"] = "ORDERED";
// keywords["I"] = "";
// keywords["J"] = "";
// keywords["K"] = "";
// keywords["NODES"] = "";
// keywords["ELEMENTS"] = "";
// keywords["FACES"] = "";
// keywords["TOTALNUMFACENODES"] = "";
// keywords["NUMCONNECTEDBOUNDARYFACES"] = "";
// keywords["TOTALNUMBOUNDARYCONNECTIONS"] = "";
// keywords["FACENEIGBORMODE"] = "LOCALONETOONE";
// keywords["FACENEIGHBORCONNECTIONS"] = "";
keywords["DT"] = "SINGLE";
keywords["DATAPACKING"] = "BLOCK";
keywords["VARLOCATION"] = "NODAL";
// keywords["VARSHARELIST"] = "";
// keywords["NV"] = "";
// keywords["CONNECTIVITYSHAREZONE"] = "";
// keywords["STRANDID"] = "";
// keywords["SOLUTIONTIME"] = "";
// keywords["PARENTZONE"] = "";
// keywords["PASSIVEVARLIST"] = "";
// keywords["AUXDATA"] = "";
// keywords[""] = "";
}
long inTec_Zone::GetPositionInFile( void ) const
{
return( ipos );
}
int inTec_Zone::SetPositionInFile( long ipos_ )
{
// reject reseting of position if it is already set
if( ipos != 0 ) {
return(1);
} else { // this is for when a zone is created but not read from a file
ipos = ipos_;
return(0);
}
}
int inTec_Zone::ParseKeywords( char *buf )
{
#ifdef _DEBUG_
printf(" i Parsing zone keywords \n");
#endif
/******* this is to make it seem like it parsed a number of items
static int itime = 0;
++itime;
if(itime < 2) return(1);
*/
size_t isize=0;
while( buf[isize] != '\0' && buf[isize] != '\n' ) ++isize;
char *data;
// create a duplicate buffer
data = (char *) malloc(((size_t) (isize+1))*sizeof(char));
if( data == NULL ) return(-1);
// copy line to buffer and add termination character
memcpy( data, buf, isize );
data[isize] = '\0';
#ifdef _DEBUG_
printf("DATA: %s\n",data);
#endif
// keep parsing for keywords and values
int iquote=0, ikey=0, ierror=0, iparse=0;
char *s=data, *es=NULL;
size_t n=0;
while( n <= isize ) {
#ifdef _DEBUG_
printf(" (key: %d, quote: %d) ", ikey,iquote);
printf(" %c s: %c ", data[n],s[0]);
// printf(" %c s: %c (key: %d, quote: %d) ", data[n],s[0],ikey,iquote);
#endif
// space or comma as keyword delimeter
if( data[n] == ' ' || data[n] == ',' ) {
if( ikey == 0 ) {
s = &( data[n+1] );
} else if( ikey == 1 ) {
if( data[n] == ',' ) { ierror = 1;printf("This is in error! (1)"); }
} else if( ikey == 2 ) {
if( data[n] == ',' ) { ierror = 1;printf("This is in error! (1b)");}
} else if( ikey == 3 ) {
if( iquote == 1 ) {
// we continue parsing because the quote is open
} else {
// this terminates the keyword
ikey = 0;
// parsing should take place
iparse = 1;
}
}
} else
// equal sign
if( data[n] == '=' ) {
if( ikey == 0 ) {
ierror = 1; printf("This is in error! (2)");
} else if( ikey == 1 ) {
// we are moving to the second stage
es = &( data[n] );
ikey = 2;
#ifdef _DEBUG_
printf(" (equal sign) ");
#endif
} else if( ikey == 2 ) {
ierror = 1; printf("This is in error! (2b)");
} else if( ikey == 3 ) {
if( iquote == 1 ) {
// we continue to swallow characters
} else {
ierror = 1; printf("This is in error! (3)");
}
}
} else
// double quote
if( data[n] == '\"' ) {
if( ikey < 2 ) {
ierror = 1; printf("This is in error! (4) (stray quote) ");
} else if( ikey == 2 ) {
// entering data section of this keyword
ikey = 3;
#ifdef _DEBUG_
printf(" (start data of keyword) ");
#endif
// open quote
iquote = 1;
} else {
if( data[n-1] == '\\' ) {
// simply pick it up as a character
} else {
// it is a functional quote (marker)
if( iquote == 1 ) {
// close the quote
iquote = 0;
// indicate that we can parse
ikey = 0;
iparse = 1;
} else {
ierror = 1; printf("This is in error! (4b) (stray quote) ");
}
}
}
} else
// newline or null
if( data[n] == '\n' || data[n] == '\0' ) {
if( ikey == 3 ) {
if( iquote == 1 ) {
ierror = 1;printf("This is in error! (5) (unterminated quote) ");
} else {
ikey = 0;
iparse = 1;
#ifdef _DEBUG_
printf(" (parsing ending) ");
#endif
}
} else if( ikey == 2 ) {
ierror = 1; printf("This is in error! (5b) (empty keyword) ");
} else if( ikey == 1 ) {
ierror = 1; printf("This is in error! (5b) (empty keyword) ");
} else {
// termination of parsing everything
#ifdef _DEBUG_
printf(" (parsing ending) ");
#endif
}
} else
// anything else
{
if( ikey == 0 ) {
// encountered keyword
ikey = 1;
#ifdef _DEBUG_
printf(" (start keyword) ");
#endif
} else if( ikey == 2 ) {
// entering data section of this keyword
ikey = 3;
#ifdef _DEBUG_
printf(" (start data of keyword) ");
#endif
}
}
// provide some output
if( iparse == 1 ) {
printf(" (parsing now)");
data[n] = '\0';//HACK HERE
HandleKeyword( s );//HACK HERE
iparse = 0;
}
++n;
#ifdef _DEBUG_
printf("\n");
#endif
}
// drop duplicate buffer
free( data );
return(0);
}
int inTec_Zone::HandleKeyword( char *buf )
{
#ifdef _DEBUG_
printf("\n i Handling keyword \n");
#endif
printf(" --- keyword -->|%s|<-- \n", buf );
return(0);
}
//
// the file object methods
//
inTec_File::inTec_File( char *fname_ )
{
#ifdef _DEBUG_
printf("File object instantiated \"%s\" \n", fname_ );
#endif
memset( name, '\0', 256 );
sprintf( name, "%s", fname_ );
fp = NULL;
istate = 0;
nline = 0;
iline = 0;
ipos = 0;
}
inTec_File::~inTec_File()
{
#ifdef _DEBUG_
printf(" i File object deconstructing \"%s\"\n", name);
#endif
zones.clear();
#ifdef _DEBUG_
printf(" i Variable names in file (%ld) follow \n", variables.size());
for(unsigned int n=0;n<variables.size();++n) {
printf(" %d \"%s\"\n", n, variables[n].c_str() );
}
printf(" i Strings in file (%ld) follow \n", strings.size());
printf(" Index Line String \n");
std::map< unsigned long, std::string > :: iterator im;
int i=0;
for( im = strings.begin(); im != strings.end(); ++im ) {
printf(" %d ", i++ );
printf(" [%ld] |%s", (*im).first, (*im).second.c_str() );
}
#endif
variables.clear();
strings.clear();
#ifdef _DEBUG2_
printf(" i Number of variables after clear %ld \n", variables.size());
printf(" i Number of strings after clear %ld \n", strings.size());
#endif
}
int inTec_File::OpenRead()
{
#ifdef _DEBUG_
printf(" i Opening file object \"%s\" \n", name );
#endif
fp = fopen( name, "r" );
if( fp == NULL ) {
printf(" e Could not open file \"%s\"\n", name );
return(1);
}
istate = 1;
iline = 0;
return(0);
}
int inTec_File::Close()
{
#ifdef _DEBUG_
printf(" i Closing file object \"%s\" \n", name );
#endif
fclose( fp );
istate = 0;
iline = 0;
ipos = 0;
return(0);
}
int inTec_File::GetState( void ) const
{
return( istate );
}
FILE* inTec_File::GetFP( void ) const
{
return( fp );
}
int inTec_File::Parse()
{
#ifdef _DEBUG_
printf(" i Parsing file \"%s\" \n", name );
#endif
if( istate != 1 ) {
printf(" e File not in a reading state\n");
return(1);
}
int iret = ParseLoop();
return(0);
}
int inTec_File::ParseLoop()
{
#ifdef _DEBUG_
printf(" i Inside \"ParseLoop()\" \n");
#endif
if( istate != 1 ) {
printf(" e File not in a reading state\n");
return(1);
}
char *buf=NULL;
size_t ibuf_size=0;
char *buf2=NULL;
size_t ibuf_size2=0;
while( !feof( fp ) ) {
int ic;
// information about the position in the file
ipos = ftell( fp );
#ifdef _DEBUG_
printf(" i Position in file at %ld bytes\n", ipos );
#endif
// prepare the buffer
memset( buf, '\0', ibuf_size );
// read a line of data; get count of bytes read
ic = inUtils_ReadTextline( &ibuf_size, &buf, fp );
//// check for errors (negative numbers)
#ifdef _DEBUG2_
printf("IC= %d, STRING: \"%s\"\n", ic, buf );//HACK
#endif
// copy the string
if( ibuf_size > ibuf_size2 ) {
//// need a temporary variable here in order to free the memory...
buf2 = (char *) realloc( buf2, ibuf_size );
///// check for errors
ibuf_size2 = ibuf_size;
}
memcpy( buf2, buf, ibuf_size );
// store string
if( ic > 0 ) {
// increase line count
++iline;
// store string in strings map
// (Presently making the "line number" the key of hte mapping, but
// it may be more useful to put the position in the file in bytes.)
strings[ iline ] = buf;
#ifdef _DEBUG2_
printf(" i Added to strings line %ld \n", iline );
#endif
// show the line
printf(" [%ld] %s", iline, buf );
}
// sanitize the line
inUtils_TrimLeadingSpaceTextline( buf2 );
// determine what this line signifies
int itype = IdentifyComponent( buf2 );
int iret;
#ifdef _DEBUG_
if( itype == Comment ) printf(" i Component is a comment line \n");
if( itype == Title ) printf(" i Component is a title line \n");
if( itype == Filetype ) printf(" i Component is a filetype line \n");
if( itype == Variables ) printf(" i Component is a variables line \n");
if( itype == Zone ) printf(" i Component is a zone \n");
if( itype == Text ) printf(" i Component is a text \n");
if( itype == Geometry ) printf(" i Component is a geometry \n");
#endif
if( itype == Title ) iret = ParseComponent_Header( 1, buf2 );
if( itype == Filetype ) iret = ParseComponent_Header( 2, buf2 );
if( itype == Variables ) iret = ParseComponent_Header( 3, buf2 );
if( itype == Zone ) iret = ParseComponent_Zone();
if( itype == Text ) iret = ParseComponent_Text();
if( itype == Geometry ) iret = ParseComponent_Geometry();
// check return code (iret)
}
// drop the buffer
free( buf );
free( buf2 );
return(0);
}
int inTec_File::IdentifyComponent( char *buf )
{
#ifdef _DEBUG2_
printf(" i Inside \"IdentifyComponent()\" \n");
#ifdef _DEBUG2_
printf("%s", buf );
#endif
#endif
if( buf == NULL ) return(-1);
size_t isize=0;
while( buf[isize] != '\n' && buf[isize] != '\0' ) ++isize;
#ifdef _DEBUG2_
printf(" i Size of buffer: %d \n", (int) isize);
#endif
if( buf[0] == '\n' ) return(0);
if( buf[0] == '#' ) return( Comment );
if( isize >= 4 ) {
if( strncasecmp( "ZONE", buf, 4 ) == 0 ) return( Zone );
if( strncasecmp( "TEXT", buf, 4 ) == 0 ) return( Text );
}
if( isize >= 5 ) {
if( strncasecmp( "TITLE", buf, 5 ) == 0 ) return( Title );
}
if( isize >= 8 ) {
if( strncasecmp( "FILETYPE", buf, 8 ) == 0 ) return( Filetype );
if( strncasecmp( "GEOMETRY", buf, 8 ) == 0 ) return( Geometry );
}
if( isize >= 9 ) {
if( strncasecmp( "VARIABLES", buf, 9 ) == 0 ) return( Variables );
}
return(0);
}
int inTec_File::IsComponent( char *buf )
{
return( IdentifyComponent( buf ) );
}
int inTec_File::ParseComponent_Header( int iop, char *buf )
{
#ifdef _DEBUG_
if( iop == 1 ) printf(" i Inside \"ParseComponent_Header(Title)\" \n");
if( iop == 2 ) printf(" i Inside \"ParseComponent_Header(Filetype)\" \n");
if( iop == 3 ) printf(" i Inside \"ParseComponent_Header(Variables)\" \n");
#endif
switch( iop ) {
case(1):
break;
case(2):
break;
case(3):
printf(" i Parsing header \"variables\" line \n");
return( ParseComponent_HeaderVariables( buf ) );
break;
default:
printf(" e Error parsing header component\n");
return(1);
}
return(0);
}
int inTec_File::ParseComponent_HeaderVariables( char *buf )
{
#ifdef _DEBUG_
printf(" i Inside \"ParseComponent_HeaderVariables\" \n");
#endif
size_t isize=0;
while( buf[isize] != '\0' && buf[isize] != '\n' ) ++isize;
char *data,*s1,*token,*sr;
// create a duplicate buffer
data = (char *) malloc(((size_t) (isize+1))*sizeof(char));
if( data == NULL ) return(-1);
// copy line to buffer and add termination character
memcpy( data, buf, isize );
data[isize] = '\0';
// first trap the equal sign
s1 = data;
token = strtok_r( s1, "=", &sr );
#ifdef _DEBUG2_
printf("---> stok: |%s| \n",token);
printf("---> data: |%s| \n",data);
#endif
// individual variables parsing
s1 = NULL;
#ifdef _DEBUG2_
printf("Inner loop\n");
#endif
for(int k=1; ; s1 = NULL, ++k) {
token = strtok_r( s1, " ", &sr );
if( token == NULL ) break;
#ifdef _DEBUG2_
printf("---> starting inner stok: |%s| \n",token);
#endif
if( token[0] == '\"' ) {
#ifdef _DEBUG2_
int n=1,inum=1;
while( token[n] != ' ' && token[n] != '\0' && token[n] != '\n' ) {
if( token[n] == '\"' ) ++inum;
++n;
}
printf(" NUMBER OF DOUBLE-QUOTES FOUND: %d \n", inum);
// show us where parsing stopped
// sr[-1] = '?'; // put an actual marker
printf(" TOKEN (temp) -->%s<-- \n", token );
#endif
// reset the changes...
if( sr[-1] != '\"' ) // only in the
sr[-1] = ' '; // reset farthest bound
s1 = token; // s1 = &(token[1]);
#ifdef _DEBUG2_
printf(" NEW STRING POINTER AT -->%s<-- \n", s1 );
#endif
token = strtok_r( s1, "\"", &sr);
if( token == NULL ) break;
// if( token[0] == '\0' ) break; // HACK
}
#ifdef _DEBUG2_
printf("Instance number %d: |%s|\n", k,token);
#endif
// deal with string-token here...
std::string sdum = token;
variables.push_back( sdum );
#ifdef _DEBUG2_
printf("\n"); usleep(100000);
#endif
}
// drop duplicate buffer
free( data );
return(0);
}
int inTec_File::ParseComponent_Zone()
{
#ifdef _DEBUG_
printf(" i Inside \"ParseComponent_Zone()\" \n");
#endif
// instantiate a zone object
inTec_Zone *zone = new inTec_Zone( this );
// check for allocation error... return(-1)
// set the position in the file for this zone
int iret = zone->SetPositionInFile( ipos );
if( iret != 0 ) {
printf(" e Error setting zone's position: %ld \n", ipos);
printf(" This should never happen (zone rejects only when new)\n");
delete zone;
return(1);
}
#warning "WORKING HERE"
//----------
// seek back to the begining of the line that got us here so we can re-parse
iret = fseek( fp, ipos, SEEK_SET );
if( iret != 0 ) {
printf(" e Error seeking to proper parsing position: %ld \n", ipos);
return(2);
}
// retract line-number as the line will be re-read
--iline;
// Looking to parse multiple keywords and over multiple lines
// T= <string>
// I=
// J=
// K=
// N= NODES=
// E= ELEMENTS=
// The idea here is to keep ingesting in lines until we find a new component
// We ingest comments that can interrupt the geometry component
// Once a new component is detected, we wrap up the process
char *buf=NULL;
size_t ibuf_size=0;
int idone_zone = 0; // flag for present zone component termination
int igot_descr = 0; // flag for whether we have a description of the zone
while( !feof( fp ) && idone_zone <= 1 ) {
int ic;
// information about the position in the file
ipos = ftell( fp );
#ifdef _DEBUG_
printf(" i Position in file at %ld bytes, line %ld \n", ipos, iline+1 );
#endif
// prepare the buffer
memset( buf, '\0', ibuf_size );
// read a line of data; get count of bytes read
ic = inUtils_ReadTextline( &ibuf_size, &buf, fp );
// check error code
// sanitize the line
inUtils_TrimLeadingSpaceTextline( buf );
size_t isize=0;
while( isize < ibuf_size && buf[isize] != '\n' ) ++isize;
if( buf[isize] == '\n' ) buf[isize] = '\0';
#ifdef _DEBUG_
printf("STRING (%p, %ld):%s\n", buf, isize, buf );
#endif
// attempt to identify this line as a new component to terminate parsing
int iparse_line=1; // default is to parse the line
iret = IdentifyComponent( buf );
printf("FOUND iret=%d idone_zone=%d \n", iret,idone_zone);//HACK
// check if we have jumped to a new component under certain conditions...
if( iret > 0 ) { // we found a component
// only allow "stray" comment components to pass through
if( iret == Comment ) {
#ifdef _DEBUG_
printf(" --- Found comment (inside Zone component) \n");
#endif
++iline;
// we will not be parsing this line
iparse_line = 0;
// store comment in strings
buf[ strlen(buf) ] = '\n';
strings[ iline ] = buf;
} else {
#ifdef _DEBUG_
printf(" --- Found component (at _or_ after Zone component)\n");
#endif
// over-write the "zone" keyword marker if this is the first pass
if( idone_zone == 0 ) {
buf[0] = ' '; buf[1] = ' '; buf[2] = ' '; buf[3] = ' ';
}
// increment termination condition variable
++idone_zone;
// will not parse new components
if( idone_zone > 1) iparse_line = 0;
}
} else {
#ifdef _DEBUG_
printf(" --- The line is part of the Zone component \n");
#endif
iparse_line = 1;
}
// parse the line only if we are still parsing the current zone field
if( iparse_line == 1 ) {
++iline;
///// we need to keep parsing pieces as they cone
if( igot_descr == 0 ) {
#ifdef _DEBUG_
printf(" --- Looking for Zone keywords \n");
#endif
int np = zone->ParseKeywords( buf );
#ifdef _DEBUG_
printf(" --- Parsed %d item(s) \n",np);
#endif
if( np == 0 ) {
igot_descr = 1;
// rewind this line
iret = fseek( fp, ipos, SEEK_SET );
if( iret != 0 ) {
printf(" e Error seeking to proper parsing position: %ld \n", ipos);
free( buf );
return(3);
}
}
} else {
#ifdef _DEBUG_
printf(" --- Collecting Zone data \n");
#endif
}
}
}
// drop the buffer
free( buf );
//----------
// temporarily drop the zone object
#ifdef _DEBUG_
printf("HACK dropping the zone object\n");
#endif
delete zone; //HACK
printf("EXITING....\n");exit(0);//HACK
#ifdef _DEBUG_
printf(" i *** Skipping parsing of ZONE component *** \n");
// we do this by returning control to the main parsing loop
#endif
return(0);
}
int inTec_File::ParseComponent_Text()
{
#ifdef _DEBUG_
printf(" i Inside \"ParseComponent_Text()\" \n");
#endif
// seek back to the begining of the line that got us here so we can re-parse
int iret = fseek( fp, ipos, SEEK_SET );
if( iret != 0 ) {
printf(" e Error seeking to proper parsing position: %ld \n", ipos);
return( iret );
}
// retract line-number as the line will be re-read
--iline;
// Looking to parse multiple keywords and possibly over multiple lines
// T= <string>
// ZN= <zone to associate the string>
// X=
// Y=
// Z=
// R=
// The idea here is to keep ingesting in lines until we find a new component
// We ingest comments that can interrupt the text component
// Once a new component is detected, we wrap up the process
char *field=NULL;
size_t ifield_size=0,ifield_pos=0;
char *buf=NULL;
size_t ibuf_size=0;
int idone_text = 0; // flag for present text component termination
while( !feof( fp ) && idone_text <= 1 ) {
int ic;
// information about the position in the file
ipos = ftell( fp );
#ifdef _DEBUG_
printf(" i Position in file at %ld bytes, line %ld \n", ipos, iline+1 );
#endif
// prepare the buffer
memset( buf, '\0', ibuf_size );
// read a line of data; get count of bytes read
ic = inUtils_ReadTextline( &ibuf_size, &buf, fp );
// check error code
// sanitize the line
inUtils_TrimLeadingSpaceTextline( buf );
size_t isize=0;
while( isize < ibuf_size && buf[isize] != '\n' ) ++isize;
if( buf[isize] == '\n' ) buf[isize] = '\0';
#ifdef _DEBUG2_
printf("STRING (%p, %ld):%s\n", buf, isize, buf );
#endif
// attempt to identify this line as a new component to terminate parsing
int iparse_line=1; // default is to parse the line
iret = IdentifyComponent( buf );
//printf("FOUND iret=%d idone_text=%d \n", iret,idone_text);//HACK
// check if we have jumped to a new component under certain conditions...
if( iret > 0 ) { // we found a component
// only allow "stray" comment components to pass through
if( iret == Comment ) {
#ifdef _DEBUG_
printf(" --- Found comment (inside Text component) \n");
#endif
++iline;
// we will not be parsing this line
iparse_line = 0;
// store comment in strings
buf[ strlen(buf) ] = '\n';
strings[ iline ] = buf;
} else {
#ifdef _DEBUG2_
printf(" --- Found component (at _or_ after Text component) \n");
#endif
// increment termination condition variable
++idone_text;
// will not parse new components
if( idone_text > 1) iparse_line = 0;
}
} else {
#ifdef _DEBUG2_
printf(" --- The line is part of the Text component \n");
#endif
iparse_line = 1;
}
// parse the line only if we are still parsing the current text field
if( iparse_line == 1 ) {
++iline;
// keep enlarging the "field" block
ifield_size += isize;
char *tmpf = (char *) realloc(field, (ifield_size+1)*sizeof(char));
if( tmpf == NULL ) {
free( field );
free( buf );
return(-2);
}
field = tmpf;
tmpf = &( field[ifield_pos] );
memset(tmpf, '\0', isize+1);
for(size_t n=0;n<isize;++n) field[ ifield_pos + n ] = buf[n];
ifield_pos = ifield_size;
field[ ifield_pos ] = '\0';
#ifdef _DEBUG2_
printf(" --- The field so far: |%s|\n", field);
#endif
}
}
// drop the buffer
free( buf );
// set all parameters of the text component
// drop the text storage
free( field );
// seek back to the begining of this line and terminate this operation
iret = fseek( fp, ipos, SEEK_SET );
if( iret != 0 ) {
printf(" e Error seeking to proper parsing position: %ld \n", ipos);
return(2);
}
#ifdef _DEBUG_
printf(" i *** Skipping storing of TEXT component *** \n");
// we do this by returning control to the main parsing loop
#endif
return(0);
}
int inTec_File::ParseComponent_Geometry()
{
#ifdef _DEBUG_
printf(" i Inside \"ParseComponent_Geometry()\" \n");
#endif
// seek back to the begining of the line that got us here so we can re-parse
int iret = fseek( fp, ipos, SEEK_SET );
if( iret != 0 ) {
printf(" e Error seeking to proper parsing position: %ld \n", ipos);
return(1);
}
// retract line-number as the line will be re-read
--iline;