// File: /workspace/github_cpp_makefile_star2_O1/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 0x313d6e(%rip), %r14    # 0x33f2e0
movq %r14, %rdi
callq 0x9120
leaq 0x314089(%rip), %r13    # 0x33f60a
movb %al, (%r13)
leal -0x147(%rbx), %ecx
cmpl $0xc, %ecx
ja 0x2b5b8
leaq 0xe0695(%rip), %rdx     # 0x10bc2c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %eax, %eax
movb %al, 0x31728e(%rip)     # 0x342836
movb %al, 0x317286(%rip)     # 0x342834
movl $0x147, %ebx            # imm = 0x147
jmp 0x2b904
cmpl $0x8, %ebx
jne 0x2b653
movb 0x31726f(%rip), %al     # 0x342836
testb %al, %al
je 0x2b7c0
decb %al
movb %al, 0x31725f(%rip)     # 0x342836
movq %rbx, -0x30(%rbp)
movzbl 0x317254(%rip), %ebx    # 0x342836
cmpb $0x0, (%r14,%rbx)
jne 0x2b60c
decq %rbx
movq %rbx, %rax
cmpq $-0x1, %rax
je 0x2b7d4
movb %al, 0x317237(%rip)     # 0x342836
movzbl %al, %ebx
decq %rax
cmpb $0x0, (%r14,%rbx)
je 0x2b5ef
addq %rbx, %r14
leaq 0x310c0a(%rip), %r15    # 0x33c220
leaq 0x313cc3(%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, 0x3171ea(%rip)    # 0x342834
movq -0x30(%rbp), %rbx
jmp 0x2b904
cmpl $0xff, %ebx
jg 0x2b904
testl %ebx, %ebx
je 0x2b904
cmpl $0xd, %ebx
je 0x2b7e3
cmpl $0x1b, %ebx
jne 0x2b811
testb %al, %al
je 0x2bafd
xorl %ebx, %ebx
movb %bl, 0x3171ad(%rip)     # 0x342836
movb %bl, (%r13)
movb %bl, (%r14)
jmp 0x2b904
xorb $0x1, 0x317199(%rip)    # 0x342835
movb $0x0, 0x317191(%rip)    # 0x342834
movl $0x152, %ebx            # imm = 0x152
jmp 0x2b904
movb 0x317183(%rip), %al     # 0x342836
testb %al, %al
je 0x2b7a5
decb %al
movb %al, 0x317173(%rip)     # 0x342836
jmp 0x2b7af
movb %al, 0x317168(%rip)     # 0x342836
movb $0x0, 0x31715f(%rip)    # 0x342834
movl $0x14f, %ebx            # imm = 0x14F
jmp 0x2b904
movzbl 0x317150(%rip), %eax    # 0x342836
leaq (%rax,%r14), %rsi
incq %rsi
leaq 0x310b2c(%rip), %rbx    # 0x33c220
movq %rbx, %rdi
callq 0x9340
movq %r14, %rdi
movq %rbx, %rsi
callq 0x9340
xorl %eax, %eax
movb %al, (%r13)
movb %al, 0x317123(%rip)     # 0x342836
movb %al, 0x31711b(%rip)     # 0x342834
movl $0x148, %ebx            # imm = 0x148
jmp 0x2b904
leaq 0x313bb6(%rip), %rbx    # 0x33f2e0
leaq 0x313caf(%rip), %rsi    # 0x33f3e0
movq %rbx, %rdi
callq 0x9340
movq %rbx, %rdi
callq 0x9120
movb %al, (%r13)
movb %al, 0x3170eb(%rip)     # 0x342836
movb $0x1, 0x3170e2(%rip)    # 0x342834
movl $0x149, %ebx            # imm = 0x149
jmp 0x2b904
movb 0x3170d4(%rip), %cl     # 0x342836
incb %cl
movb %cl, 0x3170cc(%rip)     # 0x342836
movl $0x20, %ebx
cmpb %al, %cl
jae 0x2b86a
movb $0x0, 0x3170b6(%rip)    # 0x342834
movl $0x14d, %ebx            # imm = 0x14D
jmp 0x2b904
movzbl 0x3170a7(%rip), %eax    # 0x342836
xorl %ecx, %ecx
movb %cl, (%r14,%rax)
movb %cl, 0x317099(%rip)     # 0x342834
movl $0x150, %ebx            # imm = 0x150
jmp 0x2b904
movl $0x12f, %edi            # imm = 0x12F
callq 0x9d80
movb $0x0, 0x31707e(%rip)    # 0x342834
movl $0x14b, %ebx            # imm = 0x14B
jmp 0x2b904
movl $0x131, %edi            # imm = 0x131
callq 0x9d80
movl $0x8, %ebx
jmp 0x2b904
movl $0x130, %edi            # imm = 0x130
callq 0x9d80
jmp 0x2b643
leaq 0x2136e6(%rip), %rax    # 0x23eed0
xorl %ecx, %ecx
movb %cl, (%rax)
movb %cl, 0x317040(%rip)     # 0x342834
leaq 0x313be5(%rip), %rdi    # 0x33f3e0
leaq 0x313ade(%rip), %rsi    # 0x33f2e0
callq 0x9340
movl $0xd, %ebx
jmp 0x2b904
cmpb $0x0, 0x31701c(%rip)    # 0x342834
je 0x2b83c
cmpb $0x0, 0x317016(%rip)    # 0x342837
jne 0x2b83c
movb $0x1, %al
movb %al, (%r13)
movb %bl, (%r14)
movb $0x0, 0x1(%r14)
movb %al, 0x316fff(%rip)     # 0x342836
jmp 0x2b8fb
cmpb $0x0, 0x316ff2(%rip)    # 0x342835
je 0x2b86a
movzbl %al, %eax
cmpl $0xf9, %eax
jb 0x2bb6a
movb $-0x7, (%r13)
movb $0x0, 0xf9(%r14)
movl $0x132, %edi            # imm = 0x132
jmp 0x2b8f6
movzbl 0x316fc5(%rip), %ecx    # 0x342836
cmpb %al, %cl
jae 0x2b884
leal 0x1(%rcx), %eax
movb %al, 0x316fb8(%rip)     # 0x342836
movb %bl, (%r14,%rcx)
jmp 0x2b8fb
cmpb $-0x7, %al
jb 0x2b8a3
movb $-0x7, %al
movb %al, (%r13)
movb $0x0, 0xf9(%r14)
movb %al, 0x316f9a(%rip)     # 0x342836
movl $0x134, %edi            # imm = 0x134
jmp 0x2b8f6
movzbl %al, %edx
leaq 0x1ecf5b(%rip), %rcx    # 0x218808
movl (%rcx), %ecx
addl $-0x3, %ecx
cmpl %edx, %ecx
jle 0x2b8df
movzbl %al, %ecx
movb %bl, (%r14,%rcx)
incb %al
movb %al, (%r13)
movzbl %al, %eax
movb $0x0, (%r14,%rax)
movb %al, 0x316f65(%rip)     # 0x342836
movq %r14, %rdi
callq 0x9120
movb %al, (%r13)
jmp 0x2b8fb
movb %cl, (%r13)
movzbl %cl, %eax
movb $0x0, (%r14,%rax)
movb %al, 0x316f45(%rip)     # 0x342836
movl $0x135, %edi            # imm = 0x135
callq 0x9d80
movb $0x0, 0x316f32(%rip)    # 0x342834
xorl %ebx, %ebx
movq %rbx, -0x30(%rbp)
cmpb $0x0, 0x316f25(%rip)    # 0x342834
jne 0x2b918
movb $0x0, 0x316f1f(%rip)    # 0x342837
leaq 0x1ecee9(%rip), %rax    # 0x218808
movl (%rax), %eax
cmpl $0xfd, %eax
movl $0xfc, %ecx
cmovgel %eax, %ecx
addl $0xffffff04, %ecx       # imm = 0xFFFFFF04
movl 0x316f02(%rip), %edi    # 0x34283c
leaq 0x313ccf(%rip), %rbx    # 0x33f610
movl (%rbx), %esi
addq 0x12462e(%rip), %rcx    # 0x14ff78
movl $0xf, %edx
callq 0xe7d0
movl (%rbx), %esi
movzbl 0x316ed9(%rip), %edi    # 0x342836
leal (%rsi,%rdi), %r8d
incl %r8d
leaq 0x1ecea5(%rip), %rax    # 0x218810
movl (%rax), %edx
leaq 0x1ecea0(%rip), %rbx    # 0x218814
movl (%rbx), %ecx
movl 0x316ebf(%rip), %r9d    # 0x34283c
imull %ecx, %r9d
leaq 0x2e0e20(%rip), %r13    # 0x30c7a8
xorl %eax, %eax
cmpb $0x60, (%r13)
leal 0x3(%rsi,%rdi), %esi
movl $0x0, %r12d
cmovel %ecx, %r12d
cmovnel %r8d, %esi
addl %r9d, %r12d
movl %esi, %r14d
imull %edx, %r14d
leaq 0x1ecede(%rip), %rdi    # 0x218890
cmpl (%rdi), %r12d
jge 0x2b9de
leaq 0x1ece9c(%rip), %rdi    # 0x21885a
addl $0x2, %esi
imull %edx, %esi
cmpb $0x0, (%rdi)
cmovel %esi, %r14d
leaq 0x1ece89(%rip), %rdx    # 0x21885b
cmpb $0x0, (%rdx)
cmovel %ecx, %eax
addl %r12d, %eax
movl %eax, %r12d
addl %r12d, %ecx
leaq 0x1ece18(%rip), %r15    # 0x218800
movl (%r15), %edx
decl %edx
xorl %edi, %edi
movl %ecx, %esi
xorl %r8d, %r8d
callq 0xe3c3
movl (%rbx), %eax
leal (%r12,%rax), %ecx
addl $0x2, %ecx
movl (%r15), %edx
decl %edx
xorl %edi, %edi
movl %ecx, %esi
xorl %r8d, %r8d
callq 0xe3c3
leaq 0x310806(%rip), %r15    # 0x33c220
leaq 0x105db3(%rip), %rsi    # 0x1317d4
leaq 0x3138b8(%rip), %rdx    # 0x33f2e0
movq %r15, %rdi
xorl %eax, %eax
callq 0x9060
cmpb $0x60, (%r13)
leaq 0x101c80(%rip), %rcx    # 0x12d6be
cmovneq %r15, %rcx
movq -0x30(%rbp), %r13
cmpl $0xd, %r13d
movl 0x316dec(%rip), %edi    # 0x34283c
leaq 0x313bb9(%rip), %rax    # 0x33f610
movl (%rax), %esi
cmovneq %r15, %rcx
movl $0xf, %edx
callq 0xe7d0
cmpl $0xd, %r13d
je 0x2bac1
movl (%rbx), %ecx
addl %r12d, %ecx
leaq 0x1ecd97(%rip), %rax    # 0x218810
movl (%rax), %eax
leal (%r14,%rax), %edx
decl %edx
movl %r14d, %edi
movl %ecx, %esi
movl $0xb, %r8d
callq 0xe3c3
cmpb $0x0, 0x316d9d(%rip)    # 0x342835
je 0x2bac1
movl (%rbx), %eax
leal (%r12,%rax), %ecx
addl $0x2, %ecx
leaq 0x1ecd66(%rip), %rax    # 0x218810
movl (%rax), %eax
leal -0x1(%r14,%rax), %edx
movl %r14d, %edi
movl %ecx, %esi
movl $0xb, %r8d
callq 0xe3c3
leaq 0x21340b(%rip), %rax    # 0x23eed3
cmpb $0x0, (%rax)
je 0x2bae6
leaq 0x2133e4(%rip), %rax    # 0x23eeb8
cmpq $0x0, (%rax)
je 0x2bae6
leaq 0x2133ef(%rip), %rax    # 0x23eed0
cmpb $0x0, (%rax)
je 0x2baeb
callq 0xab5f
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
movb %al, 0x316d2f(%rip)     # 0x342834
movb %al, 0x316d2c(%rip)     # 0x342837
leaq 0x2e0c96(%rip), %rax    # 0x30c7a8
cmpb $0x60, (%rax)
jne 0x2bb2b
leaq 0x30fd0a(%rip), %rax    # 0x33b828
movl $0x0, (%rax)
callq 0x23ad7
jmp 0x2bb3d
leaq 0x30fcf6(%rip), %rax    # 0x33b828
cmpl $0x0, (%rax)
je 0x2bb3d
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x2133fa(%rip), %rax    # 0x23ef3e
movb $0x1b, %r13b
cmpb $0x0, (%rax)
je 0x2baeb
leaq 0x1ef605(%rip), %rax    # 0x21b158
leaq 0x1ef5ff(%rip), %rcx    # 0x21b159
movb (%rcx), %cl
orb (%rax), %cl
je 0x2baeb
movb $0x0, (%rax)
callq 0xfb1a
jmp 0x2baeb
leaq 0x1ecc97(%rip), %rcx    # 0x218808
movl (%rcx), %ecx
addl $-0x3, %ecx
cmpl %ecx, %eax
jge 0x2bbb8
movq %rbx, %r12
movzbl 0x316cb2(%rip), %ebx    # 0x342836
leaq (%r14,%rbx), %rsi
leaq 0x310691(%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, 0x316c83(%rip)     # 0x342836
jmp 0x2b8d1
movb %cl, (%r13)
movzbl %cl, %eax
movb $0x0, (%r14,%rax)
movl $0x133, %edi            # imm = 0x133
jmp 0x2b8f6