// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, -0x60(%rbp)
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %r13
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
xorl %r15d, %r15d
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq -0x70(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
addq %r9, %rdi
movq %rdi, -0x58(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rbx
movq %r13, %rdi
movq %rbx, %rdx
callq 0x2160
addl %ebx, (%r14)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
leaq 0x24fb(%rip), %rcx      # 0x821f
xorl %r8d, %r8d
callq 0x2360
movq %r13, %rbx
testl %r15d, %r15d
jne 0x5d55
movq (%r12), %rsi
movq %r13, %rdi
movq %r14, %rdx
callq 0x65ee
movq %rax, %rbx
testq %rax, %rax
je 0x5e72
movl $0x1, %r15d
cmpl $0x1, %r15d
jne 0x5d7f
movq %rbx, %rdi
leaq 0x239e(%rip), %rsi      # 0x8103
movq %r14, %rdx
callq 0x65ee
testq %rax, %rax
je 0x5e38
movl $0x2, %r15d
movq %rax, %rbx
cmpl $0x2, %r15d
jne 0x5de2
movl (%r14), %eax
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
leaq 0x24ad(%rip), %rsi      # 0x8242
leaq -0x2c(%rbp), %rdx
callq 0x664c
movq %rax, %r15
cmpq $0x1, %rax
movl $0x3, %ecx
sbbl $0x0, %ecx
movq -0x60(%rbp), %rdx
movq %rdx, %rax
testb $0x1, %dl
je 0x5dc9
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rdx
movq -0x1(%rax,%rdx), %rax
movl -0x2c(%rbp), %edx
movq -0x58(%rbp), %rdi
movq %rbx, %rsi
leaq -0x80(%rbp), %r8
callq *%rax
testq %r15, %r15
je 0x5ea9
movq (%r12), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x65ee
testq %rax, %rax
jne 0x5ed9
movq %rbx, %rdi
leaq 0x2339(%rip), %rsi      # 0x813d
movq %r14, %rdx
callq 0x65ee
movl $0x3, %r15d
testq %rax, %rax
je 0x5eb4
decq %rax
movslq (%r14), %r8
incq %r8
movq -0x48(%rbp), %rdx
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x2360
jmp 0x5eb4
movq %rbx, %rdi
leaq 0x22fb(%rip), %rsi      # 0x813d
movq %r14, %rdx
callq 0x65ee
movl $0x1, %r15d
testq %rax, %rax
je 0x5eb4
decq %rax
movslq (%r14), %r8
incq %r8
movq -0x48(%rbp), %rdx
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x2360
jmp 0x5eb4
movq %r13, %rdi
leaq 0x22c1(%rip), %rsi      # 0x813d
movq %r14, %rdx
callq 0x65ee
testq %rax, %rax
je 0x5eb1
decq %rax
movslq (%r14), %r8
incq %r8
xorl %r15d, %r15d
movq -0x48(%rbp), %rdx
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x2360
jmp 0x5eb4
movl $0x2, %r15d
jmp 0x5eb4
xorl %r15d, %r15d
movq -0x48(%rbp), %rax
leaq (%rax,%r13), %rsi
movl $0x400, %edx            # imm = 0x400
subq %rax, %rdx
movl 0x10(%rbp), %edi
callq 0x2300
movl %eax, (%r14)
testl %eax, %eax
jg 0x5cfe
jmp 0x5ee7
movl (%r14), %edx
movq %r13, %rdi
movq %rax, %rsi
callq 0x6706
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x5f00
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2230
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5f19
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2230
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5f2c
jmp 0x5f2c
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x5f48
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2230
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5f61
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x23c0
nop