// File: skyshore2001[P]symfind/symfind.cpp
// Function: main
int main(int argc, const char *argv[])
{
	if (argc <= 1) {
		printf("Usage: symfind <repo>\n");
		return -1;
	}
	if (argv[1][0] == '-') {
		const char *opt = argv[1]+1;
		if (STR_EQ(opt, "v") || STR_EQ(opt, "version") || STR_EQ(opt, "-version")) {
			printf("symfind version %s\n", VERSION);
			return 0;
		}
		else {
			printf("*** unknown option: '%s'\n", opt);
			return 1;
		}
	}
	if (g_forsvr) {
		fputs("(for symsvr)\n", stdout);
		setbuf(stdout, NULL);
		setbuf(stderr, NULL);
	}
	-- argc;
	++ argv;
	LoadRepofiles(argc, argv);

// 	printf("for attach (pid=%d)...\n", getpid());
// 	sleep(10);

	// !!! to debug the loading and iterator, run: $ SF_TEST=1 symfind 1.repo.gz
	if (getenv("SF_TEST") != NULL)
		return TestShow();

	char buf[1024];
	FILE *fp;
	char rcfile[1024] = RC_FILE;
	fp = fopen(rcfile, "r");
	if (fp == NULL) {
		sprintf(rcfile, "%s/%s", getenv("HOME"), RC_FILE);
		fp = fopen(rcfile, "r");
	}
	if (fp)
	{
		const char *prompt = "rc> ";
		printf("(load rc file: %s)\n", rcfile);
		fputs(prompt, stdout);
		while (fgets(buf, 1024, fp)) {
			fputs(buf, stdout);
			if (ExecCmd(buf, prompt))
				break;
		}
		fclose(fp);
	}

	fputs("> ", stdout);
	if (g_forsvr)
		fputs("\n", stdout);
	while (fgets(buf, 1024, stdin)) {
		if (ExecCmd(buf))
			break;
	}
	FreeRepos();
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x840, %rsp            # imm = 0x840
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x1, -0x8(%rbp)
jg 0x5539
leaq 0x60e2(%rip), %rdi      # 0xb608
movb $0x0, %al
callq 0x2030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5812
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x55db
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x60b7(%rip), %rsi      # 0xb61f
callq 0x2330
cmpl $0x0, %eax
je 0x559c
movq -0x18(%rbp), %rdi
leaq 0x60a5(%rip), %rsi      # 0xb622
callq 0x2330
cmpl $0x0, %eax
je 0x559c
movq -0x18(%rbp), %rdi
leaq 0x608f(%rip), %rsi      # 0xb621
callq 0x2330
cmpl $0x0, %eax
jne 0x55bd
leaq 0x6087(%rip), %rdi      # 0xb62a
leaq 0x6094(%rip), %rsi      # 0xb63e
movb $0x0, %al
callq 0x2030
movl $0x0, -0x4(%rbp)
jmp 0x5812
movq -0x18(%rbp), %rsi
leaq 0x607a(%rip), %rdi      # 0xb642
movb $0x0, %al
callq 0x2030
movl $0x1, -0x4(%rbp)
jmp 0x5812
testb $0x1, 0xbd2e(%rip)      # 0x11310
je 0x5620
movq 0xb9d5(%rip), %rax      # 0x10fc0
movq (%rax), %rsi
leaq 0x6067(%rip), %rdi      # 0xb65c
callq 0x22b0
movq 0xb9bf(%rip), %rax      # 0x10fc0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2350
movq 0xb9cc(%rip), %rax      # 0x10fe0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2350
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x2f40
leaq 0x6022(%rip), %rdi      # 0xb66a
callq 0x22f0
cmpq $0x0, %rax
je 0x5660
callq 0x4a40
movl %eax, -0x4(%rbp)
jmp 0x5812
leaq -0x830(%rbp), %rdi
leaq 0x60e2(%rip), %rsi      # 0xb750
movl $0x400, %edx            # imm = 0x400
callq 0x21c0
leaq -0x830(%rbp), %rdi
leaq 0x5f1a(%rip), %rsi      # 0xb5a0
callq 0x22c0
movq %rax, -0x428(%rbp)
cmpq $0x0, -0x428(%rbp)
jne 0x56ef
leaq -0x830(%rbp), %rax
movq %rax, -0x840(%rbp)
leaq 0x5fc7(%rip), %rdi      # 0xb678
callq 0x22f0
movq -0x840(%rbp), %rdi
movq %rax, %rdx
leaq 0x5fab(%rip), %rsi      # 0xb672
leaq 0x5faf(%rip), %rcx      # 0xb67d
movb $0x0, %al
callq 0x2050
leaq -0x830(%rbp), %rdi
leaq 0x5ebd(%rip), %rsi      # 0xb5a0
callq 0x22c0
movq %rax, -0x428(%rbp)
cmpq $0x0, -0x428(%rbp)
je 0x5792
leaq 0x5f84(%rip), %rax      # 0xb688
movq %rax, -0x838(%rbp)
leaq -0x830(%rbp), %rsi
leaq 0x5f74(%rip), %rdi      # 0xb68d
movb $0x0, %al
callq 0x2030
movq -0x838(%rbp), %rdi
movq 0xb892(%rip), %rax      # 0x10fc0
movq (%rax), %rsi
callq 0x22b0
leaq -0x420(%rbp), %rdi
movq -0x428(%rbp), %rdx
movl $0x400, %esi            # imm = 0x400
callq 0x23b0
cmpq $0x0, %rax
je 0x5786
leaq -0x420(%rbp), %rdi
movq 0xb85e(%rip), %rax      # 0x10fc0
movq (%rax), %rsi
callq 0x22b0
leaq -0x420(%rbp), %rdi
movq -0x838(%rbp), %rsi
callq 0x50a0
cmpl $0x0, %eax
je 0x5784
jmp 0x5786
jmp 0x5736
movq -0x428(%rbp), %rdi
callq 0x2230
movq 0xb827(%rip), %rax      # 0x10fc0
movq (%rax), %rsi
leaq 0x5ee7(%rip), %rdi      # 0xb68a
callq 0x22b0
testb $0x1, 0xbb61(%rip)      # 0x11310
je 0x57c7
movq 0xb808(%rip), %rax      # 0x10fc0
movq (%rax), %rsi
leaq 0x5b20(%rip), %rdi      # 0xb2e2
callq 0x22b0
jmp 0x57c9
leaq -0x420(%rbp), %rdi
movq 0xb801(%rip), %rax      # 0x10fd8
movq (%rax), %rdx
movl $0x400, %esi            # imm = 0x400
callq 0x23b0
cmpq $0x0, %rax
je 0x5806
leaq -0x420(%rbp), %rdi
leaq 0x5e92(%rip), %rsi      # 0xb68a
callq 0x50a0
cmpl $0x0, %eax
je 0x5804
jmp 0x5806
jmp 0x57c9
callq 0x3080
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x840, %rsp            # imm = 0x840
popq %rbp
retq
nop