// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathui.cpp
// Function: rpn_calc()
int rpn_calc()
{
   // rpn calculator
   if(last_touch_key == 999) {  // ? command sent from touch keyboard
      show_rpn_help = 1;
   }

   rpn_break = 0;
   if(edit_buffer[0] == 0) {  // empty line, exit calculator
      if(zoom_screen) remove_zoom();
      rpn_mode = 0;
      show_version_header();
      rpn_unnest();
      rpn_err_flag = 0;
      return 0;
   }

// rpn_err_flag = 0;
   rpn_mode = 1;
   show_version_header();
   strlwr(edit_buffer);
   strcpy(nmea_msg, edit_buffer);  // prepare to parse the line
   msg_col = 0;

if(strstr(edit_buffer, "z`")) goto poop;

   // process the line of calculator commands (separated by spaces)
   rpn_again:
   msg_field[0] = 0;
   while(get_msg_field()) {
//      if(!strcmp(msg_field, "?") == 0) {
      if(strcmp(msg_field, "?")) {
         if(last_touch_key == 999) { last_touch_key = 0; show_rpn_help = 0;}
      }

      if(rpn_break) {   // stop parsing line on any errors or "break" command
         rpn_break = 0;
         skip_next_rpn = 0;
         break;
      }

      if(skip_next_rpn > 1) {  // conditional was true skip second operand
         --skip_next_rpn;
      }
      else if(skip_next_rpn == 1) {  // skip next command
         skip_next_rpn = 0;
         continue;
      }
      else if(skip_next_rpn < 0) {  // skip rest of line
         skip_next_rpn = 0;
         break;
      }

      // see what we just got
      if((msg_field[0] == '.') && msg_field[1]) {  // floating point number
         if(valid_num(msg_field)) get_rpn_num();
         else {
            sprintf(out, "Invalid number: %s", msg_field);
            rpn_error(out);
            break;
         }
      }
      else if((msg_field[0] == '+') && msg_field[1]) { // signed number
         if(valid_num(msg_field)) get_rpn_num();
         else {
            sprintf(out, "Invalid number: %s", msg_field);
            rpn_error(out);
            break;
         }
      }
      else if((msg_field[0] == '-') && msg_field[1]) { // signed number
         if(valid_num(msg_field)) get_rpn_num();
         else {
            sprintf(out, "Invalid number: %s", msg_field);
            rpn_error(out);
            break;
         }
      }
      else if(isdigit(msg_field[0])) { // possible number
         if((msg_field[0] == '0') && (msg_field[1] == 'x')) {  // hex number
            if(valid_hex(&msg_field[2])) get_rpn_num();
            else {
               sprintf(out, "Invalid hex constant: %s", msg_field);
               rpn_error(out);
               break;
            }
         }
         else if((msg_field[0] == '0') && (msg_field[1] == 'o')) {  // octal number
            if(valid_octal(&msg_field[2])) get_rpn_num();
            else {
               sprintf(out, "Invalid octal constant: %s", msg_field);
               rpn_error(out);
               break;
            }
         }
         else if((msg_field[0] == '0') && (msg_field[1] == 'b')) {  // binary number
            if(valid_binary(&msg_field[2])) get_rpn_num();
            else {
               sprintf(out, "Invalid binary constant: %s", msg_field);
               rpn_error(out);
               break;
            }
         }
         else if(valid_num(msg_field)) {  // decimal number
            get_rpn_num();
         }
         else {
            sprintf(out, "Invalid number: %s", msg_field);
            rpn_error(out);
            break;
         }
      }
      else if(rpn_const()) ;   // calculator operations (constants, etc - rpn_const() must be called before rpn_math)
      else if(rpn_math()) ;    // calculator operations (math, etc)
      else if(!strcmp(msg_field, "?"))    { show_rpn_help = 1; }
      else if(!strcmp(msg_field, "help")) { show_rpn_help = 1; }
      else if(!strcmp(msg_field, "showdefs")) { show_rpn_help = 2; }
      else if(!strcmp(msg_field, "zoom")) {
         add_kbd(ESC_CHAR);
         start_calc_zoom(10);
      }
      else if(msg_field[0]) {
         sprintf(out, "Unknown operation: (%s)", msg_field);
         rpn_error(out);
         break;
      }
      else break;  // end of line
   }

poop:
   skip_next_rpn = 0;
   if(rpn_unnest()) {  // we got to the end of a user defined command, go back to where we were
      goto rpn_again;
   }

   rpn_show(); // show the rpn stack
   rpn_mode = (-1);

   return rpn_err_flag;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x1e391d(%rip), %r13    # 0x205228
cmpl $0x3e7, (%r13)          # imm = 0x3E7
jne 0x21922
leaq 0x303f10(%rip), %rax    # 0x32582c
movl $0x1, (%rax)
andl $0x0, 0x30b427(%rip)    # 0x32cd50
leaq 0x3079b0(%rip), %rax    # 0x3292e0
cmpb $0x0, (%rax)
je 0x21989
leaq 0x303eec(%rip), %rax    # 0x325828
movl $0x1, (%rax)
callq 0x68b5b
leaq 0x307992(%rip), %rbx    # 0x3292e0
movq %rbx, %rdi
callq 0x986c
leaq 0x303ed3(%rip), %rdi    # 0x325830
movq %rbx, %rsi
callq 0x9330
leaq 0x3042d8(%rip), %rax    # 0x325c44
andl $0x0, (%rax)
leaq 0xd6121(%rip), %rsi     # 0xf7a97
movq %rbx, %rdi
callq 0x9090
testq %rax, %rax
jne 0x21bd9
jmp 0x219bc
leaq 0x2d4e18(%rip), %rax    # 0x2f67a8
cmpb $0x0, (%rax)
je 0x2199a
callq 0x21d0b
leaq 0x303e87(%rip), %rax    # 0x325828
andl $0x0, (%rax)
callq 0x68b5b
callq 0x21db6
andl $0x0, 0x30cd63(%rip)    # 0x32e718
xorl %eax, %eax
jmp 0x21c02
leaq 0x30407d(%rip), %rbx    # 0x325a40
movb $0x0, (%rbx)
leaq 0x303e5f(%rip), %r15    # 0x32582c
leaq 0x2(%rbx), %r14
leaq 0xd690a(%rip), %r12     # 0xf82e2
callq 0x75767
testl %eax, %eax
je 0x21bd9
movzwl (%rbx), %eax
cmpw $0x3f, %ax
je 0x21a01
cmpl $0x3e7, (%r13)          # imm = 0x3E7
jne 0x21a01
andl $0x0, (%r13)
andl $0x0, (%r15)
cmpl $0x0, 0x30b348(%rip)    # 0x32cd50
jne 0x21ba9
movl 0x30b338(%rip), %ecx    # 0x32cd4c
cmpl $0x2, %ecx
jl 0x21a23
decl %ecx
movl %ecx, 0x30b32b(%rip)    # 0x32cd4c
jmp 0x21a39
cmpl $0x1, %ecx
jne 0x21a31
andl $0x0, 0x30b31d(%rip)    # 0x32cd4c
jmp 0x219d8
testl %ecx, %ecx
js 0x21bd9
cmpb $0x2e, %al
setne %cl
cmpw $0x100, %ax             # imm = 0x100
setb %dl
orb %cl, %dl
je 0x21a69
cmpw $0x100, %ax             # imm = 0x100
setb %cl
cmpb $0x2b, %al
setne %dl
orb %cl, %dl
je 0x21a69
cmpw $0x100, %ax             # imm = 0x100
setb %cl
cmpb $0x2d, %al
setne %dl
orb %cl, %dl
jne 0x21a83
movq %rbx, %rdi
callq 0x22a78
testl %eax, %eax
je 0x21bb2
callq 0x22b4d
jmp 0x219d8
movsbl %al, %ecx
addl $-0x30, %ecx
cmpl $0x9, %ecx
ja 0x21aba
movl %eax, %ecx
shrl $0x8, %ecx
cmpb $0x30, %al
setne %dl
cmpw $0x78, %cx
setne %sil
orb %dl, %sil
jne 0x21b41
movq %r14, %rdi
callq 0x22994
testl %eax, %eax
jne 0x21a79
jmp 0x21c11
callq 0x22c9e
testl %eax, %eax
jne 0x219d8
callq 0x2399b
testl %eax, %eax
jne 0x219d8
movzwl (%rbx), %eax
cmpw $0x3f, %ax
je 0x21b91
movw %ax, -0x2a(%rbp)
movq %rbx, %rdi
movq %r12, %rsi
pushq $0x5
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x21b91
movq %rbx, %rdi
leaq 0xd5ff8(%rip), %rsi     # 0xf7afd
pushq $0x9
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x21b9d
movq %rbx, %rdi
leaq 0xd5fe7(%rip), %rsi     # 0xf7b06
pushq $0x5
popq %rdx
callq 0x9380
testl %eax, %eax
jne 0x21c44
pushq $0x1b
popq %rdi
callq 0xd140
callq 0x1f6f0
jmp 0x219d8
cmpb $0x30, %al
setne %dl
cmpw $0x6f, %cx
setne %sil
orb %dl, %sil
jne 0x21b68
movq %r14, %rdi
callq 0x229ee
testl %eax, %eax
jne 0x21a79
jmp 0x21c21
cmpb $0x30, %al
setne %al
cmpw $0x62, %cx
setne %cl
orb %al, %cl
jne 0x21a69
movq %r14, %rdi
callq 0x22a33
testl %eax, %eax
jne 0x21a79
jmp 0x21c31
movl $0x1, (%r15)
jmp 0x219d8
movl $0x2, (%r15)
jmp 0x219d8
andl $0x0, 0x30b1a0(%rip)    # 0x32cd50
jmp 0x21bd9
leaq 0x304667(%rip), %rbx    # 0x326220
leaq 0xd5eda(%rip), %rsi     # 0xf7a9a
leaq 0x303e79(%rip), %rdx    # 0x325a40
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
callq 0x1f963
andl $0x0, 0x30b16c(%rip)    # 0x32cd4c
callq 0x21db6
testl %eax, %eax
jne 0x219bc
callq 0x225c6
leaq 0x303c2f(%rip), %rax    # 0x325828
orl $-0x1, (%rax)
movl 0x30cb16(%rip), %eax    # 0x32e718
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x304608(%rip), %rbx    # 0x326220
leaq 0xd5e8e(%rip), %rsi     # 0xf7aad
jmp 0x21bc0
leaq 0x3045f8(%rip), %rbx    # 0x326220
leaq 0xd5e97(%rip), %rsi     # 0xf7ac6
jmp 0x21bc0
leaq 0x3045e8(%rip), %rbx    # 0x326220
leaq 0xd5ea2(%rip), %rsi     # 0xf7ae1
jmp 0x21bc0
cmpb $0x0, -0x2a(%rbp)
je 0x21bd9
leaq 0x3045cf(%rip), %rbx    # 0x326220
leaq 0xd5eb3(%rip), %rsi     # 0xf7b0b
jmp 0x21bc0