// File: /workspace/github_c_makefile_star2_O2/mcaimi[P]st/st.c
// Function: strhandle
void
strhandle(void)
{
  char *p = NULL;
  int j, narg, par;

  const struct { int idx; char *str; } osc_table[] = {
    { defaultfg, "foreground" },
    { defaultbg, "background" },
    { defaultcs, "cursor" }
  };

  term.esc &= ~(ESC_STR_END|ESC_STR);
  strparse();
  par = (narg = strescseq.narg) ? atoi(strescseq.args[0]) : 0;

  switch (strescseq.type) {
  case ']': /* OSC -- Operating System Command */
    switch (par) {
    case 0:
      if (narg > 1) {
        xsettitle(strescseq.args[1], 0);
        xseticontitle(strescseq.args[1]);
      }
      return;
    case 1:
      if (narg > 1)
        xseticontitle(strescseq.args[1]);
      return;
    case 2:
      if (narg > 1)
        xsettitle(strescseq.args[1], 0);
      return;
    case 52:
      if (narg > 2 && allowwindowops) {
        char *dec;

        dec = base64dec(strescseq.args[2]);
        if (dec) {
          xsetsel(dec);
          xclipcopy();
        } else {
          fprintf(stderr, "erresc: invalid base64\n");
        }
      }
      return;
   case 10:
   case 11:
   case 12:
     if (narg < 2)
       break;

     p = strescseq.args[1];

     if ((j = par - 10) < 0 || j >= LEN(osc_table))
       break; // should not be possible

     if (!strcmp(p, "?")) {
       osc_color_response(par, osc_table[j].idx, 0);
     } else if (xsetcolorname(osc_table[j].idx, p)) {
       fprintf(stderr, "erresc: invalid %s color: %s\n", osc_table[j].str, p);
     } else {
       tfulldirt();
     }
     return;
    case 4: /* color set */
      if (narg < 3)
        break;
      p = strescseq.args[2];
      /* FALLTHROUGH */
    case 104: /* color reset */
      j = (narg > 1) ? atoi(strescseq.args[1]) : -1;

     if ( p && !strcmp(p, "?")) {
       osc_color_response(j, 0, 1);
     } else if (xsetcolorname(j, p)) {
        if (par == 104 && narg <= 1) {
          xloadcols();
          return; /* color reset without parameter */
        }
        fprintf(stderr, "erresc: invalid color j=%d, p=%s\n",
                j, p ? p : "(null)");
      } else {
        /*
         * TODO if defaultbg color is changed, borders
         * are dirty
         */
        tfulldirt();
      }
      return;
    }
    break;
  case 'k': /* old title set compatibility */
    xsettitle(strescseq.args[0], 0);
    return;
  case 'P': /* DCS -- Device Control String */
    /* https://gitlab.com/gnachman/iterm2/-/wikis/synchronized-updates-spec */
    if (strstr(strescseq.buf, "=1s") == strescseq.buf)
      tsync_begin(), term.mode &= ~ESC_STR;  /* BSU */
    else if (strstr(strescseq.buf, "=2s") == strescseq.buf)
      tsync_end(), term.mode &= ~ESC_STR;  /* ESU */
    return;
  case '_': /* APC -- Application Program Command */
  case '^': /* PM -- Privacy Message */
    return;
  }

  if (debug) { 
    fprintf(stderr, "erresc: unknown str "); 
    strdump();
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
leaq 0x12fde(%rip), %rax     # 0x1d5b0
movl (%rax), %eax
movl %eax, 0x10(%rsp)
leaq 0x7271(%rip), %rax      # 0x11850
movq %rax, 0x18(%rsp)
leaq 0x12fc1(%rip), %rax     # 0x1d5ac
movl (%rax), %eax
movl %eax, 0x20(%rsp)
leaq 0x7263(%rip), %rax      # 0x1185b
movq %rax, 0x28(%rsp)
leaq 0x12fb0(%rip), %rax     # 0x1d5b4
movl (%rax), %eax
movl %eax, 0x30(%rsp)
leaq 0x7255(%rip), %rax      # 0x11866
movq %rax, 0x38(%rsp)
andb $-0x15, 0x140db(%rip)   # 0x1e6f8
movq 0x1611c(%rip), %r14     # 0x20740
andl $0x0, 0x161ad(%rip)     # 0x207d8
movq 0x1611e(%rip), %rax     # 0x20750
movb $0x0, (%r14,%rax)
cmpb $0x0, (%r14)
je 0xa693
xorl %r12d, %r12d
leaq 0x160f1(%rip), %rax     # 0x20738
movq %r14, %rcx
cmpq $0x10, %r12
je 0xa687
movq %rcx, 0x20(%rax,%r12,8)
incq %r12
incq %rcx
movzbl -0x1(%rcx), %edx
cmpl $0x3b, %edx
je 0xa66a
testl %edx, %edx
jne 0xa658
jmp 0xa670
movb $0x0, -0x1(%rcx)
jmp 0xa64a
movl %r12d, 0x16161(%rip)    # 0x207d8
movq 0x160da(%rip), %rdi     # 0x20758
callq 0x6520
movl %eax, %ebx
jmp 0xa698
movl %r12d, 0x1614a(%rip)    # 0x207d8
testl %r12d, %r12d
jne 0xa677
xorl %r12d, %r12d
xorl %ebx, %ebx
movzbl 0x16099(%rip), %eax     # 0x20738
leal -0x5e(%rax), %ecx
cmpl $0x2, %ecx
jb 0xa803
cmpl $0x50, %eax
je 0xa771
cmpl $0x6b, %eax
je 0xa755
cmpl $0x5d, %eax
jne 0xa7f3
cmpl $0xc, %ebx
ja 0xa7bf
movl %ebx, %eax
leaq 0x6c84(%rip), %rcx      # 0x1135c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x2, %r12d
jl 0xa7f3
movq 0x1606e(%rip), %r14     # 0x20760
leal -0xa(%rbx), %r15d
cmpb $0x3f, (%r14)
jne 0xa707
cmpb $0x0, 0x1(%r14)
je 0xaac3
shlq $0x4, %r15
movl 0x10(%rsp,%r15), %edi
movq %r14, %rsi
callq 0xb75f
testl %eax, %eax
je 0xaab0
leaq (%rsp,%r15), %rax
addq $0x10, %rax
movq 0x128c1(%rip), %rcx     # 0x1cff0
movq (%rcx), %rdi
movq 0x8(%rax), %rdx
leaq 0x7148(%rip), %rsi      # 0x11885
movq %r14, %rcx
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6970
movq 0x15ffc(%rip), %rdi     # 0x20758
xorl %esi, %esi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbdd2
cmpb $0x3d, (%r14)
jne 0xa803
cmpb $0x31, 0x1(%r14)
jne 0xa7a1
cmpb $0x73, 0x2(%r14)
jne 0xa7a1
leaq 0x13ec8(%rip), %rsi     # 0x1e658
pushq $0x1
popq %rdi
callq 0x6150
movb $0x1, 0x13eb1(%rip)     # 0x1e650
jmp 0xa7b6
cmpb $0x32, 0x1(%r14)
jne 0xa803
cmpb $0x73, 0x2(%r14)
jne 0xa803
movb $0x0, 0x13e9a(%rip)     # 0x1e650
andb $-0x5, 0x13f37(%rip)    # 0x1e6f4
jmp 0xa803
cmpl $0x34, %ebx
je 0xa85a
cmpl $0x68, %ebx
jne 0xa7f3
xorl %r14d, %r14d
cmpl $0x2, %r12d
jge 0xaa4d
pushq $-0x1
popq %rbp
leaq 0x70e1(%rip), %r15      # 0x118c5
jmp 0xaa7c
cmpl $0x3, %r12d
jge 0xaa46
leaq 0x16292(%rip), %rax     # 0x20a8c
cmpl $0x0, (%rax)
jne 0xa959
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %r12d
jl 0xa803
movq 0x15f41(%rip), %rdi     # 0x20760
jmp 0xa75c
cmpl $0x2, %r12d
jl 0xa803
jmp 0xa840
cmpl $0x2, %r12d
jl 0xa803
movq 0x15f27(%rip), %rdi     # 0x20760
xorl %esi, %esi
callq 0xbdd2
movq 0x15f19(%rip), %rdi     # 0x20760
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbd20
cmpl $0x3, %r12d
jl 0xa803
leaq 0x16255(%rip), %rax     # 0x20abc
cmpl $0x0, (%rax)
je 0xa803
movq 0x15ef5(%rip), %r15     # 0x20768
movq %rsp, %rax
movq %r15, (%rax)
movq %r15, %rdi
callq 0x63b0
addq $0x3, %rax
shrq $0x2, %rax
leaq (%rax,%rax,2), %rdi
incq %rdi
callq 0x6be0
movq %rax, %r13
leaq 0x2(%rax), %rbp
movq %rax, 0x8(%rsp)
cmpb $0x0, (%r15)
je 0xaad2
movq %rsp, %r12
movq %r12, %rdi
callq 0xacdf
movzbl %al, %eax
leaq 0x6bf0(%rip), %rbx      # 0x114b0
movb (%rax,%rbx), %r14b
movq %r12, %rdi
callq 0xacdf
movzbl %al, %eax
movb (%rax,%rbx), %r15b
movq %r12, %rdi
callq 0xacdf
movzbl %al, %eax
movb (%rax,%rbx), %bl
movq %r12, %rdi
callq 0xacdf
cmpb $-0x1, %r14b
je 0xaaf2
cmpb $-0x1, %r15b
je 0xaaf2
movzbl %al, %eax
leaq 0x6ba9(%rip), %rcx      # 0x114b0
movb (%rax,%rcx), %al
shlb $0x2, %r14b
movl %r15d, %ecx
shrb $0x4, %cl
andb $0x3, %cl
orb %r14b, %cl
movb %cl, -0x2(%rbp)
cmpb $-0x1, %bl
je 0xaaf7
shlb $0x4, %r15b
movl %ebx, %ecx
shrb $0x2, %cl
andb $0xf, %cl
orb %r15b, %cl
movb %cl, -0x1(%rbp)
cmpb $-0x1, %al
je 0xaafa
shlb $0x6, %bl
orb %bl, %al
addq $0x3, %r13
movb %al, (%rbp)
movq (%rsp), %r15
addq $0x3, %rbp
jmp 0xa8a1
movq 0x12690(%rip), %r12     # 0x1cff0
movq (%r12), %rcx
leaq 0x6f61(%rip), %rdi      # 0x118cc
pushq $0x14
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x6900
movq (%r12), %rdi
movsbl 0x15db4(%rip), %edx     # 0x20738
leaq 0x6ff5(%rip), %rsi      # 0x11980
xorl %eax, %eax
callq 0x6970
pushq $0x4
popq %r15
leaq 0x6ff8(%rip), %rbp      # 0x11995
xorl %r13d, %r13d
cmpq 0x15da9(%rip), %r13     # 0x20750
jae 0xab20
movq 0x15d8c(%rip), %rax     # 0x20740
movzbl (%rax,%r13), %r14d
testl %r14d, %r14d
je 0xaa2c
callq 0x63e0
movq (%rax), %rax
testb $0x40, 0x1(%rax,%r14,2)
movq (%r12), %rcx
je 0xa9e2
movl %r14d, %edi
movq %rcx, %rsi
callq 0x6560
incq %r13
jmp 0xa9a0
cmpl $0x1b, %r14d
je 0xaa06
cmpl $0xd, %r14d
je 0xa9fd
cmpl $0xa, %r14d
jne 0xaa1a
leaq 0x6f8b(%rip), %rdi      # 0x11986
jmp 0xaa0d
leaq 0x6f87(%rip), %rdi      # 0x1198b
jmp 0xaa0d
leaq 0x6f83(%rip), %rdi      # 0x11990
movq %r15, %rsi
movq %rbx, %rdx
callq 0x6900
jmp 0xa9dd
movq %rcx, %rdi
movq %rbp, %rsi
movl %r14d, %edx
xorl %eax, %eax
callq 0x6970
jmp 0xa9dd
movq (%r12), %rsi
pushq $0xa
popq %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6560
movq 0x15d1b(%rip), %r14     # 0x20768
movq 0x15d0c(%rip), %rdi     # 0x20760
callq 0x6520
movl %eax, %ebp
testq %r14, %r14
je 0xaa72
cmpb $0x3f, (%r14)
jne 0xaa6d
cmpb $0x0, 0x1(%r14)
je 0xaad8
movq %r14, %r15
jmp 0xaa7c
leaq 0x6e4c(%rip), %r15      # 0x118c5
xorl %r14d, %r14d
movl %ebp, %edi
movq %r14, %rsi
callq 0xb75f
testl %eax, %eax
je 0xaab0
cmpl $0x1, %r12d
jg 0xab2f
cmpl $0x68, %ebx
jne 0xab2f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb4d8
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x84d5
shlq $0x4, %r15
movl 0x10(%rsp,%r15), %esi
movl %ebx, %edi
xorl %edx, %edx
jmp 0xaadf
addq $-0x2, %rbp
jmp 0xaafa
pushq $0x1
popq %rdx
movl %ebp, %edi
xorl %esi, %esi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xabce
movq %r13, %rbp
jmp 0xaafa
decq %rbp
movb $0x0, (%rbp)
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xab5a
callq 0xb46b
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb40c
movq (%r12), %rcx
leaq 0x6e71(%rip), %rdi      # 0x1199c
pushq $0x5
jmp 0xab6d
movq 0x124ba(%rip), %rax     # 0x1cff0
movq (%rax), %rdi
leaq 0x6d63(%rip), %rsi      # 0x118a3
movl %ebp, %edx
movq %r15, %rcx
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6970
movq 0x1248f(%rip), %rax     # 0x1cff0
movq (%rax), %rcx
leaq 0x6d02(%rip), %rdi      # 0x1186d
pushq $0x17
popq %rsi
pushq $0x1
popq %rdx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6900