// File: nompelis[P]INTecplotLib/intecplot.cpp
// Function: inTec_Zone::ParseKeywords(char*)
int inTec_Zone::ParseKeywords( char *buf )
{
#ifdef _DEBUG_
   printf(" i Parsing zone keywords \n");
#endif
   size_t isize=0;
   while( buf[isize] != '\0' && buf[isize] != '\n' ) ++isize;

   char *data;
   // 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';
#ifdef _DEBUG3_
   printf("DATA: %s\n",data);
#endif

   // keep parsing for keywords and values
   int np=0;
   int ipar=0, ibra=0, iquote=0, ikey=0, ierror=0, iparse=0;
   char *s=data, *es=NULL;
   size_t n=0;
   while( n <= isize ) {
#ifdef _DEBUG2_
      printf(" (key: %d, quote: %d)  ", ikey,iquote);
      printf("  %c   s: %c   ", data[n],s[0]);
  //  printf("  %c   s: %c    (key: %d, quote: %d)  ", data[n],s[0],ikey,iquote);
#endif
      // space or comma as keyword delimeter
      if( data[n] == ' ' || data[n] == ',' ) {
         if( ikey == 0 ) {
              s = &( data[n+1] );
         } else if( ikey == 1 ) {
            if( data[n] == ',' ) { ierror = 1;printf("This is in error! (1)"); }
         } else if( ikey == 2 ) {
            if( data[n] == ',' ) { ierror = 1;printf("This is in error! (1b)");}
         } else if( ikey == 3 ) {
            if( iquote == 1 || ibra == 1 || ipar == 1 ) {
               // we continue parsing because the quote/bracket/paren. is open
            } else {
               // this terminates the keyword
               ikey = 0;
               // parsing should take place
               iparse = 1;
            }
         }

      } else 

      // equal sign
      if( data[n] == '=' ) {
         if( ikey == 0 ) {
            ierror = 1; printf("This is in error! (2)");
         } else if( ikey == 1 ) {
            // we are moving to the second stage
            es = &( data[n] );
            ikey = 2;
#ifdef _DEBUG2_
            printf(" (equal sign) ");
#endif
         } else if( ikey == 2 ) {
            ierror = 1; printf("This is in error! (2b)");
         } else if( ikey == 3 ) {
            if( iquote == 1 || ibra == 1 || ipar == 1 ) {
               // we continue parsing because the quote/bracket/paren. is open
#ifdef _DEBUG2_
               printf(" (equal sign in key=3) ");
#endif
            } else {
               ierror = 1; printf("This is in error! (3)");
            }
         }
      } else

      // double quote
      if( data[n] == '\"' ) {
         if( ikey < 2 ) {
            ierror = 1; printf("This is in error! (4) (stray quote) ");
         } else if( ikey == 2 ) {
            // entering data section of this keyword
            ikey = 3;
#ifdef _DEBUG2_
            printf(" (start data of keyword) ");
#endif
            // open quote
            iquote = 1;
         } else {
            if( data[n-1] == '\\' ) {
               // simply pick it up as a character
            } else {
               // it is a functional quote (marker)
               if( iquote == 1 ) {
                  // close the quote
                  iquote = 0;
             //   // indicate that we can parse
             //   ikey = 0;
             //   iparse = 1;
                  // let the next encounter terminate the parsing
               } else {
                  ierror = 1; printf("This is in error! (4b) (stray quote) ");
               }
            }
         }
      } else 

      // newline or null
      if( data[n] == '\n' || data[n] == '\0' ) {
         if( ikey == 3 ) {
            if( iquote == 1 || ibra == 1 || ipar == 1 ) {
               ierror = 1;printf("This is in error! (5) (unterminated quote/bracket/paren.) ");
            } else {
               ikey = 0;
               iparse = 1;
#ifdef _DEBUG2_
               printf(" (parsing ending) ");
#endif
            }
         } else if( ikey == 2 ) {
               ierror = 1; printf("This is in error! (5b) (empty keyword) ");
         } else if( ikey == 1 ) {
               ierror = 1; printf("This is in error! (5b) (empty keyword) ");
         } else {
            // termination of parsing everything
#ifdef _DEBUG2_
            printf(" (parsing ending) ");
#endif
         }
      } else 

      // open bracket
      if( data[n] == '[' ) {
         if( ikey < 2 ) {
            ierror = 1; printf("This is in error! (6) (stray bracket) ");
         } else if( ikey == 2 ) {
            // entering data section of this keyword...
            ikey = 3;
            // ...with an open bracket
            ibra = 1;
#ifdef _DEBUG2_
            printf(" (start data of keyword with bracket) ");
#endif
         } else {
            // simply open bracket
            ibra = 1;
#ifdef _DEBUG2_
            printf(" (open bracket) ");
#endif
         }
      } else 

      // close bracket
      if( data[n] == ']' ) {
         if( ikey < 3 ) {
            ierror = 1; printf("This is in error! (7a) (stray bracket) ");
         } else {
            if( ibra != 1 ) {
               ierror = 1; printf("This is in error! (7b) (stray bracket) ");
            } else {
               // simply close bracket
               ibra = 0;
#ifdef _DEBUG2_
               printf(" (close bracket) ");
#endif
            }
         }
      } else

      // open parenthesis
      if( data[n] == '(' ) {
         if( ikey < 2 ) {
            ierror = 1; printf("This is in error! (8) (stray paren.) ");
         } else if( ikey == 2 ) {
            // entering data section of this keyword...
            ikey = 3;
            // ...with an open parenthesis
            ipar = 1;
#ifdef _DEBUG2_
            printf(" (start data of keyword with paren.) ");
#endif
         } else {
            // simply open parenthesis
            ipar = 1;
#ifdef _DEBUG2_
            printf(" (open paren.) ");
#endif
         }
      } else

      // close parenthesis
      if( data[n] == ')' ) {
         if( ikey < 3 ) {
            ierror = 1; printf("This is in error! (9) (stray paren.) ");
         } else {
            if( ipar != 1 ) {
               ierror = 1; printf("This is in error! (9b) (stray paren.) ");
            } else {
               // simply close parenthesis
               ipar = 0;
#ifdef _DEBUG2_
               printf(" (close paren.) ");
#endif
            }
         }
      } else

      // anything else
      {
         if( ikey == 0 ) {
            // check whether we are in a line of data
            if( CheckCharForNum( data[n] ) == 1 ) {
               // terminate parsing immediately; the zone header must be done
               free( data );
#ifdef _DEBUG2_
               printf(" (numerical string) \n");
#endif
               return( -100 );
            }

            // encountered keyword
            ikey = 1;
#ifdef _DEBUG2_
            printf(" (start keyword) ");
#endif
         } else if( ikey == 2 ) {
            // entering data section of this keyword
            ikey = 3;
#ifdef _DEBUG2_
            printf(" (start data of keyword) ");
#endif
         }
      }

      // provide some output
      if( iparse == 1 ) {
#ifdef _DEBUG2_
         printf(" (parsing now)");
#endif
         data[n+0] = '\0';//HACK

         int iret = HandleKeyword( s );
         // allow for the possibility of dealiing with this differently...
         if( iret == 0 ) ++np;

         iparse = 0;
      }

      ++n;
#ifdef _DEBUG2_
      printf("\n");
#endif
   }

   // drop duplicate buffer
   free( data );

   if( ierror == 0 ) {
      return( np );
   } else {
#ifdef _DEBUG_
      printf(" --- Error returned: %d \n", -10*ierror );
#endif
      return( -10*ierror );
   }
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x117f9(%rip), %rdi     # 0x281b8
movb $0x0, %al
callq 0x13070
movq $0x0, 0x58(%rsp)
movq 0x60(%rsp), %rax
movq 0x58(%rsp), %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x7(%rsp)
je 0x16a00
movq 0x60(%rsp), %rax
movq 0x58(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
setne %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x16a0a
jmp 0x16a1a
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x58(%rsp)
jmp 0x169cf
movq 0x58(%rsp), %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
callq 0x145f0
movq %rax, 0x50(%rsp)
cmpq $0x0, 0x50(%rsp)
jne 0x16a46
movl $0xffffffff, 0x74(%rsp) # imm = 0xFFFFFFFF
jmp 0x17029
movq 0x50(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %rdx
callq 0x13c70
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movl $0x0, 0x4c(%rsp)
movl $0x0, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, 0x40(%rsp)
movl $0x0, 0x3c(%rsp)
movl $0x0, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x18(%rsp), %rax
cmpq 0x58(%rsp), %rax
ja 0x16fec
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
je 0x16af6
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2c, %eax
jne 0x16bb7
cmpl $0x0, 0x3c(%rsp)
jne 0x16b18
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
addq $0x1, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
jmp 0x16bb2
cmpl $0x1, 0x3c(%rsp)
jne 0x16b4a
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2c, %eax
jne 0x16b48
movl $0x1, 0x38(%rsp)
leaq 0x11692(%rip), %rdi     # 0x281d3
movb $0x0, %al
callq 0x13070
jmp 0x16bb0
cmpl $0x2, 0x3c(%rsp)
jne 0x16b7c
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2c, %eax
jne 0x16b7a
movl $0x1, 0x38(%rsp)
leaq 0x11676(%rip), %rdi     # 0x281e9
movb $0x0, %al
callq 0x13070
jmp 0x16bae
cmpl $0x3, 0x3c(%rsp)
jne 0x16bac
cmpl $0x1, 0x40(%rsp)
je 0x16b98
cmpl $0x1, 0x44(%rsp)
je 0x16b98
cmpl $0x1, 0x48(%rsp)
jne 0x16b9a
jmp 0x16baa
movl $0x0, 0x3c(%rsp)
movl $0x1, 0x34(%rsp)
jmp 0x16bac
jmp 0x16bae
jmp 0x16bb0
jmp 0x16bb2
jmp 0x16f97
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3d, %eax
jne 0x16c6d
cmpl $0x0, 0x3c(%rsp)
jne 0x16bed
movl $0x1, 0x38(%rsp)
leaq 0x1161c(%rip), %rdi     # 0x28200
movb $0x0, %al
callq 0x13070
jmp 0x16c68
cmpl $0x1, 0x3c(%rsp)
jne 0x16c0d
movq 0x50(%rsp), %rax
addq 0x18(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x2, 0x3c(%rsp)
jmp 0x16c66
cmpl $0x2, 0x3c(%rsp)
jne 0x16c2c
movl $0x1, 0x38(%rsp)
leaq 0x115f3(%rip), %rdi     # 0x28216
movb $0x0, %al
callq 0x13070
jmp 0x16c64
cmpl $0x3, 0x3c(%rsp)
jne 0x16c62
cmpl $0x1, 0x40(%rsp)
je 0x16c48
cmpl $0x1, 0x44(%rsp)
je 0x16c48
cmpl $0x1, 0x48(%rsp)
jne 0x16c4a
jmp 0x16c60
movl $0x1, 0x38(%rsp)
leaq 0x115d4(%rip), %rdi     # 0x2822d
movb $0x0, %al
callq 0x13070
jmp 0x16c62
jmp 0x16c64
jmp 0x16c66
jmp 0x16c68
jmp 0x16f95
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x22, %eax
jne 0x16d07
cmpl $0x2, 0x3c(%rsp)
jge 0x16ca3
movl $0x1, 0x38(%rsp)
leaq 0x115a9(%rip), %rdi     # 0x28243
movb $0x0, %al
callq 0x13070
jmp 0x16d02
cmpl $0x2, 0x3c(%rsp)
jne 0x16cbc
movl $0x3, 0x3c(%rsp)
movl $0x1, 0x40(%rsp)
jmp 0x16d00
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5c, %eax
jne 0x16cd5
jmp 0x16cfe
cmpl $0x1, 0x40(%rsp)
jne 0x16ce6
movl $0x0, 0x40(%rsp)
jmp 0x16cfc
movl $0x1, 0x38(%rsp)
leaq 0x11573(%rip), %rdi     # 0x28268
movb $0x0, %al
callq 0x13070
jmp 0x16cfe
jmp 0x16d00
jmp 0x16d02
jmp 0x16f93
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
je 0x16d31
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x16dc0
cmpl $0x3, 0x3c(%rsp)
jne 0x16d77
cmpl $0x1, 0x40(%rsp)
je 0x16d4d
cmpl $0x1, 0x44(%rsp)
je 0x16d4d
cmpl $0x1, 0x48(%rsp)
jne 0x16d65
movl $0x1, 0x38(%rsp)
leaq 0x11532(%rip), %rdi     # 0x2828e
movb $0x0, %al
callq 0x13070
jmp 0x16d75
movl $0x0, 0x3c(%rsp)
movl $0x1, 0x34(%rsp)
jmp 0x16dbb
cmpl $0x2, 0x3c(%rsp)
jne 0x16d96
movl $0x1, 0x38(%rsp)
leaq 0x1153c(%rip), %rdi     # 0x282c9
movb $0x0, %al
callq 0x13070
jmp 0x16db9
cmpl $0x1, 0x3c(%rsp)
jne 0x16db5
movl $0x1, 0x38(%rsp)
leaq 0x1151d(%rip), %rdi     # 0x282c9
movb $0x0, %al
callq 0x13070
jmp 0x16db7
jmp 0x16db7
jmp 0x16db9
jmp 0x16dbb
jmp 0x16f91
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5b, %eax
jne 0x16e1a
cmpl $0x2, 0x3c(%rsp)
jge 0x16df2
movl $0x1, 0x38(%rsp)
leaq 0x11508(%rip), %rdi     # 0x282f1
movb $0x0, %al
callq 0x13070
jmp 0x16e15
cmpl $0x2, 0x3c(%rsp)
jne 0x16e0b
movl $0x3, 0x3c(%rsp)
movl $0x1, 0x44(%rsp)
jmp 0x16e13
movl $0x1, 0x44(%rsp)
jmp 0x16e15
jmp 0x16f8f
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5d, %eax
jne 0x16e7a
cmpl $0x3, 0x3c(%rsp)
jge 0x16e4c
movl $0x1, 0x38(%rsp)
leaq 0x114d5(%rip), %rdi     # 0x28318
movb $0x0, %al
callq 0x13070
jmp 0x16e75
cmpl $0x1, 0x44(%rsp)
je 0x16e6b
movl $0x1, 0x38(%rsp)
leaq 0x114de(%rip), %rdi     # 0x28340
movb $0x0, %al
callq 0x13070
jmp 0x16e73
movl $0x0, 0x44(%rsp)
jmp 0x16e75
jmp 0x16f8d
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x28, %eax
jne 0x16ed4
cmpl $0x2, 0x3c(%rsp)
jge 0x16eac
movl $0x1, 0x38(%rsp)
leaq 0x114c5(%rip), %rdi     # 0x28368
movb $0x0, %al
callq 0x13070
jmp 0x16ecf
cmpl $0x2, 0x3c(%rsp)
jne 0x16ec5
movl $0x3, 0x3c(%rsp)
movl $0x1, 0x48(%rsp)
jmp 0x16ecd
movl $0x1, 0x48(%rsp)
jmp 0x16ecf
jmp 0x16f8b
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x29, %eax
jne 0x16f31
cmpl $0x3, 0x3c(%rsp)
jge 0x16f06
movl $0x1, 0x38(%rsp)
leaq 0x11491(%rip), %rdi     # 0x2838e
movb $0x0, %al
callq 0x13070
jmp 0x16f2f
cmpl $0x1, 0x48(%rsp)
je 0x16f25
movl $0x1, 0x38(%rsp)
leaq 0x11498(%rip), %rdi     # 0x283b4
movb $0x0, %al
callq 0x13070
jmp 0x16f2d
movl $0x0, 0x48(%rsp)
jmp 0x16f2f
jmp 0x16f89
cmpl $0x0, 0x3c(%rsp)
jne 0x16f76
movq 0x8(%rsp), %rdi
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x150c0
cmpl $0x1, %eax
jne 0x16f6c
movq 0x50(%rsp), %rdi
callq 0x14380
movl $0xffffff9c, 0x74(%rsp) # imm = 0xFFFFFF9C
jmp 0x17029
movl $0x1, 0x3c(%rsp)
jmp 0x16f87
cmpl $0x2, 0x3c(%rsp)
jne 0x16f85
movl $0x3, 0x3c(%rsp)
jmp 0x16f87
jmp 0x16f89
jmp 0x16f8b
jmp 0x16f8d
jmp 0x16f8f
jmp 0x16f91
jmp 0x16f93
jmp 0x16f95
jmp 0x16f97
cmpl $0x1, 0x34(%rsp)
jne 0x16fd9
movq 0x8(%rsp), %rdi
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x28(%rsp), %rsi
callq 0x14420
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
jne 0x16fd1
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
movl $0x0, 0x34(%rsp)
movq 0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x18(%rsp)
jmp 0x16abc
movq 0x50(%rsp), %rdi
callq 0x14380
cmpl $0x0, 0x38(%rsp)
jne 0x17007
movl 0x4c(%rsp), %eax
movl %eax, 0x74(%rsp)
jmp 0x17029
imull $0xfffffff6, 0x38(%rsp), %esi # imm = 0xFFFFFFF6
leaq 0x113c5(%rip), %rdi     # 0x283db
movb $0x0, %al
callq 0x13070
imull $0xfffffff6, 0x38(%rsp), %eax # imm = 0xFFFFFFF6
movl %eax, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)