JBoolean SVNPropertiesList::SchedulePropertiesForRemove() { JTableSelection& s = GetTableSelection(); JTableSelectionIterator iter(&s); JPoint cell; JString cmd, prop, file = JPrepArgForExec(itsFullName); JSubstitute subst; while (iter.Next(&cell)) { const JString* line = (GetStringList()).NthElement(cell.y); prop = JPrepArgForExec(*line); cmd = kPropRemoveCmd; subst.DefineVariable("prop_name", prop); subst.DefineVariable("file_name", file); subst.Substitute(&cmd); itsRemovePropertyCmdList->Append(cmd); } RemoveNextProperty(); return kJTrue; }
JBoolean SVNPropertiesList::CreateProperty1() { assert( itsCreatePropertyDialog != NULL ); const JString prop = JPrepArgForExec(itsCreatePropertyDialog->GetString()); const JString file = JPrepArgForExec(itsFullName); JSubstitute subst; subst.DefineVariable("prop_name", prop); subst.DefineVariable("file_name", file); JString cmd = kPropEditCmd; subst.Substitute(&cmd); JSimpleProcess* p; const JError err = JSimpleProcess::Create(&p, cmd, kJTrue); if (err.OK()) { itsProcessList->Append(p); ListenTo(p); return kJTrue; } else { err.ReportIfError(); return kJFalse; } }
void SyGViewManPageDialog::ViewManPage ( const JCharacter* item, const JCharacter index, const JBoolean apropos ) { JString cmd = itsViewCmd; cmd += " "; if (apropos) { cmd += "-k "; } else if (index != ' ') { #ifdef _J_MAN_SECTION_VIA_DASH_S if (itsViewCmd != kDefaultViewCmd) { cmd += "-s "; } #endif const JCharacter pageIndexStr[] = { index, ' ', '\0' }; cmd += pageIndexStr; } cmd += JPrepArgForExec(item); JSimpleProcess::Create(cmd, kJTrue); }
void SyGViewManPageDialog::ViewManPages ( const JPtrArray<JString>& list ) { if (itsViewCmd == kDefaultViewCmd) { JString cmd = kDefaultViewBin; const JSize count = list.GetElementCount(); for (JIndex i=1; i<=count; i++) { cmd += kDefaultViewArg; cmd += JPrepArgForExec(*(list.NthElement(i))); } JSimpleProcess::Create(cmd, kJTrue); } else { const JSize count = list.GetElementCount(); for (JIndex i=1; i<=count; i++) { ViewManPage(*(list.NthElement(i))); } } }
JBoolean SVNTabBase::Prepare ( JString* cmd, const JCharacter* warnMsgID, const JBoolean includeDeleted ) { JPtrArray<JString> list(JPtrArrayT::kDeleteAll); GetSelectedFiles(&list, includeDeleted); if (list.IsEmpty()) { return kJFalse; } if (warnMsgID != NULL && !(JGetUserNotification())->AskUserNo(JGetString(warnMsgID))) { return kJFalse; } const JSize count = list.GetElementCount(); JString fileList; for (JIndex i=1; i<=count; i++) { fileList += JPrepArgForExec(*(list.NthElement(i))); fileList += " "; } JSubstitute subst; subst.DefineVariable("file_name", fileList); subst.Substitute(cmd); return kJTrue; }
JError JUncompressFile ( const JCharacter* origFileName, JString* newFileName, const JCharacter* dirName, JProcess** process ) { // generate a file name if one is not provided if (newFileName->IsEmpty()) { const JError err = JCreateTempFile(dirName, NULL, newFileName); if (!err.OK()) { return err; } } else if (!JStringEmpty(dirName)) { *newFileName = JCombinePathAndName(dirName, *newFileName); } // construct the command JString cmd = "gunzip --to-stdout "; cmd += JPrepArgForExec(origFileName); cmd += " >| "; cmd += JPrepArgForExec(*newFileName); cmd = "/bin/sh -c " + JPrepArgForExec(cmd); // run the command if (process != NULL) { return JProcess::Create(process, cmd); } else { JString errText; return JRunProgram(cmd, &errText); } }
JBoolean SyGDeleteDirEntry ( const JCharacter* fullName ) { const JString sysCmd = "rm -rf " + JPrepArgForExec(fullName); return SyGExec(sysCmd); }
JString SVNPropertiesList::GetCommand ( const JCharacter* fullName ) { JString cmd = "svn --non-interactive proplist "; cmd += JPrepArgForExec(fullName); return cmd; }
JBoolean SVNTabBase::ExecuteDiff ( const JCharacter* origCmd, const JCharacter* rev, const JBoolean isPrev ) { JPtrArray<JString> fileList(JPtrArrayT::kDeleteAll); JArray<JIndex> revList; GetSelectedFilesForDiff(&fileList, &revList); if (fileList.IsEmpty()) { return kJFalse; } (JXGetApplication())->DisplayBusyCursor(); JSubstitute subst; subst.DefineVariable("rev_option", rev); const JBoolean customPrev = JI2B( isPrev && !revList.IsEmpty() ); const JSize count = fileList.GetElementCount(); JString cmd, fullName, r; for (JIndex i=1; i<=count; i++) { cmd = origCmd; fullName = JPrepArgForExec(*(fileList.NthElement(i))); if (customPrev) { const JIndex j = revList.GetElement(i); r = JString(j-1, JString::kBase10); r += ":"; r += JString(j, JString::kBase10); subst.DefineVariable("rev_option", r); } subst.DefineVariable("file_name", fullName); subst.Substitute(&cmd); if (itsDirector->HasPath()) { JSimpleProcess::Create(itsDirector->GetPath(), cmd, kJTrue); } else { JSimpleProcess::Create(cmd, kJTrue); } } return kJTrue; }
void SyGFindFileDialog::SearchFileName ( const JCharacter* path, const JCharacter* pattern ) { JString expr = "-iname "; expr += JPrepArgForExec(pattern); SearchExpr(path, expr); }
void SVNPropertiesList::OpenSelectedItems() { JTableSelection& s = GetTableSelection(); JTableSelectionIterator iter(&s); JPoint cell; JString cmd, prop, file = JPrepArgForExec(itsFullName); JSubstitute subst; while (iter.Next(&cell)) { const JString* line = (GetStringList()).NthElement(cell.y); prop = JPrepArgForExec(*line); cmd = kPropEditCmd; subst.DefineVariable("prop_name", prop); subst.DefineVariable("file_name", file); subst.Substitute(&cmd); JSimpleProcess::Create(cmd, kJTrue); } }
JError JXFSBindingManager::Exec ( const JCharacter* path, const JCharacter* origCmd, const JFSBinding::CommandType type ) { JXFSBindingManager* me = Instance(); JString cmd = origCmd, u, q; // build shell command if (type == JFSBinding::kRunInShell || type == JFSBinding::kRunInWindow || (me->itsBindingList->WillAutoUseShellCommand() && strpbrk(origCmd, kShellMetaCharList) != NULL)) { u = cmd; q = JPrepArgForExec(cmd); cmd = me->itsBindingList->GetShellCommand(); BuildCommand(&cmd, q, u, "", ""); } // build window command if (type == JFSBinding::kRunInWindow) { u = cmd; q = JPrepArgForExec(cmd); cmd = me->itsBindingList->GetWindowCommand(); BuildCommand(&cmd, q, u, "", ""); } // exec command return JSimpleProcess::Create(path, cmd, kJTrue); }
JError SVNInfoLog::StartProcess ( JProcess** p, int* outFD ) { JString cmd = "svn --non-interactive info " + JPrepArgForExec(itsFullName); Execute(cmd); cmd = "svn --non-interactive log "; if (!itsRevision.IsEmpty()) { cmd += "-v -r "; cmd += JPrepArgForExec(itsRevision); cmd += " "; } cmd += JPrepArgForExec(itsFullName); return JProcess::Create(p, cmd, kJIgnoreConnection, NULL, kJForceNonblockingPipe, outFD, kJAttachToFromFD); }
JBoolean JGetSVNEntryType ( const JCharacter* url, JString* type, JString* error ) { type->Clear(); error->Clear(); JString cmd = "svn info --xml " + JPrepArgForExec(url); JProcess* p; int fromFD, errFD; JError err = JProcess::Create(&p, cmd, kJIgnoreConnection, NULL, kJCreatePipe, &fromFD, kJCreatePipe, &errFD); if (!err.OK()) { err.ReportIfError(); return kJFalse; } p->WaitUntilFinished(); if (p->SuccessfulFinish()) { xmlDoc* doc = xmlReadFd(fromFD, NULL, NULL, XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA); close(fromFD); if (doc != NULL) { xmlNode* root = xmlDocGetRootElement(doc); if (root != NULL && strcmp((char*) root->name, "info") == 0 && strcmp((char*) root->children->name, "entry") == 0) { *type = JGetXMLNodeAttr(root->children, "kind"); return kJTrue; } } } JReadAll(errFD, error, kJTrue); return kJFalse; }
JBoolean SVNTabBase::ExecuteJCCDiff ( const JString& rev, const JBoolean isPrev ) { JPtrArray<JString> fileList(JPtrArrayT::kDeleteAll); JArray<JIndex> revList; GetSelectedFilesForDiff(&fileList, &revList); if (fileList.IsEmpty()) { return kJFalse; } const JBoolean customPrev = JI2B( isPrev && !revList.IsEmpty() ); const JSize count = fileList.GetElementCount(); JString cmd, s, fullName; JSubstitute subst; for (JIndex i=1; i<=count; i++) { if (customPrev) { const JIndex j = revList.GetElement(i); s = JString(j-1, JString::kBase10); s += ":"; s += JString(j, JString::kBase10); } else { s = rev; } s += " $file_name"; fullName = JPrepArgForExec(*(fileList.NthElement(i))); subst.DefineVariable("file_name", fullName); subst.Substitute(&s); if (count == 1) { s.Prepend(" --svn-diff "); } else { s.Prepend(" --svn-diff-silent "); } cmd += s; } cmd.Prepend("jcc"); if (itsDirector->HasPath()) { JSimpleProcess::Create(itsDirector->GetPath(), cmd, kJTrue); } else { JSimpleProcess::Create(cmd, kJTrue); } return kJTrue; }
void JXFSBindingManager::Exec ( const JIndex startIndex, const JIndex endIndex ) { // check if same path for all files JBoolean samePath = kJTrue; JString path, name; if (endIndex > startIndex) { JString p; for (JIndex i=startIndex; i<=endIndex; i++) { const JString& fullName = (itsFileList->NthElement(i))->GetPattern(); JSplitPathAndName(fullName, &p, &name); if (i > startIndex && p != path) { samePath = kJFalse; break; } path = p; } } // build $q, $u, $qf, $uf JString q, u, qf, uf; for (JIndex i=startIndex; i<=endIndex; i++) { const JString& fullName = (itsFileList->NthElement(i))->GetPattern(); if (samePath) { JSplitPathAndName(fullName, &path, &name); } else { name = fullName; } q += JPrepArgForExec(name); q += " "; u += name; u += " "; qf += JPrepArgForExec(fullName); qf += " "; uf += fullName; uf += " "; } // run command JFSBinding* f = itsFileList->NthElement(startIndex); JSplitPathAndName(f->GetPattern(), &path, &name); JFSBinding::CommandType type; JBoolean singleFile; JString cmd = f->GetCommand(&type, &singleFile); assert( ( singleFile && startIndex == endIndex) || (!singleFile && startIndex <= endIndex) ); BuildCommand(&cmd, q, u, qf, uf); Exec(path, cmd, type); }
void LLDBGetAssembly::HandleSuccess ( const JString& cmdData ) { LLDBLink* link = dynamic_cast<LLDBLink*>(CMGetLink()); if (link == NULL) { return; } lldb::SBCommandInterpreter interp = link->GetDebugger()->GetCommandInterpreter(); if (!interp.IsValid()) { return; } const CMLocation& loc = (GetDirector())->GetDisassemblyLocation(); const JString cmd = "disassemble -n " + JPrepArgForExec(loc.GetFunctionName()); lldb::SBCommandReturnObject result; interp.HandleCommand(cmd, result); JPtrArray<JString> addrList(JPtrArrayT::kDeleteAll); JString instText; if (result.IsValid() && result.Succeeded() && result.HasResult()) { std::istringstream input(result.GetOutput()); JString line, s; JSize maxOffsetLength = 0; while (!input.eof() && !input.fail()) { line = JReadLine(input); JIndex i; if (line.LocateSubstring(":", &i) && i < line.GetLength()) { s = line.GetSubstring(1, i-1); if (s.BeginsWith("->") && s.GetLength() > 2) { s = s.GetSubstring(3, s.GetLength()); } s.TrimWhitespace(); addrList.Append(s); JIndexRange r; if (offsetPattern.Match(s, &r)) { maxOffsetLength = JMax(maxOffsetLength, r.GetLength()); } if (!instText.IsEmpty()) { instText.AppendCharacter('\n'); } s = line.GetSubstring(i+1, line.GetLength()); s.TrimWhitespace(); instText.Append(s); } } const JSize count = addrList.GetElementCount(); for (JIndex i=1; i<count; i++) { JString* s = addrList.NthElement(i); JIndexRange r; if (offsetPattern.Match(*s, &r)) { const JSize pad = maxOffsetLength - r.GetLength(); for (JIndex j=0; j<pad; j++) { s->InsertCharacter('0', r.first+2); } } } } (GetDirector())->DisplayDisassembly(&addrList, instText); }
JBoolean CBCommand::StartProcess() { // check if we are finished while (!itsCmdList->IsEmpty() && (itsCmdList->GetElement(1)).IsEndOfSequence()) { CmdInfo info = itsCmdList->GetElement(1); info.Free(kJTrue); itsCmdList->RemoveElement(1); } if (itsCmdList->IsEmpty()) { if (itsBeepFlag && itsParent == NULL) { ((JXGetApplication())->GetCurrentDisplay())->Beep(); } DeleteThis(); return kJFalse; } // check if we can use the window itsInQueueFlag = kJFalse; if (itsOutputDoc != NULL && itsOutputDoc->ProcessRunning()) { itsInQueueFlag = kJTrue; ListenTo(itsOutputDoc); return kJTrue; // wait for message from itsOutputDoc } // check if need to run a subroutine CmdInfo info = itsCmdList->GetElement(1); if (info.cmdObj != NULL) { StopListening(itsOutputDoc); // wait for CBCommand to notify us const JBoolean result = (info.cmdObj)->Start(*(info.cmdInfo)); info.Free(kJFalse); itsCmdList->RemoveElement(1); return result; } // start process assert( info.cmd != NULL ); JShouldIncludeCWDOnPath(kJTrue); JProcess* p; int toFD, fromFD; JError execErr = JNoError(); if (itsOutputDoc != NULL) { execErr = JProcess::Create(&p, itsCmdPath, *(info.cmd), kJCreatePipe, &toFD, kJCreatePipe, &fromFD, kJAttachToFromFD, NULL); } else { JSimpleProcess* p1; execErr = JSimpleProcess::Create(&p1, itsCmdPath, *(info.cmd), kJTrue); p = p1; } JShouldIncludeCWDOnPath(kJFalse); if (!execErr.OK()) { execErr.ReportIfError(); DeleteThis(); return kJFalse; } if (itsOutputDoc != NULL) { const JSize count = info.cmd->GetElementCount(); JString cmd; for (JIndex i=1; i<=count; i++) { cmd += JPrepArgForExec(*info.cmd->NthElement(i)); cmd += " "; } itsOutputDoc->SetConnection(p, fromFD, toFD, itsWindowTitle, itsDontCloseMsg, itsCmdPath, cmd, kJTrue); // We can't do this in Start() because we might be waiting for // itsMakeDependCmd. We must not listen to both at the same time. ListenTo(itsOutputDoc); } else { ListenTo(p); JThisProcess::Ignore(p); } info.Free(kJTrue); itsCmdList->RemoveElement(1); return kJTrue; }
JError JRenameVCS ( const JCharacter* oldFullName, const JCharacter* newFullName ) { if (!JNameUsed(oldFullName)) { return JDirEntryDoesNotExist(oldFullName); } JString oldPath, newPath, name; JSplitPathAndName(newFullName, &newPath, &name); JSplitPathAndName(oldFullName, &oldPath, &name); // must be second const JString origPath = JGetCurrentDirectory(); if (JChangeDirectory(oldPath) != kJNoError) { return JAccessDenied(oldPath); } JVCSType type1 = JGetVCSType(oldPath); JVCSType type2 = JGetVCSType(newPath); JError err = JNoError(); JBoolean tryPlain = kJFalse; JString cmd; JProcess* p = NULL; if (type1 != type2) { tryPlain = kJTrue; } else if (type1 == kJSVNType || type1 == kJGitType) { if (type1 == kJSVNType) { cmd = "svn mv --force "; cmd += JPrepArgForExec(oldFullName); cmd += " "; cmd += JPrepArgForExec(newFullName); } else if (type1 == kJGitType) { cmd = "git mv -f "; cmd += JPrepArgForExec(name); cmd += " "; cmd += JPrepArgForExec(newFullName); } err = JProcess::Create(&p, cmd); if (err.OK()) { p->WaitUntilFinished(); } if (p != NULL && !p->SuccessfulFinish()) { err = JAccessDenied(oldFullName, newFullName); tryPlain = kJTrue; } } else if (type1 == kJUnknownVCSType) { tryPlain = kJTrue; } else { err = JUnsupportedVCS(oldFullName); } if (tryPlain && JProgramAvailable("mv")) { cmd = "mv "; cmd += JPrepArgForExec(oldFullName); cmd += " "; cmd += JPrepArgForExec(newFullName); JSimpleProcess* p1; err = JSimpleProcess::Create(&p1, cmd); p = p1; if (err.OK()) { p->WaitUntilFinished(); if (!p->SuccessfulFinish()) { err = JAccessDenied(oldFullName, newFullName); } } } else if (tryPlain) { err = JRenameDirEntry(oldFullName, newFullName); } delete p; JChangeDirectory(origPath); return err; }
JError JRemoveVCS ( const JCharacter* fullName, const JBoolean sync, JProcess** returnP ) { if (returnP != NULL) { *returnP = NULL; } if (!JNameUsed(fullName)) { return JDirEntryDoesNotExist(fullName); } JString path, name; JSplitPathAndName(fullName, &path, &name); const JString origPath = JGetCurrentDirectory(); if (JChangeDirectory(path) != kJNoError) { return JAccessDenied(path); } JVCSType type = JGetVCSType(path); JError err = JNoError(); JBoolean tryPlain = kJFalse; JString cmd; JProcess* p = NULL; if (type == kJSVNType || type == kJGitType) { const JCharacter *binary = NULL; if (type == kJSVNType) { binary = "svn rm --force "; } else if (type == kJGitType) { binary = "git rm -rf "; } cmd = binary; cmd += JPrepArgForExec(name); err = JProcess::Create(&p, cmd); if (err.OK()) { p->WaitUntilFinished(); } if (p != NULL && !p->SuccessfulFinish()) { err = JAccessDenied(fullName); tryPlain = kJTrue; } } else if (type == kJUnknownVCSType) { tryPlain = kJTrue; } else { err = JUnsupportedVCS(fullName); } if (tryPlain && JKillDirectory(fullName, sync, returnP)) { err = JNoError(); } else if (tryPlain) { err = JAccessDenied(fullName); } delete p; JChangeDirectory(origPath); return err; }