// File: /workspace/github_c_makefile_star2_O1/uobikiemukot[P]yaft/./ctrlseq/osc.h
// Function: glyph_width_report
void glyph_width_report(struct terminal_t *term, void *arg)
{
	/*
	glyph width report
		* request *
		OSC 8900 ; Ps ; Pw ; ? : Pf : Pt ST
			Ps: reserved
			Pw: width (0 or 1 or 2)
			Pfrom: beginning of unicode code point
			Pto: end of unicode code point
			ST: BEL(0x07) or ESC(0x1B) BACKSLASH(0x5C)
		* answer *
		OSC 8900 ; Ps ; Pv ; Pw ; Pf : Pt ; Pf : Pt ; ... ST
			Ps: responce code
				0: ok (default)
				1: recognized but not supported
				2: not recognized
			Pv: reserved (maybe East Asian Width Version)
			Pw: width (0 or 1 or 2)
			Pfrom: beginning of unicode code point
			Pto: end of unicode code point
			ST: BEL(0x07) or ESC(0x1B) BACKSLASH(0x5C)
	ref
		http://uobikiemukot.github.io/yaft/glyph_width_report.html
		https://gist.github.com/saitoha/8767268
	*/
	struct parm_t *pt = (struct parm_t *) arg, sub_parm;
	int i, argc = pt->argc, width, from, to, left, right, w, wcw; //reserved
	char **argv = pt->argv, buf[BUFSIZE];

	if (argc < 4)
		return;

	reset_parm(&sub_parm);
	parse_arg(argv[3], &sub_parm, ':', isdigit_or_questionmark);

	if (sub_parm.argc != 3 || *sub_parm.argv[0] != '?')
		return;

	//reserved = dec2num(argv[1]);
	width = dec2num(argv[2]);
	from  = dec2num(sub_parm.argv[1]);
	to    = dec2num(sub_parm.argv[2]);

	if ((width < 0) || (width > 2))
		return;

	/* unicode private area: plane 16 (DRCSMMv1) is always half */
	if ((from < 0) || (to >= UCS2_CHARS))
		return;

	snprintf(buf, BUFSIZE, "\033]8900;0;0;%d;", width); /* OSC 8900 ; Ps; Pv ; Pw ; */
	ewrite(term->fd, buf, strlen(buf));

	left = right = -1;
	for (i = from; i <= to; i++) {
		wcw = wcwidth(i);
		if (wcw <= 0) /* zero width */
			w = 0;
		else if (term->glyph[i] == NULL) /* missing glyph */
			w = wcw;
		else
			w = term->glyph[i]->width;

		if (w != width) {
			if (right != -1) {
				snprintf(buf, BUFSIZE, "%d:%d;", left, right);
				ewrite(term->fd, buf, strlen(buf));
			} else if (left != -1) {
				snprintf(buf, BUFSIZE, "%d:%d;", left, left);
				ewrite(term->fd, buf, strlen(buf));
			}
			left = right = -1;
		} else {
			if (left == -1)
				left = i;
			else
				right = i;
		}
	}

	if (right != -1) {
		snprintf(buf, BUFSIZE, "%d:%d;", left, right);
		ewrite(term->fd, buf, strlen(buf));
	} else if (left != -1) {
		snprintf(buf, BUFSIZE, "%d:%d;", left, left);
		ewrite(term->fd, buf, strlen(buf));
	}

	ewrite(term->fd, "\033\\", 2); /* ST (ESC BACKSLASH) */
}

// Assembly:
cmpl $0x4, (%rsi)
jl 0x5eb0
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4a8, %rsp            # imm = 0x4A8
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x18(%rsp), %r15
movl $0x0, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r15)
movups %xmm0, 0x18(%r15)
movups %xmm0, 0x28(%r15)
movups %xmm0, 0x38(%r15)
movups %xmm0, 0x48(%r15)
movups %xmm0, 0x58(%r15)
movups %xmm0, 0x68(%r15)
movups %xmm0, 0x78(%r15)
movq 0x20(%rsi), %rdi
leaq -0x86(%rip), %rcx       # 0x5bca
movq %r15, %rsi
movl $0x3a, %edx
callq 0x2db0
cmpl $0x3, (%r15)
jne 0x5e9f
movq 0x20(%rsp), %rax
cmpb $0x3f, (%rax)
jne 0x5e9f
movq 0x18(%r14), %rdi
xorl %r15d, %r15d
movl $0x0, %r14d
testq %rdi, %rdi
je 0x5c96
xorl %esi, %esi
movl $0xa, %edx
callq 0x2d03
movq %rax, %r14
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x5caf
xorl %esi, %esi
movl $0xa, %edx
callq 0x2d03
movq %rax, %r15
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x5ccc
xorl %esi, %esi
movl $0xa, %edx
callq 0x2d03
movq %rax, 0x8(%rsp)
jmp 0x5cd5
movq $0x0, 0x8(%rsp)
cmpl $0x2, %r14d
ja 0x5e9f
testl %r15d, %r15d
js 0x5e9f
cmpl $0xffff, 0x8(%rsp)      # imm = 0xFFFF
jg 0x5e9f
leaq 0x4cf23(%rip), %rdx     # 0x52c20
leaq 0xa0(%rsp), %r13
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2120
movl (%rbx), %ebp
movq %r13, %rdi
callq 0x20d0
movl %ebp, %edi
movq %r13, %rsi
movq %rax, %rdx
callq 0x286e
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl 0x8(%rsp), %r15d
jg 0x5e44
movl %r15d, %eax
leaq (%rbx,%rax,8), %r12
addq $0x488, %r12            # imm = 0x488
movq %r14, 0x10(%rsp)
movl %r15d, %edi
callq 0x21f0
movl $0x0, %ecx
testl %eax, %eax
jle 0x5d79
movq (%r12), %rcx
testq %rcx, %rcx
je 0x5d77
movzbl 0x4(%rcx), %ecx
jmp 0x5d79
movl %eax, %ecx
cmpl %r14d, %ecx
jne 0x5d8e
cmpl $-0x1, %ebp
cmovnel %r15d, %r13d
cmovel %r15d, %ebp
jmp 0x5e2e
cmpl $-0x1, %r13d
jne 0x5de4
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $-0x1, %ebp
je 0x5e29
movl $0x400, %esi            # imm = 0x400
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
leaq 0x4ce75(%rip), %rdx     # 0x52c2f
movl %ebp, %ecx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x2120
movl (%rbx), %ebp
movq %r14, %rdi
callq 0x20d0
movl %ebp, %edi
movq %r14, %rsi
movq 0x10(%rsp), %r14
movq %rax, %rdx
callq 0x286e
jmp 0x5e29
movl $0x400, %esi            # imm = 0x400
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
leaq 0x4ce34(%rip), %rdx     # 0x52c2f
movl %ebp, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x2120
movl (%rbx), %ebp
movq %r14, %rdi
callq 0x20d0
movl %ebp, %edi
movq %r14, %rsi
movq 0x10(%rsp), %r14
movq %rax, %rdx
callq 0x286e
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leal 0x1(%r15), %eax
addq $0x8, %r12
cmpl %r15d, 0x8(%rsp)
movl %eax, %r15d
jg 0x5d57
cmpl $-0x1, %r13d
jne 0x5e52
movl %ebp, %r13d
cmpl $-0x1, %ebp
je 0x5e8c
leaq 0x4cdd6(%rip), %rdx     # 0x52c2f
leaq 0xa0(%rsp), %r14
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
movl %ebp, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x2120
movl (%rbx), %ebp
movq %r14, %rdi
callq 0x20d0
movl %ebp, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0x286e
movl (%rbx), %edi
leaq 0x4cd88(%rip), %rsi     # 0x52c1d
movl $0x2, %edx
callq 0x286e
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq