void SVNInfoLog::Execute ( const JCharacter* cmd ) { (JXGetApplication())->DisplayBusyCursor(); pid_t pid; int outFD, errFD; JError err = JExecute(cmd, &pid, kJIgnoreConnection, NULL, kJCreatePipe, &outFD, kJCreatePipe, &errFD); if (!err.OK()) { err.ReportIfError(); return; } const JFontStyle red(kJTrue, kJFalse, 0, kJFalse, (GetColormap())->GetRedColor()); JString text; JReadAll(errFD, &text); SetCurrentFontStyle(red); Paste(text); JReadAll(outFD, &text); SetCurrentFontStyle(JFontStyle()); Paste(text); }
JError JSimpleProcess::Create ( JSimpleProcess** process, const JPtrArray<JString>& argList, const JBoolean deleteWhenFinished ) { pid_t childPID; int errFD; const JError err = JExecute(argList, &childPID, kJIgnoreConnection, NULL, kJTossOutput, NULL, kJCreatePipe, &errFD); if (err.OK()) { *process = new JSimpleProcess(childPID, errFD, deleteWhenFinished); assert( *process != NULL ); } else { *process = NULL; } return err; }
CMChooseProcessDialog::CMChooseProcessDialog ( JXDirector* supervisor, const JBoolean attachToSelection, const JBoolean stopProgram ) : JXDialogDirector(supervisor, kJTrue), itsAttachToSelectionFlag(attachToSelection), itsStopProgramFlag(stopProgram) { BuildWindow(); int inFD; const JError err = JExecute(kCmdStr, NULL, kJIgnoreConnection, NULL, kJCreatePipe, &inFD); if (err.OK()) { JString text; JReadAll(inFD, &text); text.TrimWhitespace(); itsText->SetText(text); } ListenTo(this); }
JError JExecute ( const JPtrArray<JString>& argList, pid_t* childPID, const JExecuteAction toAction, int* toFD, const JExecuteAction fromAction, int* fromFD, const JExecuteAction errAction, int* errFD ) { const JSize argc = argList.GetElementCount(); const JCharacter** argv = new const JCharacter* [ argc+1 ]; assert( argv != NULL ); for (JIndex i=1; i<=argc; i++) { argv[i-1] = *(argList.NthElement(i)); } argv[argc] = NULL; const JError err = JExecute(argv, (argc+1) * sizeof(JCharacter*), childPID, toAction, toFD, fromAction, fromFD, errAction, errFD); delete [] argv; return err; }
JError JExecute ( const JCharacter* workingDirectory, const JCharacter* argv[], const JSize size, pid_t* childPID, const JExecuteAction toAction, int* toFD, const JExecuteAction fromAction, int* fromFD, const JExecuteAction errAction, int* errFD ) { const JString origPath = JGetCurrentDirectory(); JError err = JChangeDirectory(workingDirectory); if (err.OK()) { err = JExecute(argv, size, childPID, toAction, toFD, fromAction, fromFD, errAction, errFD); JChangeDirectory(origPath); } return err; }
void JMount ( const JCharacter* path, const JBoolean mount, const JBoolean block ) { const JCharacter* argv[] = { mount ? "mount" : "umount", path, NULL }; pid_t pid; JExecute(argv, sizeof(argv), block ? (pid_t*) NULL : &pid, kJIgnoreConnection, NULL, kJTossOutput, NULL, kJTossOutput, NULL); }
JBoolean JKillDirectory ( const JCharacter* dirName ) { const JCharacter* argv[] = {"rm", "-rf", dirName, NULL}; const JError err = JExecute(argv, sizeof(argv), NULL, kJIgnoreConnection, NULL, kJIgnoreConnection, NULL, kJTossOutput, NULL); if (err.OK()) { return JNegate( JNameUsed(dirName) ); } else { return kJFalse; } }
void CBApp::GetSystemIncludeDirectories() { int pid, fd, inFD; const JError err = JExecute("gcc -Wp,-v -x c++ -fsyntax-only -", &pid, kJCreatePipe, &inFD, kJCreatePipe, &fd, kJAttachToFromFD); if (!err.OK()) { for (const JCharacter* s : kSysIncludeDir) { itsSystemIncludeDirs->Append(s); } return; } close(inFD); JString s; while (1) { s = JReadUntil(fd, '\n'); if (s.IsEmpty()) { break; } if (s.GetFirstCharacter() == ' ') { s.RemoveSubstring(1,1); if (!s.Contains(" ")) { itsSystemIncludeDirs->Append(s); } } } }
JError JExecute ( const JCharacter* cmd, pid_t* childPID, const JExecuteAction toAction, int* toFD, const JExecuteAction fromAction, int* fromFD, const JExecuteAction errAction, int* errFD ) { // parse the string into a list of arguments JPtrArray<JString> argList(JPtrArrayT::kDeleteAll); JParseArgsForExec(cmd, &argList); // pass the arguments to JExecute return JExecute(argList, childPID, toAction, toFD, fromAction, fromFD, errAction, errFD); }
void GXDataDocument::LoadImportFile() { JIndex filterIndex = itsFileImportDialog->GetFilterIndex(); if (filterIndex <= kInternalModuleCount) { LoadInternalFile(filterIndex); } else { JString filter; if (!((GLGetApplication())->GetImportModulePath(filterIndex - kInternalModuleCount, &filter))) { return; } const JCharacter* argv[] = { filter, itsCurrentFileName, NULL }; int inFD; pid_t pid; JError err = JExecute(argv, sizeof(argv), &pid, kJIgnoreConnection, NULL, kJCreatePipe, &inFD, kJIgnoreConnection, NULL); if (!err.OK()) { JGetUserNotification()->ReportError("Error executing filter."); return; } std::ifstream ip; JString tempName; if (JConvertToStream(inFD, &ip, &tempName)) { int type; ip >> type; if (type == kGloveDataError) { JGetUserNotification()->ReportError("This file is not readable by this filter."); return; } itsData->ShouldBroadcast(kJFalse); itsListenToData = kJFalse; JLatentPG pg(10); pg.VariableLengthProcessBeginning("Loading file...", kJTrue, kJFalse); JBoolean keepGoing = kJTrue; if (type == kGloveMatrixDataFormat) { JSize colCount; ip >> colCount; for (JIndex i = 1; i <= colCount; i++) { itsData->AppendCol(); } while (keepGoing) { for (JIndex i = 1; i <= colCount && keepGoing; i++) { JFloat value; ip >> value; if (ip.fail() || (ip.eof() && i < colCount)) { keepGoing = kJFalse; break; } itsData->AppendElement(i, value); keepGoing = pg.IncrementProgress(); } } } else if (type == kGloveRaggedDataFormat)
JBoolean CBCtagsUser::HasExuberantCtags() { if (itsHasExuberantCtagsFlag == kUntested) { itsHasExuberantCtagsFlag = kFailure; // this hack is required on Linux kernel 2.3.x (4/19/2000) j_sig_func* origHandler = signal(SIGCHLD, emptyHandler); pid_t pid; #if defined _J_SUNOS pid_t* ppid = NULL; #else pid_t* ppid = &pid; #endif int fromFD; JError err = JExecute(kCheckVersionCmd, ppid, kJIgnoreConnection, NULL, kJCreatePipe, &fromFD, kJTossOutput, NULL); if (err.OK()) { JString vers; JReadAll(fromFD, &vers); JArray<JIndexRange> matchList; if (versionPattern.Match(vers, &matchList)) { matchList.RemoveElement(1); const JSize count = matchList.GetElementCount(); JString s; for (JIndex i=1; i<=count; i++) { JUInt v = 0; const JIndexRange r = matchList.GetElement(i); if (!r.IsEmpty()) { s = vers.GetSubstring(r); while (!isdigit(s.GetFirstCharacter())) { s.RemoveSubstring(1, 1); } const JBoolean ok = s.ConvertToUInt(&v); assert( ok ); } if (v > kMinVersion[i-1] || (i == count && v == kMinVersion[i-1])) { itsHasExuberantCtagsFlag = kSuccess; break; } else if (v < kMinVersion[i-1]) { break; } } } } if (origHandler != SIG_ERR) { signal(SIGCHLD, origHandler); } } return JI2B( itsHasExuberantCtagsFlag == kSuccess ); }
int main ( int argc, char* argv[] ) { // find the configuration files if (!FindConfigFile(&classMapFile) || !FindConfigFile(&optionMapFile) || !FindConfigFile(&needFontListFile) || !FindConfigFile(&needStringListFile) || !FindConfigFile(&needCreateListFile)) { return 1; } // parse the command line options JString inputName, codePath, stringPath, codeSuffix, headerSuffix; JString postCmd; JPtrArray<JString> userFormList(JPtrArrayT::kDeleteAll); // empty => generate all forms JPtrArray<JString> backupList(JPtrArrayT::kDeleteAll); // forms that have been backed up GetOptions(argc, argv, &inputName, &codePath, &stringPath, &codeSuffix, &headerSuffix, &postCmd, &userFormList); // generate each requested form JBoolean changed = kJFalse; ifstream input(inputName); while (!input.eof() && !input.fail()) { const JString line = JReadLine(input); if (line == kBeginFormLine) { // get form name JString formName = JReadLine(input); RemoveIdentifier(kFormNameMarker, &formName); // look for custom tag const JSize formNameLength = formName.GetLength(); JString tagName = kDefaultDelimTag; JString enclName; JIndex tagMarkerIndex; if (formName.LocateSubstring(kCustomTagMarker, &tagMarkerIndex) && tagMarkerIndex <= formNameLength - kCustomTagMarkerLength) { tagName = formName.GetSubstring( tagMarkerIndex + kCustomTagMarkerLength, formNameLength); formName.RemoveSubstring(tagMarkerIndex, formNameLength); // get enclosure name const JSize tagNameLength = tagName.GetLength(); JIndex enclMarkerIndex; if (tagName.LocateSubstring(kCustomTagMarker, &enclMarkerIndex) && enclMarkerIndex <= tagNameLength - kCustomTagMarkerLength) { enclName = tagName.GetSubstring( enclMarkerIndex + kCustomTagMarkerLength, tagNameLength); tagName.RemoveSubstring(enclMarkerIndex, tagNameLength); } // report errors if (tagName != kDefaultDelimTag) { if (enclName.IsEmpty()) { cerr << formName << ", " << tagName; cerr << ": no enclosure specified" << endl; } } else if (!enclName.IsEmpty() && enclName != kDefTopEnclVarName) { cerr << formName << ", " << tagName; cerr << ": not allowed to specify enclosure other than "; cerr << kDefTopEnclVarName << endl; } } if (ShouldGenerateForm(formName, userFormList)) { GenerateForm(input, formName, tagName, enclName, codePath, stringPath, codeSuffix, headerSuffix, &backupList); changed = kJTrue; } } } if (changed && !postCmd.IsEmpty()) { const JError err = JExecute(postCmd, NULL); err.ReportIfError(); } return 0; }