// File: nompelis[P]INTecplotLib/intecplot.cpp
// Function: inTec_File::ParseComponent_Text()
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 _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_text=%d \n", iret,idone_text);
#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 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;
#ifdef _DEBUG_
            printf(" i Added comment to strings line %ld \n", iline );
#endif
            // show the line
            printf(" [%ld]  %s", 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);
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0xa05b(%rip), %rdi      # 0x2997e
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 0x1f982
movq 0x20(%rsp), %rax
movq 0x128(%rax), %rsi
leaq 0x9dea(%rip), %rdi      # 0x29752
movb $0x0, %al
callq 0x13070
movl 0x84(%rsp), %eax
movl %eax, 0x94(%rsp)
jmp 0x1fd98
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 0x1f9f8
cmpl $0x1, 0x54(%rsp)
setle %al
movb %al, 0x1f(%rsp)
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x1fa05
jmp 0x1fd19
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 0x9f64(%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 0x1fab2
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 0x1fabc
jmp 0x1facc
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x1fa88
movq 0x60(%rsp), %rax
movq 0x48(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x1faed
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 0x1fc09
cmpl $0x64, 0x84(%rsp)
jne 0x1fbeb
leaq 0x9ea1(%rip), %rdi      # 0x299cf
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
movq 0x20(%rsp), %rax
movq 0x120(%rax), %rsi
leaq 0x9c25(%rip), %rdi      # 0x297e8
movb $0x0, %al
callq 0x13070
movq 0x20(%rsp), %rax
movq 0x120(%rax), %rsi
movq 0x60(%rsp), %rdx
leaq 0x97d3(%rip), %rdi      # 0x293b5
movb $0x0, %al
callq 0x13070
jmp 0x1fc07
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
cmpl $0x1, 0x54(%rsp)
jle 0x1fc05
movl $0x0, 0x44(%rsp)
jmp 0x1fc07
jmp 0x1fc11
movl $0x1, 0x44(%rsp)
cmpl $0x1, 0x44(%rsp)
jne 0x1fd14
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 0x1fc8a
movq 0x78(%rsp), %rdi
callq 0x14380
movq 0x60(%rsp), %rdi
callq 0x14380
movl $0xfffffffe, 0x94(%rsp) # imm = 0xFFFFFFFE
jmp 0x1fd98
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 0x1fcfc
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 0x1fcc1
movq 0x70(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x78(%rsp), %rax
movq 0x68(%rsp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x1f9ce
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 0x1fd7f
movq 0x20(%rsp), %rax
movq 0x128(%rax), %rsi
leaq 0x99e7(%rip), %rdi      # 0x29752
movb $0x0, %al
callq 0x13070
movl $0x2, 0x94(%rsp)
jmp 0x1fd98
leaq 0x9c76(%rip), %rdi      # 0x299fc
movb $0x0, %al
callq 0x13070
movl $0x0, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq
nopw (%rax,%rax)