Ejemplo n.º 1
0
// Set the Current variable to the current directory.
void FileSystem::callDirectory(CharString location) {
    if(location.Compare("..",2)) {
        if(Current->Parent != 0x0) {
            Current = Current->Parent;
        }
    } else {
        FileStructureNode* node = getNodeFromString(location);
        if(node != 0x0) {
            if(node->type == Directory) {
                Current = node;
            } else {
                // throw error!
                CharString cs = CharString("cd: ");
                cs.concata(location);
                cs.concata(": not a directory",17);
                this->ErrorString = cs.get();
                throw 10;
            }
        } else {
            // throw error!
            CharString cs = CharString("cd: ");
            cs.concata(location);
            cs.concata(": directory does not exist",26);
            this->ErrorString = cs.get();
            throw 9;
        }
    }
}
Ejemplo n.º 2
0
// Removes a directory from the current directory based on location.
// Input: String location
void FileSystem::removeDir(CharString location) {
    FileStructureNode* node = getNodeFromString(location);
    if(node != 0x0 && node != Root) {
        // type-dir
        if(node->type == Directory) {
            // determine if CD is inside this dir.
            bool isCD = false;
            if(node->Child != 0x0) {
                FileStructureNode* cc = node->Child;
                while(cc != 0x0 && !isCD) {
                    // search through all of the relatives.
                    if(cc == Current) {
                        isCD = true;
                        break;
                    } else if(cc->Sibling != 0x0) {
                        FileStructureNode* ccd = cc->Sibling;
                        while(ccd != 0x0) {
                            if(ccd == Current) {
                                isCD=true;
                                break;
                            }
                            ccd = ccd->Sibling;
                        }
                    }
                    cc = cc->Child;
                }
            } else if(node == Current) {
                isCD = true;
            }


            if(!isCD) {
                node->del();
            } else {
                // this is restricted by call directory
                CharString cs = CharString("rmdir: ");
                cs.concata(location);
                cs.concata(": directory cannot be deleted",29);
                this->ErrorString = cs.get();
                throw 15;
            }

        } else {
            // cannot find!
            CharString cs = CharString("rmdir: ");
            cs.concata(location);
            cs.concata(": directory does not exist",26);
            this->ErrorString = cs.get();
            throw 8;
        }
    } else {
        // throw error!
        CharString cs = CharString("rmdir: ");
        cs.concata(location);
        cs.concata(": directory does not exist",26);
        this->ErrorString = cs.get();
        throw 7;
    }
}
Ejemplo n.º 3
0
// if connected, send out a message
// returns false if not connected or error.
// auto-splits large messages larger than buffer.
bool SockClient::sendc(CharString message){
    CharString emsg = (encryptor!=0x0) ? encryptor(message) : message; // Apply encryption
    if(emsg.getSize() <= 2) return false;
    //cout << "Send message(" << emsg.getSize() << ")" << emsg.get() << endl;
    cout << "Send message(" << emsg.getSize() << ")"<< endl;

    int flags=0;
    int looptimes=1;
    int i, msgret, msgsize;
    char* msg;
#ifdef LINUXXX
     if(!testAlive()){
         // uh...
         return false;
     }
    
    if(ctype == SC_TCP){
        //msgret = send(sockd, message.get(), message.getSize(), flags);
        //cout << "Pre-write SC_TCP " << emsg.getSize() << endl;
        if(testAlive())
            msgret = write(sockd, emsg.get(), emsg.getSize());
        //cout << "post-write" << endl;
    }else{
        socklen_t addrlen = sizeof(struct sockaddr_in);
        //msgret = sendto(sockd, emsg.get(), emsg.getSize(), &cli_addr, address);
    }
    // detect error
    if(msgret == -1) return false;
#endif
    return true;
}
Ejemplo n.º 4
0
void Logger::processLog(CharString data){
    if(console){
        cout << data.get() << endl;
        cout.flush();
    }
    
    // push data to file
}
Ejemplo n.º 5
0
/* Returns the name of the end point.
*  Input: String location
*  Output: Very ending of string after last "/"
 */
CharString FileSystem::getNameFromString(CharString location) {
    // gets the name of the last "/dir/dir2/name", even if it ends with "/".
    if(location.get()[location.getSize()-1] == '/') {
        // remove trailing "/".
        location.get()[location.getSize()-1] = '\0';
        location.setSize(location.getSize()-1);
    }

    CharString result = CharString("");
    // split all by "/".
    if(location.contains("/")) {
        // get the very last result of the split.
        LinkedList<CharString>* sresult = location.split('/','`');
        result = *sresult->get(sresult->size()-1);
    } else {
        result = location;
    }

    return result;
}
Ejemplo n.º 6
0
void testPriorityQueue() {
    cout << "PriorityQueue => ";
    PriorityQueue* q = new PriorityQueue();
    CharString* cc = new CharString("test@#$%^*()_+1234567890",24);
    q->insert(0,cc);
    CharString* qq = (CharString*)q->removeMin();
    if(qq == cc) {
        cout << "Pass" << endl;
    } else {
        cout << "Fail" << "(" << qq->get() << ")" << endl;
    }
}
Ejemplo n.º 7
0
// tests the queue for ability.
void testQueue() {
    cout << "Queue => ";
    Queue* q = new Queue();
    CharString* cc = new CharString("test@#$%^*()_+1234567890");
    q->push(cc);
    CharString* qq = (CharString*)q->pop();
    if(qq == cc) {
        cout << "Pass" << endl;
    } else {
        cout << "Fail" << "(" << qq->get() << ")" << endl;
    }
}
Ejemplo n.º 8
0
void Logger::processLog(CharString data){
    if(console){
        cout << data;// << endl;
        cout.flush();
    }
    
    // push data to file
    if(file.is_open()){
        file.write(data.get(), data.getSize());
        file.write((char*)"\n", 1);
    }
}
Ejemplo n.º 9
0
// if ASYNC, start thread
Logger::Logger(CharString logfileloc, CharString prefix, bool async, bool console, bool clearfile){
    this->logfileloc = logfileloc;
    this->prefix = prefix;
    this->async = async;
    this->console = console;
    this->ending = false;
    
    //cout << "Logger 1" << endl;
    // open file
    if(clearfile) file.open (logfileloc.get(), ios::out | ios::app);
    else file.open (logfileloc.get(), ios::out | ios::app | ios::trunc);
    file.seekp(0, ios::end);
    
    //cout << "Logger 2" << endl;
    
    if(async){
        asyncthread = std::thread(loggerThread, this);
        cout << "Logger 3thrstart" << endl;
    }
    //cout << "Logger 3" << endl;
}
Ejemplo n.º 10
0
// Desc: Removes a file from the current directory based on location.
// Input: String location
void FileSystem::removeFile(CharString location) {
    FileStructureNode* node = getNodeFromString(location);
    if(node != 0x0) { // is node available?
        if(node->type == File) { // is node a file?
            // directly delete file.
            node->del();
        } else { // else throw DNE error
            CharString cs = CharString("rm: ");
            cs.concata(location);
            cs.concata(": file does not exist",21);
            this->ErrorString = cs.get();
            throw 6;
        }
    } else { // else throw DNE error
        // throw error!
        CharString cs = CharString("rm: ");
        cs.concata(location);
        cs.concata(": file does not exist",21);
        this->ErrorString = cs.get();
        throw 5;
    }
}
Ejemplo n.º 11
0
// Handle basic client stuff
void ClientHandler_(SockClient* tclient) {
    // Talk with the client, pre-load into a buffer
    int n;
    char buffer[BUFFER_SIZEX];

    while(tclient->alive) {
#if __linux__ || __unix__


        n = read(tclient->sockd, buffer, BUFFER_SIZEX);
        if (n < 0) error("ERROR reading from socket");

        CharString* writeto = new CharString(); // writeto is a string that we write to, used by the

        if(tclient->_clientHandler != 0x0) {
            tclient->_clientHandler(new CharString(buffer,BUFFER_SIZEX), writeto);

            n = write(tclient->sockd, writeto->get(), writeto->getSize());
            if (n < 0) error("ERROR writing to socket");
        }
#endif // __linux__
    }
}
Ejemplo n.º 12
0
// input redirection
void InputRedirection::handleInputLine(CharString* input) {
    double ii = 0;
    double time1 = clock()/CLOCKS_PER_SEC;
    double basetime = clock()/CLOCKS_PER_SEC;
    if(input->Compare("exit",4)) {
        this->stop = true;
    } else if(input->Compare("help",4)) {
        cout << "[Commands]:" << endl;
        cout << "  test         - lists possible tests" << endl;
        cout << "  exit         - Exits the program" << endl;
    } else if(input->Compare("MathTest",8)) {
        testMath();
    } else if(input->Compare("AsmTest",7)) {
        //testASM();
    } else if(input->Compare("ExHashTest",10)) {
        testExHash();
    } else if(input->Compare("PhysTest",8)) {
        testGravity();
    } else if(input->Compare("EngineerTest",12)) {

    } else if(input->Compare("AbstractDB",10)) {
        testAbstractDB();
    } else if(input->Compare("EventHandler",12)) {
        testEventHandler();
    } else if(input->Compare("GameTest",8)) {

    } else if(input->Compare("CTest",5)) {
        CharString* c = new CharString("-12038.22828282302012031929319",30);
        cout << "STRTEST Float: -" << c->get() << " = " << c->getFloat() << endl;
        c = new CharString("0.0000000000000000000000000123",30);
        cout << "STRTEST Float: " << c->get() << " = " << c->getFloat() << endl;
        c = new CharString("-120382282828230201203.1929319",30);
        cout << "STRTEST Float: -" << c->get() << " = " << c->getFloat() << endl;
        c = new CharString("-1.2345e+9",10);
        cout << "STRTEST Float: -" << c->get() << " = " << c->getFloat() << endl;
        c = new CharString("1.2345e+120",11);
        cout << "STRTEST Float: -" << c->get() << " = " << c->getFloat() << endl;
    } else if(input->Compare("LinearTest",10)) {
        char* a = new char();
        strcpy(a,"[LinearTest] ");
        testStructures(a);
    } else if(input->Compare("DataStruTest",12)) {
        testDataStructures();
    } else if(input->Compare("PTypeTest",9)) {
        testPType();
    } else if(input->Compare("SerializerTest",12)) {
        testSerializers();
    } else if(input->Compare("TestALL",8)) {
        testDataStructures();
        testMath();
        char a[14];
        strcpy(a,"[LinearTest] ");
        testStructures(a);
        testGravity();
        //testASM();
    } else if(input->Compare("test",4)) {
        cout << "[Tests]:" << endl;
        cout << "  AbstractDB    - tests the Abstract Database" << endl;
        cout << "  AsmTest       - tests embedded assembler" << endl;
        cout << "  ExHashTest    - tests embedded assembler" << endl;
        cout << "  MathTest      - tests basic math systems" << endl;
        cout << "  LinearTest    - tests linear algebra" << endl;
        cout << "  GameTest      - tests backend game systems" << endl;
        cout << "  EventHandler  - tests Event Handler" << endl;
        cout << "  EngineerTest  - tests Engineering systems" << endl;
        cout << "  PhysTest      - tests Physics systems" << endl;
        cout << "  DataStruTest  - tests Data structures" << endl;
        cout << "  NetworkTest   - tests Networking systems (P2p, Server, Client, ect)" << endl;
        cout << "  RenderTest    - tests rendering systems" << endl;
        cout << "  SerializerTest- tests rendering systems" << endl;
        cout << "  TestALL       - tests all the above" << endl;
    } else {
        cout << "Unknown command; Try `help`." << endl;
    }
    double totalTime = ((double)clock()/CLOCKS_PER_SEC) - basetime;
    cout << "Total test time: " << totalTime*1000 << " Milliseconds" << endl;
}
Ejemplo n.º 13
0
/*
 * Desc: Takes in a single line and expresses the line in a math formula to solve it.
 * Input: CharString* Line.
 * Output: (Console) Output of all expressions.
 * */
CharString Eval(CharString Line) {
    //cout << line << endl;
    // get length of line
    int lsize = 0;
    for(int i=0; i<Line.getSize(); i++) {
        if(Line.get()[i] != 0x0) {
            lsize++;
        }
    }
    Line.setSize(lsize);


    // PARSE each section. Format SHOULD be like this:
    // 1 + 2 [number operator number]
    // 1 + 2 * 3 [n o n o n]
    // 1 + 5 * 10^2 [n o n o non]
    // 110/ 98 [no n] (Automatic parse finding)

    // list of operators:
    // () + - / * ^ % < > = <= >= [NOTE that as of this time, parentheses will not be used]

    // Thus, it can be infered that we can break up each system by placing the most important
    //  System (order of operations) on the top of the stack and placing the least important
    // +/- at the bottom of the stack...

    // Order of operations:
    //  ^  /  *  +  -  (>= = <= < > [END-CLASS operators])

    // Parse method:
    //  1.) loop-through n times to get full stack.

    NumStack = new Stack(); // NumStack is used to store the initial numbers
    OpStack = new Stack(); // OpStack is used to store the initial operators

    // note that both stacks store information through the same MathOperationNode Type.
    //  This will be solved later when we interlace the operators with the variables.
    char* LineD = Line.get();
    char* NumTemp = new char();
    int NumTempLen = 0;
    MOperator OpTemp = none;
    for(int i=0; i<Line.getSize(); i++) {
        char g = LineD[i];
        MOperator tOp = getOperatorFromChar(g);

        if(isCharNumber(g)) { // is this a number?
            // this is a single digit for NumTemp. Add to it.
            NumTemp[NumTempLen] = g;
            NumTempLen++;

            // dump OpTemp if it is available.
            dumpOp(OpTemp);
            OpTemp = none;
        } else if (tOp != none) {
            if(OpTemp != none) {
                MOperator gox = combineOperators(tOp,OpTemp);
                if(gox != none) OpTemp = gox;
            } else {
                OpTemp = tOp;
            }

            // dump NumTemp if it is available.
            dumpNum(NumTemp,NumTempLen);
            NumTempLen=0;
        } else {
            // dump NumTemp if it is available.
            // dump OpTemp if it is available.
            dumpNum(NumTemp,NumTempLen);
            NumTempLen=0;
            dumpOp(OpTemp);
            OpTemp = none;
        }
    }

    // dump NumTemp if it is available.
    // dump OpTemp if it is available.
    dumpNum(NumTemp,NumTempLen);
    NumTempLen=0;
    dumpOp(OpTemp);
    OpTemp = none;

    while(OpStack->size > 0) {
        int res = doOp();
        //cout << "=" << res << endl;
        NumStack->push(res);
    }
    int c = NumStack->pop();
    if(c == -98) cout << "F";
    else if(c == -99) cout << "T";
    else cout << c;

    return CharString::ConvertFromInt(c);
}