// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x498, %rsp            # imm = 0x498
cmpl $0x4, (%rsi)
jl 0x5276
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x2cf9
movq 0x20(%r14), %rdi
leaq -0x58(%rip), %rcx       # 0x51c5
pushq $0x3a
popq %rdx
movq %r15, %rsi
callq 0x2d23
cmpl $0x3, (%r15)
jne 0x5276
movq 0x10(%rsp), %rax
cmpb $0x3f, (%rax)
jne 0x5276
movq 0x18(%r14), %rdi
callq 0x2dd7
movl %eax, %ebp
movq 0x18(%rsp), %rdi
callq 0x2dd7
movl %eax, %r15d
movq 0x20(%rsp), %rdi
callq 0x2dd7
cmpl $0x2, %ebp
ja 0x5276
movl %eax, %r14d
testl %r15d, %r15d
sets %al
cmpl $0x10000, %r14d         # imm = 0x10000
setge %cl
orb %al, %cl
je 0x5288
addq $0x498, %rsp            # imm = 0x498
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4c9b1(%rip), %rdx     # 0x51c40
leaq 0x90(%rsp), %r13
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x2110
movl (%rbx), %r12d
movq %r13, %rdi
callq 0x20d0
movl %r12d, %edi
movq %r13, %rsi
movq %rax, %rdx
callq 0x283d
movl %r15d, %r12d
pushq $-0x1
popq %r13
movl %r13d, %r15d
movl %ebp, 0x4(%rsp)
cmpl %r12d, %r14d
jl 0x5391
movl %r12d, %edi
callq 0x21e0
testl %eax, %eax
jle 0x52f7
movq 0x488(%rbx,%r12,8), %rcx
testq %rcx, %rcx
je 0x52f9
movzbl 0x4(%rcx), %eax
jmp 0x52f9
xorl %eax, %eax
cmpl %ebp, %eax
jne 0x530e
cmpl $-0x1, %r13d
cmovnel %r12d, %r15d
cmovel %r12d, %r13d
movl %r13d, %eax
jmp 0x5386
cmpl $-0x1, %r15d
jne 0x533f
pushq $-0x1
popq %rax
movl %eax, %r15d
cmpl $-0x1, %r13d
je 0x5386
movl $0x400, %esi            # imm = 0x400
leaq 0x90(%rsp), %rbp
movq %rbp, %rdi
leaq 0x4c918(%rip), %rdx     # 0x51c4f
movl %r13d, %ecx
movl %r13d, %r8d
jmp 0x535c
movl $0x400, %esi            # imm = 0x400
leaq 0x90(%rsp), %rbp
movq %rbp, %rdi
leaq 0x4c8f9(%rip), %rdx     # 0x51c4f
movl %r13d, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x2110
movl (%rbx), %r15d
movq %rbp, %rdi
callq 0x20d0
movl %r15d, %edi
movq %rbp, %rsi
movl 0x4(%rsp), %ebp
movq %rax, %rdx
callq 0x283d
pushq $-0x1
popq %rax
movl %eax, %r15d
incq %r12
movl %eax, %r13d
jmp 0x52cf
cmpl $-0x1, %r15d
jne 0x53a0
movl %r13d, %r15d
cmpl $-0x1, %r13d
je 0x53db
leaq 0x4c8a8(%rip), %rdx     # 0x51c4f
leaq 0x90(%rsp), %r14
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
movl %r13d, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x2110
movl (%rbx), %ebp
movq %r14, %rdi
callq 0x20d0
movl %ebp, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0x283d
movl (%rbx), %edi
leaq 0x4c859(%rip), %rsi     # 0x51c3d
pushq $0x2
popq %rdx
addq $0x498, %rsp            # imm = 0x498
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x283d