// File: billDrett[P]Bulletin-Boards/boardServer.cpp
// Function: BoardServer::parseCommandPrototype(char*, int&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, void (BoardServer::*)(char*, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&), int)
void BoardServer::parseCommandPrototype(char* buffer, int &nread, std::string CommandType, void (BoardServer::*foo)(char* buffer, int nread, int state, std::string& previousRead), int pipeToRead)
{//o buffer krataei ta perienxomena autou pou diavasame, to commandType einai to string pou perimenoume na diavasoume arxika kai sto telos, kai o pointer se function einai thn tha ekteleitai mexri na synanththei <end>
    string tmpTag , previousRead;
    char* tmp;
    char* tmp1;

    int stateCommand = waitingCommand;

    do
    {
        strncpy(buffer, tmpTag.c_str(), tmpTag.size());
        nread += tmpTag.size();
        tmpTag = "";
        tmp = buffer; //dn ta kanw if else if giati mporei na allaksoun state mesa se ena loop analoga me ta perienxomena tou buffer

        if(stateCommand == waitingCommand)
        {
            tmp1 = getAfterTag(tmp, CommandType.c_str(), nread);
            if(tmp1 == NULL)
            {
                if((tmp1 = getAfterTag(tmp, "<", nread)) != NULL)
                {
                    tmpTag.assign(tmp1-1, nread+1); // -1 giati thelw na krathsw kai to "< kai +1 sto read gia na to symperilavw
                }
                continue;
            }
            tmp = tmp1;
            stateCommand = waitingStart;
        }

        if(stateCommand == waitingStart)
        {
            tmp1 = getAfterTag(tmp, "<start>", nread);
            if(tmp1 == NULL)
            {
                if((tmp1 = getAfterTag(tmp, "<", nread)) != NULL)
                {
                    tmpTag.assign(tmp1-1, nread+1); // -1 giati thelw na krathsw kai to "< kai +1 sto read gia na to symperilavw
                }
                continue;
            }
            tmp = tmp1;
            stateCommand = waitingEnd;
        }

        if(stateCommand == waitingEnd)
        {

            int copyNread = nread;
            if(getBeforeTag(tmp, "<end>", copyNread) != NULL)
            {
                stateCommand = waitingEndCommand;
            }

            (this->*foo)(tmp, copyNread, stateCommand, previousRead); //kalw thn synarthsh pou mou dothike ws parametros
        }

        if(stateCommand == waitingEndCommand)
        {
            tmp1 = getAfterTag(tmp, CommandType.c_str(), nread);
            if(tmp1 == NULL)
            {
                if((tmp1 = getAfterTag(tmp, "<", nread)) != NULL)
                {
                    tmpTag.assign(tmp1-1, nread+1); // -1 giati thelw na krathsw kai to "< kai +1 sto read gia na to symperilavw
                }
                continue;
            }
            tmp = tmp1;
            shiftArray(buffer, tmp, nread);//strncpy(buffer, tmp, nread); //apothikeuw ta ypoloipa tou buffer sthn arxh tou gia na ta diaxeiristei to menu
            return;
        }
    }while(((nread = read(pipeToRead, buffer + tmpTag.size(), BUFFERSIZE - tmpTag.size())) > 0)); //an dn exoun diavastei ola osa thelw kanw ksana read apo to pipe pou mou dwthike
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %r8, %rax
movq %rcx, -0xd0(%rbp)
movq %rdx, %rcx
movq -0xd0(%rbp), %rdx
movq %rcx, -0xc8(%rbp)
movq %rsi, %rcx
movq -0xc8(%rbp), %rsi
movq %rcx, -0xc0(%rbp)
movq %rdi, %r8
movq -0xc0(%rbp), %rdi
movl 0x10(%rbp), %ecx
movq %rax, -0x10(%rbp)
movq %r9, -0x8(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movq %r8, -0x18(%rbp)
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x33e0
leaq -0x80(%rbp), %rdi
callq 0x33e0
movl $0x0, -0x94(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x3130
movq -0xd8(%rbp), %rdi
movq %rax, -0xe0(%rbp)
callq 0x3210
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movq %rax, %rdx
callq 0x31c0
movq -0xd8(%rbp), %rdi
callq 0x3210
movq -0xd8(%rbp), %rdi
movq %rax, %rdx
movq -0x28(%rbp), %rax
movl (%rax), %ecx
addl %edx, %ecx
movl %ecx, (%rax)
leaq 0x3427(%rip), %rsi      # 0xb1f5
callq 0x33d0
jmp 0x7dd5
movq -0x20(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpl $0x0, -0x94(%rbp)
jne 0x7edb
movq -0xd0(%rbp), %rdi
movq -0x88(%rbp), %rax
movq %rax, -0xf8(%rbp)
callq 0x3130
movq -0xf8(%rbp), %rdi
movq %rax, %rsi
movq -0x28(%rbp), %rdx
callq 0x8de0
movq %rax, -0xf0(%rbp)
jmp 0x7e23
movq -0xf0(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0x7ec3
movq -0x88(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x32c2(%rip), %rsi      # 0xb113
callq 0x8de0
movq %rax, -0x100(%rbp)
jmp 0x7e5f
movq -0x100(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
je 0x7ebe
movq -0x90(%rbp), %rsi
decq %rsi
movq -0x28(%rbp), %rax
movl (%rax), %eax
incl %eax
movslq %eax, %rdx
leaq -0x60(%rbp), %rdi
callq 0x33c0
jmp 0x7e93
jmp 0x7ebe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x31f0
leaq -0x60(%rbp), %rdi
callq 0x31f0
jmp 0x81f7
jmp 0x8155
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
movl $0x1, -0x94(%rbp)
cmpl $0x1, -0x94(%rbp)
jne 0x7f93
movq -0x88(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x31df(%rip), %rsi      # 0xb0d9
callq 0x8de0
movq %rax, -0x108(%rbp)
jmp 0x7f08
movq -0x108(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0x7f7b
movq -0x88(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x31e1(%rip), %rsi      # 0xb113
callq 0x8de0
movq %rax, -0x110(%rbp)
jmp 0x7f40
movq -0x110(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
je 0x7f76
movq -0x90(%rbp), %rsi
decq %rsi
movq -0x28(%rbp), %rax
movl (%rax), %eax
incl %eax
movslq %eax, %rdx
leaq -0x60(%rbp), %rdi
callq 0x33c0
jmp 0x7f74
jmp 0x7f76
jmp 0x8155
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
movl $0x2, -0x94(%rbp)
cmpl $0x2, -0x94(%rbp)
jne 0x806b
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xa8(%rbp)
movq -0x88(%rbp), %rdi
leaq 0x325e(%rip), %rsi      # 0xb218
leaq -0xa8(%rbp), %rdx
callq 0x8e70
movq %rax, -0x118(%rbp)
jmp 0x7fcf
movq -0x118(%rbp), %rax
cmpq $0x0, %rax
je 0x7fe6
movl $0x3, -0x94(%rbp)
movq -0xb8(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x38(%rbp), %rdx
addq %rdx, %rcx
movq %rcx, -0x120(%rbp)
andq $0x1, %rax
cmpq $0x0, %rax
je 0x8032
movq -0x128(%rbp), %rcx
movq -0x120(%rbp), %rax
movq (%rax), %rax
subq $0x1, %rcx
movq (%rax,%rcx), %rax
movq %rax, -0x130(%rbp)
jmp 0x8040
movq -0x128(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x120(%rbp), %rdi
movq -0x130(%rbp), %rax
movq -0x88(%rbp), %rsi
movl -0xa8(%rbp), %edx
movl -0x94(%rbp), %ecx
leaq -0x80(%rbp), %r8
callq *%rax
jmp 0x8069
jmp 0x806b
cmpl $0x3, -0x94(%rbp)
jne 0x8153
movq -0xd0(%rbp), %rdi
movq -0x88(%rbp), %rax
movq %rax, -0x140(%rbp)
callq 0x3130
movq -0x140(%rbp), %rdi
movq %rax, %rsi
movq -0x28(%rbp), %rdx
callq 0x8de0
movq %rax, -0x138(%rbp)
jmp 0x80ae
movq -0x138(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0x811e
movq -0x88(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x303b(%rip), %rsi      # 0xb113
callq 0x8de0
movq %rax, -0x148(%rbp)
jmp 0x80e6
movq -0x148(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
je 0x811c
movq -0x90(%rbp), %rsi
decq %rsi
movq -0x28(%rbp), %rax
movl (%rax), %eax
incl %eax
movslq %eax, %rdx
leaq -0x60(%rbp), %rdi
callq 0x33c0
jmp 0x811a
jmp 0x811c
jmp 0x8155
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x28(%rbp), %rax
movl (%rax), %edx
callq 0x8f60
jmp 0x8144
movl $0x1, -0xac(%rbp)
jmp 0x81dc
jmp 0x8155
movl 0x10(%rbp), %eax
movl %eax, -0x15c(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x3210
movq -0x170(%rbp), %rdi
movq %rax, %rcx
movq -0x168(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x158(%rbp)
callq 0x3210
movl -0x15c(%rbp), %edi
movq -0x158(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
subq %rax, %rdx
callq 0x3400
movq %rax, -0x150(%rbp)
jmp 0x81bc
movq -0x150(%rbp), %rax
movq -0x28(%rbp), %rcx
movl %eax, (%rcx)
cmpl $0x0, %eax
jg 0x7d63
movl $0x0, -0xac(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x31f0
leaq -0x60(%rbp), %rdi
callq 0x31f0
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0xa0(%rbp), %rdi
callq 0x34b0
nopw %cs:(%rax,%rax)