QString ATCommand::cmd() { if (mParameters.count() > 0) { QString cmd = cmdString().left(cmdString().find("=") + 1); // kdDebug() << "--1-cmd: " << cmd << endl; for(uint i=0; i<mParameters.count(); ++i) { cmd += mParameters.at(i)->value(); if (i < mParameters.count() - 1) cmd += ","; } // kdDebug() << "--2-cmd: " << cmd << endl; return cmd; } else { return cmdString(); } }
void CommandBuilder::BuildCommand(const wxString &cmdStringArg) { wxString cmdString(cmdStringArg); // Find the command name terminator... If there is more than one word and // no terminator, the command is badly formed cmdString.Trim(true); cmdString.Trim(false); int splitAt = cmdString.Find(wxT(':')); if (splitAt < 0 && cmdString.Find(wxT(' ')) >= 0) { mError = wxT("Command is missing ':'"); ScriptCommandRelay::SendResponse(wxT("\n")); mValid = false; return; } wxString cmdName = cmdString.Left(splitAt); wxString cmdParams = cmdString.Mid(splitAt+1); if( splitAt < 0 ) cmdParams = ""; cmdName.Trim(true); cmdParams.Trim(false); BuildCommand(cmdName, cmdParams); }
void ATCommand::extractParameters() { // kdDebug() << "Arg String: " << cmdString() << endl; int pos = cmdString().find("="); if (pos < 0) return; QString paraString = cmdString().mid(pos+1); // kdDebug() << "Para String: " << paraString << endl; QStringList paraList = QStringList::split(",",paraString); QStringList::ConstIterator it = paraList.begin(); QStringList::ConstIterator end = paraList.end(); int argNum = 1; while(it != end) { addParameter(new ATParameter(*it,i18n("Arg %1").arg(QString::number(argNum++)), false)); ++it; } }
int console_blit_completion(ContextPtr env, char *cmd) { if(!cmd) return 0; ViewPortPtr screen = getSelectedScreen(); if(!screen) { ::error("no screen currently selected"); return 0; } // Find completions BlitPtr exactBlit; LinkList<Blit> retList; LinkList<Blit> &list = screen->getBlitter()->getBlits(); std::string cmdString(cmd); std::transform(cmdString.begin(), cmdString.end(), cmdString.begin(), ::tolower); std::copy_if(list.begin(), list.end(), retList.begin(), [&] (BlitPtr blit) { std::string name = blit->getName(); std::transform(name.begin(), name.end(), name.begin(), ::tolower); if(name == cmdString) { exactBlit = blit; } return name.compare(cmdString) == 0; }); if(retList.empty()) return 0; if(exactBlit != NULL) { snprintf(cmd, MAX_CMDLINE, "%s = ", exactBlit->getName().c_str()); return 1; } if(cmdString.empty()) { notice("List available blits"); } else { notice("List available blits starting with \"%s\"", cmd); } int c = 0; char tmp[256]; std::for_each(retList.begin(), retList.end(), [&] (BlitPtr b) { if(c % 4 == 0) { if(c != 0) { ::act("%s", tmp); } tmp[0] = '\0'; } strncat(tmp, "\t", sizeof(tmp) - 1); strncat(tmp, b->getName().c_str(), sizeof(tmp) - 1); ++c; }); return c; }
int console_filter_completion(ContextPtr env, char *cmd) { if(!cmd) return 0; // Find completions FilterPtr exactFilter; LinkList<Filter> retList; LinkList<Filter> &list = env->getFilters(); std::string cmdString(cmd); std::transform(cmdString.begin(), cmdString.end(), cmdString.begin(), ::tolower); std::copy_if(list.begin(), list.end(), retList.begin(), [&] (FilterPtr filter) { std::string name = filter->getName(); std::transform(name.begin(), name.end(), name.begin(), ::tolower); if(name == cmdString) { exactFilter = filter; } return name.compare(cmdString) == 0; }); if(retList.empty()) return 0; if(exactFilter != NULL) { ::notice("%s :: %s", exactFilter->getName().c_str(), exactFilter->getDescription().c_str()); snprintf(cmd, MAX_CMDLINE, "%s", exactFilter->getName().c_str()); return 1; } if(cmdString.empty()) { notice("List available filters"); } else { notice("List available filters with \"%s\"", cmd); } int c = 0; char tmp[256]; std::for_each(retList.begin(), retList.end(), [&] (FilterPtr f) { if(c % 4 == 0) { if(c != 0) { ::act("%s", tmp); } tmp[0] = '\0'; } strncat(tmp, "\t", sizeof(tmp) - 1); strncat(tmp, f->getName().c_str(), sizeof(tmp) - 1); ++c; }); return c; }
//----- OnBnClickedBtNscopeColl() ------------------------------------------- void CFormChunkMergeView::OnBnClickedBtNscopeColl() { string cmdString(Configuration::getInstance()->_pathNifSkope); if (!cmdString.empty()) { STARTUPINFO startupInfo = {0}; PROCESS_INFORMATION processInfo = {0}; stringstream sStream; startupInfo.cb = sizeof(startupInfo); UpdateData(TRUE); sStream << "\"" << cmdString << "\" \"" << CStringA(_fileNameColl).GetString() << "\""; CreateProcess(CString(cmdString.c_str()).GetString(), (LPWSTR) CString(sStream.str().c_str()).GetString(), NULL, NULL, TRUE, CREATE_NEW_PROCESS_GROUP, NULL, NULL, &startupInfo, &processInfo); } else { AfxMessageBox(_T("You didn't specify the NifSkope\r\nexecuteable in options."), MB_OK | MB_ICONEXCLAMATION); } }
int console_filebrowse_completion(ContextPtr env, char *cmd) { LinkList<Entry> files; struct stat filestatus; #if defined (HAVE_DARWIN) || defined (HAVE_FREEBSD) struct dirent **filelist; #else struct dirent **filelist; #endif char path[MAX_CMDLINE]; char needle[MAX_CMDLINE]; bool incomplete = false; if(cmd[0] != '/') // path is relative: prefix our location snprintf(path, MAX_CMDLINE, "%s/%s", getenv("PWD"), cmd); else // path is absolute strncpy(path, cmd, MAX_CMDLINE); if(stat(path, &filestatus) < 0) { // no file there? int c = 0; // parse backwards to the first '/' and zero it, // store the word of the right part in needle for(c = strlen(path); path[c] != '/' && c > 0; c--) ; strncpy(needle, &path[c + 1], MAX_CMDLINE); path[c + 1] = '\0'; incomplete = true; if(stat(path, &filestatus) < 0) { // yet no valid file? error("error on file completion path %s: %s", path, strerror(errno)); return 0; } } else { // we have a file! if(S_ISREG(filestatus.st_mode)) return 1; // is a regular file! // is it a directory? then append the trailing slash if(S_ISDIR(filestatus.st_mode)) { int c = strlen(path); if(path[c - 1] != '/') { path[c] = '/'; path[c + 1] = '\0'; } } strncpy(cmd, path, MAX_CMDLINE); } func("file completion: %s", cmd); // at this point in path there should be something valid int found = scandir (path, &filelist, filebrowse_completion_selector, alphasort); if(found < 0) { error("filebrowse_completion: scandir: %s", strerror(errno)); return 0; } for(int c = found - 1; c > 0; c--) { // insert each entry found in a linklist EntryPtr e = MakeShared<Entry>(filelist[c]->d_name); files.push_back(e); } int c = 0; // counter for entries found if(incomplete) { // list all files in directory *path starting with *needle // Find completions EntryPtr exactEntry; LinkList<Entry> retList; std::string cmdString(needle); std::transform(cmdString.begin(), cmdString.end(), cmdString.begin(), ::tolower); std::copy_if(files.begin(), files.end(), retList.begin(), [&] (EntryPtr entry) { std::string name = entry->getName(); std::transform(name.begin(), name.end(), name.begin(), ::tolower); if(name == cmdString) { exactEntry = entry; } return name.compare(cmdString) == 0; }); c = retList.size(); if(exactEntry != NULL) { snprintf(cmd, MAX_CMDLINE, "%s%s", path, exactEntry->getName().c_str()); } else { notice("list of %s* files in %s:", needle, path); std::for_each(retList.begin(), retList.end(), [&] (EntryPtr entry) { ::act(" %s", entry->getName().c_str()); }); } } else { // list all entries notice("list of all files in %s:", path); std::for_each(files.begin(), files.end(), [&] (EntryPtr e) { ::act("%s", e->getName().c_str()); }); } return(c); }
int console_blit_param_completion(ContextPtr env, char *cmd) { ViewPortPtr screen = getSelectedScreen(); if(!screen) { ::error("no screen currently selected"); return 0; } LayerPtr lay = getSelectedLayer(); if(!lay) { ::error("no layer currently selected"); return 0; } BlitInstancePtr b = lay->getCurrentBlit(); if(!b) { ::error("no blit selected on layer %s", lay->getName().c_str()); return 0; } // Find completions // Find completions ParameterInstancePtr exactParam; LinkList<ParameterInstance> retList; LinkList<ParameterInstance> &list = b->getParameters(); std::string cmdString(cmd); std::transform(cmdString.begin(), cmdString.end(), cmdString.begin(), ::tolower); std::copy_if(list.begin(), list.end(), retList.begin(), [&] (ParameterInstancePtr param) { std::string name = param->getName(); std::transform(name.begin(), name.end(), name.begin(), ::tolower); if(name == cmdString) { exactParam = param; } return name.compare(cmdString) == 0; }); if(retList.empty()) return 0; if(exactParam != NULL) { snprintf(cmd, MAX_CMDLINE, "%s = ", exactParam->getName().c_str()); return 1; } if(cmdString.empty()) { notice("List available blit parameters"); } else { notice("List available blit parameters starting with \"%s\"", cmd); } int c = 0; std::for_each(retList.begin(), retList.end(), [&] (ParameterInstancePtr p) { switch(p->getType()) { case Parameter::BOOL: ::act("(bool) %s = %s :: %s", p->getName().c_str(), (*(bool*)p->get() == true) ? "true" : "false", p->getDescription().c_str()); break; case Parameter::NUMBER: ::act("(number) %s = %.2f :: %s", p->getName().c_str(), *(float*)p->get(), p->getDescription().c_str()); break; case Parameter::STRING: ::act("(string) %s = %s :: %s", p->getName().c_str(), (char*)p->get(), p->getDescription().c_str()); break; case Parameter::POSITION: { float *val = (float*)p->get(); ::act("(position) %s = %.2f x %.2f :: %s", p->getName().c_str(), val[0], val[1], p->getDescription().c_str()); } break; case Parameter::COLOR: ::act("%s (color) %s", p->getName().c_str(), p->getDescription().c_str()); break; default: ::error("%s (unknown) %s", p->getName().c_str(), p->getDescription().c_str()); break; } ++c; }); return c; }