// File: /workspace/github_cpp_makefile_star2_O2/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 $0x4d8, %rsp            # imm = 0x4D8
movq 0x631b(%rip), %rax      # 0x9260
leaq 0xb0(%rsp), %rcx
movq %rax, -0x8(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rcx)
andq $0x0, 0x18(%rcx)
leaq 0x90(%rsp), %rax
andl $0x0, 0x80(%rsp)
movq %rax, 0x20(%rax)
movaps %xmm0, 0x70(%rsp)
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x50(%rsp), %rbp
movaps %xmm0, (%rbp)
andq $0x0, 0x10(%rbp)
leaq 0x30(%rsp), %r13
andq $0x0, 0x10(%r13)
movaps %xmm0, (%r13)
movq $0x0, (%rsp)
leaq 0x338a(%rip), %rbx      # 0x6339
movq %rbx, %rsi
callq 0x22d0
movzbl (%rsp), %r15d
testq %rax, %rax
je 0x3061
movq %rax, %r12
cmpb $0x0, 0x1(%rax)
movb (%rax), %r14b
jne 0x2fde
movsbl %r14b, %edi
callq 0x2240
testl %eax, %eax
jne 0x3041
cmpb $0x23, %r14b
jne 0x2ff4
incq %r12
movq %rbp, %r14
leaq 0xd0(%rsp), %r15
jmp 0x3024
movq %r12, %rdi
callq 0x20b0
movzbl -0x1(%r12,%rax), %ecx
cmpl $0x5c, %ecx
leaq 0xd0(%rsp), %r15
je 0x3014
cmpl $0x2f, %ecx
jne 0x301f
movb $0x0, -0x1(%r12,%rax)
movq %r13, %r14
jmp 0x3024
leaq 0x10(%rsp), %r14
movq %r15, %rdi
movq %r12, %rsi
callq 0x3fea
movq %r14, %rdi
movq %r15, %rsi
callq 0x45c2
xorl %edi, %edi
jmp 0x2faf
movl $0x0, %edi
cmpb $0x13, (%rsp)
ja 0x2faf
movq (%rsp), %rax
incb %al
movq %rax, (%rsp)
movb %r14b, 0x70(%rsp,%r15)
jmp 0x303a
movb $0x73, 0x6200(%rip)     # 0x9268
movq 0x6201(%rip), %rax      # 0x9270
cmpq %rax, 0x6202(%rip)      # 0x9278
je 0x307f
movq %rax, 0x61f9(%rip)      # 0x9278
orl $-0x1, 0x6202(%rip)     # 0x9288
leaq 0x90(%rsp), %rdi
callq 0x4132
testq %rax, %rax
je 0x328e
movq 0xc8(%rsp), %r13
movzwl (%r13), %r14d
movzwl 0x4(%r13), %eax
leaq (%rax,%r13), %rbx
addq $0x10, %rbx
cmpb $0x0, (%rsp)
je 0x30d0
movq %rbx, %rdi
leaq 0x70(%rsp), %rsi
movq %r15, %rdx
callq 0x20d0
testl %eax, %eax
jne 0x3086
leaq 0x10(%r13), %rax
movq %rax, 0x8(%rsp)
addq %r13, %r14
addq $0x10, %r14
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %rbp
cmpq %rbp, %r12
je 0x3106
movq %r12, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x40a6
addq $0x20, %r12
testb %al, %al
jne 0x30ea
jmp 0x3086
movq 0x50(%rsp), %rbp
movq 0x58(%rsp), %r12
cmpq %rbp, %r12
je 0x3168
movq %rbx, %rdi
leaq 0x32c3(%rip), %rsi      # 0x63e2
callq 0x2260
testl %eax, %eax
je 0x313f
movq %rbx, %rdi
leaq 0x32b6(%rip), %rsi      # 0x63e8
callq 0x2260
testl %eax, %eax
jne 0x3086
movzwl 0x6(%r13), %r14d
addq 0x8(%rsp), %r14
cmpq %r12, %rbp
je 0x3168
movq %rbp, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x40a6
addq $0x20, %rbp
testb %al, %al
jne 0x3149
jmp 0x3086
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %r12
cmpq %r14, %r12
je 0x31a7
cmpq %r12, %r14
je 0x31a7
movq 0xb8(%rsp), %rax
movq 0xc0(%rsp), %rcx
movq (%rcx), %rsi
movq (%rax), %rdx
movq %r14, %rdi
callq 0x40a6
addq $0x20, %r14
testb %al, %al
jne 0x3177
jmp 0x3086
leaq 0x60c2(%rip), %rdi      # 0x9270
leaq 0xb0(%rsp), %rsi
callq 0x410c
movq 0x60b6(%rip), %rbp      # 0x9278
subq 0x60a7(%rip), %rbp      # 0x9270
shrq $0x5, %rbp
movzwl (%r13), %r14d
movq 0x8(%rsp), %rcx
addq %rcx, %r14
movzwl 0x6(%r13), %r12d
addq %rcx, %r12
movq 0xc0(%rsp), %rax
movq (%rax), %r9
movzwl 0x2(%r13), %r13d
addq %rcx, %r13
cmpb $0x0, 0x6094(%rip)      # 0x9290
je 0x324d
movq 0xb0(%rsp), %rax
movq 0xb8(%rsp), %rcx
movq (%rax), %rsi
movq (%rcx), %rdx
leaq 0xd0(%rsp), %rdi
xorl %ecx, %ecx
movq %r9, 0x8(%rsp)
callq 0x2b69
leaq 0x31d6(%rip), %rdi      # 0x6405
movl %ebp, %esi
movq %rbx, %rdx
movq %r14, %rcx
movq %r12, %r8
movq 0x8(%rsp), %r9
xorl %eax, %eax
leaq 0xd0(%rsp), %r10
pushq %r10
jmp 0x3265
subq $0x8, %rsp
leaq 0x3199(%rip), %rdi      # 0x63f1
movl %ebp, %esi
movq %rbx, %rdx
movq %r14, %rcx
movq %r12, %r8
xorl %eax, %eax
pushq %r13
callq 0x2030
popq %rcx
popq %rdx
movq 0x6023(%rip), %rax      # 0x9298
movl 0x4(%rax), %esi
cmpl %ebp, %esi
jg 0x3086
leaq 0x314d(%rip), %rdi      # 0x63d4
xorl %eax, %eax
callq 0x2030
leaq 0x30(%rsp), %rdi
callq 0x458e
leaq 0x50(%rsp), %rdi
callq 0x458e
leaq 0x10(%rsp), %rdi
callq 0x458e
addq $0x4d8, %rsp            # imm = 0x4D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x32c8
jmp 0x32c8
jmp 0x32c8
jmp 0x32c8
jmp 0x32c8
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x458e
leaq 0x50(%rsp), %rdi
callq 0x458e
leaq 0x10(%rsp), %rdi
callq 0x458e
movq %rbx, %rdi
callq 0x2310