// File: /workspace/github_c_makefile_star2_O1/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 0xa0d8
movq %rsi, %r15
movq %rdi, %rbx
movaps 0x6f4d0(%rip), %xmm0    # 0x79250
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 0x73c19(%rip), %rsi     # 0x7d9ce
movq %r15, %rdi
callq 0x8340
testq %rax, %rax
je 0xa0d8
movq %rax, %r14
callq 0x93d6
leaq 0x6f496(%rip), %rsi     # 0x7926b
movq %rax, -0x38(%rbp)
movq %rax, %rdi
callq 0x9484
leaq -0x440(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdx
callq 0x84c0
testq %rax, %rax
je 0xa0d0
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 0x9e50
cmpq %r12, -0x440(%rbp)
jne 0x9e63
leaq -0x438(%rbp), %rdi
callq 0x84b0
movl %eax, 0x4(%rbx)
jmp 0xa0a8
leaq -0x437(%rbp), %rdi
callq 0x84b0
movl %eax, (%rbx)
jmp 0xa0a8
movl -0x440(%rbp), %eax
movl $0x4e424f4a, %ecx       # imm = 0x4E424F4A
xorl %ecx, %eax
movl -0x43d(%rbp), %ecx
movl $0x3d4d554e, %edx       # imm = 0x3D4D554E
xorl %edx, %ecx
orl %eax, %ecx
je 0xa074
movl -0x440(%rbp), %eax
movl $0x50454544, %ecx       # imm = 0x50454544
xorl %ecx, %eax
movl -0x43d(%rbp), %ecx
movl $0x3d485450, %edx       # imm = 0x3D485450
xorl %edx, %ecx
orl %eax, %ecx
je 0xa085
movl -0x440(%rbp), %eax
movl $0x4854454d, %ecx       # imm = 0x4854454D
xorl %ecx, %eax
movl -0x43d(%rbp), %ecx
movl $0x3d444f48, %edx       # imm = 0x3D444F48
xorl %edx, %ecx
orl %eax, %ecx
je 0xa096
movl -0x440(%rbp), %eax
cmpl $0x534c5255, %eax       # imm = 0x534C5255
je 0xa03d
cmpl $0x45444f4d, %eax       # imm = 0x45444F4D
jne 0xa0a8
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdx
callq 0x84c0
testq %rax, %rax
movq %rbx, -0x40(%rbp)
je 0xa0a8
movl -0x440(%rbp), %eax
movl $0x4e45, %ecx           # imm = 0x4E45
xorl %ecx, %eax
movzbl -0x43e(%rbp), %ecx
xorl $0x44, %ecx
orw %ax, %cx
je 0xa0a8
movq %r14, %r15
movq %r13, %rdi
movl $0x7c, %esi
callq 0x8100
testq %rax, %rax
je 0x9fa6
movq %rax, %r14
leaq 0x1(%rax), %r12
movq %r12, %rdi
movl $0x7c, %esi
callq 0x8100
testq %rax, %rax
je 0x9fa6
movq %rax, %rbx
xorl %eax, %eax
movb %al, (%r14)
movb %al, (%rbx)
movq %r13, %rdi
callq 0x84b0
cltq
movq -0x30(%rbp), %rcx
cmpq $0x0, (%rcx,%rax,8)
jne 0x9fa6
incq %rbx
movl $0x10, %edi
callq 0x82f0
movq %rax, %r14
movq %rbx, %rdi
callq 0x84b0
movq %r14, %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0xa4a0
movq %r13, %rdi
callq 0x84b0
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 0x84c0
testq %rax, %rax
movq -0x40(%rbp), %rbx
movabsq $0x4e4f495441525544, %r15 # imm = 0x4E4F495441525544
movabsq $0x3d54554f454d4954, %r12 # imm = 0x3D54554F454D4954
jne 0x9f02
jmp 0xa0a8
movq %r13, %rdi
movl $0x7c, %esi
callq 0x8100
testq %rax, %rax
je 0xa03d
movb $0x0, (%rax)
incq %rax
movq %rax, %rdi
callq 0x84b0
leaq -0x840(%rbp), %rdi
leaq 0x6f2ed(%rip), %rsi     # 0x792fa
movq %r13, %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0x8080
movq %r13, %rdi
callq 0x8966
testl %eax, %eax
jne 0xa03d
movq %r13, %rdi
callq 0x8938
movq -0x38(%rbp), %rdi
leaq -0x840(%rbp), %rsi
callq 0x9484
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdx
callq 0x84c0
testq %rax, %rax
je 0xa0a8
movl -0x440(%rbp), %eax
movl $0x4e45, %ecx           # imm = 0x4E45
xorl %ecx, %eax
movzbl -0x43e(%rbp), %ecx
xorl $0x44, %ecx
orw %ax, %cx
jne 0x9fdf
jmp 0xa0a8
leaq -0x439(%rbp), %rdi
callq 0x84b0
movl %eax, 0x8(%rbx)
jmp 0xa0a8
leaq -0x439(%rbp), %rdi
callq 0x84b0
movl %eax, 0xc(%rbx)
jmp 0xa0a8
leaq -0x439(%rbp), %rdi
callq 0x84b0
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 0x84c0
testq %rax, %rax
jne 0x9e19
movq %r14, %rdi
callq 0x82e0
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 0x8300
movq %rbx, %rdi
callq 0x8510
nop