// File: jeffchan[P]blockchain-parser/keyboard.cpp
// Function: getInputString(unsigned int&)
const char ** getInputString(uint32_t &argc)
{
	argc = 0;
	static char buf[256];
	static int index = 0;
	static const char			*argv[MAX_ARGS];

	if ( !kbhit() ) return NULL;

	char c = (char)getch();

	if ( c == 10 || c == 13 )
	{
		buf[index] = 0;

		char *scan = buf;
		while ( *scan == 32 ) scan++;	// skip leading spaces

		if ( *scan )	// if not EOS
		{
			argc = 1;
			argv[0] = scan;	// set the first argument

			while ( *scan && argc < MAX_ARGS)	// while still data and we haven't exceeded the maximum argument count.
			{
				while ( *scan && *scan != 32 ) scan++;	// scan forward to the next space
				if ( *scan == 32 )	// if we hit a space
				{
					*scan = 0; // null-terminate the argument
					scan++;	// skip to the next character
					while ( *scan == 32 ) scan++;	// skip any leading spaces
					if ( *scan )	// if there is still a valid non-space character process that as the next argument
					{
						argv[argc] = scan;
						argc++;
					}
				}
			}
		}
		printf("\r\n");
		index = 0;
		return argc ? argv : NULL;
	}
	else if ( c == 27 )
	{
		buf[index] = 0;
	}
	else if ( c == 8 )
	{
		if ( index )
		{
			index--;
			printf("%c",c);
			printf(" ");
			printf("%c",c);
		}
	}
	else
	{
		if ( c >= 32 && c <= 127 )
		{
			buf[index] = c;
			index++;
#ifdef _MSC_VER
			printf("%c",c);
#else
#endif
		}
	}

	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
callq 0x2e6c0
cmpl $0x0, %eax
jne 0x2e82d
movq $0x0, -0x8(%rbp)
jmp 0x2ea5e
callq 0x2e7c0
movb %al, -0x11(%rbp)
movsbl -0x11(%rbp), %eax
cmpl $0xa, %eax
je 0x2e84b
movsbl -0x11(%rbp), %eax
cmpl $0xd, %eax
jne 0x2e9a6
movslq 0xb19e(%rip), %rcx      # 0x399f0
leaq 0xb097(%rip), %rax      # 0x398f0
movb $0x0, (%rax,%rcx)
leaq 0xb08c(%rip), %rax      # 0x398f0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x2e882
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2e868
movq -0x20(%rbp), %rax
cmpb $0x0, (%rax)
je 0x2e96f
movq -0x10(%rbp), %rax
movl $0x1, (%rax)
movq -0x20(%rbp), %rax
movq %rax, 0xb15c(%rip)      # 0x39a00
movq -0x20(%rbp), %rcx
xorl %eax, %eax
cmpb $0x0, (%rcx)
movb %al, -0x21(%rbp)
je 0x2e8bf
movq -0x10(%rbp), %rax
cmpl $0x20, (%rax)
setb %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
testb $0x1, %al
jne 0x2e8cb
jmp 0x2e96d
jmp 0x2e8cd
movq -0x20(%rbp), %rcx
xorl %eax, %eax
cmpb $0x0, (%rcx)
movb %al, -0x22(%rbp)
je 0x2e8eb
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
setne %al
movb %al, -0x22(%rbp)
movb -0x22(%rbp), %al
testb $0x1, %al
jne 0x2e8f4
jmp 0x2e902
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2e8cd
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x2e968
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x2e93b
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2e921
movq -0x20(%rbp), %rax
cmpb $0x0, (%rax)
je 0x2e966
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, %ecx
leaq 0xb0a9(%rip), %rax      # 0x39a00
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x2e968
jmp 0x2e8a4
jmp 0x2e96f
leaq 0x2aa6(%rip), %rdi      # 0x3141c
movb $0x0, %al
callq 0x2050
movl $0x0, 0xb069(%rip)      # 0x399f0
movq -0x10(%rbp), %rax
movl (%rax), %edx
xorl %eax, %eax
leaq 0xb06a(%rip), %rcx      # 0x39a00
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0x8(%rbp)
jmp 0x2ea5e
movsbl -0x11(%rbp), %eax
cmpl $0x1b, %eax
jne 0x2e9c6
movslq 0xb03a(%rip), %rcx      # 0x399f0
leaq 0xaf33(%rip), %rax      # 0x398f0
movb $0x0, (%rax,%rcx)
jmp 0x2ea54
movsbl -0x11(%rbp), %eax
cmpl $0x8, %eax
jne 0x2ea1b
cmpl $0x0, 0xb01a(%rip)      # 0x399f0
je 0x2ea19
movl 0xb012(%rip), %eax      # 0x399f0
addl $-0x1, %eax
movl %eax, 0xb009(%rip)      # 0x399f0
movsbl -0x11(%rbp), %esi
leaq 0x48fe(%rip), %rdi      # 0x332f0
movb $0x0, %al
callq 0x2050
leaq 0x30bf(%rip), %rdi      # 0x31abf
movb $0x0, %al
callq 0x2050
movsbl -0x11(%rbp), %esi
leaq 0x48de(%rip), %rdi      # 0x332f0
movb $0x0, %al
callq 0x2050
jmp 0x2ea52
movsbl -0x11(%rbp), %eax
cmpl $0x20, %eax
jl 0x2ea50
movsbl -0x11(%rbp), %eax
cmpl $0x7f, %eax
jg 0x2ea50
movb -0x11(%rbp), %dl
movslq 0xafb9(%rip), %rcx      # 0x399f0
leaq 0xaeb2(%rip), %rax      # 0x398f0
movb %dl, (%rax,%rcx)
movl 0xafa9(%rip), %eax      # 0x399f0
addl $0x1, %eax
movl %eax, 0xafa0(%rip)      # 0x399f0
jmp 0x2ea52
jmp 0x2ea54
jmp 0x2ea56
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)