// File: lotuskip[P]yuxtapa/client/input.cpp
// Function: (anonymous namespace)::check_typing()
bool check_typing()
{
	int k;
	wint_t key;

	if((k = get_wch(&key)) == KEY_CODE_YES)
	{
		switch(key)
		{
		/* In my experience, KEY_ENTER never works. But here it is in case
		 * it might, on some obscure platform. */
		case KEY_ENTER:
			typing_done();
			return true;
		// The rest appear to work fine:
		case KEY_BACKSPACE:
			if(type_pos > 0)
			{
				del(viewn_str, type_pos-1);
				typed_str = viewn_str;
				prev_str_it = prev_strs.end();
				if(--type_pos < printb_pos)
					printb_pos = max(0, printb_pos - MSG_WIN_X/2);
				--str_syms;
			}
			break;
		case KEY_DC: // delete key
			if(type_pos < str_syms)
			{
				del(viewn_str, type_pos);
				typed_str = viewn_str;
				prev_str_it = prev_strs.end();
				--str_syms;
			}
			break;
		case KEY_LEFT:
			if(type_pos > 0)
			{
				if(--type_pos < printb_pos)
					printb_pos = max(0, printb_pos - MSG_WIN_X/2);
			}
			break;
		case KEY_RIGHT:
			if(type_pos < str_syms)
			{
				if(++type_pos >= MSG_WIN_X)
					++printb_pos;
			}
			break;
		case KEY_HOME:
			type_pos = printb_pos = 0;
			break;
		case KEY_END:
			type_pos = str_syms;
			printb_pos = max(0, str_syms - MSG_WIN_X + 1);
			break;
		case KEY_UP:
			loop_up();
			break;
		case KEY_DOWN:
			loop_down();
			break;
		case KEY_NPAGE: // pageDown
			prev_str_it = prev_strs.end();
			if(viewn_str != typed_str)
				set_viewn_str(typed_str);
			else
			{
				set_viewn_str("");
				typed_str.clear();
			}	
			break;
		default: // unknown control key
			return false;
		}
	} // control key
	else if(k == OK) // key holds a proper wide character
	{
		if(key == KEYCODE_ENTER)
		{
			typing_done();
			return true;
		}
		// else
		if(key == 27 || key == '\t' || key == KEYCODE_INT) // escape, tab, interrupt
		{
			viewn_str.clear();
			typing_done();
			return true;
		}
		// else
		ins(viewn_str, key, type_pos);
		typed_str = viewn_str;
		prev_str_it = prev_strs.end();
		++str_syms; // string got longer
		++type_pos;
		if(type_pos == str_syms && type_pos >= MSG_WIN_X)
			++printb_pos;
	}
	else // no key at all
		return false;

	// color by chat/say:
	k = (clientstate == CS_TYPE_CHAT) ? 7 : 11;
	Base::print_str(mb_substr(viewn_str, printb_pos,
		min(str_syms - printb_pos, int(MSG_WIN_X))).c_str(),
		k, 0, MSG_WIN_Y-1, MSG_WIN, true);
	Base::type_cursor(type_pos - printb_pos);
	return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq 0x1b5f6(%rip), %rax     # 0x27fb8
movq (%rax), %rdi
leaq -0xc(%rbp), %rsi
callq 0x5320
movl %eax, -0x8(%rbp)
cmpl $0x100, %eax            # imm = 0x100
jne 0xcdd9
movl -0xc(%rbp), %eax
movl %eax, -0xcc(%rbp)
subl $0x102, %eax            # imm = 0x102
je 0xccdc
jmp 0xc9f2
movl -0xcc(%rbp), %eax
subl $0x103, %eax            # imm = 0x103
je 0xccd2
jmp 0xca05
movl -0xcc(%rbp), %eax
subl $0x104, %eax            # imm = 0x104
je 0xcbdd
jmp 0xca18
movl -0xcc(%rbp), %eax
subl $0x105, %eax            # imm = 0x105
je 0xcc38
jmp 0xca2b
movl -0xcc(%rbp), %eax
subl $0x106, %eax            # imm = 0x106
je 0xcc7b
jmp 0xca3e
movl -0xcc(%rbp), %eax
subl $0x107, %eax            # imm = 0x107
je 0xcaa6
jmp 0xca4d
movl -0xcc(%rbp), %eax
subl $0x14a, %eax            # imm = 0x14A
je 0xcb66
jmp 0xca60
movl -0xcc(%rbp), %eax
subl $0x152, %eax            # imm = 0x152
je 0xcce6
jmp 0xca73
movl -0xcc(%rbp), %eax
subl $0x157, %eax            # imm = 0x157
je 0xca98
jmp 0xca82
movl -0xcc(%rbp), %eax
subl $0x168, %eax            # imm = 0x168
je 0xcc92
jmp 0xcdcb
callq 0xd0b0
movb $0x1, -0x1(%rbp)
jmp 0xcfcf
movswl 0x1c593(%rip), %eax     # 0x29040
cmpl $0x0, %eax
jle 0xcb61
movswl 0x1c583(%rip), %esi     # 0x29040
subl $0x1, %esi
leaq 0x1c559(%rip), %rdi     # 0x29020
callq 0x1a270
leaq 0x1c52d(%rip), %rdi     # 0x29000
leaq 0x1c546(%rip), %rsi     # 0x29020
callq 0x5060
leaq 0x1c502(%rip), %rdi     # 0x28fe8
callq 0xa9f0
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0xd400
movq -0x18(%rbp), %rax
movq %rax, 0x1c541(%rip)     # 0x29048
movw 0x1c532(%rip), %ax      # 0x29040
addw $-0x1, %ax
movw %ax, 0x1c527(%rip)      # 0x29040
cwtl
movswl 0x1c52f(%rip), %ecx     # 0x29050
cmpl %ecx, %eax
jge 0xcb4f
movl $0x0, -0x24(%rbp)
movswl 0x1c51d(%rip), %eax     # 0x29050
subl $0x1c, %eax
movl %eax, -0x28(%rbp)
leaq -0x24(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xd440
movl (%rax), %eax
movw %ax, 0x1c501(%rip)      # 0x29050
movw 0x1c4fc(%rip), %ax      # 0x29052
addw $-0x1, %ax
movw %ax, 0x1c4f1(%rip)      # 0x29052
jmp 0xcdd4
movswl 0x1c4d3(%rip), %eax     # 0x29040
movswl 0x1c4de(%rip), %ecx     # 0x29052
cmpl %ecx, %eax
jge 0xcbd8
movswl 0x1c4c1(%rip), %esi     # 0x29040
leaq 0x1c49a(%rip), %rdi     # 0x29020
callq 0x1a270
leaq 0x1c46e(%rip), %rdi     # 0x29000
leaq 0x1c487(%rip), %rsi     # 0x29020
callq 0x5060
leaq 0x1c443(%rip), %rdi     # 0x28fe8
callq 0xa9f0
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xd400
movq -0x30(%rbp), %rax
movq %rax, 0x1c482(%rip)     # 0x29048
movw 0x1c485(%rip), %ax      # 0x29052
addw $-0x1, %ax
movw %ax, 0x1c47a(%rip)      # 0x29052
jmp 0xcdd4
movswl 0x1c45c(%rip), %eax     # 0x29040
cmpl $0x0, %eax
jle 0xcc33
movw 0x1c450(%rip), %ax      # 0x29040
addw $-0x1, %ax
movw %ax, 0x1c445(%rip)      # 0x29040
cwtl
movswl 0x1c44d(%rip), %ecx     # 0x29050
cmpl %ecx, %eax
jge 0xcc31
movl $0x0, -0x3c(%rbp)
movswl 0x1c43b(%rip), %eax     # 0x29050
subl $0x1c, %eax
movl %eax, -0x40(%rbp)
leaq -0x3c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xd440
movl (%rax), %eax
movw %ax, 0x1c41f(%rip)      # 0x29050
jmp 0xcc33
jmp 0xcdd4
movswl 0x1c401(%rip), %eax     # 0x29040
movswl 0x1c40c(%rip), %ecx     # 0x29052
cmpl %ecx, %eax
jge 0xcc76
movw 0x1c3ef(%rip), %ax      # 0x29040
addw $0x1, %ax
movw %ax, 0x1c3e4(%rip)      # 0x29040
cwtl
cmpl $0x39, %eax
jl 0xcc74
movw 0x1c3e7(%rip), %ax      # 0x29050
addw $0x1, %ax
movw %ax, 0x1c3dc(%rip)      # 0x29050
jmp 0xcc76
jmp 0xcdd4
movw $0x0, 0x1c3cc(%rip)     # 0x29050
movw $0x0, 0x1c3b3(%rip)     # 0x29040
jmp 0xcdd4
movw 0x1c3b9(%rip), %ax      # 0x29052
movw %ax, 0x1c3a0(%rip)      # 0x29040
movl $0x0, -0x44(%rbp)
movswl 0x1c3a4(%rip), %eax     # 0x29052
subl $0x39, %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
leaq -0x44(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xd440
movl (%rax), %eax
movw %ax, 0x1c383(%rip)      # 0x29050
jmp 0xcdd4
callq 0xd1b0
jmp 0xcdd4
callq 0xd290
jmp 0xcdd4
leaq 0x1c2fb(%rip), %rdi     # 0x28fe8
callq 0xa9f0
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xd400
movq -0x50(%rbp), %rax
movq %rax, 0x1c33a(%rip)     # 0x29048
leaq 0x1c30b(%rip), %rdi     # 0x29020
leaq 0x1c2e4(%rip), %rsi     # 0x29000
callq 0xd480
testb $0x1, %al
jne 0xcd27
jmp 0xcd38
leaq 0x1c2d2(%rip), %rdi     # 0x29000
callq 0xd390
jmp 0xcdc9
leaq -0x79(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x5840
movq -0xd8(%rbp), %rdx
leaq 0xf733(%rip), %rsi      # 0x1c489
leaq -0x78(%rbp), %rdi
callq 0xa030
jmp 0xcd61
leaq -0x78(%rbp), %rdi
callq 0xd390
jmp 0xcd6c
leaq -0x78(%rbp), %rdi
callq 0x5968
leaq -0x79(%rbp), %rdi
callq 0x5540
leaq 0x1c27b(%rip), %rdi     # 0x29000
callq 0x56c0
jmp 0xcdc9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xcdbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5968
leaq -0x79(%rbp), %rdi
callq 0x5540
jmp 0xcfdd
jmp 0xcdd4
movb $0x0, -0x1(%rbp)
jmp 0xcfcf
jmp 0xcee1
cmpl $0x0, -0x8(%rbp)
jne 0xced6
cmpl $0xd, -0xc(%rbp)
jne 0xcdf7
callq 0xd0b0
movb $0x1, -0x1(%rbp)
jmp 0xcfcf
cmpl $0x1b, -0xc(%rbp)
je 0xce09
cmpl $0x9, -0xc(%rbp)
je 0xce09
cmpl $0x3, -0xc(%rbp)
jne 0xce23
leaq 0x1c210(%rip), %rdi     # 0x29020
callq 0x56c0
callq 0xd0b0
movb $0x1, -0x1(%rbp)
jmp 0xcfcf
movl -0xc(%rbp), %esi
movswl 0x1c213(%rip), %edx     # 0x29040
leaq 0x1c1ec(%rip), %rdi     # 0x29020
callq 0x1a4c0
leaq 0x1c1c0(%rip), %rdi     # 0x29000
leaq 0x1c1d9(%rip), %rsi     # 0x29020
callq 0x5060
leaq 0x1c195(%rip), %rdi     # 0x28fe8
callq 0xa9f0
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xd400
movq -0x98(%rbp), %rax
movq %rax, 0x1c1c8(%rip)     # 0x29048
movw 0x1c1cb(%rip), %ax      # 0x29052
addw $0x1, %ax
movw %ax, 0x1c1c0(%rip)      # 0x29052
movw 0x1c1a7(%rip), %ax      # 0x29040
addw $0x1, %ax
movw %ax, 0x1c19c(%rip)      # 0x29040
movswl 0x1c195(%rip), %eax     # 0x29040
movswl 0x1c1a0(%rip), %ecx     # 0x29052
cmpl %ecx, %eax
jne 0xced4
movswl 0x1c183(%rip), %eax     # 0x29040
cmpl $0x39, %eax
jl 0xced4
movw 0x1c187(%rip), %ax      # 0x29050
addw $0x1, %ax
movw %ax, 0x1c17c(%rip)      # 0x29050
jmp 0xcedf
movb $0x0, -0x1(%rbp)
jmp 0xcfcf
jmp 0xcee1
movl 0x1c0f9(%rip), %eax     # 0x28fe0
subl $0x1, %eax
setne %al
movzbl %al, %ecx
movl %ecx, %eax
leal 0x7(,%rax,4), %eax
movl %eax, -0x8(%rbp)
movswl 0x1c14d(%rip), %ecx     # 0x29050
movl %ecx, -0xe4(%rbp)
movswl 0x1c142(%rip), %eax     # 0x29052
subl %ecx, %eax
movl %eax, -0xc4(%rbp)
movl $0x39, -0xc8(%rbp)
leaq -0xc4(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xd4b0
movl -0xe4(%rbp), %edx
movswl (%rax), %ecx
leaq 0x1c0db(%rip), %rsi     # 0x29020
leaq -0xc0(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x1a9f0
movq -0xe0(%rbp), %rdi
callq 0x5200
movq %rax, %rdi
movzbl -0x8(%rbp), %esi
xorl %edx, %edx
movl $0xe, %ecx
movl $0x2, %r8d
movl $0x1, %r9d
callq 0x9480
jmp 0xcf85
leaq -0xc0(%rbp), %rdi
callq 0x5968
movswl 0x1c0a8(%rip), %eax     # 0x29040
movswl 0x1c0b1(%rip), %ecx     # 0x29050
subl %ecx, %eax
movsbl %al, %edi
callq 0x99d0
movb $0x0, -0x1(%rbp)
jmp 0xcfcf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x5968
jmp 0xcfdd
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xf0, %rsp
popq %rbp
retq
movq -0x88(%rbp), %rdi
callq 0x5830
nopl (%rax)