// File: /workspace/github_cpp_makefile_star2_O3/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 0x2c00(%rip), %xmm0     # 0x6438
leaq 0x10b(%rsp), %r14
movups %xmm0, -0xf(%r14)
movups 0x2be0(%rip), %xmm0     # 0x642c
movaps %xmm0, -0x1b(%r14)
leaq 0x2ae1(%rip), %r15      # 0x6339
leaq 0x2c18(%rip), %r12      # 0x6477
movq %r15, %rsi
callq 0x22a0
movq %rax, %rbx
movzbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x388b
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2040
cltq
addq %rax, %r14
xorl %edi, %edi
jmp 0x385f
testl %eax, %eax
je 0x38ab
movq %rbx, %r15
incq %r15
movsbl %al, %edi
callq 0x2110
testl %eax, %eax
jne 0x38b6
movb (%r15), %al
incq %r15
testb %al, %al
jne 0x3895
movl $0x692d20, (%r14)       # imm = 0x692D20
addq $0x3, %r14
leaq 0x2b8b(%rip), %rsi      # 0x6448
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2040
movslq %eax, %rbx
addq %r14, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x2a52(%rip), %rsi      # 0x6339
xorl %edi, %edi
callq 0x22a0
testq %rax, %rax
je 0x3982
movq %rax, %rbp
leaq 0x30(%rsp), %r14
leaq 0x2a33(%rip), %r15      # 0x6339
leaq 0x20(%rsp), %r12
movq %rsp, %r13
cmpb $0x2d, (%rbp)
jne 0x3932
incq %rbp
movq %rbx, %rdi
leaq 0x2b30(%rip), %rsi      # 0x6451
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2040
cltq
addq %rax, %rbx
jmp 0x3970
movq %r14, 0x20(%rsp)
movq %rbp, %rdi
callq 0x20b0
leaq (%rax,%rbp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x4c6a
movq %r13, %rdi
movq %r12, %rsi
callq 0x4d00
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x3970
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21a0
xorl %edi, %edi
movq %r15, %rsi
callq 0x22a0
movq %rax, %rbp
testq %rax, %rax
jne 0x390e
movq (%rsp), %r12
movq 0x8(%rsp), %r13
cmpq %r12, %r13
jne 0x39a1
movq %rsp, %rdi
callq 0x36e1
movq (%rsp), %r12
movq 0x8(%rsp), %r13
cmpq %r13, %r12
je 0x39d2
leaq 0x2ab4(%rip), %r15      # 0x6461
movq (%r12), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2040
movslq %eax, %r14
addq %rbx, %r14
addq $0x20, %r12
movq %r14, %rbx
cmpq %r13, %r12
jne 0x39ad
jmp 0x39d5
movq %rbx, %r14
movq 0x5874(%rip), %rcx      # 0x9250
leaq 0xb0(%rsp), %rax
movq %rcx, 0x18(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rax)
movq $0x0, 0x38(%rax)
leaq 0x2970(%rip), %rbx      # 0x636e
movq 0x18(%rax), %rax
movq %rax, 0xd0(%rsp)
testq %rax, %rax
je 0x3a44
movq 0x5872(%rip), %rdi      # 0x9288
addq $0x8, %rdi
movq (%rax), %rsi
callq 0x2dc2
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2040
cltq
addq %rax, %r14
movq 0xd0(%rsp), %rax
testq %rax, %rax
jne 0x39fe
cmpb $0x1, 0x5835(%rip)      # 0x9280
jne 0x3a5f
leaq 0xf0(%rsp), %rdi
callq 0x2280
jmp 0x3b0c
movq 0x57c2(%rip), %rdx      # 0x9228
leaq 0x2a04(%rip), %rsi      # 0x6471
movq %r14, %rdi
xorl %eax, %eax
callq 0x2040
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
callq 0x2280
movq %rbx, %rdi
callq 0x2140
movq 0x5792(%rip), %rdi      # 0x9228
leaq 0x20(%rsp), %rsi
callq 0x2160
testl %eax, %eax
jne 0x3b0c
cmpq $0x0, 0x50(%rsp)
jle 0x3b0c
movq 0x5775(%rip), %rsi      # 0x9228
leaq 0x29c1(%rip), %rdi      # 0x647b
xorl %eax, %eax
callq 0x2030
leaq 0x56f8(%rip), %rbx      # 0x91c0
leaq 0x29ce(%rip), %r14      # 0x649d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2050
testq %rax, %rax
cmoveq %r14, %rbx
movq 0x5740(%rip), %rcx      # 0x9228
leaq 0x29b1(%rip), %rsi      # 0x64a0
leaq 0xf0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2040
movq %r14, %rdi
callq 0x2140
movq %rsp, %rdi
callq 0x4666
addq $0x8f8, %rsp            # imm = 0x8F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3b2c
jmp 0x3b2c
jmp 0x3b2c
movq %rax, %rbx
jmp 0x3b4b
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x3b4b
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21a0
movq %rsp, %rdi
callq 0x4666
movq %rbx, %rdi
callq 0x22e0