// File: 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:
subq $0xa8, %rsp
movq %rdi, 0x98(%rsp)
movq %rsi, 0x90(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x9355(%rip), %rdi      # 0x295d0
movb $0x0, %al
callq 0x13070
movq 0x20(%rsp), %rdi
addq $0x160, %rdi            # imm = 0x160
callq 0x14e70
cmpq $0x0, %rax
jbe 0x202d3
leaq 0x935d(%rip), %rdi      # 0x295fd
movb $0x0, %al
callq 0x13070
leaq 0x9384(%rip), %rdi      # 0x29632
movb $0x0, %al
callq 0x13070
leaq 0x93af(%rip), %rdi      # 0x2966b
movb $0x0, %al
callq 0x13070
movl $0x64, 0xa4(%rsp)
jmp 0x2051e
movq $0x0, 0x88(%rsp)
movq 0x90(%rsp), %rax
movq 0x88(%rsp), %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x1f(%rsp)
je 0x2031c
movq 0x90(%rsp), %rax
movq 0x88(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
setne %al
movb %al, 0x1f(%rsp)
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x20326
jmp 0x2033c
movq 0x88(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x88(%rsp)
jmp 0x202df
movq 0x88(%rsp), %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
callq 0x145f0
movq %rax, 0x80(%rsp)
cmpq $0x0, 0x80(%rsp)
jne 0x20374
movl $0xffffffff, 0xa4(%rsp) # imm = 0xFFFFFFFF
jmp 0x2051e
movq 0x80(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %rdx
callq 0x13c70
movq 0x80(%rsp), %rax
movq 0x88(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x80(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rdi
leaq 0x92ec(%rip), %rsi      # 0x296aa
leaq 0x68(%rsp), %rdx
callq 0x14de0
movq %rax, 0x70(%rsp)
movq $0x0, 0x78(%rsp)
movl $0x1, 0x64(%rsp)
movq 0x78(%rsp), %rdi
leaq 0x8932(%rip), %rsi      # 0x28d1c
leaq 0x68(%rsp), %rdx
callq 0x14de0
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x70(%rsp)
jne 0x20406
jmp 0x20506
movq 0x70(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
jne 0x2045e
movq 0x68(%rsp), %rax
movsbl -0x1(%rax), %eax
cmpl $0x22, %eax
je 0x2042a
movq 0x68(%rsp), %rax
movb $0x20, -0x1(%rax)
movq 0x70(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rdi
leaq 0x926c(%rip), %rsi      # 0x296ac
leaq 0x68(%rsp), %rdx
callq 0x14de0
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x70(%rsp)
jne 0x2045c
jmp 0x20506
jmp 0x2045e
movq 0x70(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x3f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x14d40
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x40(%rsp), %rdi
callq 0x14c40
jmp 0x2048d
leaq 0x3f(%rsp), %rdi
callq 0x14120
movq 0x20(%rsp), %rdi
addq $0x160, %rdi            # imm = 0x160
leaq 0x40(%rsp), %rsi
callq 0x136d0
jmp 0x204af
leaq 0x40(%rsp), %rdi
callq 0x138c0
movq $0x0, 0x78(%rsp)
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x203de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
leaq 0x3f(%rsp), %rdi
callq 0x14120
jmp 0x2052d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x138c0
jmp 0x2052d
movq 0x80(%rsp), %rdi
callq 0x14380
movl $0x0, 0xa4(%rsp)
movl 0xa4(%rsp), %eax
addq $0xa8, %rsp
retq
movq 0x30(%rsp), %rdi
callq 0x14d20
nopw (%rax,%rax)