// File: /workspace/github_cpp_makefile_star2_O1/skyshore2001[P]symfind/symfind.cpp
// Function: QuerySymbol(char*)
void QuerySymbol(char *arg)
{
	SfSymbolIter it(g_repos);

	char pat_kind[20] = {0};
	char kindlen = 0;
	vector<SfPattern> pats, pats_val, pats_path;

	char *p;
	while (p = strtok(arg, " ")) {
		arg = NULL; // make strtok continue

		if (*(p+1) == 0 && islower(*p)) { // only 1 char for pat_kind
			if (kindlen < sizeof(pat_kind))
				pat_kind[kindlen++] = *p;
			continue;
		}

		SfPatterns *ppats = &pats;
		if (*p == '#') {
			++ p;
			ppats = &pats_val;
		}
		else {
			char *p1 = strchr(p, 0)-1;
			if (*p1 == '/' || *p1 == '\\') {
				*p1 -- = 0;
				ppats = &pats_path;
			}
		}
		ppats->push_back(SfPattern(p));
	}

	g_result.Init('s');
	while (it.Next()) {
		SfSymbol *symbol = it.Value();

		char *name = symbol->name();
		bool ok = true;

		char *kind = symbol->kind();
		if (kindlen && strncmp(kind, pat_kind, kindlen) != 0)
			continue;

		for (SfPattern &pat: pats) {
			if (! pat.Match(name)) {
				ok = false;
				break;
			}
		}
		if (ok && pats_val.size() > 0) {
			ok = strcmp(kind, "macro") == 0 || strcmp(kind, "variable") == 0;
			if (ok) {
				char *extra = symbol->extra();
				for (SfPattern &pat: pats_val) {
					if (! pat.Match(extra)) {
						ok = false;
						break;
					}
				}
			}
		}
		if (ok && pats_path.size() > 0) {
			const SfContext &ctx = it.GetContext();
			for (SfPattern &pat: pats_path) {
				if (! pat.Match(ctx.file->name, ctx.folder->name)) {
					ok = false;
					break;
				}
			}
		}
		if (ok) {
			auto &items = g_result.items;
			const SfContext &ctx = it.GetContext();
			items.push_back(ctx);
			int cnt = items.size();
			char buf[1024];
			if (!g_forsvr)
				printf("%d:\t%s\t%s\t%s\t%s:%s\n", cnt, kind, symbol->name(), symbol->extra(), ctx.file->name, symbol->line());
			else
				printf("%d:\t%s\t%s\t%s\t%s:%s\t%s\n", cnt, kind, symbol->name(), symbol->extra(), ctx.file->name, symbol->line(), 
						GetFullName(buf, ctx.repo->root, ctx.folder->name));
			if (cnt >= MAX_FOUND) {
				printf("... (max %d)\n", MAX_FOUND);
				break;
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4e8, %rsp            # imm = 0x4E8
movq 0x6106(%rip), %rax      # 0x9250
leaq 0xa0(%rsp), %rcx
movq %rax, 0x18(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rcx)
movups %xmm0, 0x30(%rcx)
movq %rcx, 0x20(%rcx)
movaps %xmm0, 0x80(%rsp)
movl $0x0, 0x90(%rsp)
xorl %eax, %eax
movq %rax, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq %rax, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq 0x319a(%rip), %rsi      # 0x6339
callq 0x22a0
testq %rax, %rax
je 0x329a
movq %rax, %r15
movq $0x0, (%rsp)
leaq 0x317a(%rip), %rbx      # 0x6339
leaq 0x30(%rsp), %r13
leaq 0xe0(%rsp), %r14
leaq 0x10(%rsp), %rbp
cmpb $0x0, 0x1(%r15)
jne 0x31ec
movb (%r15), %r12b
movsbl %r12b, %edi
callq 0x2210
testl %eax, %eax
jne 0x327e
cmpb $0x23, (%r15)
jne 0x31fa
incq %r15
movq %r13, %r12
jmp 0x3222
movq %r15, %rdi
callq 0x20b0
movzbl -0x1(%r15,%rax), %ecx
cmpl $0x5c, %ecx
je 0x3212
cmpl $0x2f, %ecx
jne 0x321d
movb $0x0, -0x1(%r15,%rax)
movq %rbp, %r12
jmp 0x3222
leaq 0x50(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x4590
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x325b
movups 0xe0(%rsp), %xmm0
movups 0xf0(%rsp), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x20, %rsi
movq %rsi, 0x8(%r12)
jmp 0x3266
movq %r12, %rdi
movq %r14, %rdx
callq 0x4a9c
xorl %edi, %edi
movq %rbx, %rsi
callq 0x22a0
movq %rax, %r15
testq %rax, %rax
jne 0x31d1
jmp 0x32a2
movq (%rsp), %rcx
cmpb $0x13, %cl
ja 0x3298
movzbl %cl, %eax
incb %cl
movq %rcx, (%rsp)
movb %r12b, 0x80(%rsp,%rax)
jmp 0x3266
movq $0x0, (%rsp)
movb $0x73, 0x5faf(%rip)     # 0x9258
movq 0x5fb0(%rip), %rax      # 0x9260
cmpq %rax, 0x5fb1(%rip)      # 0x9268
je 0x32c0
movq %rax, 0x5fa8(%rip)      # 0x9268
movl $0xffffffff, 0x5fae(%rip) # imm = 0xFFFFFFFF
movq (%rsp), %rbx
movsbq %bl, %rax
movq %rax, 0x78(%rsp)
xorl %r14d, %r14d
leaq 0xa0(%rsp), %rdi
callq 0x46ec
testq %rax, %rax
je 0x35b0
movq 0xd8(%rsp), %r15
movzwl (%r15), %r13d
movzwl 0x4(%r15), %eax
leaq (%r15,%rax), %rbp
addq $0x10, %rbp
testb %bl, %bl
je 0x332f
movq %rbp, %rdi
leaq 0x80(%rsp), %rsi
movq 0x78(%rsp), %rdx
callq 0x20c0
movl $0x4, %ecx
testl %eax, %eax
jne 0x35a7
movq 0x50(%rsp), %rbx
movq 0x58(%rsp), %r12
cmpq %r12, %rbx
movq %rbp, 0x8(%rsp)
je 0x3382
leaq (%r15,%r13), %rbp
addq $0x10, %rbp
movb $0x1, %r13b
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rdi
addq %rbx, %rdi
testb $0x1, %al
je 0x3365
movq (%rdi), %rcx
movq -0x1(%rcx,%rax), %rax
movq %rbp, %rsi
callq *%rax
movzbl %r13b, %r13d
cmpb %al, 0xa(%rbx)
cmovel %r14d, %r13d
je 0x3385
addq $0x20, %rbx
cmpq %r12, %rbx
jne 0x334e
jmp 0x3385
movb $0x1, %r13b
leaq 0x10(%r15), %rax
movq %rax, 0x70(%rsp)
testb $0x1, %r13b
je 0x341f
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r12
cmpq %rbx, %r12
je 0x341f
movq 0x8(%rsp), %r13
movq %r13, %rdi
leaq 0x302c(%rip), %rsi      # 0x63e2
callq 0x2230
testl %eax, %eax
je 0x33d6
movq %r13, %rdi
leaq 0x301f(%rip), %rsi      # 0x63e8
callq 0x2230
testl %eax, %eax
sete %r13b
jmp 0x33d9
movb $0x1, %r13b
testb %r13b, %r13b
je 0x341f
cmpq %r12, %rbx
je 0x341f
movzwl 0x6(%r15), %ebp
addq 0x70(%rsp), %rbp
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rdi
addq %rbx, %rdi
testb $0x1, %al
je 0x3404
movq (%rdi), %rcx
movq -0x1(%rcx,%rax), %rax
movq %rbp, %rsi
callq *%rax
movzbl %r13b, %r13d
cmpb %al, 0xa(%rbx)
cmovel %r14d, %r13d
je 0x341f
addq $0x20, %rbx
cmpq %r12, %rbx
jne 0x33ed
testb $0x1, %r13b
je 0x346a
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r12
cmpq %rbx, %r12
je 0x346a
movq 0xc8(%rsp), %rax
movq 0xd0(%rsp), %rcx
movq (%rcx), %rsi
movq (%rax), %rdx
movq %rbx, %rdi
callq 0x4686
movzbl %r13b, %r13d
testb %al, %al
cmovel %r14d, %r13d
addq $0x20, %rbx
cmpq %r12, %rbx
setne %cl
testb %cl, %al
jne 0x3434
testb $0x1, %r13b
movq (%rsp), %rbx
je 0x35a5
movq 0x5de9(%rip), %rsi      # 0x9268
cmpq 0x5dea(%rip), %rsi      # 0x9270
je 0x34a8
leaq 0xc0(%rsp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x20, 0x5dc2(%rip)     # 0x9268
jmp 0x34bc
leaq 0x5db1(%rip), %rdi      # 0x9260
leaq 0xc0(%rsp), %rdx
callq 0x4bfa
movq 0x5da5(%rip), %rbp      # 0x9268
subq 0x5d96(%rip), %rbp      # 0x9260
shrq $0x5, %rbp
movzwl (%r15), %ebx
movq 0x70(%rsp), %rax
addq %rax, %rbx
movzwl 0x6(%r15), %r13d
addq %rax, %r13
movzwl 0x2(%r15), %r12d
addq %rax, %r12
cmpb $0x0, 0x5d8f(%rip)      # 0x9280
je 0x3548
movq 0xd0(%rsp), %rax
movq (%rax), %r15
movq 0xc0(%rsp), %rax
movq 0xc8(%rsp), %rcx
movq (%rax), %rsi
movq (%rcx), %rdx
leaq 0xe0(%rsp), %rdi
xorl %ecx, %ecx
callq 0x2c60
leaq 0x2edb(%rip), %rdi      # 0x6405
movl %ebp, %esi
movq 0x8(%rsp), %rdx
movq %rbx, %rcx
movq %r13, %r8
movq %r15, %r9
xorl %eax, %eax
leaq 0xe0(%rsp), %r10
pushq %r10
jmp 0x356d
movq 0xd0(%rsp), %rax
movq (%rax), %r9
subq $0x8, %rsp
leaq 0x2e93(%rip), %rdi      # 0x63f1
movl %ebp, %esi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
movq %r13, %r8
xorl %eax, %eax
pushq %r12
callq 0x2030
addq $0x10, %rsp
movq 0x5d09(%rip), %rax      # 0x9288
movl 0x4(%rax), %ebx
xorl %ecx, %ecx
cmpl %ebp, %ebx
jg 0x359d
leaq 0x2e45(%rip), %rdi      # 0x63d4
movl %ebx, %esi
xorl %eax, %eax
callq 0x2030
movl $0x5, %ecx
cmpl %ebp, %ebx
movq (%rsp), %rbx
jle 0x35a7
xorl %ecx, %ecx
cmpl $0x5, %ecx
jne 0x32da
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x35c7
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x35de
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x35f5
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
addq $0x4e8, %rsp            # imm = 0x4E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3611
jmp 0x3611
jmp 0x3611
jmp 0x3611
jmp 0x3611
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x362b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3642
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3659
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq %rbx, %rdi
callq 0x22e0