// File: /workspace/github_cpp_makefile_star2_O2/roberty65[P]bServer/common/src/ConfigProperty.cpp
// Function: ConfigProperty::parse(char const*)
int ConfigProperty::parse(const char *file)
{
	FILE *fp = fopen(file, "r");
	if (fp == NULL) return -1;
	
	int lineno = 0;
	char buf[(CP_NAME_MAX + CP_VALUE_MAX) * 2];

	while (fgets(buf, sizeof buf, fp) != NULL) {
		++lineno;
		if (*buf == '#') continue;

		int slen = strlen(buf);	
		while (slen > 0 && (buf[slen - 1] == '\n' || buf[slen - 1] == '\r'))
			--slen;
		buf[slen] = 0;

		char *endptr = buf + slen;
		if ((endptr = strchr(buf, '#')) != NULL) {
			*endptr = 0;
		}

#define SKIP_SPACE(p)	do { while (isspace(*(p))) (p)++; } while (0)
#define SKIP_CHARS(p)	do { while (*(p) && !isspace(*(p))) (p)++; } while (0)

		char *nptr = buf;
		SKIP_SPACE(nptr);
		if (*nptr == 0) continue; // empty-line

		char *vptr = strchr(nptr, '=');
		if (vptr == NULL) {
			fprintf(stderr, "No '=' found at line: %d\n", lineno);
			errno = EINVAL;
			fclose(fp);
			return -1;
		}
		else {
			*vptr++ = 0;
		}

		SKIP_SPACE(nptr); endptr = nptr; SKIP_CHARS(endptr); *endptr = 0;
		SKIP_SPACE(vptr); endptr = vptr; SKIP_CHARS(endptr); *endptr = 0;
#undef SKIP_SPACE
#undef SKIP_CHARS
		properties.insert(std::make_pair(std::string(nptr), std::string(vptr)));
	}

	fclose(fp);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xaa8, %rsp            # imm = 0xAA8
movq %rsi, %rax
movq %rdi, 0x18(%rsp)
leaq 0x32d5(%rip), %rsi      # 0xae4f
movq %rax, %rdi
callq 0x33f0
testq %rax, %rax
je 0x7d5b
movq %rax, %r12
leaq 0xa0(%rsp), %rbx
xorl %r15d, %r15d
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
movl $0xa00, %esi            # imm = 0xA00
movq %r12, %rdx
callq 0x3580
testq %rax, %rax
je 0x7d4f
incl %r15d
cmpb $0x23, 0xa0(%rsp)
je 0x7b9e
movq %rbx, %rdi
callq 0x3140
movl %eax, %edx
movl %eax, %ecx
sarl $0x1f, %ecx
andl %eax, %ecx
testl %edx, %edx
jle 0x7bf2
movzbl 0x9f(%rsp,%rdx), %eax
cmpl $0xd, %eax
je 0x7beb
cmpl $0xa, %eax
jne 0x7bf0
decq %rdx
jmp 0x7bd5
movl %edx, %ecx
movslq %ecx, %rax
movb $0x0, 0xa0(%rsp,%rax)
movq %rbx, %rdi
pushq $0x23
popq %rsi
callq 0x3110
testq %rax, %rax
je 0x7c10
movb $0x0, (%rax)
leaq 0xa1(%rsp), %rcx
leaq 0x9f(%rsp), %r13
movq %r13, %rbp
movq %rcx, %r14
incq %r13
movb 0x1(%rbp), %bl
movsbl %bl, %edi
callq 0x3070
leaq 0x1(%r14), %rcx
testl %eax, %eax
jne 0x7c20
testb %bl, %bl
leaq 0xa0(%rsp), %rbx
je 0x7b9e
movq %r13, %rdi
pushq $0x3d
popq %rsi
callq 0x3110
testq %rax, %rax
je 0x7d72
movq %rax, %r13
movb $0x0, (%rax)
movq %r14, %r12
movb 0x1(%rbp), %bl
incq %rbp
movsbl %bl, %edi
callq 0x3070
incq %r14
testl %eax, %eax
jne 0x7c66
jmp 0x7c87
movb (%r12), %bl
incq %r12
testb %bl, %bl
je 0x7c97
movsbl %bl, %edi
callq 0x3070
testl %eax, %eax
je 0x7c80
movb $0x0, -0x1(%r12)
movq %r13, %rcx
addq $0x2, %rcx
movq %rcx, %r14
movb 0x1(%r13), %bl
incq %r13
movsbl %bl, %edi
callq 0x3070
leaq 0x1(%r14), %rcx
testl %eax, %eax
jne 0x7ca4
movq 0x10(%rsp), %r12
testb %bl, %bl
je 0x7cdb
movsbl %bl, %edi
callq 0x3070
testl %eax, %eax
jne 0x7cdb
movb (%r14), %bl
incq %r14
jmp 0x7cc3
movb $0x0, -0x1(%r14)
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
leaq 0xf(%rsp), %rdx
callq 0x4168
leaq 0x20(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
leaq 0xe(%rsp), %rdx
callq 0x4168
leaq 0x60(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x825e
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x8284
leaq 0xa0(%rsp), %rbx
movq %r13, %rdi
callq 0x8248
movq %rbp, %rdi
callq 0x3150
movq %r14, %rdi
callq 0x3150
jmp 0x7b9e
xorl %ebx, %ebx
movq %r12, %rdi
callq 0x3330
jmp 0x7d5e
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0xaa8, %rsp            # imm = 0xAA8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x825f(%rip), %rax      # 0xffd8
movq (%rax), %rdi
leaq 0x369e(%rip), %rsi      # 0xb421
movl %r15d, %edx
xorl %eax, %eax
callq 0x3510
callq 0x3060
movl $0x16, (%rax)
pushq $-0x1
popq %rbx
jmp 0x7d51
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x8248
leaq 0x20(%rsp), %rdi
callq 0x3150
jmp 0x7db9
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x3150
movq %rbx, %rdi
callq 0x3600
nop