// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathui.cpp
// Function: edit_string(int)
u08 edit_string(int c)
{
int row, col;
int attr;

   // perform an edit operation on the text string that we are building

   edit_ptr = strlen(edit_buffer);

   if(c == INS_CHAR) { // toggle insert mode
      insert_mode ^=1;
      first_edit = 0;
   }
   else if(c == LEFT_CHAR) {   // move cursor left
      if(edit_cursor) --edit_cursor;
      else BEEP(303);
      first_edit = 0;
   }
   else if(c == RIGHT_CHAR) {  // move cursor right
      if(++edit_cursor >= edit_ptr) {  // if past end of string, append blanks
         c = ' ';
         goto add_char;
      }
      first_edit = 0;
   }
   else if(c == END_CHAR) {  // move end-of-line
      edit_cursor = edit_ptr;
      first_edit = 0;
   }
   else if(c == HOME_CHAR) {  // move to start of line
      edit_cursor = 0;
      first_edit = 0;
   }
   else if(c == DOWN_CHAR) {  // delete to end-of-line
      edit_buffer[edit_cursor] = 0;
      first_edit = 0;
   }
   else if(c == UP_CHAR) {  // delete to start-of-line
      strcpy(out, &edit_buffer[edit_cursor+1]);
      strcpy(edit_buffer, out);
      edit_cursor = edit_ptr = 0;  // strlen(edit_buffer);
      first_edit = 0;
   }
   else if(c == PAGE_UP) {  // edit last line
      strcpy(edit_buffer, last_edit_buf);
      edit_cursor = edit_ptr = strlen(edit_buffer);
      first_edit = 1;
   }
   else if(c == DEL_CHAR) {  // delete char at cursor
      delete_char:
      if(edit_buffer[edit_cursor]) {
         strcpy(out, edit_buffer);
         strcpy(&edit_buffer[edit_cursor], &out[edit_cursor+1]);
         edit_ptr = strlen(edit_buffer);
      }
      else if(edit_cursor) {
         --edit_cursor;
         goto delete_char;
      }
      else BEEP(304);
      first_edit = 0;
   }
   else if(c == 0x08) { // back up and delete a char
      if(edit_cursor) {
         --edit_cursor;
         goto delete_char;
      }
      else BEEP(305);
   }
   else if(c >= 0x0100) {  // ignore unused cursor and function keys
   }
   else if(c == ESC_CHAR) {  // erase edit buffer
      if(edit_ptr) {  // if something is in the buffer,  erase the buffer
         edit_ptr = edit_cursor = c = 0;
         edit_buffer[edit_ptr] = 0;
      }
      else {  // ESC with nothing in the buffer,  abandon the edit
         first_edit = 0;
         no_auto_erase = 0;

         if(zoom_screen == '`') {  // cancel zoomed calculator
            rpn_mode = 0;
            remove_zoom();
         }
         else if(rpn_mode) {
            rpn_mode = (-1);
         }

         if(luxor && (prot_menu || show_prots)) {
            prot_menu = 0;
            redraw_screen();
         }
         return ESC_CHAR;
      }
   }
   else if(c == 0x0D) {  // end of edit
      script_pause = 0;
      first_edit = 0;
      strcpy(last_edit_buf, edit_buffer);
   }
   else if(c) {  // normal text char - insert it into the buffer
      if(first_edit && (no_auto_erase == 0)) {  // first char typed erases old buffer contents
         edit_ptr = 0;
         edit_buffer[edit_ptr++] = c;
         edit_buffer[edit_ptr] = 0;
         edit_cursor = edit_ptr;
      }
      else if(insert_mode) {
         if(edit_ptr >= (SLEN-1)) {  // gone too far
            edit_ptr = (SLEN-1);
            edit_buffer[edit_ptr] = 0;
            BEEP(306);
         }
         else if(edit_ptr >= (TEXT_COLS-3)) {  // gone too far
            edit_ptr = (TEXT_COLS-3);
            edit_buffer[edit_ptr] = 0;
            BEEP(307);
         }
         else {
            strcpy(out, &edit_buffer[edit_cursor]);
            edit_buffer[edit_cursor] = c;
            strcpy(&edit_buffer[edit_cursor+1], out);
            ++edit_cursor;
            edit_ptr = strlen(edit_buffer);
         }
      }
      else {  // overwrite mode
         add_char:
         if(edit_cursor >= edit_ptr) {  // append char to end of string
            if(edit_ptr >= (SLEN-1)) {  // gone too far
               edit_ptr = (SLEN-1);
               edit_buffer[edit_ptr] = 0;
               edit_cursor = edit_ptr;
               BEEP(308);
            }
            else if(edit_ptr >= (TEXT_COLS-3)) {  // gone too far
               edit_ptr = (TEXT_COLS-3);
               edit_buffer[edit_ptr] = 0;
               edit_cursor = edit_ptr;
               BEEP(309);
            }
            else {
               edit_buffer[edit_ptr] = c;
               edit_buffer[++edit_ptr] = 0;
               edit_cursor = edit_ptr;
               edit_ptr = strlen(edit_buffer);
            }
         }
         else {  // replace char in the string at the cursor
            edit_buffer[edit_cursor++] = c;
         }
      }

      c = 0;
      first_edit = 0;
   }

   if(first_edit == 0) no_auto_erase = 0;

   attr = WHITE;

   col = TEXT_COLS-SLEN-2;
   if(col < 0) col = 0;
   vidstr(e_row, EDIT_COL, WHITE, &blanks[col]);

   // kludgy,  but no-brainer way to erase old edit cursor
   col = (EDIT_COL+1+edit_cursor) * TEXT_WIDTH;
   row = e_row * TEXT_HEIGHT;
   if(zoom_screen == '`') {
      row += TEXT_HEIGHT;
      col += TEXT_WIDTH*2;
   }
   if(row < PLOT_TEXT_ROW) {  // undo Windows margin offsets
      if(no_x_margin == 0) col += TEXT_X_MARGIN; //*vc_font_scale / 100;
      if(no_y_margin == 0) row += TEXT_Y_MARGIN; //*vc_font_scale / 100;
   }
   line(0,row+TEXT_HEIGHT, SCREEN_WIDTH-1,row+TEXT_HEIGHT, BLACK);
   line(0,row+TEXT_HEIGHT+2, SCREEN_WIDTH-1,row+TEXT_HEIGHT+2, BLACK);

   sprintf(out, ">%s", edit_buffer);
   if((c == 0x0D) && (zoom_screen == '`')) {  // show empty edit line
      vidstr(e_row, EDIT_COL, WHITE, ">");
   }
   else vidstr(e_row, EDIT_COL, WHITE, out);  // show current edit line

   if(c != 0x0D) {  // draw the edit cursor under the char
      line(col,row+TEXT_HEIGHT, col+TEXT_WIDTH-1,row+TEXT_HEIGHT, PROMPT_COLOR);
      if(insert_mode) line(col,row+TEXT_HEIGHT+2, col+TEXT_WIDTH-1,row+TEXT_HEIGHT+2, PROMPT_COLOR);
   }

   if(fast_script && script_file && (script_pause == 0)) ;  // this makes script go faster,  but you can't see what is happening
   else refresh_page();

   return c;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
leaq 0x313a50(%rip), %r14    # 0x33f2e0
movq %r14, %rdi
callq 0x9120
leaq 0x313d6b(%rip), %r13    # 0x33f60a
movb %al, (%r13)
leal -0x147(%rbx), %ecx
cmpl $0xc, %ecx
ja 0x2b8d6
leaq 0xe037f(%rip), %rdx     # 0x10bc34
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %eax, %eax
movb %al, 0x316f70(%rip)     # 0x342836
movb %al, 0x316f68(%rip)     # 0x342834
movl $0x147, %ebx            # imm = 0x147
jmp 0x2bc5e
cmpl $0x8, %ebx
jne 0x2b8f7
movb 0x316f55(%rip), %al     # 0x342836
testb %al, %al
je 0x2bad8
movq %rbx, -0x30(%rbp)
decb %al
movb %al, 0x316f41(%rip)     # 0x342836
jmp 0x2b943
cmpl $0xff, %ebx
jg 0x2bae7
testl %ebx, %ebx
je 0x2bae7
cmpl $0xd, %ebx
je 0x2bb08
cmpl $0x1b, %ebx
jne 0x2bb36
testb %al, %al
je 0x2bb8f
xorl %ebx, %ebx
movb %bl, 0x316f09(%rip)     # 0x342836
movb %bl, (%r13)
movb %bl, (%r14)
jmp 0x2bae7
movq %rbx, -0x30(%rbp)
movb 0x316ef3(%rip), %al     # 0x342836
movzbl %al, %ebx
cmpb $0x0, (%r14,%rbx)
jne 0x2b970
decq %rbx
movq %rbx, %rax
cmpq $-0x1, %rax
je 0x2baf9
movb %al, 0x316ed3(%rip)     # 0x342836
movzbl %al, %ebx
decq %rax
cmpb $0x0, (%r14,%rbx)
je 0x2b953
addq %rbx, %r14
leaq 0x3108a6(%rip), %r15    # 0x33c220
leaq 0x31395f(%rip), %r12    # 0x33f2e0
movq %r15, %rdi
movq %r12, %rsi
callq 0x9340
leaq (%rbx,%r15), %rsi
incq %rsi
movq %r14, %rdi
callq 0x9340
movq %r12, %rdi
callq 0x9120
movb %al, (%r13)
movb $0x0, 0x316e86(%rip)    # 0x342834
movq -0x30(%rbp), %rbx
jmp 0x2bc5e
movb 0x316e79(%rip), %cl     # 0x342836
incb %cl
movb %cl, 0x316e71(%rip)     # 0x342836
movb $0x20, %bl
cmpb %al, %cl
jae 0x2bbca
movb $0x0, 0x316e5e(%rip)    # 0x342834
movl $0x14d, %ebx            # imm = 0x14D
jmp 0x2bc5e
movzbl 0x316e4f(%rip), %eax    # 0x342836
xorl %ecx, %ecx
movb %cl, (%r14,%rax)
movb %cl, 0x316e41(%rip)     # 0x342834
movl $0x150, %ebx            # imm = 0x150
jmp 0x2bc5e
leaq 0x3138dc(%rip), %rbx    # 0x33f2e0
leaq 0x3139d5(%rip), %rsi    # 0x33f3e0
movq %rbx, %rdi
callq 0x9340
movq %rbx, %rdi
callq 0x9120
movb %al, (%r13)
movb %al, 0x316e11(%rip)     # 0x342836
movb $0x1, 0x316e08(%rip)    # 0x342834
movl $0x149, %ebx            # imm = 0x149
jmp 0x2bc65
movb 0x316dfa(%rip), %al     # 0x342836
testb %al, %al
je 0x2babd
decb %al
movb %al, 0x316dee(%rip)     # 0x342836
jmp 0x2bac7
movzbl 0x316de5(%rip), %eax    # 0x342836
leaq (%rax,%r14), %rsi
incq %rsi
leaq 0x3107c1(%rip), %rbx    # 0x33c220
movq %rbx, %rdi
callq 0x9340
movq %r14, %rdi
movq %rbx, %rsi
callq 0x9340
xorl %eax, %eax
movb %al, (%r13)
movb %al, 0x316db8(%rip)     # 0x342836
movb %al, 0x316db0(%rip)     # 0x342834
movl $0x148, %ebx            # imm = 0x148
jmp 0x2bc5e
movb %al, 0x316da2(%rip)     # 0x342836
movb $0x0, 0x316d99(%rip)    # 0x342834
movl $0x14f, %ebx            # imm = 0x14F
jmp 0x2bc5e
xorb $0x1, 0x316d89(%rip)    # 0x342835
movb $0x0, 0x316d81(%rip)    # 0x342834
movl $0x152, %ebx            # imm = 0x152
jmp 0x2bc5e
movl $0x12f, %edi            # imm = 0x12F
callq 0x9d78
movb $0x0, 0x316d66(%rip)    # 0x342834
movl $0x14b, %ebx            # imm = 0x14B
jmp 0x2bc5e
movl $0x131, %edi            # imm = 0x131
callq 0x9d78
movl $0x8, %ebx
cmpb $0x0, 0x316d46(%rip)    # 0x342834
jne 0x2bc65
jmp 0x2bc5e
movl $0x130, %edi            # imm = 0x130
callq 0x9d78
jmp 0x2b9a7
leaq 0x2133c1(%rip), %rax    # 0x23eed0
xorl %ecx, %ecx
movb %cl, (%rax)
movb %cl, 0x316d1b(%rip)     # 0x342834
leaq 0x3138c0(%rip), %rdi    # 0x33f3e0
leaq 0x3137b9(%rip), %rsi    # 0x33f2e0
callq 0x9340
movl $0xd, %ebx
jmp 0x2bc5e
cmpb $0x0, 0x316cf7(%rip)    # 0x342834
je 0x2bb61
cmpb $0x0, 0x316cf1(%rip)    # 0x342837
jne 0x2bb61
movb $0x1, %al
movb %al, (%r13)
movb %bl, (%r14)
movb $0x0, 0x1(%r14)
movb %al, 0x316cda(%rip)     # 0x342836
jmp 0x2bc55
cmpb $0x0, 0x316ccd(%rip)    # 0x342835
je 0x2bbc4
movzbl %al, %eax
cmpl $0xf9, %eax
jb 0x2beb1
movb $-0x7, (%r13)
movb $0x0, 0xf9(%r14)
movl $0x132, %edi            # imm = 0x132
jmp 0x2bc50
xorl %eax, %eax
movb %al, 0x316c9d(%rip)     # 0x342834
movb %al, 0x316c9a(%rip)     # 0x342837
leaq 0x2e0c04(%rip), %rax    # 0x30c7a8
cmpb $0x60, (%rax)
jne 0x2be73
leaq 0x30fc74(%rip), %rax    # 0x33b828
movl $0x0, (%rax)
callq 0x238a8
jmp 0x2be85
movb 0x316c6c(%rip), %cl     # 0x342836
cmpb %al, %cl
jae 0x2bbe0
leal 0x1(%rcx), %eax
movb %al, 0x316c5f(%rip)     # 0x342836
movzbl %cl, %eax
movb %bl, (%r14,%rax)
jmp 0x2bc55
cmpb $-0x7, %al
jb 0x2bbff
movb $-0x7, %al
movb %al, (%r13)
movb $0x0, 0xf9(%r14)
movb %al, 0x316c3e(%rip)     # 0x342836
movl $0x134, %edi            # imm = 0x134
jmp 0x2bc50
movzbl %al, %edx
leaq 0x1ecbff(%rip), %rcx    # 0x218808
movl (%rcx), %ecx
addl $-0x3, %ecx
cmpl %edx, %ecx
jle 0x2bc39
movzbl %al, %ecx
movb %bl, (%r14,%rcx)
movzbl %al, %eax
movb $0x0, 0x1(%r14,%rax)
incq %rax
movb %al, 0x316c0b(%rip)     # 0x342836
movq %r14, %rdi
callq 0x9120
movb %al, (%r13)
jmp 0x2bc55
movb %cl, (%r13)
movzbl %cl, %eax
movb $0x0, (%r14,%rax)
movb %al, 0x316beb(%rip)     # 0x342836
movl $0x135, %edi            # imm = 0x135
callq 0x9d78
movb $0x0, 0x316bd8(%rip)    # 0x342834
xorl %ebx, %ebx
movb $0x0, 0x316bd2(%rip)    # 0x342837
leaq 0x1ecb9c(%rip), %rax    # 0x218808
movl (%rax), %eax
cmpl $0xfd, %eax
movl $0xfc, %ecx
cmovgel %eax, %ecx
addl $0xffffff04, %ecx       # imm = 0xFFFFFF04
movl 0x316bb5(%rip), %edi    # 0x34283c
leaq 0x313982(%rip), %r14    # 0x33f610
movl (%r14), %esi
addq 0x1242e0(%rip), %rcx    # 0x14ff78
movl $0xf, %edx
callq 0xe787
movl (%r14), %esi
movzbl 0x316b8a(%rip), %edi    # 0x342836
leal (%rsi,%rdi), %r8d
incl %r8d
leaq 0x1ecb56(%rip), %rax    # 0x218810
movl (%rax), %edx
leaq 0x1ecb51(%rip), %rax    # 0x218814
movl (%rax), %ecx
movl 0x316b70(%rip), %r9d    # 0x34283c
imull %ecx, %r9d
leaq 0x2e0ad1(%rip), %r10    # 0x30c7a8
xorl %eax, %eax
cmpb $0x60, (%r10)
leal 0x3(%rsi,%rdi), %esi
movl $0x0, %r15d
cmovel %ecx, %r15d
cmovnel %r8d, %esi
addl %r9d, %r15d
movl %esi, %r14d
imull %edx, %r14d
leaq 0x1ecb90(%rip), %rdi    # 0x218890
cmpl (%rdi), %r15d
jge 0x2bd31
movq %rbx, %r13
leaq 0x1ecb4b(%rip), %rdi    # 0x21885a
addl $0x2, %esi
imull %edx, %esi
cmpb $0x0, (%rdi)
cmovel %esi, %r14d
leaq 0x1ecb38(%rip), %rdx    # 0x21885b
cmpb $0x0, (%rdx)
cmovel %ecx, %eax
addl %r15d, %eax
movl %eax, %r15d
jmp 0x2bd34
movq %rbx, %r13
addl %r15d, %ecx
leaq 0x1ecac2(%rip), %rbx    # 0x218800
movl (%rbx), %edx
decl %edx
xorl %edi, %edi
movl %ecx, %esi
xorl %r8d, %r8d
callq 0xe38a
leal 0x2(%r15), %r12d
leaq 0x1ecabb(%rip), %rax    # 0x218814
movl (%rax), %ecx
addl %r12d, %ecx
movl (%rbx), %edx
decl %edx
xorl %edi, %edi
movl %ecx, %esi
xorl %r8d, %r8d
callq 0xe38a
leaq 0x3104ab(%rip), %rdi    # 0x33c220
leaq 0x105b48(%rip), %rsi    # 0x1318c4
leaq 0x31355d(%rip), %rdx    # 0x33f2e0
xorl %eax, %eax
callq 0x9060
movl 0x316aac(%rip), %edi    # 0x34283c
leaq 0x313879(%rip), %rax    # 0x33f610
movl (%rax), %esi
movq %r13, %rbx
cmpl $0xd, %ebx
jne 0x2bdc0
leaq 0x2e0a00(%rip), %rax    # 0x30c7a8
cmpb $0x60, (%rax)
jne 0x2bdc0
leaq 0x1019fa(%rip), %rcx    # 0x12d7ae
movl $0xf, %edx
callq 0xe787
jmp 0x2be38
leaq 0x310459(%rip), %rcx    # 0x33c220
movl $0xf, %edx
callq 0xe787
cmpl $0xd, %ebx
je 0x2be38
leaq 0x1eca37(%rip), %rax    # 0x218814
addl (%rax), %r15d
leal -0x1(%r14), %r13d
leaq 0x1eca25(%rip), %rax    # 0x218810
movl (%rax), %edx
addl %r13d, %edx
movl %r14d, %edi
movl %r15d, %esi
movl %r15d, %ecx
movl $0xb, %r8d
callq 0xe38a
cmpb $0x0, 0x316a2a(%rip)    # 0x342835
je 0x2be38
leaq 0x1eca00(%rip), %rax    # 0x218814
addl (%rax), %r12d
leaq 0x1ec9f2(%rip), %rax    # 0x218810
addl (%rax), %r13d
movl %r14d, %edi
movl %r12d, %esi
movl %r13d, %edx
movl %r12d, %ecx
movl $0xb, %r8d
callq 0xe38a
leaq 0x213094(%rip), %rax    # 0x23eed3
cmpb $0x0, (%rax)
je 0x2be5d
leaq 0x21306d(%rip), %rax    # 0x23eeb8
cmpq $0x0, (%rax)
je 0x2be5d
leaq 0x213078(%rip), %rax    # 0x23eed0
cmpb $0x0, (%rax)
je 0x2be62
callq 0xab54
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30f9ae(%rip), %rax    # 0x33b828
cmpl $0x0, (%rax)
je 0x2be85
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x2130b2(%rip), %rax    # 0x23ef3e
movb $0x1b, %bl
cmpb $0x0, (%rax)
je 0x2be62
leaq 0x1ef2be(%rip), %rax    # 0x21b158
leaq 0x1ef2b8(%rip), %rcx    # 0x21b159
movb (%rcx), %cl
orb (%rax), %cl
je 0x2be62
movb $0x0, (%rax)
callq 0xfa97
jmp 0x2be62
leaq 0x1ec950(%rip), %rcx    # 0x218808
movl (%rcx), %ecx
addl $-0x3, %ecx
cmpl %ecx, %eax
jge 0x2beff
movq %rbx, %r12
movzbl 0x31696b(%rip), %ebx    # 0x342836
leaq (%r14,%rbx), %rsi
leaq 0x31034a(%rip), %r15    # 0x33c220
movq %r15, %rdi
callq 0x9340
leaq (%r14,%rbx), %rdi
incq %rdi
movb %r12b, -0x1(%rdi)
movq %r15, %rsi
callq 0x9340
leal 0x1(%rbx), %eax
movb %al, 0x31693c(%rip)     # 0x342836
jmp 0x2bc2b
movb %cl, (%r13)
movzbl %cl, %eax
movb $0x0, (%r14,%rax)
movl $0x133, %edi            # imm = 0x133
jmp 0x2bc50