// File: /workspace/github_cpp_makefile_star2_O2/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 0x3840(%rip), %rdi      # 0x10b5b
callq 0x77b0
movq 0x168(%rbx), %rax
cmpq 0x160(%rbx), %rax
je 0xd35c
leaq 0x3850(%rip), %rdi      # 0x10b87
callq 0x77b0
leaq 0x3878(%rip), %rdi      # 0x10bbb
callq 0x77b0
leaq 0x38a4(%rip), %rdi      # 0x10bf3
callq 0x77b0
pushq $0x64
popq %rax
jmp 0xd43d
addq $0x160, %rbx            # imm = 0x160
xorl %r15d, %r15d
movzbl (%r14,%r15), %eax
testl %eax, %eax
je 0xd379
cmpl $0xa, %eax
je 0xd379
incq %r15
jmp 0xd366
leaq 0x1(%r15), %rdi
callq 0x76e0
testq %rax, %rax
je 0xd44c
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x73e0
movb $0x0, (%r12,%r15)
leaq 0x2a78(%rip), %rsi      # 0xfe20
leaq 0x10(%rsp), %r15
movq %r12, 0x8(%rsp)
movq %r12, %rdi
movq %r15, %rdx
callq 0x7910
leaq 0x2519(%rip), %r12      # 0xf8dd
leaq 0x2a57(%rip), %r13      # 0xfe22
leaq 0x18(%rsp), %rbp
leaq 0x7(%rsp), %r14
xorl %edi, %edi
movq %r12, %rsi
movq %r15, %rdx
callq 0x7910
testq %rax, %rax
je 0xd431
cmpb $0x22, (%rax)
jne 0xd40e
movq 0x10(%rsp), %rcx
cmpb $0x22, -0x1(%rcx)
je 0xd3fb
movb $0x20, -0x1(%rcx)
movq %rax, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x7910
testq %rax, %rax
je 0xd431
movq %rbp, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x7890
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7270
movq %rbp, %rdi
callq 0x7200
jmp 0xd3d5
movq 0x8(%rsp), %rdi
callq 0x75c0
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x1
jmp 0xd356
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x7200
movq %rbx, %rdi
callq 0x78d0