// File: skyshore2001[P]symfind/symfind.cpp
// Function: QueryFile(char*)
void QueryFile(char *arg)
{
	SfFileIter it(g_repos);
	SfPatterns pats, pats_dir;

	char *p;
	while (p = strtok(arg, " ")) {
		arg = NULL; // make strtok contine
		char *p1 = strchr(p, 0)-1;
		SfPatterns *ppats = &pats;
		if (*p1 == '/' || *p1 == '\\') {
			*p1 -- = 0;
			ppats = &pats_dir;
		}
		ppats->push_back(SfPattern(p));
	}

	g_result.Init('f');
	while (it.Next()) {
		const SfContext &ctx = it.GetContext();
		char *name = ctx.file->name;
		bool ok = true;
		for (SfPattern &pat: pats) {
			if (! pat.Match(name)) {
				ok = false;
				break;
			}
		}
		if (ok && pats_dir.size() > 0) {
			name = ctx.folder->name;
			for (SfPattern &pat: pats_dir) {
				if (! pat.Match(name)) {
					ok = false;
					break;
				}
			}
		}
		if (ok) {
			auto &items = g_result.items;
			items.push_back(ctx);
			int cnt = items.size();
			char buf[1024];
			printf("%d:\t%s\t%s\n", cnt, ctx.file->name, GetFullName(buf, ctx.repo->root, ctx.folder->name));
			if (cnt >= MAX_FOUND) {
				printf("... (max %d)\n", MAX_FOUND);
				break;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x570, %rsp            # imm = 0x570
movq %rdi, -0x8(%rbp)
movq 0xde3a(%rip), %rsi      # 0x112e0
leaq -0x48(%rbp), %rdi
callq 0x5980
leaq -0x60(%rbp), %rdi
callq 0x59b0
leaq -0x78(%rbp), %rdi
callq 0x59b0
movq -0x8(%rbp), %rdi
leaq 0x81bf(%rip), %rsi      # 0xb68b
callq 0x23a0
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
je 0x35ac
movq $0x0, -0x8(%rbp)
movq -0x80(%rbp), %rdi
xorl %esi, %esi
callq 0x20a0
addq $-0x1, %rax
movq %rax, -0x88(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x3526
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5c, %eax
jne 0x3549
movq -0x88(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x88(%rbp)
movb $0x0, (%rax)
leaq -0x78(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x538(%rbp)
movq -0x80(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x5a00
jmp 0x3569
movq -0x538(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x59d0
jmp 0x357e
jmp 0x34c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5e90
leaq -0x60(%rbp), %rdi
callq 0x5e90
jmp 0x388f
leaq 0xdd35(%rip), %rdi      # 0x112e8
movl $0x66, %esi
callq 0x5b30
jmp 0x35bf
jmp 0x35c1
leaq -0x48(%rbp), %rdi
callq 0x5b70
movq %rax, -0x540(%rbp)
jmp 0x35d3
movq -0x540(%rbp), %rax
cmpq $0x0, %rax
je 0x3874
leaq -0x48(%rbp), %rdi
callq 0x5bd0
movq %rax, -0x548(%rbp)
jmp 0x35f6
movq -0x548(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq %rax, -0xd0(%rbp)
movb $0x1, -0xd1(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rdi
callq 0x5bf0
movq %rax, -0xe8(%rbp)
movq -0xe0(%rbp), %rdi
callq 0x5c20
movq %rax, -0xf0(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x5c50
testb $0x1, %al
jne 0x366a
jmp 0x36c1
leaq -0xe8(%rbp), %rdi
callq 0x5c90
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x5cb0
movb %al, -0x549(%rbp)
jmp 0x369c
movb -0x549(%rbp), %al
testb $0x1, %al
jne 0x36b1
jmp 0x36a8
movb $0x0, -0xd1(%rbp)
jmp 0x36c1
jmp 0x36b3
leaq -0xe8(%rbp), %rdi
callq 0x5dc0
jmp 0x3651
testb $0x1, -0xd1(%rbp)
je 0x3799
leaq -0x78(%rbp), %rdi
callq 0x5de0
cmpq $0x0, %rax
jbe 0x3799
movq -0xc8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0xd0(%rbp)
leaq -0x78(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rdi
callq 0x5bf0
movq %rax, -0x108(%rbp)
movq -0x100(%rbp), %rdi
callq 0x5c20
movq %rax, -0x110(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x5c50
testb $0x1, %al
jne 0x3740
jmp 0x3797
leaq -0x108(%rbp), %rdi
callq 0x5c90
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rdi
movq -0xd0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x5cb0
movb %al, -0x54a(%rbp)
jmp 0x3772
movb -0x54a(%rbp), %al
testb $0x1, %al
jne 0x3787
jmp 0x377e
movb $0x0, -0xd1(%rbp)
jmp 0x3797
jmp 0x3789
leaq -0x108(%rbp), %rdi
callq 0x5dc0
jmp 0x3727
jmp 0x3799
testb $0x1, -0xd1(%rbp)
je 0x386f
leaq 0xdb43(%rip), %rdi      # 0x112f0
movq %rdi, -0x120(%rbp)
movq -0xc8(%rbp), %rsi
callq 0x5e00
jmp 0x37c2
leaq 0xdb27(%rip), %rdi      # 0x112f0
callq 0x5e70
movl %eax, -0x124(%rbp)
movl -0x124(%rbp), %eax
movl %eax, -0x564(%rbp)
movq -0xc8(%rbp), %rax
movq 0x10(%rax), %rcx
movq (%rcx), %rcx
movq %rcx, -0x560(%rbp)
movq (%rax), %rcx
movq 0x8(%rax), %rax
movq (%rcx), %rsi
movq (%rax), %rdx
xorl %eax, %eax
movl %eax, %ecx
leaq -0x530(%rbp), %rdi
callq 0x31a0
movq %rax, -0x558(%rbp)
jmp 0x381b
movq -0x558(%rbp), %rcx
movq -0x560(%rbp), %rdx
movl -0x564(%rbp), %esi
leaq 0x7bfe(%rip), %rdi      # 0xb434
xorl %eax, %eax
callq 0x2030
jmp 0x383f
movl -0x124(%rbp), %eax
movq 0xdacc(%rip), %rcx      # 0x11318
cmpl 0x4(%rcx), %eax
jl 0x386d
movq 0xdac0(%rip), %rax      # 0x11318
movl 0x4(%rax), %esi
leaq 0x7bdd(%rip), %rdi      # 0xb43f
xorl %eax, %eax
callq 0x2030
jmp 0x386b
jmp 0x3874
jmp 0x386f
jmp 0x35c1
leaq -0x78(%rbp), %rdi
callq 0x5e90
leaq -0x60(%rbp), %rdi
callq 0x5e90
addq $0x570, %rsp            # imm = 0x570
popq %rbp
retq
movq -0xb8(%rbp), %rdi
callq 0x23e0
nopl (%rax,%rax)