// File: jkingan[P]ladyheather/heathui.cpp
// Function: read_rpn_file(char*, int)
int read_rpn_file(char *rpn_name, int erase)
{
FILE *file;
int i;
char *s;
int old_mode;

   // read in user defined calculator functions from a file

   i = 0;
   if(rpn_name == 0) return (-1);
   s = strchr(rpn_name, '.');
   if(s == 0) {  // add .rpn extension if none given
//    strcat(rpn_name, ".rpn");
   }
   file = topen(rpn_name, "r");

   if(file) {
      old_mode = rpn_mode;
      rpn_err_flag = 0;
      while(fgets(out, sizeof out, file) != NULL) {
         msg_col = 0;
         msg_field[0] = 0;

         s = strchr(out, 0x0D);  // trim trailing CR and LF
         if(s) *s = 0;
         s = strchr(out, 0x0A);
         if(s) *s = 0;

         if(out[0] == 0) continue;
         if(out[0] == ' ') continue;
         if(out[0] == '\t') continue;

         strlwr(out);
         strcpy(edit_buffer, out);
         i = rpn_calc(); // execute the line
         if(i) {  // error in RPN file
            i = (-2);
            break;
         }
      }

      fclose(file);
      file = 0;

      rpn_mode = old_mode;
      if(erase) {  // erase calculator results from the plot area
         debug_text[0] = 0;
         debug_text2[0] = 0;
         debug_text3[0] = 0;
         debug_text4[0] = 0;
         debug_text5[0] = 0;
         debug_text6[0] = 0;
         debug_text7[0] = 0;
      }
   }
   else i = (-1);  // bad file name

   edit_buffer[0] = 0;
   nmea_msg[0] = 0;
   msg_col = 0;

   return i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x24(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x31119
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x312f5
movq -0x10(%rbp), %rdi
movl $0x2e, %esi
callq 0x9100
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x31134
jmp 0x31134
movq -0x10(%rbp), %rdi
leaq 0x152ece(%rip), %rsi    # 0x18400d
callq 0x9b20
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x312c7
leaq 0x3698ae(%rip), %rax    # 0x39aa08
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movl $0x0, 0x37278f(%rip)    # 0x3a38f8
movq -0x20(%rbp), %rdx
leaq 0x36a28c(%rip), %rdi    # 0x39b400
movl $0x201, %esi            # imm = 0x201
callq 0x95e0
cmpq $0x0, %rax
je 0x3125c
leaq 0x369c95(%rip), %rax    # 0x39ae24
movl $0x0, (%rax)
leaq 0x369a84(%rip), %rax    # 0x39ac20
movb $0x0, (%rax)
leaq 0x36a25a(%rip), %rdi    # 0x39b400
movl $0xd, %esi
callq 0x9100
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x311c2
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
leaq 0x36a237(%rip), %rdi    # 0x39b400
movl $0xa, %esi
callq 0x9100
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x311e5
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
leaq 0x36a214(%rip), %rax    # 0x39b400
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x311f9
jmp 0x31169
leaq 0x36a200(%rip), %rax    # 0x39b400
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x3120d
jmp 0x31169
leaq 0x36a1ec(%rip), %rax    # 0x39b400
movsbl (%rax), %eax
cmpl $0x9, %eax
jne 0x31221
jmp 0x31169
leaq 0x36a1d8(%rip), %rdi    # 0x39b400
callq 0x9850
leaq 0x36d28c(%rip), %rdi    # 0x39e4c0
leaq 0x36a1c5(%rip), %rsi    # 0x39b400
callq 0x9350
callq 0x31300
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x31257
movl $0xfffffffe, -0x24(%rbp) # imm = 0xFFFFFFFE
jmp 0x3125c
jmp 0x31169
movq -0x20(%rbp), %rdi
callq 0x9380
movq $0x0, -0x20(%rbp)
movl -0x34(%rbp), %ecx
leaq 0x369791(%rip), %rax    # 0x39aa08
movl %ecx, (%rax)
cmpl $0x0, -0x14(%rbp)
je 0x312c5
leaq 0x36c8fa(%rip), %rax    # 0x39db80
movb $0x0, (%rax)
leaq 0x36ca40(%rip), %rax    # 0x39dcd0
movb $0x0, (%rax)
leaq 0x36cb86(%rip), %rax    # 0x39de20
movb $0x0, (%rax)
leaq 0x36cccc(%rip), %rax    # 0x39df70
movb $0x0, (%rax)
leaq 0x36ce12(%rip), %rax    # 0x39e0c0
movb $0x0, (%rax)
leaq 0x36cf58(%rip), %rax    # 0x39e210
movb $0x0, (%rax)
leaq 0x36d09e(%rip), %rax    # 0x39e360
movb $0x0, (%rax)
jmp 0x312ce
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
leaq 0x36d1eb(%rip), %rax    # 0x39e4c0
movb $0x0, (%rax)
leaq 0x369731(%rip), %rax    # 0x39aa10
movb $0x0, (%rax)
leaq 0x369b3b(%rip), %rax    # 0x39ae24
movl $0x0, (%rax)
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop