// File: /workspace/github_cpp_makefile_star2_O1/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, 0x320034(%rip)   # 0x343088
jl 0x2306c
leaq 0xea52b(%rip), %rdi     # 0x10d588
callq 0x2326e
movl $0x1, %eax
jmp 0x2325f
leaq 0x3187b5(%rip), %r15    # 0x33b828
movl (%r15), %r12d
movl $0x1, %eax
movl %eax, (%r15)
leaq 0x318bbf(%rip), %r13    # 0x33bc44
movl (%r13), %r14d
movl %eax, 0x31fcc1(%rip)    # 0x342d50
testl %edi, %edi
je 0x2309c
callq 0x811da
movl (%r13), %r14d
callq 0x811da
testl %eax, %eax
je 0x23160
leaq 0x318990(%rip), %rbx    # 0x33ba40
movsbl (%rbx), %edi
callq 0x9640
testl %eax, %eax
je 0x23179
movl $0x69666564, %eax       # imm = 0x69666564
xorl (%rbx), %eax
movl $0x656e69, %ecx         # imm = 0x656E69
xorl 0x3(%rbx), %ecx
orl %eax, %ecx
je 0x23192
leaq 0x318962(%rip), %rdi    # 0x33ba40
callq 0x22fc9
movl %eax, %ebx
testl %eax, %eax
js 0x231ab
movl %ebx, %r15d
leaq 0x31fc69(%rip), %rcx    # 0x342d60
movq (%rcx,%r15,8), %rdi
testq %rdi, %rdi
je 0x23114
callq 0x9440
leaq 0x31fc54(%rip), %rcx    # 0x342d60
movq $0x0, (%rcx,%r15,8)
movl 0x31ff6e(%rip), %eax    # 0x343088
testl %eax, %eax
je 0x23143
cmpl %eax, %ebx
jge 0x2313b
leaq (%rcx,%r15,8), %rcx
addq $0x8, %rcx
movq (%rcx), %rdx
movq %rdx, -0x8(%rcx)
addq $0x8, %rcx
incl %ebx
cmpl %ebx, %eax
jg 0x2312a
decl %eax
movl %eax, 0x31ff45(%rip)    # 0x343088
movslq (%r13), %rax
leaq 0x3186e2(%rip), %rcx    # 0x33b830
cmpb $0x0, (%rcx,%rax)
leaq 0x3186cf(%rip), %r15    # 0x33b828
jne 0x231bd
jmp 0x2322e
leaq 0xea4d8(%rip), %rdi     # 0x10d63f
callq 0x2326e
movl %r12d, (%r15)
movl $0x6, %eax
jmp 0x2325f
leaq 0xea427(%rip), %rdi     # 0x10d5a7
callq 0x2326e
movl %r12d, (%r15)
movl $0x2, %eax
jmp 0x2325f
leaq 0xea43b(%rip), %rdi     # 0x10d5d4
callq 0x2326e
movl %r12d, (%r15)
movl $0x16, %eax
jmp 0x2325f
cmpl $-0x1, %ebx
je 0x231bd
movl %r12d, (%r15)
movl $0x5, %eax
jmp 0x2325f
movslq (%r13), %rax
leaq 0x318668(%rip), %rcx    # 0x33b830
cmpb $0x0, (%rcx,%rax)
je 0x23235
movslq %r14d, %r14
addq 0x12cca8(%rip), %r14    # 0x14fe80
movq %r14, %rdi
callq 0x9120
leaq 0x1(%rax), %rdi
movl $0x1, %esi
callq 0x9230
testq %rax, %rax
je 0x2324b
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
callq 0x9340
cmpb $0x0, (%rbx)
jne 0x23214
movq %rbx, %rdi
callq 0x9120
movw $0x20, (%rbx,%rax)
movslq 0x31fe6d(%rip), %rax    # 0x343088
leaq 0x31fb3e(%rip), %rcx    # 0x342d60
movq %rbx, (%rcx,%rax,8)
incl %eax
movl %eax, 0x31fe5a(%rip)    # 0x343088
movl %r12d, (%r15)
xorl %eax, %eax
jmp 0x2325f
leaq 0xea3df(%rip), %rdi     # 0x10d61b
callq 0x2326e
movl %r12d, (%r15)
movl $0x7, %eax
jmp 0x2325f
leaq 0xea3a7(%rip), %rdi     # 0x10d5f9
callq 0x2326e
movl %r12d, (%r15)
movl $0x4, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq