// File: /workspace/github_cpp_makefile_star2_O1/nompelis[P]INTecplotLib/intecplot.cpp
// Function: inTec_File::ParseComponent_HeaderVariables(char*)
int inTec_File::ParseComponent_HeaderVariables( char *buf )
{
#ifdef _DEBUG_
   printf(" i Inside \"ParseComponent_HeaderVariables\" \n");
#endif
   // make sure we had not picked up a variables line earlier
   // (this is a possibiliy, where we may have to pick a mixed number of
   // variables from the file; we will deal with this later...)
   if( variables.size() > 0 ) {
      printf(" i Encountered an extra variables line in the file \n");
      printf(" --- For now we simply ignore it and hope for the best \n");
      printf("     (We hope that the number of variables does not change!) \n");
      return(100);
      // Should the number of variables be the same as previously (very likely),
      // there will be no problem parsing other zones. But if we wanted to be
      // very general about this treatment, we would pick up the _new_ variables
      // in a new container, compare the ones that are existing ones, and have a
      // way of parsing all the new ones but maintaining only the old ones.
      // This sounds easier than it is, especially with the current framework.
   }

   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 _DEBUG3_
   printf("---> stok: |%s| \n",token);
   printf("---> data: |%s| \n",data);
#endif

   // individual variables parsing
   s1 = NULL;
#ifdef _DEBUG4_
   printf("Inner loop\n");
#endif
   for(int k=1; ; s1 = NULL, ++k) {
      token = strtok_r( s1, " ,", &sr );   // search delim either ' ' or ','
      if( token == NULL ) break;
#ifdef _DEBUG3_
      printf("---> starting inner stok: |%s| \n",token);
#endif

      if( token[0] == '\"' ) {
#ifdef _DEBUG4_
         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 _DEBUG4_
         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 _DEBUG4_
      printf("Instance number %d: |%s|\n", k,token);
#endif

      // deal with string-token here...
      std::string sdum = token;
      variables.push_back( sdum );

#ifdef _DEBUG4_
printf("\n"); usleep(100000);
#endif
   }

   // drop duplicate buffer
   free( data );

   return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x3c5a(%rip), %rdi      # 0xfac3
callq 0x5580
movq 0x168(%rbx), %rax
cmpq 0x160(%rbx), %rax
je 0xbeac
leaq 0x3c6a(%rip), %rdi      # 0xfaef
callq 0x5580
leaq 0x3c92(%rip), %rdi      # 0xfb23
callq 0x5580
leaq 0x3cbe(%rip), %rdi      # 0xfb5b
callq 0x5580
movl $0x64, %eax
jmp 0xbfd9
addq $0x160, %rbx            # imm = 0x160
xorl %r15d, %r15d
movzbl (%r14,%r15), %eax
testl %eax, %eax
je 0xbec9
cmpl $0xa, %eax
je 0xbec9
incq %r15
jmp 0xbeb6
leaq 0x1(%r15), %rdi
callq 0x54f0
testq %rax, %rax
je 0xbfd4
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x52f0
movb $0x0, (%r12,%r15)
leaq 0x2e90(%rip), %rsi      # 0xed88
leaq 0x8(%rsp), %r14
movq %r12, 0x10(%rsp)
movq %r12, %rdi
movq %r14, %rdx
callq 0x5690
leaq 0x2931(%rip), %rsi      # 0xe845
xorl %edi, %edi
movq %r14, %rdx
callq 0x5690
testq %rax, %rax
je 0xbfc6
movq %rax, %r14
leaq 0x28(%rsp), %r15
leaq 0x8(%rsp), %r13
leaq 0x18(%rsp), %rbp
leaq 0x2905(%rip), %r12      # 0xe845
cmpb $0x22, (%r14)
jne 0xbf6f
movq 0x8(%rsp), %rax
cmpb $0x22, -0x1(%rax)
je 0xbf55
movb $0x20, -0x1(%rax)
movq %r14, %rdi
leaq 0x2e2b(%rip), %rsi      # 0xed8a
movq %r13, %rdx
callq 0x5690
movq %rax, %r14
testq %rax, %rax
je 0xbfc6
movq %r15, 0x18(%rsp)
movq %r14, %rdi
callq 0x5150
leaq (%rax,%r14), %rdx
movq %rbp, %rdi
movq %r14, %rsi
callq 0x5110
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x51b0
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0xbfad
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5390
xorl %edi, %edi
movq %r12, %rsi
movq %r13, %rdx
callq 0x5690
movq %rax, %r14
testq %rax, %rax
jne 0xbf40
movq 0x10(%rsp), %rdi
callq 0x5430
xorl %eax, %eax
jmp 0xbfd9
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0xc002
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5390
movq %rbx, %rdi
callq 0x5650