const QStringList MyProcess::splitArgList(SCRef cmd) { // return argument list handling quotes and double quotes // substring, as example from: // cmd some_arg "some thing" v='some value' // to (comma separated fields) // sl = <cmd,some_arg,some thing,v='some value'> // early exit the common case if (!( cmd.contains(QGit::QUOTE_CHAR) || cmd.contains("\"") || cmd.contains("\'"))) return cmd.split(' ', QString::SkipEmptyParts); // we have some work to do... // first find a possible separator const QString sepList("#%&!?"); // separator candidates int i = 0; while (cmd.contains(sepList[i]) && i < sepList.length()) i++; if (i == sepList.length()) { dbs("ASSERT no unique separator found."); return QStringList(); } const QChar& sepChar(sepList[i]); // remove all spaces QString newCmd(cmd); newCmd.replace(QChar(' '), sepChar); // re-add spaces in quoted sections restoreSpaces(newCmd, sepChar); // QUOTE_CHAR is used internally to delimit arguments // with quoted text wholly inside as // arg1 = <[patch] cool patch on "cool feature"> // and should be removed before to feed QProcess newCmd.remove(QGit::QUOTE_CHAR); // QProcess::setArguments doesn't want quote // delimited arguments, so remove trailing quotes QStringList sl(newCmd.split(sepChar, QString::SkipEmptyParts)); QStringList::iterator it(sl.begin()); for ( ; it != sl.end(); ++it) { if (((*it).left(1) == "\"" && (*it).right(1) == "\"") || ((*it).left(1) == "\'" && (*it).right(1) == "\'")) *it = (*it).mid(1, (*it).length() - 2); } return sl; }
MainWindow::MainWindow(QWidget* parent): QMainWindow(parent), pop(0), msg(0) { setupUi(this); settings = new QSettings(QSettings::UserScope,"Qxt", "MailTest", this); pop = new QxtPop3(this); pop->sslSocket()->setProtocol(QSsl::TlsV1_0); pop->sslSocket()->setPeerVerifyMode(QSslSocket::QueryPeer); QString username = settings->value("username").toString(); QString hostname = settings->value("hostname").toString(); QString pass = settings->value("password").toString(); int port = settings->value("port").toInt(); bool ok; Encryption enc = Encryption(settings->value("encryption").toInt(&ok)); if (!ok) enc = Clear; switch (enc) { case UseSSL: sslRadioButton->setChecked(true); break; case UseStartTLS: startTLSRadioButton->setChecked(true); break; case Clear: default: clearRadioButton->setChecked(true); break; } usernameLineEdit->setText(username); hostnameLineEdit->setText(hostname); passwordLineEdit->setText(pass); if (port != 0) portLineEdit->setText(QString::number(port)); connect(connectPushButton, SIGNAL(clicked()), this, SLOT(connectToHost())); connect(settingsPushButton, SIGNAL(clicked()), this, SLOT(saveSettings())); connect(pop, SIGNAL(disconnected()), this, SLOT(disconnected())); connect(pop, SIGNAL(connected()), this, SLOT(connected())); connect(pop, SIGNAL(connectionFailed(QByteArray)), this, SLOT(handleSslError(QByteArray))); connect(pop, SIGNAL(encryptionFailed(QByteArray)), this, SLOT(handleSslError(QByteArray))); connect(pop, SIGNAL(authenticationFailed(QByteArray)), this, SLOT(handleAuthError(QByteArray))); connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(newCmd())); help(); }
void addCommand(const std::string &command, std::function<CommandResult (ServerConnection*, std::shared_ptr<User>, const std::string&, const std::string&, Args...)> fun, const std::string &description = "", bool displayDescription = true) { std::string::size_type commandEnd = command.find(' '); std::string commandName = command.substr(0, commandEnd); std::string rest = commandEnd == std::string::npos ? "" : command.substr( commandEnd + 1); // There can be errors if (commandEnd + 1) is out of range // They will only occur if a command name string is malformated // (has one trailing space) so be sure to not mess up the command names. if (commandEnd == std::string::npos || command[commandEnd + 1] == '<' || command[commandEnd + 1] == '[') { // Command end point subCommands.emplace_back(new Command<Args...>(commandName, rest, fun, description, displayDescription)); } else { // New command group // Search for existing command group with the same name for (std::unique_ptr<AbstractCommand> &sub : subCommands) { CommandGroup *cmdGroup = dynamic_cast<CommandGroup*>(sub.get()); if (cmdGroup && sub->getName() == commandName) { cmdGroup->addCommand(rest, fun, description, displayDescription); return; } } // Name not found -> insert a new command group std::unique_ptr<AbstractCommand> newCmd(new CommandGroup(commandName)); CommandGroup *group = static_cast<CommandGroup*>(newCmd.get()); group->addCommand(rest, fun, description, displayDescription); subCommands.push_back(std::move(newCmd)); } }
static Cmd mkCmd(Token inpipe) { Cmd c; while ( CmdToken(LA) ) // skip over ; and & Next(); if ( LA != Tword ) { // a word begins every command if ( LA == Tend ) return &End; if ( LA == Tnl || LA == Terror ) // don't complain about empty lines or twice about same error return &Empty; printf(ERR_MSG); #if 0 while ( !CmdToken(LA) && !EndOfInput(LA) ) // kill rest of pipe Next(); #endif return NULL; } assert(LA == Tword); c = newCmd(Word); Next(); c->in = inpipe; while ( InCmd(LA) ) { // loop until next command switch ( LA ) { case Tin: if ( c->in != Tnil ) { // two Tin in one command printf("Ambiguous input redirect.\n"); // skip to end of line do { Next(); } while ( !EndOfInput(LA) ); freeCmd(c); return NULL; } c->in = LA; Next(); if ( LA != Tword ) { printf(ERR_MSG); // skip to end of line do { Next(); } while ( !EndOfInput(LA) ); freeCmd(c); return NULL; } c->infile = mkWord(Word); // save "in" file Next(); break; case Tout: case ToutErr: case Tapp: case TappErr: if ( c->out != Tnil ) { printf("Ambiguous output redirect.\n"); // skip to end of line do { Next(); } while ( !EndOfInput(LA) ); freeCmd(c); return NULL; } c->out = LA; // remember which kind Next(); if ( LA != Tword) { printf(ERR_MSG); // skip to end of line do { Next(); } while ( !EndOfInput(LA) ); freeCmd(c); return NULL; } c->outfile = mkWord(Word); // save "out" file Next(); break; case Tword: if ( c->args == NULL ) { printf("Hmmm...\n"); exit(-2); } // if we've exceeded the size of the arg array double it if ( c->nargs + 2 > c->maxargs ) { c->maxargs += c->maxargs; c->args = realloc(c->args, c->maxargs*sizeof(char *)); if ( c->args == NULL ) { perror("realloc"); exit(errno); } } c->args[c->nargs++] = mkWord(Word); // save the arg Next(); break; default: printf("Shouldn't get here\n"); exit(-1); break; } } if ( LA == Terror ) { // shouldn't happen, but what the heck ... freeCmd(c); return NULL; } if ( LA == Tsemi ) // skip over ending semi Next(); else if ( LA == Tamp ){ // remember the & c->exec = Tamp; Next(); } c->args[c->nargs] = NULL; return c; } /*---------- End of mkCmd -------------------------------------------------*/
void CCommandAI::ExecuteInsert(const Command& c, bool fromSynced) { if (c.params.size() < 3) { return; } // make the command Command newCmd((int)c.params[1], (unsigned char)c.params[2]); for (int p = 3; p < (int)c.params.size(); p++) { newCmd.params.push_back(c.params[p]); } // validate the command if (!AllowedCommand(newCmd, fromSynced)) { return; } CCommandQueue* queue = &commandQue; bool facBuildQueue = false; CFactoryCAI* facCAI = dynamic_cast<CFactoryCAI*>(this); if (facCAI) { if (c.options & CONTROL_KEY) { // check the build order const map<int, CFactoryCAI::BuildOption>& bOpts = facCAI->buildOptions; if ((newCmd.GetID() != CMD_STOP) && (newCmd.GetID() != CMD_WAIT) && ((newCmd.GetID() >= 0) || (bOpts.find(newCmd.GetID()) == bOpts.end()))) { return; } facBuildQueue = true; } else { // use the new commands queue = &facCAI->newUnitCommands; } } // FIXME: handle CMD_LOOPBACKATTACK, etc... CCommandQueue::iterator insertIt = queue->begin(); if (c.options & ALT_KEY) { // treat param0 as a position int pos = (int)c.params[0]; const unsigned int qsize = queue->size(); if (pos < 0) { pos = qsize + pos + 1; // convert the negative index if (pos < 0) { pos = 0; } } if (pos > qsize) { pos = qsize; } std::advance(insertIt, pos); } else { // treat param0 as a command tag const unsigned int tag = (unsigned int)c.params[0]; CCommandQueue::iterator ci; bool found = false; for (ci = queue->begin(); ci != queue->end(); ++ci) { const Command& qc = *ci; if (qc.tag == tag) { insertIt = ci; found = true; break; } } if (!found) { return; } if ((c.options & RIGHT_MOUSE_KEY) && (insertIt != queue->end())) { ++insertIt; // insert after the tagged command } } if (facBuildQueue) { facCAI->InsertBuildCommand(insertIt, newCmd); if (!owner->stunned) { SlowUpdate(); } return; } // shutdown the current order if the insertion is at the beginning if (!queue->empty() && (insertIt == queue->begin())) { inCommand = false; targetDied = false; unimportantMove = false; SetOrderTarget(NULL); const Command& cmd = queue->front(); eoh->CommandFinished(*owner, cmd); eventHandler.UnitCmdDone(owner, cmd.GetID(), cmd.tag); } queue->insert(insertIt, newCmd); if (!owner->stunned) { SlowUpdate(); } }