// File: /workspace/github_c_makefile_star2_O2/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 0x9fbb
movq %rsi, %r14
movq %rdi, %rbx
movaps 0x5e57c(%rip), %xmm0    # 0x68250
movups %xmm0, (%rdi)
movb $0x1, 0x10(%rdi)
addq $0x18, %rdi
movl $0xa0, %edx
movq %rdi, -0x38(%rbp)
xorl %esi, %esi
callq 0x8160
leaq -0x840(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x8160
leaq 0x62cc5(%rip), %rsi     # 0x6c9ce
movq %r14, %rdi
callq 0x8350
testq %rax, %rax
je 0x9fbb
movq %rax, %r15
movq %rbx, -0x30(%rbp)
callq 0x933e
leaq 0x5e53e(%rip), %rsi     # 0x6826b
movq %rax, -0x40(%rbp)
movq %rax, %rdi
callq 0x93e4
leaq -0x440(%rbp), %r13
pushq $0x7
popq %r14
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x84d0
testq %rax, %rax
je 0x9fb3
movq %r13, %rdi
leaq 0x5e571(%rip), %rsi     # 0x682d8
pushq $0x9
popq %rdx
callq 0x8320
testl %eax, %eax
je 0x9da1
movq -0x440(%rbp), %rbx
movabsq $0x3d54554f454d4954, %rax # imm = 0x3D54554F454D4954
cmpq %rax, %rbx
jne 0x9db8
leaq -0x438(%rbp), %rdi
callq 0x84c0
movq -0x30(%rbp), %rcx
movl %eax, 0x4(%rcx)
jmp 0x9f9f
leaq -0x437(%rbp), %rdi
callq 0x84c0
movq -0x30(%rbp), %rcx
movl %eax, (%rcx)
jmp 0x9f9f
movq %r13, %rdi
leaq 0x5e520(%rip), %rsi     # 0x682e2
movq %r14, %rdx
callq 0x8320
testl %eax, %eax
je 0x9f5f
movq %r13, %rdi
leaq 0x5e50e(%rip), %rsi     # 0x682ea
movq %r14, %rdx
callq 0x8320
testl %eax, %eax
je 0x9f74
movq %r13, %rdi
leaq 0x5e4fc(%rip), %rsi     # 0x682f2
movq %r14, %rdx
callq 0x8320
testl %eax, %eax
je 0x9f89
cmpl $0x534c5255, %ebx       # imm = 0x534C5255
je 0x9f2e
cmpl $0x45444f4d, %ebx       # imm = 0x45444F4D
jne 0x9f9f
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x84d0
testq %rax, %rax
je 0x9f9f
movq %r13, %rdi
leaq 0x5e1e3(%rip), %rsi     # 0x68024
pushq $0x3
popq %rdx
callq 0x8320
testl %eax, %eax
je 0x9f9f
movq %r13, %rdi
pushq $0x7c
popq %rsi
callq 0x8100
testq %rax, %rax
je 0x9e1e
movq %rax, %rbx
leaq 0x1(%rax), %r14
movq %r14, %rdi
pushq $0x7c
popq %rsi
callq 0x8100
testq %rax, %rax
je 0x9e1e
movq %rax, %r12
xorl %eax, %eax
movb %al, (%rbx)
movb %al, (%r12)
movq %r13, %rdi
callq 0x84c0
cltq
movq -0x38(%rbp), %rcx
cmpq $0x0, (%rcx,%rax,8)
jne 0x9e1e
incq %r12
pushq $0x10
popq %rdi
callq 0x8300
movq %rax, %rbx
movq %r12, %rdi
callq 0x84c0
movq %rbx, %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0xa330
movq %r13, %rdi
callq 0x84c0
cltq
movq -0x38(%rbp), %rcx
movq %rbx, (%rcx,%rax,8)
jmp 0x9e1e
movq %r13, %rdi
pushq $0x7c
popq %rsi
callq 0x8100
testq %rax, %rax
je 0x9f2e
movb $0x0, (%rax)
incq %rax
movq %rax, %rdi
callq 0x84c0
leaq -0x840(%rbp), %rdi
leaq 0x5e3fc(%rip), %rsi     # 0x682fa
movq %r13, %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0x8080
movq %r13, %rdi
callq 0x887a
testl %eax, %eax
jne 0x9f2e
movq %r13, %rdi
callq 0x884c
movq -0x40(%rbp), %rdi
leaq -0x840(%rbp), %rsi
callq 0x93e4
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x84d0
testq %rax, %rax
je 0x9f9f
movq %r13, %rdi
leaq 0x5e0d7(%rip), %rsi     # 0x68024
pushq $0x3
popq %rdx
callq 0x8320
testl %eax, %eax
jne 0x9ed2
jmp 0x9f9f
leaq -0x439(%rbp), %rdi
callq 0x84c0
movq -0x30(%rbp), %rcx
movl %eax, 0x8(%rcx)
jmp 0x9f9f
leaq -0x439(%rbp), %rdi
callq 0x84c0
movq -0x30(%rbp), %rcx
movl %eax, 0xc(%rcx)
jmp 0x9f9f
leaq -0x439(%rbp), %rdi
callq 0x84c0
testl %eax, %eax
movq -0x30(%rbp), %rax
setne 0x10(%rax)
movl $0x400, %edx            # imm = 0x400
movq %r13, %rdi
xorl %esi, %esi
callq 0x8160
jmp 0x9d40
movq %r15, %rdi
callq 0x82f0
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0x8310
movq %r14, %rdi
callq 0x8520
nop