// File: /workspace/github_cpp_makefile_star2_O3/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
movapd 0x2729(%rip), %xmm0     # 0x66f0
movq %rsp, %rax
movapd %xmm0, (%rax)
movl $0x0, 0x10(%rax)
movzbl (%rdi), %ecx
cmpl $0xa, %ecx
je 0x3fee
cmpl $0xd, %ecx
je 0x3fee
cmpl $0x21, %ecx
je 0x4316
movq %rdi, %rax
leaq 0x2305(%rip), %rsi      # 0x62fa
movq %rax, %rdi
callq 0x22a0
movq %rax, %r12
leaq 0x22ea(%rip), %rsi      # 0x62f1
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x22a0
movq %rax, %r15
movb (%r12), %al
testb %al, %al
je 0x403e
xorl %r14d, %r14d
movsbl %al, %eax
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x403e
leal (%r14,%r14,4), %ecx
leal (%rax,%rcx,2), %r14d
movb 0x1(%r12), %al
incq %r12
testb %al, %al
jne 0x401f
movl %r14d, %edi
callq 0x3e97
movzbl (%r12), %eax
xorl %ecx, %ecx
cmpl $0x66, %eax
jle 0x4063
cmpl $0x67, %eax
je 0x4095
cmpl $0x71, %eax
je 0x40b5
cmpl $0x73, %eax
je 0x406d
jmp 0x40d5
cmpl $0x3f, %eax
je 0x40c7
cmpl $0x66, %eax
jne 0x40d5
cmpb $0x0, 0x1(%r12)
jne 0x40d3
callq 0x20f0
movq %rax, %r13
cmpb $0x66, (%r12)
jne 0x427a
movq %r15, %rdi
callq 0x2e47
jmp 0x4282
movb $0x1, %cl
cmpb $0x0, 0x1(%r12)
jne 0x40d5
testq %r15, %r15
je 0x42bd
movq %r15, %rdi
callq 0x3820
jmp 0x42bd
cmpb $0x0, 0x1(%r12)
jne 0x40d3
movl $0x1, %ebp
jmp 0x4305
cmpb $0x0, 0x1(%r12)
je 0x4262
xorl %ecx, %ecx
cmpb $0x0, 0x51a4(%rip)      # 0x9280
jne 0x4123
testb %cl, %cl
je 0x40f6
cmpb $0x6f, 0x1(%r12)
jne 0x40f6
cmpb $0x0, 0x2(%r12)
je 0x41c3
cmpl $0x4e, %eax
je 0x4100
cmpl $0x6e, %eax
jne 0x410c
cmpb $0x0, 0x1(%r12)
je 0x41c3
leaq 0x23dc(%rip), %rsi      # 0x64ef
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x41d3
leaq 0x23d7(%rip), %rsi      # 0x6501
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x416f
leaq 0x23d0(%rip), %rsi      # 0x650d
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x4197
leaq 0x23cb(%rip), %rsi      # 0x651b
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x4201
leaq 0x23b8(%rip), %rdi      # 0x651f
movq %r12, %rsi
jmp 0x41f5
testq %r15, %r15
je 0x4248
movq %r15, %rdi
callq 0x2290
movq 0x5101(%rip), %rcx      # 0x9288
testl %eax, %eax
jle 0x424f
movl %eax, 0x4(%rcx)
jmp 0x424f
testq %r15, %r15
je 0x41af
movq 0x50e5(%rip), %rdi      # 0x9288
addq $0x8, %rdi
movq %r15, %rsi
callq 0x3d94
movq 0x50d2(%rip), %rsi      # 0x9288
addq $0x8, %rsi
leaq 0x2351(%rip), %rdi      # 0x6512
jmp 0x41f5
movq %r12, %rdi
movq %r15, %rsi
callq 0x35df
jmp 0x42bd
testq %r15, %r15
je 0x41e7
leaq 0x4fe1(%rip), %rdi      # 0x91c0
movq %r15, %rsi
callq 0x2170
leaq 0x2308(%rip), %rdi      # 0x64f6
leaq 0x4fcb(%rip), %rsi      # 0x91c0
xorl %eax, %eax
callq 0x2030
jmp 0x42bd
testq %r15, %r15
je 0x42bd
leaq 0x2128(%rip), %rbx      # 0x6339
movq %r15, %rdi
movq %rbx, %rsi
callq 0x22a0
movq %rax, 0x20(%rsp)
xorl %r14d, %r14d
xorl %edi, %edi
movq %rbx, %rsi
callq 0x22a0
movq %rax, 0x28(%rsp,%r14,8)
incq %r14
testq %rax, %rax
jne 0x4224
leaq 0x20(%rsp), %rsi
movl %r14d, %edi
callq 0x2b04
movq 0x5039(%rip), %rcx      # 0x9288
movl 0x4(%rcx), %esi
leaq 0x22ac(%rip), %rdi      # 0x6505
xorl %eax, %eax
callq 0x2030
jmp 0x42bd
movq 0x4d5f(%rip), %rax      # 0x8fc8
movq (%rax), %rsi
leaq 0x1dbb(%rip), %rdi      # 0x602e
callq 0x21c0
jmp 0x42bd
movq %r15, %rdi
callq 0x3131
movq 0x4fdf(%rip), %r15      # 0x9268
subq 0x4fd0(%rip), %r15      # 0x9260
sarq $0x5, %r15
callq 0x20f0
subq %r13, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x1d5c(%rip), %xmm0     # 0x6008
leaq 0x221c(%rip), %rdi      # 0x64cf
movq %r15, %rsi
movb $0x1, %al
callq 0x2030
testl %r14d, %r14d
je 0x42d3
leaq 0x2285(%rip), %rdi      # 0x654e
movl %r14d, %esi
xorl %eax, %eax
callq 0x2030
leaq 0x219e(%rip), %rdi      # 0x6478
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2030
cmpb $0x1, 0x4f93(%rip)      # 0x9280
jne 0x4305
movq 0x4cd2(%rip), %rax      # 0x8fc8
movq (%rax), %rsi
leaq 0x1ff2(%rip), %rdi      # 0x62f2
callq 0x21c0
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incq %rdi
callq 0x2140