// File: /workspace/github_c_makefile_star2_O3/shifengbin[P]bishe/ConfigParser/configparser.cpp
// Function: ConfigParser::ConfigParser(char const*)
ConfigParser::ConfigParser(const char *filename)
{

    if ( filename == NULL )
        return;
    init();
    char buf[BUFSIZE];
    char sql[BUFSIZE] = { 0 };
    char *pre;
    char *next;
    Persistence *db;

    FILE *fp = fopen( filename , "r" );

    if (fp == NULL)
    {
        return;
    }

    db = Persistence::getPersistence();
    db->exec("create table URL(id integer primary key,urlstr varchar(100),type int,deep int default 0,state int default 0)");

    while(fgets( buf , BUFSIZE , fp) != NULL)
    {


        if ( !strncmp( buf , DURATION , strlen( DURATION ) ) )
        {
            this->duration = atoi(buf+strlen(DURATION));
        }

        else if ( !strncmp( buf , TIMEOUT , strlen(TIMEOUT) ) )
        {
            this->timeout = atoi( buf + strlen( TIMEOUT ));
        }

        else if ( !strncmp( buf , JOBNUM , strlen( JOBNUM )) )
        {
            this->jobnum = atoi( buf + strlen( JOBNUM ));
        }

        else if ( !strncmp( buf  , DEEPTH , strlen(DEEPTH)) )
        {
            this->deepth = atoi( buf + strlen( DEEPTH ));
        }

        else if ( !strncmp( buf  , METHOD , strlen( METHOD )) )
        {
            this->method = atoi( buf + strlen( METHOD ));
        }

        else if ( !strncmp( buf, URLS, strlen(URLS)) )
        {
            while( fgets( buf , BUFSIZE , fp )!= NULL)
            {
                if( !strncmp( buf , END , strlen(END)))
                {
                    break;
                }

                if ( (pre = strstr( buf , SEPARATOR )) != NULL)
                {
                    //应该写入数据库
                    *pre = '\0';
		    pre++;
//                    std::cout <<"URL:"<<buf<<" TYPE:"<<atoi(pre)<<std::endl;
		    sprintf( sql ,"insert into URL(urlstr,type) values('%s',%d)",buf,atoi(pre));
		    
//		    db->exec(sql);
		    if ( !Bloom::isExist(buf) )
		    {
			Bloom::addFilter(buf);
			db->exec(sql);
		    }
                }
            }

        }

        else if ( !strncmp( buf ,MODE , strlen(MODE) ))
        {
            while( fgets( buf , BUFSIZE , fp ) != NULL )
            {
                if( !strncmp( buf , END , strlen(END)))
                {
                    break;
                }

                if ( (pre = strstr( buf , SEPARATOR )) != NULL &&
                     (next = strstr( pre + 1 , SEPARATOR )) != NULL)
                {
                    *pre = '\0';
                    pre++;
                    *next = '\0';
                    next++;
		    if ( this->modes[atoi(buf)] == NULL )
                    {
			this->modes[atoi(buf)] = new ModePair(pre,atoi(next));
		    }
                }
            }
        }

        memset(buf , 0 , BUFSIZE);
    }

	fclose(fp);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x818, %rsp            # imm = 0x818
testq %rsi, %rsi
je 0xa0d5
movq %rsi, %r15
movq %rdi, %rbx
movaps 0x6d4d0(%rip), %xmm0    # 0x77250
movups %xmm0, (%rdi)
movb $0x1, 0x10(%rdi)
addq $0x18, %rdi
movl $0xa0, %edx
movq %rdi, -0x30(%rbp)
xorl %esi, %esi
callq 0x8160
leaq -0x840(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x8160
leaq 0x71c29(%rip), %rsi     # 0x7b9de
movq %r15, %rdi
callq 0x8350
testq %rax, %rax
je 0xa0d5
movq %rax, %r14
callq 0x93ea
leaq 0x6d496(%rip), %rsi     # 0x7726b
movq %rax, -0x38(%rbp)
movq %rax, %rdi
callq 0x9496
leaq -0x440(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdx
callq 0x84d0
testq %rax, %rax
je 0xa0cd
movabsq $0x4e4f495441525544, %r15 # imm = 0x4E4F495441525544
leaq -0x440(%rbp), %r13
movabsq $0x3d54554f454d4954, %r12 # imm = 0x3D54554F454D4954
movq -0x440(%rbp), %rax
xorq %r15, %rax
movzbl -0x438(%rbp), %ecx
xorq $0x3d, %rcx
orq %rax, %rcx
je 0x9e53
movq -0x440(%rbp), %rax
cmpq %r12, %rax
jne 0x9e66
leaq -0x438(%rbp), %rdi
callq 0x84c0
movl %eax, 0x4(%rbx)
jmp 0xa0a5
leaq -0x437(%rbp), %rdi
callq 0x84c0
movl %eax, (%rbx)
jmp 0xa0a5
movl -0x440(%rbp), %ecx
movl $0x4e424f4a, %edx       # imm = 0x4E424F4A
xorl %edx, %ecx
movl -0x43d(%rbp), %edx
movl $0x3d4d554e, %esi       # imm = 0x3D4D554E
xorl %esi, %edx
orl %ecx, %edx
je 0xa071
movl -0x440(%rbp), %ecx
movl $0x50454544, %edx       # imm = 0x50454544
xorl %edx, %ecx
movl -0x43d(%rbp), %edx
movl $0x3d485450, %esi       # imm = 0x3D485450
xorl %esi, %edx
orl %ecx, %edx
je 0xa082
movl -0x440(%rbp), %ecx
movl $0x4854454d, %edx       # imm = 0x4854454D
xorl %edx, %ecx
movl -0x43d(%rbp), %edx
movl $0x3d444f48, %esi       # imm = 0x3D444F48
xorl %esi, %edx
orl %ecx, %edx
je 0xa093
cmpl $0x534c5255, %eax       # imm = 0x534C5255
je 0xa03a
cmpl $0x45444f4d, %eax       # imm = 0x45444F4D
jne 0xa0a5
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdx
callq 0x84d0
testq %rax, %rax
movq %rbx, -0x40(%rbp)
je 0xa0a5
movl -0x440(%rbp), %eax
movl $0x4e45, %ecx           # imm = 0x4E45
xorl %ecx, %eax
movzbl -0x43e(%rbp), %ecx
xorl $0x44, %ecx
orw %ax, %cx
je 0xa0a5
movq %r14, %r15
movq %r13, %rdi
movl $0x7c, %esi
callq 0x8100
testq %rax, %rax
je 0x9fa3
movq %rax, %r14
leaq 0x1(%rax), %r12
movq %r12, %rdi
movl $0x7c, %esi
callq 0x8100
testq %rax, %rax
je 0x9fa3
movq %rax, %rbx
xorl %eax, %eax
movb %al, (%r14)
movb %al, (%rbx)
movq %r13, %rdi
callq 0x84c0
cltq
movq -0x30(%rbp), %rcx
cmpq $0x0, (%rcx,%rax,8)
jne 0x9fa3
incq %rbx
movl $0x10, %edi
callq 0x8300
movq %rax, %r14
movq %rbx, %rdi
callq 0x84c0
movq %r14, %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0xa49c
movq %r13, %rdi
callq 0x84c0
cltq
movq -0x30(%rbp), %rcx
movq %r14, (%rcx,%rax,8)
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %r14
movq %r15, %rdx
callq 0x84d0
testq %rax, %rax
movq -0x40(%rbp), %rbx
movabsq $0x4e4f495441525544, %r15 # imm = 0x4E4F495441525544
movabsq $0x3d54554f454d4954, %r12 # imm = 0x3D54554F454D4954
jne 0x9eff
jmp 0xa0a5
movq %r13, %rdi
movl $0x7c, %esi
callq 0x8100
testq %rax, %rax
je 0xa03a
movb $0x0, (%rax)
incq %rax
movq %rax, %rdi
callq 0x84c0
leaq -0x840(%rbp), %rdi
leaq 0x6d2f0(%rip), %rsi     # 0x772fa
movq %r13, %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0x8080
movq %r13, %rdi
callq 0x8976
testl %eax, %eax
jne 0xa03a
movq %r13, %rdi
callq 0x8948
movq -0x38(%rbp), %rdi
leaq -0x840(%rbp), %rsi
callq 0x9496
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdx
callq 0x84d0
testq %rax, %rax
je 0xa0a5
movl -0x440(%rbp), %eax
movl $0x4e45, %ecx           # imm = 0x4E45
xorl %ecx, %eax
movzbl -0x43e(%rbp), %ecx
xorl $0x44, %ecx
orw %ax, %cx
jne 0x9fdc
jmp 0xa0a5
leaq -0x439(%rbp), %rdi
callq 0x84c0
movl %eax, 0x8(%rbx)
jmp 0xa0a5
leaq -0x439(%rbp), %rdi
callq 0x84c0
movl %eax, 0xc(%rbx)
jmp 0xa0a5
leaq -0x439(%rbp), %rdi
callq 0x84c0
testl %eax, %eax
setne 0x10(%rbx)
movl $0x400, %edx            # imm = 0x400
movq %r13, %rdi
xorl %esi, %esi
callq 0x8160
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdx
callq 0x84d0
testq %rax, %rax
jne 0x9e19
movq %r14, %rdi
callq 0x82f0
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x10, %esi
movq %r14, %rdi
callq 0x8310
movq %rbx, %rdi
callq 0x8520
nop