GMMIMEParser::GMMIMEParser ( JString* data, const JCharacter* rootDir ) : itsTextSegments(NULL), itsTextInfo(NULL), itsAttachInfo(NULL), itsIsSuccessful(kJTrue), itsTextFileIndex(100), itsData(data) { std::istrstream input(data->GetCString(), data->GetLength()); JError err = JCreateTempDirectory(rootDir, kAttachDirPrefix, &itsAttachDir); if (!err.OK()) { itsIsSuccessful = kJFalse; err.ReportIfError(); } err = JCreateTempDirectory(rootDir, kTextDirPrefix, &itsTextDir); if (!err.OK()) { itsIsSuccessful = kJFalse; err.ReportIfError(); } if (itsIsSuccessful) { if (!JDirInfo::Create(itsTextDir, &itsTextInfo)) { itsIsSuccessful = kJFalse; err.ReportIfError(); } if (!JDirInfo::Create(itsAttachDir, &itsAttachInfo)) { itsIsSuccessful = kJFalse; err.ReportIfError(); } } if (itsIsSuccessful) { itsTextInfo->ShowHidden(kJTrue); itsAttachInfo->ShowHidden(kJTrue); Parse(input, itsData->GetLength()); } }
JBoolean SyGExec ( const JCharacter* cmd, const JBoolean report ) { JString errOutput; const JError err = JRunProgram(cmd, &errOutput); if (!err.OK() && report) { (JGetUserNotification())->ReportError(err.GetMessage()); } return err.OK(); }
JBoolean GFGLink::StartCTags() { assert( itsCTagsProcess == NULL ); JString cmd = kCTagsCmd; int toFD, fromFD; const JError err = JProcess::Create(&itsCTagsProcess, cmd, kJCreatePipe, &toFD, kJCreatePipe, &fromFD, kJAttachToFromFD, NULL); if (err.OK()) { itsOutputLink = jnew JOutPipeStream(toFD, kJTrue); assert( itsOutputLink != NULL ); itsInputFD = fromFD; assert( itsInputFD != ACE_INVALID_HANDLE ); ListenTo(itsCTagsProcess); return kJTrue; } else { (JGetStringManager())->ReportError(kUnableToStartCTagsID, err); return kJFalse; } }
JError JDirInfo::GoTo ( const JCharacter* origDirName ) { JString dirName; if (JStringEmpty(origDirName) || !JConvertToAbsolutePath(origDirName, NULL, &dirName)) { return JBadPath(origDirName); } if (JSameDirEntry(dirName, *itsCWD)) { Update(); return JNoError(); } JAppendDirSeparator(&dirName); const JString origCWD = *itsCWD; *itsCWD = dirName; const JError err = BuildInfo(); if (err.OK()) { Broadcast(PathChanged()); } else { *itsCWD = origCWD; } return err; }
void SVNListBase::RefreshContent() { if (itsProcess != NULL) { JProcess* p = itsProcess; itsProcess = NULL; p->Kill(); delete p; DeleteLinks(); } else { itsSavedSelection->CleanOut(); JTableSelection& s = GetTableSelection(); JTableSelectionIterator iter(&s); JPoint cell; while (iter.Next(&cell)) { const JString* line = itsLineList->NthElement(cell.y); itsSavedSelection->InsertSorted(new JString(ExtractRelativePath(*line))); } } itsDisplayState = SaveDisplayState(); itsLineList->CleanOut(); int outFD, errFD; JError err = JNoError(); if ((GetDirector())->HasPath()) { err = JProcess::Create(&itsProcess, GetPath(), itsCmd, kJIgnoreConnection, NULL, kJCreatePipe, &outFD, kJCreatePipe, &errFD); } else // working with URL { err = JProcess::Create(&itsProcess, itsCmd, kJIgnoreConnection, NULL, kJCreatePipe, &outFD, kJCreatePipe, &errFD); } if (err.OK()) { itsProcess->ShouldDeleteWhenFinished(); ListenTo(itsProcess); (GetDirector())->RegisterActionProcess(this, itsProcess, itsRefreshRepoFlag, itsRefreshStatusFlag, itsReloadOpenFilesFlag); SetConnection(outFD, errFD); } else { err.ReportIfError(); } }
JMemoryManager* JMemoryManager::Instance() { // Guarantees access is only through this function static JMemoryManager* manager = NULL; if (manager == NULL) { theConstructingFlag = kJTrue; manager = new(__FILE__, __LINE__) JMemoryManager; assert(manager != NULL); // Create the error printer proxy to do the printing work. // Construction of the error printer must take place here, after // the manager is fully constructed; the recursive call to Instance // is harmless. manager->itsErrorPrinter = new(__FILE__, __LINE__) JMMErrorPrinter; assert(manager->itsErrorPrinter != NULL); const JCharacter* pipeName = getenv("JMM_PIPE"); if (!JStringEmpty(pipeName)) { manager->itsErrorStream = new(__FILE__, __LINE__) JMMDebugErrorStream; assert(manager->itsErrorStream != NULL); } theConstructingFlag = kJFalse; manager->EmptyStacks(); // do it here since it calls delete as well as new if (!JStringEmpty(pipeName)) { manager->ConnectToDebugger(pipeName); ACE_Object_Manager::at_exit(NULL, ::JMMHandleACEExit, NULL); // If we create the file when we actually need it, it // re-constructs JStringManager. JString fileName; const JError err = JCreateTempFile(&fileName); if (err.OK()) { theInternalFlag = kJTrue; manager->itsExitStatsFileName = new JString(fileName); assert( manager->itsExitStatsFileName != NULL ); theInternalFlag = kJFalse; } else { cerr << "Failed to create exit stats file:" << endl; cerr << err.GetMessage() << endl; } } } return manager; }
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); }
void JXFLInputBase::Receive ( JBroadcaster* sender, const Message& message ) { if (sender == itsHistoryMenu && message.Is(JXMenu::kItemSelected)) { const JString origStr = GetText(); const JString newStr = itsHistoryMenu->GetItemText(message); SetText(newStr); const JError err = Apply(); if (err.OK()) { itsHistoryMenu->AddString(newStr); } else { SetText(origStr); err.ReportIfError(); } } else { JXInputField::Receive(sender, message); } }
JError JXImage::CreateFromJPEG ( JXDisplay* display, JXColormap* colormap, const JCharacter* fileName, JXImage** image, const JBoolean allowApproxColors ) { *image = new JXImage(display, colormap); assert( *image != NULL ); const JBoolean saveApprox = colormap->WillApproximateColors(); const JBoolean savePre = colormap->WillPreemptivelyApproximateColors(); colormap->ShouldApproximateColors(allowApproxColors); colormap->ShouldPreemptivelyApproximateColors(kJTrue); const JError err = (**image).ReadJPEG(fileName); colormap->ShouldApproximateColors(saveApprox); colormap->ShouldPreemptivelyApproximateColors(savePre); if (!err.OK()) { delete *image; *image = NULL; } return err; }
void GMMIMEParser::WriteAttachment ( const JString& data, const GMIMEHeader& header ) { JString filename = header.GetFileName(); if (filename.IsEmpty()) { const JError err = JCreateTempFile(itsAttachDir, NULL, &filename); if (!err.OK()) { err.ReportIfError(); return; } } else { filename = JCombinePathAndName(itsAttachDir, filename); } AdjustAttachmentName(header, &filename); std::ofstream os(filename); if (header.GetEncoding() == kBase64Encoding) { std::istrstream is(data.GetCString(), data.GetLength()); JDecodeBase64(is, os); } else { data.Print(os); } }
JBoolean JXRegexReplaceInput::InputValid() { if (!JXInputField::InputValid()) { return kJFalse; } else { const JString& text = GetText(); if (!IsRequired() && text.IsEmpty()) { return kJTrue; } const JError err = itsTestRegex->SetReplacePattern(text); if (err.OK()) { return kJTrue; } else { err.ReportIfError(); return kJFalse; } } }
JBoolean JDirInfo::ForceUpdate() { if (JDirectoryExists(*itsCWD)) { Broadcast(ContentsWillBeUpdated()); const JError err = BuildInfo(); if (err.OK()) { return kJTrue; } } if (itsSwitchIfInvalidFlag) { JString path; if (!JGetHomeDirectory(&path) || !OKToCreate(path)) { path = JGetRootDirectory(); } GoTo(path); } else { itsIsValidFlag = kJFalse; itsIsWritableFlag = kJFalse; itsDirEntries->CleanOut(); itsVisEntries->CleanOut(); itsAlphaEntries->CleanOut(); } return kJFalse; }
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; }
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; }
JBoolean SVNPropertiesList::RemoveNextProperty() { if (!itsRemovePropertyCmdList->IsEmpty()) { const JString cmd = *(itsRemovePropertyCmdList->FirstElement()); itsRemovePropertyCmdList->DeleteElement(1); 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; } } else { if ((GetDirector())->OKToStartActionProcess()) { RefreshContent(); } (GetDirector())->ScheduleStatusRefresh(); 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; } }
JError JCreateDirectory ( const JCharacter* dirName, const mode_t mode ) { if (JDirectoryExists(dirName)) { return JSetPermissions(dirName, mode); } JString path = dirName; JCleanPath(&path); JAppendDirSeparator(&path); JString dir; JIndex slashIndex = 2; while (path.LocateNextSubstring("/", &slashIndex)) { dir = path.GetSubstring(1, slashIndex); if (!JDirectoryExists(dir)) { const JError err = JMkDir(dir, mode); if (!err.OK()) { return err; } } slashIndex++; // move past the slash we found } return JNoError(); }
JError JFormatPartition ( const JCharacter* path, const JCharacter* type, JProcess** process ) { JBoolean writable, isTop; JString device; if (JIsMounted(path, &writable, &isTop, &device) && isTop) { JMount(path, kJFalse, kJTrue); if (!JIsMounted(path)) { const JCharacter* argv[] = { "xterm", "-T", "Format disk", "-n", "Format disk", "-e", "/sbin/mkfs", "-t", type, "-c", device, NULL }; const JError err = JProcess::Create(process, argv, sizeof(argv)); if (err.OK()) { JThisProcess::Ignore(*process); } return err; } } *process = NULL; return JAccessDenied(path); }
void CBFileListTable::ScanDirectory ( const JString& origPath, const JBoolean recurse, const JPtrArray<JString>& allSuffixList, CBSymbolList* symbolList, CBCTree* cTree, CBJavaTree* javaTree, JProgressDisplay& pg ) { JString path; JDirInfo* info; if (!JGetTrueName(origPath, &path) || !JDirInfo::Create(path, &info)) { return; } const JSize count = info->GetEntryCount(); for (JIndex i=1; i<=count; i++) { const JDirEntry& entry = info->GetEntry(i); // If it's a directory, recurse. if (entry.IsDirectory() && recurse && !entry.IsLink() && !JIsVCSDirectory(entry.GetName())) { ScanDirectory(entry.GetFullName(), recurse, allSuffixList, symbolList, cTree, javaTree, pg); } // If it's a file ending in one of the suffixes, parse it. else if (entry.IsFile()) { JString trueName = entry.GetFullName(); time_t modTime = entry.GetModTime(); if (entry.IsWorkingLink()) { const JBoolean ok = JGetTrueName(entry.GetFullName(), &trueName); assert( ok ); const JError err = JGetModificationTime(trueName, &modTime); assert( err.OK() ); } ParseFile(trueName, allSuffixList, modTime, symbolList, cTree, javaTree); } pg.IncrementProgress(); } delete info; }
JVCSType JGetVCSType ( const JCharacter* path, const JBoolean deepInspection ) { JString p = path, n; if (JFileExists(path) || !JDirectoryExists(path)) // broken link { JSplitPathAndName(path, &p, &n); } // can't read newer versions JString vcsDir = JCombinePathAndName(p, kSubversionDirName); vcsDir = JCombinePathAndName(vcsDir, kSubversionFileName); if (JFileExists(vcsDir)) { if (!deepInspection) { return kJSVNType; } JSize size; const JError err = JGetFileLength(vcsDir, &size); if (err.OK() && size > 10) { return kJSVNType; } } vcsDir = JCombinePathAndName(p, kCVSDirName); if (JDirectoryExists(vcsDir)) { return kJCVSType; } vcsDir = JCombinePathAndName(p, kSCCSDirName); if (JDirectoryExists(vcsDir)) { return kJSCCSType; } // check git & new svc last, since they need to search directory tree up to root if (JSearchGitRoot(p, &n)) { return kJGitType; } else if (!deepInspection && jSearchVCSRoot(p, kSubversionDirName, &n)) { return kJSVNType; } return kJUnknownVCSType; }
JError JDirInfo::BuildInfo() { if (!JDirectoryReadable(*itsCWD)) { return JAccessDenied(*itsCWD); } const JString origDir = JGetCurrentDirectory(); JError err = JChangeDirectory(*itsCWD); if (!err.OK()) { return err; } // clear old information itsDirEntries->CleanOut(); // update instance variables JStripTrailingDirSeparator(itsCWD); // keep Windows happy ACE_stat stbuf; ACE_OS::stat(*itsCWD, &stbuf); itsIsValidFlag = kJTrue; itsIsWritableFlag = JDirectoryWritable(*itsCWD); itsModTime = stbuf.st_mtime; itsStatusTime = stbuf.st_ctime; JAppendDirSeparator(itsCWD); // process files in the directory JLatentPG pg(itsContentRegex == NULL ? 100 : 10); if (itsPG != NULL) { pg.SetPG(itsPG, kJFalse); } pg.VariableLengthProcessBeginning("Scanning directory...", kJTrue, kJFalse); BuildInfo1(pg); pg.ProcessFinished(); err = JChangeDirectory(origDir); assert_ok( err ); ApplyFilters(kJFalse); return JNoError(); }
JBoolean JXFSBindingTable::ExtractInputData ( const JPoint& cell ) { assert( itsTextInput != NULL ); const JString& s = itsTextInput->GetText(); JBoolean ok = itsTextInput->InputValid(); if (ok && cell.x == kPatternColumn) { const JFSBinding* b = itsBindingList->GetBinding(cell.y); const JBoolean changed = JI2B(b->GetPattern() != s); if (JFSBinding::WillBeRegex(s)) { const JError err = itsTestRegex->SetPattern(s); err.ReportIfError(); ok = err.OK(); } JIndex newIndex; if (ok && changed && itsBindingList->SetPattern(cell.y, s, &newIndex)) { JTableSelection& s = GetTableSelection(); s.ClearSelection(); s.SelectCell(newIndex, kPatternColumn); Broadcast(DataChanged()); } else if (ok && changed) { ok = kJFalse; const JCharacter* map[] = { "pattern", s.GetCString() }; const JString msg = JGetString(kPatternUsedID, map, sizeof(map)); (JGetUserNotification())->ReportError(msg); } } else if (ok && cell.x == kCommandColumn && itsBindingList->SetCommand(cell.y, s)) { Broadcast(DataChanged()); } return ok; }
void JStringManager::ReportError ( const JCharacter* id, const JError& err ) const { if (!err.OK()) { ReportError(id, err.GetMessage()); } }
JBoolean SyGGetTrashDirectory ( JString* path, const JBoolean reportErrors ) { if (!theTrashDir.IsEmpty()) { *path = theTrashDir; return kJTrue; } if (!JGetPrefsDirectory(path)) { if (reportErrors) { (JGetUserNotification())->ReportError(JGetString(kNoPrefsDirID)); } return kJFalse; } *path = JCombinePathAndName(*path, kTrashDirName); JError err = JNoError(); if (!JDirectoryExists(*path)) { err = JCreateDirectory(*path, kTrashCanPerms); } else { err = JSetPermissions(*path, kTrashCanPerms); } if (err.OK()) { theTrashDir = *path; const JBoolean ok = JDirInfo::Create(theTrashDir, &theTrashDirInfo); assert( ok ); return kJTrue; } else { path->Clear(); if (reportErrors) { (JGetStringManager())->ReportError(kCreateTrashErrorID, err); } return kJFalse; } }
void JXSaveFileDialog::Save ( const JCharacter* path ) { JDirInfo* dirInfo = GetDirInfo(); const JError err = dirInfo->GoTo(path); err.ReportIfError(); if (err.OK() && itsFileNameInput->Focus()) { EndDialog(kJTrue); } }
JBoolean SyGGetRecentFileDirectory ( JString* path, const JBoolean reportErrors ) { if (!theRecentFileDir.IsEmpty()) { *path = theRecentFileDir; return kJTrue; } if (!JGetPrefsDirectory(path)) { if (reportErrors) { (JGetUserNotification())->ReportError(JGetString(kNoPrefsDirID)); } return kJFalse; } *path = JCombinePathAndName(*path, kRecentFileDirName); JError err = JNoError(); if (!JDirectoryExists(*path)) { err = JCreateDirectory(*path, kRecentFileDirPerms); } else { err = JSetPermissions(*path, kRecentFileDirPerms); } if (err.OK()) { theRecentFileDir = *path; return kJTrue; } else { path->Clear(); if (reportErrors) { (JGetStringManager())->ReportError(kCreateRecentFileDirErrorID, err); } return kJFalse; } }
JBoolean CBCtagsUser::StartProcess ( const CBTextFileType fileType, CBLanguage* lang ) { *lang = kCBOtherLang; if (itsIsActiveFlag && itsProcess == NULL) { JString cmd = kBaseExecCmd; cmd += itsArgs; int toFD, fromFD; const JError err = JProcess::Create(&itsProcess, cmd, kJCreatePipe, &toFD, kJCreatePipe, &fromFD); if (err.OK()) { ListenTo(itsProcess); itsCmdPipe = new JOutPipeStream(toFD, kJTrue); assert( itsCmdPipe != NULL ); itsResultFD = fromFD; assert( itsResultFD != ACE_INVALID_HANDLE ); InitCtags(*itsCmdPipe); } else { itsIsActiveFlag = kJFalse; DeleteProcess(); } } if (itsProcess != NULL) { assert( kFTCount == kCBFTCount && kFTInfo[fileType].fileType == fileType ); *lang = kFTInfo[fileType].lang; *itsCmdPipe << kFTInfo[fileType].cmd << endl; } return itsIsActiveFlag; }
JError JSimpleProcess::Create ( const JCharacter* cmdStr, const JBoolean detach ) { JSimpleProcess* p; const JError err = Create(&p, cmdStr, kJTrue); err.ReportIfError(); if (err.OK() && detach) { JThisProcess::Ignore(p); } return err; }
JError JSimpleProcess::Create ( const JPtrArray<JString>& argList, const JBoolean detach ) { JSimpleProcess* p; const JError err = Create(&p, argList, kJTrue); err.ReportIfError(); if (err.OK() && detach) { JThisProcess::Ignore(p); } return err; }