// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathui.cpp
// Function: rpn_define(int)
int rpn_define(int skip_first)
{
int i, j;
int def_col;
char *s;
int old_mode;

   // create a user define command

   if(num_rpn_defs >= MAX_RPN_DEFS) {
      edit_error("Too many DEFINE commands seen!");
      return 1;
   }
   old_mode = rpn_mode;
   rpn_mode = 1;   // make sure get_msg_field() works

   def_col = msg_col;
   rpn_break = 1;
   if(skip_first) {
      get_msg_field();
      def_col = msg_col;
   }

   if(get_msg_field()) {
      if(!isalpha(msg_field[0])) {
         edit_error("DEFINE name must start with a letter!");
         rpn_mode = old_mode;
         return 2;
      }
      if(!strcmp(msg_field, "define")) {
         edit_error("Cannot re-define the DEFINE command!");
         rpn_mode = old_mode;
         return 22;
      }

      i = find_rpn_def(msg_field);
      if(i >= 0) {  // redefine
         if(rpn_defs[i]) {      // delete old define
            free(rpn_defs[i]);
            rpn_defs[i] = 0;
         }
         if(num_rpn_defs) {
            for(j=i; j<num_rpn_defs; j++) {
               rpn_defs[j] = rpn_defs[j+1];
            }
            --num_rpn_defs;
         }
         if(nmea_msg[msg_col]) {
            goto do_define;
         }
      }
      else if(i == (-1)) {  // new define
         do_define:
         if(nmea_msg[msg_col]) {
            s = (char *) (void *) calloc(strlen(&nmea_msg[def_col])+1, sizeof(char));
            if(s) {
               strcpy(s, &nmea_msg[def_col]);
               if(s[0] == 0) strcat(s, " ");
               rpn_defs[num_rpn_defs] = s;
               ++num_rpn_defs;
            }
            else {
               edit_error("Could not allocate DEFINE memory!");
               rpn_mode = old_mode;
               return 4;
            }
         }
         else {
            edit_error("No operations specified for DEFINE!");
            rpn_mode = old_mode;
            return 7;
         }
      }
      else {
         rpn_mode = old_mode;
         return 5;  // should never happen
      }
   }
   else {
      edit_error("DEFINE name missing!");
      rpn_mode = old_mode;
      return 6;
   }

   rpn_mode = old_mode;
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl $0x64, 0x30bda6(%rip)   # 0x32d088
jl 0x212f7
leaq 0xd63b1(%rip), %rdi     # 0xf769c
callq 0x214df
pushq $0x1
jmp 0x214cf
leaq 0x30452a(%rip), %r15    # 0x325828
movl (%r15), %r12d
pushq $0x1
popq %rax
movl %eax, (%r15)
leaq 0x304936(%rip), %r13    # 0x325c44
movl (%r13), %r14d
movl %eax, 0x30ba38(%rip)    # 0x32cd50
testl %edi, %edi
je 0x21325
callq 0x75767
movl (%r13), %r14d
callq 0x75767
testl %eax, %eax
je 0x213c6
leaq 0x304707(%rip), %rax    # 0x325a40
movsbl (%rax), %edi
callq 0x9640
testl %eax, %eax
je 0x213dc
leaq 0x3046f0(%rip), %rdi    # 0x325a40
leaq 0xd638a(%rip), %rsi     # 0xf76e1
pushq $0x7
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x213f2
leaq 0x3046d2(%rip), %rdi    # 0x325a40
callq 0x21259
movl %eax, %ebx
leaq 0x30b9e4(%rip), %rsi    # 0x32cd60
testl %eax, %eax
js 0x2148a
movl %ebx, %r15d
movq (%rsi,%r15,8), %rdi
testq %rdi, %rdi
je 0x213a1
callq 0x9440
leaq 0x30b9c4(%rip), %rsi    # 0x32cd60
andq $0x0, (%rsi,%r15,8)
movl 0x30bce1(%rip), %eax    # 0x32d088
testl %eax, %eax
je 0x21410
leaq (%rsi,%r15,8), %rcx
addq $0x8, %rcx
cmpl %ebx, %eax
jle 0x21408
movq (%rcx), %rdx
movq %rdx, -0x8(%rcx)
addq $0x8, %rcx
incl %ebx
jmp 0x213b3
leaq 0xd6386(%rip), %rdi     # 0xf7753
callq 0x214df
movl %r12d, (%r15)
pushq $0x6
jmp 0x214cf
leaq 0xd62d8(%rip), %rdi     # 0xf76bb
callq 0x214df
movl %r12d, (%r15)
pushq $0x2
jmp 0x214cf
leaq 0xd62ef(%rip), %rdi     # 0xf76e8
callq 0x214df
movl %r12d, (%r15)
pushq $0x16
jmp 0x214cf
decl %eax
movl %eax, 0x30bc78(%rip)    # 0x32d088
movslq (%r13), %rax
leaq 0x304415(%rip), %rcx    # 0x325830
cmpb $0x0, (%rcx,%rax)
leaq 0x304402(%rip), %r15    # 0x325828
je 0x21483
movq %rsi, %r13
movslq %r14d, %r14
addq 0x118a53(%rip), %r14    # 0x139e88
movq %r14, %rdi
callq 0x9120
leaq 0x1(%rax), %rdi
pushq $0x1
popq %rsi
callq 0x9220
testq %rax, %rax
je 0x21496
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
callq 0x9330
cmpb $0x0, (%rbx)
jne 0x2146f
movq %rbx, %rdi
callq 0x9120
movw $0x20, (%rbx,%rax)
movslq 0x30bc12(%rip), %rax    # 0x32d088
movq %rbx, (%r13,%rax,8)
incl %eax
movl %eax, 0x30bc05(%rip)    # 0x32d088
movl %r12d, (%r15)
xorl %eax, %eax
jmp 0x214d0
cmpl $-0x1, %ebx
je 0x214a9
movl %r12d, (%r15)
pushq $0x5
jmp 0x214cf
leaq 0xd6270(%rip), %rdi     # 0xf770d
callq 0x214df
movl %r12d, (%r15)
pushq $0x4
jmp 0x214cf
movslq (%r13), %rax
leaq 0x30437c(%rip), %rcx    # 0x325830
cmpb $0x0, (%rcx,%rax)
jne 0x21428
leaq 0xd626a(%rip), %rdi     # 0xf772f
callq 0x214df
movl %r12d, (%r15)
pushq $0x7
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq