// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %r8, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %rdx, %r14
movq %rsi, %r12
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %r15d, %r15d
movb %r15b, (%rax)
leaq -0x78(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %r15b, (%rax)
addq %r9, %rdi
movq %rdi, -0x38(%rbp)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rbx
movq %r12, %rdi
movq %rbx, %rdx
callq 0x2180
addl %ebx, (%r14)
leaq -0x68(%rbp), %rdi
leaq 0x258d(%rip), %rsi      # 0x721b
callq 0x23d0
movq %r12, %rbx
cmpl $0x2, %r15d
je 0x4ced
movq %r12, %r13
cmpl $0x1, %r15d
je 0x4ccf
movq %r12, %rbx
testl %r15d, %r15d
jne 0x4d4f
movq -0x48(%rbp), %rax
movq (%rax), %rsi
movq %r12, %rdi
movq %r14, %rdx
callq 0x5421
movq %rax, %r13
testq %rax, %rax
je 0x4dce
movq %r13, %rdi
leaq 0x2426(%rip), %rsi      # 0x70ff
movq %r14, %rdx
callq 0x5421
movq %rax, %rbx
testq %rax, %rax
je 0x4d9c
movl (%r14), %eax
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
leaq 0x2541(%rip), %rsi      # 0x723e
leaq -0x2c(%rbp), %rdx
callq 0x547f
movq %rax, %r13
cmpq $0x1, %rax
pushq $0x3
popq %rcx
sbbl $0x0, %ecx
movq -0x40(%rbp), %rdx
movq %rdx, %rax
testb $0x1, %dl
je 0x4d2f
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rdx
movq -0x1(%rax,%rdx), %rax
movl -0x2c(%rbp), %edx
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
leaq -0x88(%rbp), %r8
callq *%rax
pushq $0x2
popq %r15
testq %r13, %r13
je 0x4dfd
movq -0x48(%rbp), %rax
movq (%rax), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x5421
testq %rax, %rax
jne 0x4e22
movq %rbx, %rdi
leaq 0x23c5(%rip), %rsi      # 0x7139
movq %r14, %rdx
callq 0x5421
pushq $0x3
popq %r15
testq %rax, %rax
je 0x4dfd
decq %rax
movslq (%r14), %rdx
incq %rdx
leaq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x22d0
jmp 0x4dfd
movq %r13, %rdi
leaq 0x2393(%rip), %rsi      # 0x7139
movq %r14, %rdx
callq 0x5421
pushq $0x1
popq %r15
testq %rax, %rax
je 0x4dfd
decq %rax
movslq (%r14), %rdx
incq %rdx
leaq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x22d0
jmp 0x4dfd
movq %r12, %rdi
leaq 0x2361(%rip), %rsi      # 0x7139
movq %r14, %rdx
callq 0x5421
xorl %r15d, %r15d
testq %rax, %rax
je 0x4dfd
decq %rax
movslq (%r14), %rdx
incq %rdx
leaq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x22d0
movq -0x60(%rbp), %rax
leaq (%r12,%rax), %rsi
movl $0x400, %edx            # imm = 0x400
subq %rax, %rdx
movl 0x10(%rbp), %edi
callq 0x2300
movl %eax, (%r14)
testl %eax, %eax
jg 0x4c6d
jmp 0x4e30
movl (%r14), %edx
movq %r12, %rdi
movq %rax, %rsi
callq 0x5515
leaq -0x88(%rbp), %rdi
callq 0x2130
leaq -0x68(%rbp), %rdi
callq 0x2130
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4e58
jmp 0x4e58
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x2130
leaq -0x68(%rbp), %rdi
callq 0x2130
movq %rbx, %rdi
callq 0x2390