// File: nompelis[P]INTecplotLib/intecplot.cpp
// Function: inTec_File::ParseComponent_Geometry()
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;

   // Looking to parse multiple keywords and 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 geometry 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_geom = 0;   // flag for present geometry component termination
   while( !feof( fp ) && idone_geom <= 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 _DEBUG3_
      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 );
#ifdef _DEBUG3_
printf("FOUND iret=%d idone_geom=%d \n", iret,idone_geom);
#endif
      // 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 Geometry 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 Geometry component)\n");
#endif
            // increment termination condition variable
            ++idone_geom;
            // will not parse new components
            if( idone_geom > 1) iparse_line = 0;
         }
      } else {
#ifdef _DEBUG2_
         printf(" --- The line is part of the Geometry component \n");
#endif
        iparse_line = 1;
      }

      // parse the line only if we are still parsing the current geometry 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 geometry 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 GEOMETRY component *** \n");
   // we do this by returning control to the main parsing loop
#endif

   return(0);
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x9c59(%rip), %rdi      # 0x29a2c
movb $0x0, %al
callq 0x13070
movq 0x20(%rsp), %rax
movq 0x110(%rax), %rdi
movq 0x128(%rax), %rsi
xorl %edx, %edx
callq 0x141f0
movl %eax, 0x84(%rsp)
cmpl $0x0, 0x84(%rsp)
je 0x1fe2f
movq 0x20(%rsp), %rax
movq 0x128(%rax), %rsi
leaq 0x993a(%rip), %rdi      # 0x29752
movb $0x0, %al
callq 0x13070
movl $0x1, 0x94(%rsp)
jmp 0x2020c
movq 0x20(%rsp), %rax
movq 0x120(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x120(%rax)
movq $0x0, 0x78(%rsp)
movq $0x0, 0x70(%rsp)
movq $0x0, 0x68(%rsp)
movq $0x0, 0x60(%rsp)
movq $0x0, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
movq 0x20(%rsp), %rax
movq 0x110(%rax), %rdi
callq 0x14990
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x1f(%rsp)
jne 0x1fea5
cmpl $0x1, 0x54(%rsp)
setle %al
movb %al, 0x1f(%rsp)
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x1feb2
jmp 0x2018d
movq 0x20(%rsp), %rax
movq 0x110(%rax), %rdi
callq 0x13030
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x128(%rax)
movq 0x128(%rax), %rsi
movq 0x120(%rax), %rdx
addq $0x1, %rdx
leaq 0x9ab7(%rip), %rdi      # 0x299a2
movb $0x0, %al
callq 0x13070
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rdx
xorl %esi, %esi
callq 0x13770
movq 0x20(%rsp), %rax
movq 0x110(%rax), %rdx
leaq 0x58(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x136b0
movl %eax, 0x50(%rsp)
movq 0x60(%rsp), %rdi
callq 0x13060
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %rcx
xorl %eax, %eax
cmpq 0x58(%rsp), %rcx
movb %al, 0x1e(%rsp)
jae 0x1ff5f
movq 0x60(%rsp), %rax
movq 0x48(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
setne %al
movb %al, 0x1e(%rsp)
movb 0x1e(%rsp), %al
testb $0x1, %al
jne 0x1ff69
jmp 0x1ff79
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x1ff35
movq 0x60(%rsp), %rax
movq 0x48(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x1ff9a
movq 0x60(%rsp), %rax
movq 0x48(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x20(%rsp), %rdi
movl $0x1, 0x44(%rsp)
movq 0x60(%rsp), %rsi
callq 0x142b0
movl %eax, 0x84(%rsp)
cmpl $0x0, 0x84(%rsp)
jle 0x2007d
cmpl $0x64, 0x84(%rsp)
jne 0x2005f
leaq 0x9a79(%rip), %rdi      # 0x29a54
movb $0x0, %al
callq 0x13070
movq 0x20(%rsp), %rax
movq 0x120(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x120(%rax)
movl $0x0, 0x44(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %rdi
callq 0x13540
movq 0x8(%rsp), %rcx
movq %rax, %rdx
movq 0x20(%rsp), %rax
movb $0xa, (%rcx,%rdx)
movq 0x60(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq %rax, %rdi
addq $0x130, %rdi            # imm = 0x130
movq 0x120(%rax), %rax
movq %rax, 0x38(%rsp)
leaq 0x38(%rsp), %rsi
callq 0x148b0
movq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x146a0
jmp 0x2007b
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
cmpl $0x1, 0x54(%rsp)
jle 0x20079
movl $0x0, 0x44(%rsp)
jmp 0x2007b
jmp 0x20085
movl $0x1, 0x44(%rsp)
cmpl $0x1, 0x44(%rsp)
jne 0x20188
movq 0x20(%rsp), %rax
movq 0x120(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x120(%rax)
movq 0x48(%rsp), %rax
addq 0x70(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rsi
addq $0x1, %rsi
shlq $0x0, %rsi
callq 0x14b50
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x200fe
movq 0x78(%rsp), %rdi
callq 0x14380
movq 0x60(%rsp), %rdi
callq 0x14380
movl $0xfffffffe, 0x94(%rsp) # imm = 0xFFFFFFFE
jmp 0x2020c
movq 0x30(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
addq 0x68(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
movq 0x48(%rsp), %rdx
addq $0x1, %rdx
xorl %esi, %esi
callq 0x13770
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
jae 0x20170
movq 0x60(%rsp), %rax
movq 0x28(%rsp), %rcx
movb (%rax,%rcx), %dl
movq 0x78(%rsp), %rax
movq 0x68(%rsp), %rcx
addq 0x28(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x20135
movq 0x70(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x78(%rsp), %rax
movq 0x68(%rsp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x1fe7b
movq 0x60(%rsp), %rdi
callq 0x14380
movq 0x78(%rsp), %rdi
callq 0x14380
movq 0x20(%rsp), %rax
movq 0x110(%rax), %rdi
movq 0x128(%rax), %rsi
xorl %edx, %edx
callq 0x141f0
movl %eax, 0x84(%rsp)
cmpl $0x0, 0x84(%rsp)
je 0x201f3
movq 0x20(%rsp), %rax
movq 0x128(%rax), %rsi
leaq 0x9573(%rip), %rdi      # 0x29752
movb $0x0, %al
callq 0x13070
movl $0x2, 0x94(%rsp)
jmp 0x2020c
leaq 0x988b(%rip), %rdi      # 0x29a85
movb $0x0, %al
callq 0x13070
movl $0x0, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq
nopl (%rax,%rax)