// File: /workspace/github_cpp_makefile_star2_O2/skyshore2001[P]symfind/symfind.cpp
// Function: GrepSymbol(char*)
void GrepSymbol(char *arg)
{
	char gcmd[2048], *p = gcmd, *p1;
	p += sprintf(p, "grep --line-buffered -Hn -R");
	char *pat = strtok(arg, " ");
	// begin with "-": as grep option. e.g. "g -w hello"
	while (pat[0] == '-') { 
		p += sprintf(p, " %s", pat);
		pat = strtok(NULL, " ");
	}
	// ignore case if contains upper letter
	if (!ContainsUpper(pat))
		p += sprintf(p, " -i");
	p += sprintf(p, " -e \"%s\"", pat);
	vector<string> incs;
	while (p1 = strtok(NULL, " ")) {
		if (p1[0] == '-') {
			++ p1;
			p += sprintf(p, " --exclude \"%s\"", p1);
		}
		else {
			incs.push_back(p1);
// 			p += sprintf(p, " --include \"%s\"", p1);
		}
	}
	if (incs.size() == 0) { // use the default patterns when scanning
		GetTagscanPats(incs);
	}
	for (const string &inc: incs) {
		p += sprintf(p, " --include \"%s\"", inc.c_str());
	}

	SfRepoIter it(g_repos);
	while (it.Next()) {
		const char *root = g_rootsubs.Substitue(it.Value()->root);
		p += sprintf(p, " \"%s\"", root);
	}
	if (g_forsvr) {
		printf("%s\n", gcmd);
	}
	else {
		p += sprintf(p, " | tee %s", TMP_OUT);
		printf("%s\n", gcmd);
		system(gcmd);
		struct stat st;
		if (stat(TMP_OUT, &st) == 0 && st.st_size > 0)
		{
			printf("(Search results are saved in %s)\n", TMP_OUT);

			const char *ed = "vi";
			if (strstr(EDITOR, "vi")) { // vi/vim/gvim
				ed = EDITOR;
			}
			sprintf(gcmd, "%s -q %s -c copen", ed, TMP_OUT);
			system(gcmd);
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8f8, %rsp            # imm = 0x8F8
movups 0x2f06(%rip), %xmm0     # 0x6438
leaq 0x10b(%rsp), %r14
movups %xmm0, -0xf(%r14)
movups 0x2ee6(%rip), %xmm0     # 0x642c
movaps %xmm0, -0x1b(%r14)
leaq 0x2de7(%rip), %rbx      # 0x6339
leaq 0x2f1e(%rip), %r12      # 0x6477
movq %rbx, %rsi
callq 0x22d0
movq %rax, %r15
cmpb $0x2d, (%rax)
jne 0x3582
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2040
cltq
addq %rax, %r14
xorl %edi, %edi
jmp 0x3559
movq %r15, %rdi
callq 0x41bc
testb %al, %al
jne 0x3599
movl $0x692d20, (%r14)       # imm = 0x692D20
addq $0x3, %r14
leaq 0x2ea8(%rip), %rsi      # 0x6448
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2040
movslq %eax, %rbx
addq %r14, %rbx
xorps %xmm0, %xmm0
movq %rsp, %r15
movaps %xmm0, (%r15)
andq $0x0, 0x10(%r15)
leaq 0x2d70(%rip), %r12      # 0x6339
leaq 0x2e81(%rip), %r13      # 0x6451
leaq 0x60(%rsp), %rbp
leaq 0x20(%rsp), %r14
xorl %edi, %edi
movq %r12, %rsi
callq 0x22d0
testq %rax, %rax
je 0x362b
cmpb $0x2d, (%rax)
je 0x3611
movq %rbp, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x41e4
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4a06
movq %rbp, %rdi
callq 0x20c0
jmp 0x35da
incq %rax
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2040
cltq
addq %rax, %rbx
jmp 0x35da
movq (%rsp), %r12
movq 0x8(%rsp), %r13
cmpq %r12, %r13
jne 0x364a
movq %rsp, %rdi
callq 0x33f3
movq (%rsp), %r12
movq 0x8(%rsp), %r13
leaq 0x2e10(%rip), %r15      # 0x6461
cmpq %r13, %r12
je 0x3672
movq (%r12), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2040
cltq
addq %rax, %rbx
addq $0x20, %r12
jmp 0x3651
movq 0x5be7(%rip), %rax      # 0x9260
movq %rax, 0x38(%rsp)
andq $0x0, 0x58(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rsp)
movq %r14, 0x40(%rsp)
leaq 0x2cd6(%rip), %r15      # 0x636e
testq %r14, %r14
je 0x36da
movq 0x18(%r14), %rax
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0x36da
movq 0x5be6(%rip), %rdi      # 0x9298
addq $0x8, %rdi
movq (%rax), %rsi
callq 0x2c90
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2040
cltq
addq %rax, %rbx
movq 0x40(%rsp), %r14
jmp 0x3698
cmpb $0x1, 0x5baf(%rip)      # 0x9290
jne 0x36f5
leaq 0xf0(%rsp), %rdi
callq 0x22b0
jmp 0x37a5
movq 0x5b3c(%rip), %rdx      # 0x9238
leaq 0x2d6e(%rip), %rsi      # 0x6471
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2040
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
callq 0x22b0
movq %rbx, %rdi
callq 0x2150
movq 0x5b0c(%rip), %rdi      # 0x9238
leaq 0x60(%rsp), %rsi
callq 0x2170
testl %eax, %eax
jne 0x37a5
cmpq $0x0, 0x90(%rsp)
jle 0x37a5
movq 0x5aec(%rip), %rsi      # 0x9238
leaq 0x2d28(%rip), %rdi      # 0x647b
xorl %eax, %eax
callq 0x2030
leaq 0x5a6f(%rip), %rbx      # 0x91d0
leaq 0x2d35(%rip), %r14      # 0x649d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2050
testq %rax, %rax
cmoveq %r14, %rbx
movq 0x5ab7(%rip), %rcx      # 0x9238
leaq 0x2d18(%rip), %rsi      # 0x64a0
leaq 0xf0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2040
movq %r14, %rdi
callq 0x2150
movq %rsp, %rdi
callq 0x4220
addq $0x8f8, %rsp            # imm = 0x8F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x37c5
jmp 0x37c5
jmp 0x37c5
movq %rax, %rbx
jmp 0x37d7
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x20c0
movq %rsp, %rdi
callq 0x4220
movq %rbx, %rdi
callq 0x2310