Example #1
0
	ShellCommand * createShellCommand(char * commandLine){

		int i;
		ShellCommand * command = allocateMemory(getGlobalHeap() , sizeof(ShellCommand));

		//parseamos el commandLine y creamos la matriz de symbolos
		parseSequence(commandLine);

		//seteamos la cantidad de argumentos
		command->argsCount = getArgumentsCount();
		
		//ponemos en 0 todos los caracteres del comando
		memset(command->commandName , '\0' , CMD_MAX_LEN);
		//ponemos en 0 todos los caracteres de todos los argumentos
		for(i=0 ; i<CMD_MAX_ARG ; i++)
			memset(command->args[i] , '\0' , CMD_MAX_LEN);

		//seteamos el comando
		strcpy(command->commandName , getCommandName());
		//seteamos todos los argumentos
		for( i=0 ; i<getArgumentsCount() ; i++){
			strcpy(command->args[i] , getArgument(i));
		}

		return command;	
	}
// called by fmi2GetReal, fmi2GetInteger, fmi2GetBoolean, fmi2GetString, fmi2ExitInitialization
// if setStartValues or environment set new values through fmi2SetXXX.
// Lazy set values for all variable that are computed from other variables.
void calculateValues(ModelInstance *comp) {
    if (comp->state == modelInitializationMode) {
        eventQueue = malloc(sizeof(node_t));
        eventQueue->next = NULL;
        parseSequence(comp);
    }
    else {
        if (!isEmpty()) {
            double epsilon = 0.00000000001;
            long t = getTime();
            double v = getValue();
            while (!isEmpty() && comp->time > t) {
                getEvent();
                t = getTime();
                v = getValue();
                i(i_) = 0;
            }
            if ( comp->time < t )
                return;
            if (comp->time == t && i(i_) == 0) {
                if ( v < (r(input_) + epsilon) &&
                     v > (r(input_) - epsilon) ) {
                    b(output_) = fmi2True;
                    i(i_) = 1;
                }
                else {
                    b(output_) = fmi2False;
                    i(i_) = 1;
                }
            }
            else if (comp->time == t && i(i_) == 1) {
                if ( v < (r(input_) + epsilon) &&
                     v > (r(input_) - epsilon) ) {
                    b(output_) = fmi2True;
                }
                else {
                    if (getTime() == getNextTime()) {
                        getEvent();
                        t = getTime();
                        v = getValue();
                        if ( v < (r(input_) + epsilon) && v > (r(input_) - epsilon) ) {
                            b(output_) = fmi2True;
                        }
                        else {
                            b(output_) = fmi2False;
                        }
                    }
                }
            }
        }
    }
}
Example #3
0
SgfTree *  Parser::parseGameTree(QIODevice & in) {
    SgfTree * tree = new SgfTree();
    char c;
    in.getChar(&c);

    try {
        if (c != '(') throw ParserException("'(' is expected but not present");
        SgfSequence * sequence = parseSequence(in); // parsing in sequences
        tree->setRoot(sequence);
        in.getChar(&c);
        while (c != ')') {                   // if we are not at the end of there is a game tree after the sequence
            in.getChar(&c);
            SgfTree * temp;
            temp = parseGameTree();
            tree->addNode(temp);              // adding gametree to the tree
        }
    } catch ( ... ) {
        delete tree;
        delete sequence;
        throw;
    }
    return tree;
}
Example #4
0
    void CodeGenerator::processRootState()
    {

	if (readAfterEOF && in!=&cin){
	   in->seekg (0, ios::end);
	   // output the last few lines or the complete file if not too big
	   if (in->tellg()>51200) {
	       in->seekg (-512, ios::end);
	       // output complete lines, ignore first line fragment
	       in->ignore(512, '\n');
	   } else {
	       in->seekg (0, ios::beg); // output complete file
	   }
	}

	string line;
	size_t i=0;
	bool tagOpen=false;
	while (true)
	{
	    if (!getline(*in, line))
	    {
		// imitate tail bahaviour, continue to read after EOF
		if (readAfterEOF)
		{
		    out->flush();
		    in->clear();
#ifdef WIN32
		    Sleep(250);
#else
		    sleep(1);
#endif
		}
		else
		{
		    //todo hier position merken, in der gui periodisch den dateizeiger auf diesen wert setzen und den neuen code einlesen
		    break;
		}
	    }
	    else
	    {
		i=0;
		size_t seqEnd=string::npos;
		while (i <line.length() )
		{
		    if (line[i]==0x1b)
		    {
		      // fix grep --colour .[K (1b 5b 4b) sequences
		      if (line.length()>i+2 && line[i+2]==0x4b){
			  seqEnd=i+2;
		      } else {

			  seqEnd=line.find_first_of('m', i+1);

			  //TODO vor ; das hier anfangen xterm: ^[]0;~^G^M^M
			  // http://www.mit.edu/afs/athena/system/x11r4/src/mit/clients/xterm/ctlseq2.txt
			  if (seqEnd==string::npos) {
			      if (line[i+1]==']') seqEnd=line.find(0x07, i+1);
			  }
			  if (seqEnd==string::npos) seqEnd=line.find(';', i+1);
			  if (seqEnd==string::npos) seqEnd=line.find('h', i+1);

			  if (!ignoreFormatting && seqEnd!=string::npos)
			  {
			      if (!elementStyle.isReset()){
				  *out <<getCloseTag();
				  tagOpen=false;
			      }
			      parseSequence(line, i, seqEnd);
			      if (!elementStyle.isReset()) {
				  *out <<getOpenTag();
				  tagOpen=true;
			      }
			  }
			}
			i= 1+ ((seqEnd!=string::npos)?seqEnd:i);
		    }
		    else
		    {
			*out << maskCharacter(line[i]);
			++i;
		    }
		}
		*out << newLineTag;
	    }
	}
	if (tagOpen){
		*out <<getCloseTag();
	}
	out->flush();
    }
Example #5
0
void PDBFormat::PDBParser::parseBioStruct3D(BioStruct3D& biostruct, U2OpStatus& ti) {

    QByteArray readBuff(DocumentFormat::READ_BUFF_SIZE + 1, 0);
    char* buf = readBuff.data();
    qint64 len = 0;
    bool firstCompndLine = true;
    while (!ti.isCoR()) {

        bool lineOk = true;

        len = io->readUntil(buf, DocumentFormat::READ_BUFF_SIZE, TextUtils::LINE_BREAKS, IOAdapter::Term_Include, &lineOk);
        if (len == 0) {
            break;
        }

        // there could be no terminator if this is end of file, so we have to check for this
        if (!lineOk && !io->isEof()) {
            ti.setError(U2::PDBFormat::tr("Line is too long"));
            return;
        }
        currentPDBLine = QString(QByteArray(buf, len));

        ti.setProgress(io->getProgress() * 0.8);

        if (currentPDBLine.startsWith("HEADER")) {
            parseHeader(biostruct, ti);
            continue;
        }

        if (currentPDBLine.startsWith("COMPND")) {
            parseMacromolecularContent(firstCompndLine, ti);
            firstCompndLine = false;
            continue;
        }

        if (currentPDBLine.startsWith("SEQRES")) {
            parseSequence(biostruct, ti);
            continue;
        }


        if (currentPDBLine.startsWith("HELIX ") || currentPDBLine.startsWith("SHEET ")
            || currentPDBLine.startsWith("TURN  ")) {
                parseSecondaryStructure(biostruct, ti);
                continue;
        }


        if (currentPDBLine.startsWith("ATOM  ") || currentPDBLine.startsWith("HETATM")) {
            parseAtom(biostruct, ti);
            continue;
        }

        if (currentPDBLine.startsWith("TER")) {
            ++currentChainIndex;
            continue;
        }

        if (currentPDBLine.startsWith("SPLIT ")) {
            parseSplitSection(ti);
            continue;
        }

        if (currentPDBLine.startsWith("MODEL")) {
            currentChainIndex = 1;
            parseModel(biostruct, ti);
            continue;
        }

        if (currentPDBLine.startsWith("ENDMDL")) {
            flagMultipleModels = true;
            ++currentModelIndex;
            continue;
        }
    }

    CHECK_OP(ti,);

    if (!flagAtomRecordPresent) {
        ti.setError(U2::PDBFormat::tr("Some mandatory records are absent"));
    }

    updateSecStructChainIndexes(biostruct);

}