// File: billDrett[P]Bulletin-Boards/boardPost.cpp
// Function: BoardPost::getChanels()
void BoardPost::getChanels()
{
    int nwrite, nread;
    char buffer[BUFFERSIZE];
    char* tmp;
    char* tmp1;
    string tmpTag;
    statesChanels state = waitingChanel;

    if((nwrite = write(pipeBoardPost2Server, "<Chanels>", 9))== -1) //stelnoume mnm sto server na epistrepsei ta chanels tou
    {
        perror("Cant write to pipe S2BP");
    }

    while((nread = read(pipeServer2BoardPost, buffer + tmpTag.size(), BUFFERSIZE - tmpTag.size())) > 0) //diavazoume thn apanthsh tou server mexri na vroume to <end><Chanel>
    {                                                                                                   //se periptwsh pou diavastike meros tou proigoumenou tag diavazw ligotera bytes kai prostheto to proigoumeno tag sthn arxh
        strncpy(buffer, tmpTag.c_str(), tmpTag.size()); //antigrafw to meros tou proigoumenou tag efoson yparxei
        nread += tmpTag.size();
        tmpTag = ""; //midenizw to proigoumeno tag
        tmp = buffer;

        if(state == waitingChanel)//perimenw na vrw to <Chanel>
        {
            tmp1 = getAfterTag(tmp, "<Chanel>", nread);
            if(tmp1 == NULL) //dn vrethike to chanel tag
            {
                if((tmp1 = getAfterTag(tmp, "<", nread)) != NULL) // mporei na pira meros tou tag, to apothikeuw kai to prosthetw sthn arxh tou neou read
                {
                    tmpTag.assign(tmp1-1, nread+1); // -1 giati thelw na krathsw kai to "< kai +1 sto read gia na to symperilavw
                }
                continue;
            }
            tmp = tmp1;
            state = waitingStart;
        }

        if(state == waitingStart) //perimenw na vrw to <start>
        {
            tmp1 = getAfterTag(tmp, "<start>", nread);
            if(tmp1 == NULL)
            {
                if((tmp1 = getAfterTag(tmp, "<", nread)) != NULL) // mporei na pira meros tou tag, to apothikeuw kai to prosthetw sthn arxh tou neou read
                {
                    tmpTag.assign(tmp1-1, nread+1); // -1 giati thelw na krathsw kai to "< kai +1 sto read gia na to symperilavw
                }
                continue;
            }
            tmp = tmp1;
            state = waitingEnd;
        }
        if(state == waitingEnd) //perimenw na vrw to <end>
        {
            int copyNread = nread;
            if(getBeforeTag(tmp, "<end>", copyNread) != NULL) //emfanizw ta chanels mexri na vrw to tag <end>, an to vrw emfanizw ta bytes mexri to <end>
            {
                state = waitingEndChanel;
            }

            write(1, tmp, copyNread); //grafw ta bytes mexri to copyNread
        }

        if(state == waitingEndChanel) //perimenw na vrw to <Chanel> meta to <end>
        {
            tmp1 = getBeforeTag(tmp, "<Chanel>", nread);
            if(tmp1 == NULL)
            {
                if((tmp1 = getAfterTag(tmp, "<", nread)) != NULL) // mporei na pira meros tou tag, to apothikeuw kai to prosthetw sthn arxh tou neou read
                {
                    tmpTag.assign(tmp1-1, nread+1); // -1 giati thelw na krathsw kai to "< kai +1 sto read gia na to symperilavw
                }
                continue;
            }
            break; //oloklirwthike to mnm
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4d0, %rsp            # imm = 0x4D0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x468(%rbp)
leaq -0x440(%rbp), %rdi
callq 0x2260
movq -0x468(%rbp), %rax
movl $0x0, -0x444(%rbp)
movl (%rax), %edi
leaq 0x13b3(%rip), %rsi      # 0x4063
movl $0x9, %edx
callq 0x20b0
movq %rax, -0x460(%rbp)
jmp 0x2cc3
movq -0x460(%rbp), %rax
movl %eax, -0xc(%rbp)
cmpl $-0x1, %eax
jne 0x2d05
leaq 0x1394(%rip), %rdi      # 0x406d
callq 0x2180
jmp 0x2ce0
jmp 0x2d05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x450(%rbp)
movl %eax, -0x454(%rbp)
leaq -0x440(%rbp), %rdi
callq 0x2150
jmp 0x3085
jmp 0x2d07
movq -0x468(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x47c(%rbp)
leaq -0x440(%rbp), %rdi
movq %rdi, -0x488(%rbp)
callq 0x2160
movq -0x488(%rbp), %rdi
leaq -0x410(%rbp,%rax), %rax
movq %rax, -0x478(%rbp)
callq 0x2160
movl -0x47c(%rbp), %edi
movq -0x478(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
subq %rax, %rdx
callq 0x2270
movq %rax, -0x470(%rbp)
jmp 0x2d68
movq -0x470(%rbp), %rax
movl %eax, -0x10(%rbp)
cmpl $0x0, %eax
jle 0x3070
leaq -0x440(%rbp), %rdi
movq %rdi, -0x490(%rbp)
callq 0x20d0
movq -0x490(%rbp), %rdi
movq %rax, -0x498(%rbp)
callq 0x2160
movq -0x498(%rbp), %rsi
movq %rax, %rdx
leaq -0x410(%rbp), %rdi
callq 0x2120
movq -0x490(%rbp), %rdi
callq 0x2160
movq -0x490(%rbp), %rdi
movq %rax, %rcx
movl -0x10(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x10(%rbp)
leaq 0x133b(%rip), %rsi      # 0x4117
callq 0x2250
jmp 0x2de3
leaq -0x410(%rbp), %rax
movq %rax, -0x418(%rbp)
cmpl $0x0, -0x444(%rbp)
jne 0x2ea9
movq -0x418(%rbp), %rdi
leaq 0x1279(%rip), %rsi      # 0x4085
leaq -0x10(%rbp), %rdx
callq 0x3d10
movq %rax, -0x4a0(%rbp)
jmp 0x2e1e
movq -0x4a0(%rbp), %rax
movq %rax, -0x420(%rbp)
cmpq $0x0, -0x420(%rbp)
jne 0x2e91
movq -0x418(%rbp), %rdi
leaq 0x124a(%rip), %rsi      # 0x408e
leaq -0x10(%rbp), %rdx
callq 0x3d10
movq %rax, -0x4a8(%rbp)
jmp 0x2e56
movq -0x4a8(%rbp), %rax
movq %rax, -0x420(%rbp)
cmpq $0x0, %rax
je 0x2e8c
movq -0x420(%rbp), %rsi
decq %rsi
movl -0x10(%rbp), %eax
incl %eax
movslq %eax, %rdx
leaq -0x440(%rbp), %rdi
callq 0x2240
jmp 0x2e8a
jmp 0x2e8c
jmp 0x2d07
movq -0x420(%rbp), %rax
movq %rax, -0x418(%rbp)
movl $0x1, -0x444(%rbp)
cmpl $0x1, -0x444(%rbp)
jne 0x2f61
movq -0x418(%rbp), %rdi
leaq 0x11db(%rip), %rsi      # 0x409f
leaq -0x10(%rbp), %rdx
callq 0x3d10
movq %rax, -0x4b0(%rbp)
jmp 0x2ed6
movq -0x4b0(%rbp), %rax
movq %rax, -0x420(%rbp)
cmpq $0x0, -0x420(%rbp)
jne 0x2f49
movq -0x418(%rbp), %rdi
leaq 0x1192(%rip), %rsi      # 0x408e
leaq -0x10(%rbp), %rdx
callq 0x3d10
movq %rax, -0x4b8(%rbp)
jmp 0x2f0e
movq -0x4b8(%rbp), %rax
movq %rax, -0x420(%rbp)
cmpq $0x0, %rax
je 0x2f44
movq -0x420(%rbp), %rsi
decq %rsi
movl -0x10(%rbp), %eax
incl %eax
movslq %eax, %rdx
leaq -0x440(%rbp), %rdi
callq 0x2240
jmp 0x2f42
jmp 0x2f44
jmp 0x2d07
movq -0x420(%rbp), %rax
movq %rax, -0x418(%rbp)
movl $0x2, -0x444(%rbp)
cmpl $0x2, -0x444(%rbp)
jne 0x2fc9
movl -0x10(%rbp), %eax
movl %eax, -0x458(%rbp)
movq -0x418(%rbp), %rdi
leaq 0x110f(%rip), %rsi      # 0x4090
leaq -0x458(%rbp), %rdx
callq 0x3da0
movq %rax, -0x4c0(%rbp)
jmp 0x2f96
movq -0x4c0(%rbp), %rax
cmpq $0x0, %rax
je 0x2fad
movl $0x3, -0x444(%rbp)
movq -0x418(%rbp), %rsi
movslq -0x458(%rbp), %rdx
movl $0x1, %edi
callq 0x20b0
jmp 0x2fc7
jmp 0x2fc9
cmpl $0x3, -0x444(%rbp)
jne 0x306b
movq -0x418(%rbp), %rdi
leaq 0x10a1(%rip), %rsi      # 0x4085
leaq -0x10(%rbp), %rdx
callq 0x3da0
movq %rax, -0x4c8(%rbp)
jmp 0x2ff6
movq -0x4c8(%rbp), %rax
movq %rax, -0x420(%rbp)
cmpq $0x0, -0x420(%rbp)
jne 0x3069
movq -0x418(%rbp), %rdi
leaq 0x1072(%rip), %rsi      # 0x408e
leaq -0x10(%rbp), %rdx
callq 0x3d10
movq %rax, -0x4d0(%rbp)
jmp 0x302e
movq -0x4d0(%rbp), %rax
movq %rax, -0x420(%rbp)
cmpq $0x0, %rax
je 0x3064
movq -0x420(%rbp), %rsi
decq %rsi
movl -0x10(%rbp), %eax
incl %eax
movslq %eax, %rdx
leaq -0x440(%rbp), %rdi
callq 0x2240
jmp 0x3062
jmp 0x3064
jmp 0x2d07
jmp 0x3070
jmp 0x2d07
leaq -0x440(%rbp), %rdi
callq 0x2150
addq $0x4d0, %rsp            # imm = 0x4D0
popq %rbp
retq
movq -0x450(%rbp), %rdi
callq 0x22a0
nopw %cs:(%rax,%rax)