Пример #1
0
int main(int argc ,char *argv[])
{
	if(argc>1){	callErrorFn();exit(1);}
	else
	{
		char input[MAXLINELENGTH+1];
		char **command;	command=malloc(1000*MAXLINELENGTH);// will contain ls -la /tmp etc etc ...
		char **path;path=malloc(1000*MAXLINELENGTH);
		path[0]=strdup("/bin");
		for(;;)
		{
			printf("whoosh> ");fflush(stdout);
			fgets(input,1300,stdin);
			//while(fgetc(stdin)!='\n'){}
			fflush(stdin);
			if(strlen(input)==1){continue;}
			if(strlen(input)>129){callErrorFn();continue;}
			parse(input,command);
			if(searchCommand(command,path)==1){callErrorFn();continue;}//0 if success and 1 if failure
			executeCommand(command,path);
		}
		return 0;
	}

}
Пример #2
0
void CommandHandler::validateCommand( const Message& command )
{
    std::string commandBody     = getFirst( command.body() );
    std::string commandAppendix = getAppendix( command.body() );

    if ( commandBody.find_first_of( "!" ) == 0 )
    {
        switch( searchCommand( commands, COMMANDCOUNT, commandBody.c_str() ) )
        {
            //!show
            case 0:
            {
                show->showCommands( command );
                break;
            }
            //!execute
            case 1:
            {
                execute->validateExecute( command );
                break;
            }
            //!learn
            case 2:
            {
                learn->learnCommand( command );
                break;
            }
            //!report
            case 3:
            {
                report->reportIssue( command );
                break;
            }
            //!help
            case 4:
            {
                help->helpCommand( command );
                break;
            }
            //!forget
            case 5:
            {
                forget->forgetCommand( command );
                break;
            }
            default:
            {
                help->sendHelp( command );
            }
        }
    }
    else
    {
        help->sendHelp( command );
    }
}
Пример #3
0
void TextEdit::showFromWidget(const QRect& r, const QString& caption) {

    qDebug("...showFromWidget....(1)...caption: |%s|",qPrintable(caption));

    if (l && l->isVisible()) { 
        setFocus();
        QString updatetitle = l->caption();
        QString updatecaption = l->text();
        l->hide();
        if (!l->isPassword()) {
            insertPlainText(l->text().trimmed());
        }
        else {
            QString text = l->text().trimmed();
            QByteArray textsha1 = QCryptographicHash::hash(QByteArray(qPrintable(text)),
                                                           QCryptographicHash::Sha1);
            insertPlainText(textsha1.toHex().data());
        }


        //insertPlainText("\n");
        insertTextRegToModify(updatetitle, updatecaption);
        if (l != NULL ) {
            l->close();
            l = NULL;
        }
     
        return;
    }


    DomModel *dommodel = ((QCmdCompleter*) c)->domModel();
    if ( dommodel == NULL ) {
        return;
    }

    QString command = searchCommand();
    QString newcaption = caption;
    qDebug("...showFromWidget....(4)...newcaption: |%s|",qPrintable(newcaption));
    if ( dommodel->prefix().length() > 0  && newcaption.endsWith(dommodel->suffix()) )  {
        newcaption.remove(0,1);
    }
    if ( dommodel->suffix().length() > 0  && newcaption.endsWith(dommodel->suffix()) )  {
        newcaption.chop(1);
    }

    qDebug("...showFromWidget....(5)...newcaption: |%s|",qPrintable(newcaption));

    l = dommodel->selWidgetFromField(command, newcaption, this);

    if ( l == NULL ) {
        SafetYAWL::streamlog << SafetLog::Warning << tr("El Widget para la etiqueta \"%1\" no pudo ser mostrado").arg(caption);
        return;
    }

    if (QString(l->metaObject()->className()) == "ListWidget") {
        l->setGeometry(cursorRect().topLeft().x(), cursorRect().topLeft().y()-cursorRect().height()/2,
                       l->getGeoParams().width(), l->getGeoParams().height()+100);

    }
    else {
    l->setGeometry(cursorRect().topLeft().x(), cursorRect().topLeft().y()-cursorRect().height()/2,
                   l->getGeoParams().width(), l->getGeoParams().height());
    }

//    Chequear

//    l->setPrevValue(newcaption);

    if (!l->isVisible()) {
        l->setPrevCursor(textCursor());
        l->show();
        l->setFocus(Qt::PopupFocusReason);
        updateDockSbMenu();
    }


}
Пример #4
0
void TextEdit::modifyCurrentField() {
    if ( l && l->isVisible()) {
        if( MainWindow::mymainwindow != NULL ) {
            MainWindow::mymainwindow->statusBar()
                    ->showMessage("Cierre el widget abierto antes de editar otro campo!",3000);
        }
        return;
    }



    moveCursor(QTextCursor::EndOfWord, QTextCursor::MoveAnchor);

    QSet<QString> blankcharacter;
    blankcharacter << " " << "\t" << "\r" << "\n";
    QString c;
    bool blankcharacterpresent = false, namefieldpresent = false;
    int length = toPlainText().length();
    int curpos = textCursor().position();
    while ( (curpos+1) < length ) {
        moveCursor(QTextCursor::NextCharacter, QTextCursor::MoveAnchor);

        c =toPlainText().mid(curpos,1);
        if  (blankcharacter.contains(c)) {
            blankcharacterpresent = true;
        }

        if ( c ==  QString(":")) {
            if ( !blankcharacterpresent  && !namefieldpresent ) {
                namefieldpresent = true;
                moveCursor(QTextCursor::NextCharacter, QTextCursor::MoveAnchor);
                curpos = textCursor().position();
                continue;
            }
            moveCursor(QTextCursor::NextCharacter, QTextCursor::MoveAnchor);
            c =toPlainText().mid(textCursor().position(),1);
            if ( !blankcharacter.contains(c)) {
                moveCursor(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor);
            }
            QString  preword = toPlainText().mid(textCursor().position(),12);

            moveCursor(QTextCursor::PreviousWord, QTextCursor::MoveAnchor);
            preword = toPlainText().mid(textCursor().position(),12);

            moveCursor(QTextCursor::PreviousWord, QTextCursor::MoveAnchor);
            preword = toPlainText().mid(textCursor().position(),12);

            moveCursor(QTextCursor::PreviousWord, QTextCursor::MoveAnchor);
            preword = toPlainText().mid(textCursor().position(),12);
            qDebug("\n4...textCursor().preword():|%s|",
                   qPrintable(preword));

//            curpos = textCursor().position();
            break;
        }
        curpos = textCursor().position();

    }
    QString preword;

    preword = toPlainText().mid(textCursor().position(),12);
    qDebug("\n5before...textCursor().preword():|%s|",
           qPrintable(preword));

#if (QT_VERSION < QT_VERSION_CHECK(4, 5, 0))
    //moveCursor(QTextCursor::EndOfWord, QTextCursor::MoveAnchor);
    QString cbefore;
    curpos = textCursor().position();
    int curr = curpos;
    while((curpos+1) < length) {
        moveCursor(QTextCursor::NextCharacter, QTextCursor::MoveAnchor);
        cbefore = toPlainText().mid(curr,curpos-curr+1);
        c =toPlainText().mid(curpos,1);
        curpos = textCursor().position();
        if ( c == ":" ) {
            moveCursor(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
            curpos = textCursor().position();
            while (curpos > 0 ) {
                c =toPlainText().mid(curpos,1);
                if (blankcharacter.contains(c)) {
                    qDebug("......check...............c: |%s|", qPrintable(c));
                    if (c == "\r" || c == "\n") {
                           while (curpos > 0 ) {
                               c =toPlainText().mid(curpos,1);
                               if (!blankcharacter.contains(c)) {
                                   break;
                               }
                               moveCursor(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor);
                               curpos = textCursor().position();


                           }

                    }
                    else {
                        while (curpos > 0 ) {
                            c =toPlainText().mid(curpos,1);
                            if (!blankcharacter.contains(c)) {
                                break;
                            }
                            moveCursor(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor);
                            curpos = textCursor().position();


                        }

//                        moveCursor(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor);
//                        moveCursor(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor);
                    }
                    break;
                }
                moveCursor(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor);
                curpos = textCursor().position();
            }


            break;
        }
    }
#else
        moveCursor(QTextCursor::EndOfWord, QTextCursor::MoveAnchor);
#endif


    preword = toPlainText().mid(textCursor().position(),12);
    qDebug("\n5...textCursor().preword():|%s|",
           qPrintable(preword));

    // ***  Eliminar los espacios en blanco al final del campo
    while((curpos+1) < length) {
        moveCursor(QTextCursor::NextCharacter, QTextCursor::MoveAnchor);
        c =toPlainText().mid(curpos,1);
        curpos = textCursor().position();
        if (!blankcharacter.contains(c)) {
            break;
        }
    }
    preword = toPlainText().mid(textCursor().position(),12);
    qDebug("\n.....6...textCursor().preword():|%s|",
           qPrintable(preword));

    // ***  Eliminar los espacios en blanco al final del campo
    curpos = textCursor().position();

    while ( (curpos-1) >  0 ) {
        moveCursor(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
        c =toPlainText().mid(textCursor().position(),1);
        if  ( c == ":") {
            qDebug("\n**1...textCursor().selectedText():|%s|",
                   qPrintable(textCursor().selectedText()));

#if (QT_VERSION > QT_VERSION_CHECK(4, 4, 3))
            moveCursor(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
            moveCursor(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
#else
            qDebug("**...version <=4.4.3");
            moveCursor(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
            moveCursor(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
#endif
            break;
        }
        curpos = textCursor().position();
    }

    // borrar y actualizar;
    //textCursor().removeSelectedText();

    QString namefield, valuefield;
    QStringList fields = textCursor().selectedText().split(":");
    qDebug("\n...textCursor().selectedText():|%s|",
           qPrintable(textCursor().selectedText()));
    namefield = fields.at(0);

    if (fields.count() > 1 ) {
        valuefield = fields.at(1);
    }

    insertPlainText(namefield+": ");
    insertPlainText("\n");
    moveCursor(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor);

    // ** Mostrar valor en el widget
    // ************************************
    DomModel *mydommodel = dommodel();
    if ( mydommodel == NULL ) {
        return;
    }
    QString command = searchCommand();


    l = mydommodel->selWidgetFromField(command, namefield, this);

    if ( l == NULL ) {
        SafetYAWL::streamlog
                << SafetLog::Warning
                << tr("El Widget para la etiqueta \"%1\" no pudo ser mostrado")
                .arg(namefield);
        return;
    }


    l->setPrevCursor(textCursor());
    l->setPrevValue(valuefield);
    if (QString(l->metaObject()->className()) == "ListWidget") {
        l->setGeometry(cursorRect().topLeft().x(), cursorRect().topLeft().y()-cursorRect().height()/2,
                       l->getGeoParams().width(), l->getGeoParams().height()+100);

    }
    else {
    l->setGeometry(cursorRect().topLeft().x(), cursorRect().topLeft().y()-cursorRect().height()/2,
                   l->getGeoParams().width(), l->getGeoParams().height());
    }


    if (!l->isVisible()) {
        l->setPrevCursor(textCursor());
        l->setText(valuefield.trimmed());
        l->show();
        l->setFocus(Qt::PopupFocusReason);
    }

}