// File: /workspace/github_cpp_makefile_star2_O2/skyshore2001[P]symfind/symfind.cpp
// Function: ExecCmd(char*, char const*)
int ExecCmd(char *buf, const char *prompt = "> ")
{
	char defaultCmd[20] = "?\n";
	if (buf[0] == '\n' || buf[0] == '\r')
		buf = defaultCmd;
	// shell cmd
	if (buf[0] == '!') {
		system(buf+1);
		goto nx;
	}

	char *cmd, *arg;
	int ses;
	cmd = strtok(buf, " \r\n");
	arg = strtok(NULL, "\r\n");
	ses = 0;
	while (*cmd && isdigit(*cmd)) {
		ses = ses * 10 + (*cmd - '0');
		++ cmd;
	}
// 		printf("### ses=%d, cmd='%s'\n", ses, cmd);
	InitSession(ses);
	if (STR_EQ(cmd, "f") || STR_EQ(cmd, "s")) {
		clock_t t0 = clock();
		if (cmd[0] == 'f')
			QueryFile(arg);
		else // 's'
			QuerySymbol(arg);
		printf("(Total %d result(s) in %.3fs.)\n", g_result.items.size(), (double)(clock()-t0)/CLOCKS_PER_SEC);
	}
	else if (STR_EQ(cmd, "g")) { // grep
		if (arg) {
			GrepSymbol(arg);
		}
	}
	else if (STR_EQ(cmd, "q")) {
		return 1;
	}
	else if (STR_EQ(cmd, "?")) {
		Help();
	}
	else if (!g_forsvr && (STR_EQ(cmd, "go") || STR_EQ(cmd, "n") || STR_EQ(cmd, "N"))) {
		GotoResult(cmd, arg);
	}
	else if (!g_forsvr && STR_EQ(cmd, "editor")) {
		if (arg) {
			strcpy(EDITOR, arg);
		}
		printf("editor %s\n", EDITOR);
	}
	else if (STR_EQ(cmd, "max")) {
		if (arg) {
			int n = atoi(arg);
			if (n > 0) {
				MAX_FOUND = n;
			}
		}
		printf("max %d\n", MAX_FOUND);
	}
	else if (STR_EQ(cmd, "root")) {
		if (arg) {
			g_rootsubs.Set(arg);
		}
		printf("root %s\n", g_rootsubs.pattern);
	}
	else if (STR_EQ(cmd, "add")) {
		if (arg) {
			int cnt = 0;
			const char *args[10];
			args[cnt++] = strtok(arg, " ");
			while ((args[cnt] = strtok(NULL, " ")) != NULL) {
				++ cnt;
			}
			LoadRepofiles(cnt, args);
		}
	}
	else {
		printf("*** unknown command: '%s'. Type '?' for help.\n", cmd);
	}
nx:
	if (ses != 0) {
		printf("(session %d)\n", ses);
	}
// 	printf("> ");
	printf("%s", prompt);
	if (g_forsvr)
		fputs("\n", stdout);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rbx
movq %rsp, %rax
andl $0x0, 0x10(%rax)
movapd 0x2b32(%rip), %xmm0     # 0x66f0
movapd %xmm0, (%rax)
movzbl (%rdi), %ecx
cmpl $0xa, %ecx
je 0x3bdb
cmpl $0xd, %ecx
je 0x3bdb
cmpl $0x21, %ecx
je 0x3ed9
movq %rdi, %rax
leaq 0x2718(%rip), %rsi      # 0x62fa
movq %rax, %rdi
callq 0x22d0
movq %rax, %r12
leaq 0x26fd(%rip), %rsi      # 0x62f1
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x22d0
movq %rax, %r15
movsbl (%r12), %eax
testl %eax, %eax
je 0x3c20
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x3c20
imull $0xa, %r14d, %ecx
addl %ecx, %eax
incq %r12
movl %eax, %r14d
jmp 0x3c01
movl %r14d, %edi
callq 0x3abf
movzbl (%r12), %eax
cmpl $0x3f, %eax
je 0x3c9e
cmpl $0x73, %eax
je 0x3c46
cmpl $0x67, %eax
je 0x3c7e
cmpl $0x71, %eax
je 0x3c6e
cmpl $0x66, %eax
jne 0x3caa
cmpb $0x0, 0x1(%r12)
jne 0x3caa
callq 0x2100
movq %rax, %r13
cmpb $0x66, (%r12)
jne 0x3e39
movq %r15, %rdi
callq 0x2d15
jmp 0x3e41
cmpb $0x0, 0x1(%r12)
jne 0x3caa
pushq $0x1
popq %rbp
jmp 0x3ec8
movb $0x1, %cl
cmpb $0x0, 0x1(%r12)
jne 0x3cac
testq %r15, %r15
je 0x3e80
movq %r15, %rdi
callq 0x351a
jmp 0x3e80
cmpb $0x0, 0x1(%r12)
je 0x3e7b
xorl %ecx, %ecx
cmpb $0x0, 0x55dd(%rip)      # 0x9290
jne 0x3cfa
testb %cl, %cl
je 0x3ccd
cmpb $0x6f, 0x1(%r12)
jne 0x3ccd
cmpb $0x0, 0x2(%r12)
je 0x3d9a
cmpl $0x4e, %eax
je 0x3cd7
cmpl $0x6e, %eax
jne 0x3ce3
cmpb $0x0, 0x1(%r12)
je 0x3d9a
leaq 0x2805(%rip), %rsi      # 0x64ef
movq %r12, %rdi
callq 0x2260
testl %eax, %eax
je 0x3daa
leaq 0x2800(%rip), %rsi      # 0x6501
movq %r12, %rdi
callq 0x2260
testl %eax, %eax
je 0x3d46
leaq 0x27f9(%rip), %rsi      # 0x650d
movq %r12, %rdi
callq 0x2260
testl %eax, %eax
je 0x3d6e
leaq 0x27f4(%rip), %rsi      # 0x651b
movq %r12, %rdi
callq 0x2260
testl %eax, %eax
je 0x3dd8
leaq 0x27e1(%rip), %rdi      # 0x651f
movq %r12, %rsi
jmp 0x3dcc
testq %r15, %r15
je 0x3e1f
movq %r15, %rdi
callq 0x22c0
movq 0x553a(%rip), %rcx      # 0x9298
testl %eax, %eax
jle 0x3e26
movl %eax, 0x4(%rcx)
jmp 0x3e26
testq %r15, %r15
je 0x3d86
movq 0x551e(%rip), %rdi      # 0x9298
addq $0x8, %rdi
movq %r15, %rsi
callq 0x39de
movq 0x550b(%rip), %rsi      # 0x9298
addq $0x8, %rsi
leaq 0x277a(%rip), %rdi      # 0x6512
jmp 0x3dcc
movq %r12, %rdi
movq %r15, %rsi
callq 0x32f1
jmp 0x3e80
testq %r15, %r15
je 0x3dbe
leaq 0x541a(%rip), %rdi      # 0x91d0
movq %r15, %rsi
callq 0x2180
leaq 0x2731(%rip), %rdi      # 0x64f6
leaq 0x5404(%rip), %rsi      # 0x91d0
xorl %eax, %eax
callq 0x2030
jmp 0x3e80
testq %r15, %r15
je 0x3e80
leaq 0x2551(%rip), %rbx      # 0x6339
movq %r15, %rdi
movq %rbx, %rsi
callq 0x22d0
movq %rax, 0x20(%rsp)
xorl %r14d, %r14d
xorl %edi, %edi
movq %rbx, %rsi
callq 0x22d0
movq %rax, 0x28(%rsp,%r14,8)
incq %r14
testq %rax, %rax
jne 0x3dfb
leaq 0x20(%rsp), %rsi
movl %r14d, %edi
callq 0x29e9
movq 0x5472(%rip), %rcx      # 0x9298
movl 0x4(%rcx), %esi
leaq 0x26d5(%rip), %rdi      # 0x6505
xorl %eax, %eax
callq 0x2030
jmp 0x3e80
movq %r15, %rdi
callq 0x2f2d
movq 0x5430(%rip), %r15      # 0x9278
subq 0x5421(%rip), %r15      # 0x9270
sarq $0x5, %r15
callq 0x2100
subq %r13, %rax
cvtsi2sd %rax, %xmm0
divsd 0x21a0(%rip), %xmm0     # 0x6008
leaq 0x2660(%rip), %rdi      # 0x64cf
movq %r15, %rsi
movb $0x1, %al
callq 0x2030
jmp 0x3e80
callq 0x253e
testl %r14d, %r14d
je 0x3e96
leaq 0x26c2(%rip), %rdi      # 0x654e
movl %r14d, %esi
xorl %eax, %eax
callq 0x2030
leaq 0x25db(%rip), %rdi      # 0x6478
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2030
cmpb $0x1, 0x53e0(%rip)      # 0x9290
jne 0x3ec8
movq 0x510f(%rip), %rax      # 0x8fc8
movq (%rax), %rsi
leaq 0x242f(%rip), %rdi      # 0x62f2
callq 0x21e0
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incq %rdi
callq 0x2150