// File: /workspace/github_cpp_makefile_star2_O2/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, %r12d
leaq 0x300216(%rip), %r14    # 0x3292e0
movq %r14, %rdi
callq 0x9120
leaq 0x300531(%rip), %r13    # 0x32960a
movb %al, (%r13)
leal -0x147(%r12), %ecx
cmpl $0xc, %ecx
ja 0x29113
leaq 0xccbbb(%rip), %rdx     # 0xf5cac
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %eax, %eax
movb %al, 0x303734(%rip)     # 0x32c836
movb %al, 0x30372c(%rip)     # 0x32c834
movl $0x147, %r12d           # imm = 0x147
jmp 0x29527
cmpl $0x8, %r12d
jne 0x29137
movb 0x303717(%rip), %bl     # 0x32c836
testb %bl, %bl
jne 0x294d2
movl $0x131, %edi            # imm = 0x131
callq 0x9d23
pushq $0x8
popq %r12
jmp 0x29144
cmpl $0xff, %r12d
jle 0x29275
cmpb $0x0, 0x3036e9(%rip)    # 0x32c834
jne 0x2952e
jmp 0x29527
movb 0x3036da(%rip), %bl     # 0x32c836
jmp 0x294c3
movb 0x3036cf(%rip), %cl     # 0x32c836
incb %cl
movb %cl, 0x3036c7(%rip)     # 0x32c836
movb $0x20, %r12b
cmpb %al, %cl
jae 0x29382
movb $0x0, 0x3036b3(%rip)    # 0x32c834
movl $0x14d, %r12d           # imm = 0x14D
jmp 0x29527
movzbl 0x3036a3(%rip), %eax    # 0x32c836
xorl %ecx, %ecx
movb %cl, (%r14,%rax)
movb %cl, 0x303695(%rip)     # 0x32c834
movl $0x150, %r12d           # imm = 0x150
jmp 0x29527
leaq 0x30012f(%rip), %rbx    # 0x3292e0
leaq 0x300228(%rip), %rsi    # 0x3293e0
movq %rbx, %rdi
callq 0x9330
movq %rbx, %rdi
callq 0x9120
movb %al, (%r13)
movb %al, 0x303664(%rip)     # 0x32c836
movb $0x1, 0x30365b(%rip)    # 0x32c834
movl $0x149, %r12d           # imm = 0x149
jmp 0x2952e
movb 0x30364c(%rip), %al     # 0x32c836
testb %al, %al
je 0x292a8
decb %al
movb %al, 0x30363c(%rip)     # 0x32c836
jmp 0x292b2
movzbl 0x303630(%rip), %eax    # 0x32c836
leaq (%rax,%r14), %rsi
incq %rsi
leaq 0x2fd00c(%rip), %rbx    # 0x326220
movq %rbx, %rdi
callq 0x9330
movq %r14, %rdi
movq %rbx, %rsi
callq 0x9330
xorl %eax, %eax
movb %al, (%r13)
movb %al, 0x303603(%rip)     # 0x32c836
movb %al, 0x3035fb(%rip)     # 0x32c834
movl $0x148, %r12d           # imm = 0x148
jmp 0x29527
movb %al, 0x3035ec(%rip)     # 0x32c836
movb $0x0, 0x3035e3(%rip)    # 0x32c834
movl $0x14f, %r12d           # imm = 0x14F
jmp 0x29527
xorb $0x1, 0x3035d2(%rip)    # 0x32c835
movb $0x0, 0x3035ca(%rip)    # 0x32c834
movl $0x152, %r12d           # imm = 0x152
jmp 0x29527
testl %r12d, %r12d
je 0x29144
cmpl $0xd, %r12d
je 0x292c4
cmpl $0x1b, %r12d
jne 0x292f1
testb %al, %al
je 0x2934a
xorl %r12d, %r12d
movb %r12b, 0x30359a(%rip)   # 0x32c836
movb %r12b, (%r13)
movb %r12b, (%r14)
jmp 0x29144
movl $0x12f, %edi            # imm = 0x12F
callq 0x9d23
movb $0x0, 0x30357b(%rip)    # 0x32c834
movl $0x14b, %r12d           # imm = 0x14B
jmp 0x29527
leaq 0x1ffc05(%rip), %rax    # 0x228ed0
xorl %ecx, %ecx
movb %cl, (%rax)
movb %cl, 0x30355f(%rip)     # 0x32c834
leaq 0x300104(%rip), %rdi    # 0x3293e0
leaq 0x2ffffd(%rip), %rsi    # 0x3292e0
callq 0x9330
pushq $0xd
popq %r12
jmp 0x29527
cmpb $0x0, 0x30353c(%rip)    # 0x32c834
je 0x2931c
cmpb $0x0, 0x303536(%rip)    # 0x32c837
jne 0x2931c
movb $0x1, %al
movb %al, (%r13)
movb %r12b, (%r14)
movb $0x0, 0x1(%r14)
movb %al, 0x30351f(%rip)     # 0x32c836
jmp 0x2940d
cmpb $0x0, 0x303512(%rip)    # 0x32c835
je 0x2937c
movzbl %al, %eax
cmpl $0xf9, %eax
jb 0x29462
movb $-0x7, (%r13)
movb $0x0, 0xf9(%r14)
movl $0x132, %edi            # imm = 0x132
jmp 0x29408
xorl %eax, %eax
movb %al, 0x3034e2(%rip)     # 0x32c834
movb %al, 0x3034df(%rip)     # 0x32c837
leaq 0x2cd449(%rip), %rax    # 0x2f67a8
cmpb $0x60, (%rax)
jne 0x2941c
leaq 0x2fc4b9(%rip), %rax    # 0x325828
andl $0x0, (%rax)
callq 0x21d0b
jmp 0x2942b
movb 0x3034b4(%rip), %cl     # 0x32c836
cmpb %al, %cl
jae 0x29398
leal 0x1(%rcx), %eax
movb %al, 0x3034a7(%rip)     # 0x32c836
movzbl %cl, %eax
movb %r12b, (%r14,%rax)
jmp 0x2940d
cmpb $-0x7, %al
jb 0x293b7
movb $-0x7, %al
movb %al, (%r13)
movb $0x0, 0xf9(%r14)
movb %al, 0x303486(%rip)     # 0x32c836
movl $0x134, %edi            # imm = 0x134
jmp 0x29408
movzbl %al, %edx
leaq 0x1d9447(%rip), %rcx    # 0x202808
movl (%rcx), %ecx
addl $-0x3, %ecx
cmpl %edx, %ecx
jle 0x293f1
movzbl %al, %ecx
movb %r12b, (%r14,%rcx)
movzbl %al, %eax
movb $0x0, 0x1(%r14,%rax)
incq %rax
movb %al, 0x303453(%rip)     # 0x32c836
movq %r14, %rdi
callq 0x9120
movb %al, (%r13)
jmp 0x2940d
movb %cl, (%r13)
movzbl %cl, %eax
movb $0x0, (%r14,%rax)
movb %al, 0x303433(%rip)     # 0x32c836
movl $0x135, %edi            # imm = 0x135
callq 0x9d23
movb $0x0, 0x303420(%rip)    # 0x32c834
xorl %r12d, %r12d
jmp 0x29527
leaq 0x2fc405(%rip), %rax    # 0x325828
cmpl $0x0, (%rax)
je 0x2942b
orl $-0x1, (%rax)
leaq 0x1ffb0c(%rip), %rax    # 0x228f3e
movb $0x1b, %bl
cmpb $0x0, (%rax)
je 0x29721
leaq 0x1dbd14(%rip), %rax    # 0x205158
leaq 0x1dbd0e(%rip), %rcx    # 0x205159
movb (%rcx), %cl
orb (%rax), %cl
je 0x29721
movb $0x0, (%rax)
callq 0xf426
jmp 0x29721
leaq 0x1d939f(%rip), %rcx    # 0x202808
movl (%rcx), %ecx
addl $-0x3, %ecx
cmpl %ecx, %eax
jge 0x294ad
movzbl 0x3033bd(%rip), %ebx    # 0x32c836
leaq (%r14,%rbx), %rsi
leaq 0x2fcd9c(%rip), %r15    # 0x326220
movq %r15, %rdi
callq 0x9330
leaq (%r14,%rbx), %rdi
incq %rdi
movb %r12b, -0x1(%rdi)
movq %r15, %rsi
callq 0x9330
leal 0x1(%rbx), %eax
movb %al, 0x30338e(%rip)     # 0x32c836
jmp 0x293e3
movb %cl, (%r13)
movzbl %cl, %eax
movb $0x0, (%r14,%rax)
movl $0x133, %edi            # imm = 0x133
jmp 0x29408
movzbl %bl, %ebx
cmpb $0x0, (%r14,%rbx)
jne 0x294dc
testq %rbx, %rbx
je 0x29516
decb %bl
movb %bl, 0x30335c(%rip)     # 0x32c836
jmp 0x294c3
addq %rbx, %r14
leaq 0x2fcd3a(%rip), %r15    # 0x326220
leaq 0x2ffdf3(%rip), %rsi    # 0x3292e0
movq %r15, %rdi
callq 0x9330
leaq (%rbx,%r15), %rsi
incq %rsi
movq %r14, %rdi
callq 0x9330
leaq 0x2ffdd5(%rip), %rdi    # 0x3292e0
callq 0x9120
movb %al, (%r13)
jmp 0x29520
movl $0x130, %edi            # imm = 0x130
callq 0x9d23
movb $0x0, 0x30330d(%rip)    # 0x32c834
movb $0x0, 0x303309(%rip)    # 0x32c837
leaq 0x1d92d3(%rip), %rax    # 0x202808
movl (%rax), %eax
cmpl $0xfd, %eax
movl $0xfc, %ecx
cmovgel %eax, %ecx
addl $0xffffff04, %ecx       # imm = 0xFFFFFF04
movl 0x3032ec(%rip), %edi    # 0x32c83c
leaq 0x3000b9(%rip), %r14    # 0x329610
movl (%r14), %esi
addq 0x110a17(%rip), %rcx    # 0x139f78
pushq $0xf
popq %rdx
callq 0xe2d2
movl (%r14), %esi
movzbl 0x3032c3(%rip), %edi    # 0x32c836
leal (%rsi,%rdi), %r8d
incl %r8d
leaq 0x1d928f(%rip), %rax    # 0x202810
movl (%rax), %edx
leaq 0x1d928a(%rip), %rax    # 0x202814
movl (%rax), %ecx
movl 0x3032a9(%rip), %r9d    # 0x32c83c
imull %ecx, %r9d
leaq 0x2cd20a(%rip), %r10    # 0x2f67a8
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 0x1d92c9(%rip), %rdi    # 0x202890
cmpl (%rdi), %r15d
jge 0x295f8
movq %r12, %r13
leaq 0x1d9284(%rip), %rdi    # 0x20285a
addl $0x2, %esi
imull %edx, %esi
cmpb $0x0, (%rdi)
cmovel %esi, %r14d
leaq 0x1d9271(%rip), %rdx    # 0x20285b
cmpb $0x0, (%rdx)
cmovel %ecx, %eax
addl %r15d, %eax
movl %eax, %r15d
jmp 0x295fb
movq %r12, %r13
addl %r15d, %ecx
leaq 0x1d91fb(%rip), %rbx    # 0x202800
movl (%rbx), %edx
decl %edx
xorl %edi, %edi
movl %ecx, %esi
xorl %r8d, %r8d
callq 0xdedf
leal 0x2(%r15), %r12d
leaq 0x1d91f4(%rip), %rax    # 0x202814
movl (%rax), %ecx
addl %r12d, %ecx
movl (%rbx), %edx
decl %edx
xorl %edi, %edi
movl %ecx, %esi
xorl %r8d, %r8d
callq 0xdedf
leaq 0x2fcbe4(%rip), %rdi    # 0x326220
leaq 0xf21a1(%rip), %rsi     # 0x11b7e4
leaq 0x2ffc96(%rip), %rdx    # 0x3292e0
xorl %eax, %eax
callq 0x9060
movl 0x3031e5(%rip), %edi    # 0x32c83c
leaq 0x2fffb2(%rip), %rax    # 0x329610
movl (%rax), %esi
movq %r13, %rbx
cmpl $0xd, %ebx
jne 0x29685
leaq 0x2cd139(%rip), %rax    # 0x2f67a8
cmpb $0x60, (%rax)
jne 0x29685
leaq 0xee053(%rip), %rcx     # 0x1176ce
pushq $0xf
popq %rdx
callq 0xe2d2
jmp 0x296f7
leaq 0x2fcb94(%rip), %rcx    # 0x326220
pushq $0xf
popq %rdx
callq 0xe2d2
cmpl $0xd, %ebx
je 0x296f7
leaq 0x1d9174(%rip), %rax    # 0x202814
addl (%rax), %r15d
leal -0x1(%r14), %r13d
leaq 0x1d9162(%rip), %rax    # 0x202810
movl (%rax), %edx
addl %r13d, %edx
pushq $0xb
popq %r8
movl %r14d, %edi
movl %r15d, %esi
movl %r15d, %ecx
callq 0xdedf
cmpb $0x0, 0x303169(%rip)    # 0x32c835
je 0x296f7
leaq 0x1d913f(%rip), %rax    # 0x202814
addl (%rax), %r12d
leaq 0x1d9131(%rip), %rax    # 0x202810
addl (%rax), %r13d
pushq $0xb
popq %r8
movl %r14d, %edi
movl %r12d, %esi
movl %r13d, %edx
movl %r12d, %ecx
callq 0xdedf
leaq 0x1ff7d5(%rip), %rax    # 0x228ed3
cmpb $0x0, (%rax)
je 0x2971c
leaq 0x1ff7ae(%rip), %rax    # 0x228eb8
cmpq $0x0, (%rax)
je 0x2971c
leaq 0x1ff7b9(%rip), %rax    # 0x228ed0
cmpb $0x0, (%rax)
je 0x29721
callq 0xaa05
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq