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; }
JBoolean SyGCreateGlobals ( SyGApplication* app ) { theApplication = app; SyGCreateIcons(); JString oldPrefsFile, newPrefsFile; if (JGetPrefsDirectory(&oldPrefsFile)) { oldPrefsFile = JCombinePathAndName(oldPrefsFile, ".gSystemG.pref"); if (JFileExists(oldPrefsFile) && (JPrefsFile::GetFullName(app->GetSignature(), &newPrefsFile)).OK() && !JFileExists(newPrefsFile)) { JRenameFile(oldPrefsFile, newPrefsFile); } } JBoolean isNew; thePrefsMgr = new SyGPrefsMgr(&isNew); assert(thePrefsMgr != NULL); JXInitHelp(kSyGTOCHelpName, kSyGHelpSectionCount, kSyGHelpSectionName); JXWDManager* wdMgr = new JXWDManager(app->GetCurrentDisplay(), kJTrue); assert( wdMgr != NULL ); // registers itself theMDIServer = new SyGMDIServer; assert( theMDIServer != NULL ); theManPageDialog = new SyGViewManPageDialog(JXGetPersistentWindowOwner()); assert( theManPageDialog != NULL ); theFindFileDialog = new SyGFindFileDialog(JXGetPersistentWindowOwner()); assert( theFindFileDialog != NULL ); theAltChooseSaveFile = new SyGChooseSaveFile(thePrefsMgr, kSAltCSSetupID); assert( theAltChooseSaveFile != NULL ); JString trashDir; SyGGetTrashDirectory(&trashDir, kJFalse); // silently creates it return isNew; }
JBoolean jSearchVCSRoot ( const JCharacter* path, const JCharacter* vcsDirName, JString* vcsRoot ) { JString p = path, n; if (JFileExists(path) || !JDirectoryExists(path)) // broken link { JSplitPathAndName(path, &p, &n); } do { n = JCombinePathAndName(p, vcsDirName); if (JDirectoryExists(n)) { *vcsRoot = p; return kJTrue; } JSplitPathAndName(p, &p, &n); } while (!JIsRootDirectory(p)); vcsRoot->Clear(); return kJFalse; }
JBoolean CMLink::FindFile ( const JCharacter* fileName, JBoolean* exists, JString* fullName ) const { const JString* s = NULL; if (JIsAbsolutePath(fileName) && JFileExists(fileName)) { *exists = kJTrue; *fullName = fileName; return kJTrue; } else if (itsFileNameMap->GetElement(fileName, &s)) { if (s == NULL) { *exists = kJFalse; fullName->Clear(); } else { *exists = kJTrue; *fullName = *s; } return kJTrue; } else { *exists = kJFalse; fullName->Clear(); return kJFalse; } /* All search paths are unreliable. See CMGetFullPath.cc for more info. if (JIsRelativePath(fileName)) { const JSize count = itsPathList->GetElementCount(); for (JIndex i=1; i<=count; i++) { *fullName = JCombinePathAndName(*(itsPathList->NthElement(i)), fileName); if (JFileExists(*fullName)) { return kJTrue; } } } else if (JFileExists(fileName)) { *fullName = fileName; return kJTrue; } fullName->Clear(); return kJFalse; */ }
void JUpdateCVSIgnore ( const JCharacter* ignoreFullName ) { JString path, name; JSplitPathAndName(ignoreFullName, &path, &name); const JString cvsFile = JCombinePathAndName(path, ".cvsignore"); if (!JFileExists(cvsFile) && JGetVCSType(path) != kJCVSType) { return; } JString cvsData; JReadFile(cvsFile, &cvsData); if (!cvsData.IsEmpty() && !cvsData.EndsWith("\n")) { cvsData += "\n"; } name += "\n"; if (!cvsData.Contains(name)) { JEditVCS(cvsFile); cvsData += name; ofstream output(cvsFile); cvsData.Print(output); } }
JBoolean JXDocumentManager::SearchFileMap ( const JCharacter* fileName, JString* newFileName ) const { const JSize mapCount = itsFileMap->GetElementCount(); for (JIndex i=mapCount; i>=1; i--) { FileMap map = itsFileMap->GetElement(i); const JBoolean match = JConvertToBoolean( *(map.oldName) == fileName ); if (match && JFileExists(*(map.newName))) { *newFileName = *(map.newName); return kJTrue; } else if (match) // newName no longer exists (lazy checking) { delete map.oldName; delete map.newName; itsFileMap->RemoveElement(i); } } return kJFalse; }
void TestjxCreateGlobals ( TestApp* app, const JBoolean wantMDI ) { theApplication = app; JXMenu::SetDefaultStyle(JXMenu::kWindowsStyle); JXCreateDefaultDocumentManager(); TestDockManager* theDockManager = new TestDockManager((JXGetApplication())->GetCurrentDisplay()); assert( theDockManager != NULL ); if (JFileExists(kDockSetupFileName)) { ifstream input(kDockSetupFileName); theDockManager->ReadSetup(input); } if (wantMDI) { theMDIServer = new TestMDIServer; assert( theMDIServer != NULL ); } JXInitHelp(NULL, kHelpSectionCount, kHelpSectionName); }
void ParseXOptions ( const int argc, char* argv[], JString* inputFileName ) { inputFileName->Clear(); long index = 1; while (index < argc) { if (argv[index][0] == '-') { std::cerr << argv[0] << ": unknown option " << argv[index] << std::endl; } else if (inputFileName->IsEmpty()) { *inputFileName = argv[index]; } index++; } if (!inputFileName->IsEmpty() && !JFileExists(*inputFileName)) { std::cerr << argv[0] << ": file not found" << std::endl; exit(1); } }
JBoolean CMBreakpointManager::GetBreakpoints ( const JCharacter* fileName, JPtrArray<CMBreakpoint>* list ) const { list->RemoveAll(); list->SetCleanUpAction(JPtrArrayT::kForgetAll); if (JIsAbsolutePath(fileName) && JFileExists(fileName)) { CMBreakpoint target(fileName, 1); JBoolean found; const JIndex startIndex = itsBPList->SearchSorted1(&target, JOrderedSetT::kFirstMatch, &found); const JSize count = itsBPList->GetElementCount(); for (JIndex i=startIndex; i<=count; i++) { CMBreakpoint* bp = itsBPList->NthElement(i); if (bp->GetFileID() == target.GetFileID()) { list->Append(bp); } else { break; } } } return !list->IsEmpty(); }
JBoolean JFileWritable ( const JCharacter* fileName ) { return JI2B(JFileExists(fileName) && (getuid() == 0 || access(fileName, W_OK) == 0)); }
JBoolean JXFileInput::InputValid() { if (itsAllowInvalidFileFlag) { return kJTrue; } else if (!JXInputField::InputValid()) { return kJFalse; } const JString& text = GetText(); if (text.IsEmpty()) { return JNegate(IsRequired()); } JString fullName; const JCharacter* errID = NULL; if (JIsRelativePath(text) && !HasBasePath()) { errID = kNoRelPathID; RecalcAll(kJTrue); } else if (!JConvertToAbsolutePath(text, itsBasePath, &fullName) || !JFileExists(fullName)) { errID = kDoesNotExistID; } else if (itsRequireReadFlag && !JFileReadable(fullName)) { errID = kUnreadableID; } else if (itsRequireWriteFlag && !JFileWritable(fullName)) { errID = kUnwritableID; } else if (itsRequireExecFlag && !JFileExecutable(fullName)) { errID = kCannotExecID; } if (JStringEmpty(errID)) { return kJTrue; } else { (JGetUserNotification())->ReportError(JGetString(errID)); return kJFalse; } }
TestDirector::TestDirector ( JXDirector* supervisor, const JBoolean isMaster, const JBoolean startIconic, const JBoolean bufferTestWidget, const JBoolean testWidgetIsImage, const JBoolean snoopWindow ) : JXWindowDirector(supervisor) { itsIsMasterFlag = isMaster; itsPSPrinter = NULL; itsEPSPrinter = NULL; itsCSF = new TestChooseSaveFile; assert( itsCSF != NULL ); BuildWindow(isMaster, bufferTestWidget, testWidgetIsImage); JXWindow* window = GetWindow(); if (snoopWindow) { itsWindowSnooper = new JBroadcastSnooper(window); assert( itsWindowSnooper != NULL ); } else { itsWindowSnooper = NULL; } if (isMaster && JFileExists(kWindowGeomFileName)) { ifstream input(kWindowGeomFileName); window->ReadGeometry(input); } if (startIconic) { window->Iconify(); } // GetDisplay() only works after SetWindow() itsPSPrinter = new JXPSPrinter(GetDisplay()); assert( itsPSPrinter != NULL ); ListenTo(itsPSPrinter); itsEPSPrinter = new JXEPSPrinter(GetDisplay()); assert( itsEPSPrinter != NULL ); ListenTo(itsEPSPrinter); }
void JXFileHistoryMenu::RemoveNonexistentFiles() { JString fullName; const JSize count = GetItemCount(); const JIndex firstIndex = GetFirstIndex(); for (JIndex i=count; i>=firstIndex; i--) { fullName = GetFile(i); if (!JFileExists(fullName)) { RemoveItem(i); } } }
JBoolean JXFileInput::GetFile ( JString* fullName ) const { const JString& text = GetText(); return JI2B(!text.IsEmpty() && (!JIsRelativePath(text) || HasBasePath()) && JConvertToAbsolutePath(text, itsBasePath, fullName) && JFileExists(*fullName) && (!itsRequireReadFlag || JFileReadable(*fullName)) && (!itsRequireWriteFlag || JFileWritable(*fullName)) && (!itsRequireExecFlag || JFileExecutable(*fullName))); }
void SCCircuitDocument::OpenSomething ( const JCharacter* fileName ) { JString fullName; if (fileName != NULL && fileName[0] != '\0') { if (JFileExists(fileName)) { fullName = fileName; } else { return; } } else if (!(JGetChooseSaveFile())->ChooseFile("File to open:", NULL, &fullName)) { return; } std::ifstream input(fullName); const FileStatus status = CanReadFile(input); JXFileDocument* doc; if (status == kFileReadable && !(JXGetDocumentManager())->FileDocumentIsOpen(fullName, &doc) && OKToClose()) { CloseAllWindows(); FileChanged(fullName, kJTrue); ReadFile(input); } else if (status == kNeedNewerVersion) { (JGetUserNotification())->ReportError( "This notebook was created by a newer version of Symcir. " "You need the newest version in order to open it."); } else if (status == kNotMyFile && OKToClose()) { input.close(); CloseAllWindows(); ReadNetlist(fullName); } }
JBoolean JXPathInput::GetDroppedDirectory ( const Time time, const JBoolean reportErrors, JString* dirName ) { dirName->Clear(); JXSelectionManager* selMgr = GetSelectionManager(); Atom returnType; unsigned char* data; JSize dataLength; JXSelectionManager::DeleteMethod delMethod; if (selMgr->GetData(GetDNDManager()->GetDNDSelectionName(), time, selMgr->GetURLXAtom(), &returnType, &data, &dataLength, &delMethod)) { if (returnType == selMgr->GetURLXAtom()) { JPtrArray<JString> fileNameList(JPtrArrayT::kDeleteAll), urlList(JPtrArrayT::kDeleteAll); JXUnpackFileNames((char*) data, dataLength, &fileNameList, &urlList); if (fileNameList.GetElementCount() == 1 && (JDirectoryExists(*(fileNameList.FirstElement())) || JFileExists(*(fileNameList.FirstElement())))) { *dirName = *(fileNameList.FirstElement()); JString homeDir; if (JGetHomeDirectory(&homeDir) && dirName->BeginsWith(homeDir)) { dirName->ReplaceSubstring(1, homeDir.GetLength(), "~" ACE_DIRECTORY_SEPARATOR_STR); } } JXReportUnreachableHosts(urlList); } selMgr->DeleteData(&data, delMethod); } return !dirName->IsEmpty(); }
JBoolean JFileExecutable ( const JCharacter* fileName ) { if (getuid() == 0) { ACE_stat stbuf; return JI2B( ACE_OS::stat(fileName, &stbuf) == 0 && (stbuf.st_mode & S_IXUSR) != 0 ); } else { return JI2B(JFileExists(fileName) && access(fileName, X_OK) == 0); } }
JBoolean GMessageTableDir::Create ( JXDirector* supervisor, JFileArray& fileArray, GMessageTableDir** dir, const JFileVersion& version ) { JFAID id = 1; std::string data; fileArray.GetElement(id, &data); std::istringstream is(data); JString mailfile; is >> mailfile; JString lockfile = JString(mailfile) + ".lock"; if (JFileExists(lockfile)) { JString report = "The mailbox \"" + JString(mailfile); report += "\" is locked. Do you want to forcibly remove the lock on mailbox"; JBoolean yes = JGetUserNotification()->AskUserYes(report); if (yes) { GUnlockFile(mailfile); } else { return kJFalse; } } *dir = new GMessageTableDir(supervisor, mailfile); assert(*dir != NULL); (*dir)->GetWindow()->ReadGeometry(is); JBoolean success = CreateX(supervisor, mailfile, dir); if (success) { (*dir)->ReadState(fileArray, version); (*dir)->ListenTo((*dir)->GetWindow()); } return success; }
void JEditVCS ( const JCharacter* fullName ) { if (JFileExists(fullName) && !JFileWritable(fullName)) { JString path, name; JSplitPathAndName(fullName, &path, &name); JString vcsDir = JCombinePathAndName(path, kCVSDirName); if (JDirectoryExists(vcsDir)) { const JString cmd = "cd " + path + "; cvs edit " + name; system(cmd); } } }
JBoolean JXFileInput::GetDroppedFileName ( const Time time, const JBoolean reportErrors, JString* fileName ) { fileName->Clear(); JXSelectionManager* selMgr = GetSelectionManager(); Atom returnType; unsigned char* data; JSize dataLength; JXSelectionManager::DeleteMethod delMethod; if (selMgr->GetData((GetDNDManager())->GetDNDSelectionName(), time, selMgr->GetURLXAtom(), &returnType, &data, &dataLength, &delMethod)) { if (returnType == selMgr->GetURLXAtom()) { JPtrArray<JString> fileNameList(JPtrArrayT::kDeleteAll), urlList(JPtrArrayT::kDeleteAll); JXUnpackFileNames((char*) data, dataLength, &fileNameList, &urlList); if (fileNameList.GetElementCount() == 1 && (JFileExists(*(fileNameList.FirstElement())) || JDirectoryExists(*(fileNameList.FirstElement())))) { *fileName = *(fileNameList.FirstElement()); } JXReportUnreachableHosts(urlList); } selMgr->DeleteData(&data, delMethod); } return JNegate( fileName->IsEmpty() ); }
void CBExecOutputDocument::ConvertSelectionToFullPath ( JString* fileName ) const { if (JIsAbsolutePath(*fileName)) { return; } const JString testName = JCombinePathAndName(itsPath, *fileName); if (JFileExists(testName)) { *fileName = testName; } else { CBTextDocument::ConvertSelectionToFullPath(fileName); } }
JBoolean JXDocumentManager::FileDocumentIsOpen ( const JCharacter* fileName, JXFileDocument** doc ) const { *doc = NULL; // check that the file exists if (!JFileExists(fileName)) { return kJFalse; } // search for an open JXFileDocument that uses this file const JSize count = itsDocList->GetElementCount(); for (JIndex i=1; i<=count; i++) { const DocInfo info = itsDocList->GetElement(i); const JXFileDocument* fileDoc = (info.doc)->CastToJXFileDocument(); if (fileDoc != NULL) { JBoolean onDisk; const JString docName = fileDoc->GetFullName(&onDisk); if (onDisk && JSameDirEntry(fileName, docName)) { *doc = const_cast<JXFileDocument*>(fileDoc); return kJTrue; } } } return kJFalse; }
void GAddressBookMgr::AddAddressBook ( const JCharacter* name, JTree* tree ) { if (!JFileExists(name)) { return; } JDirEntry* dirEntry = new JDirEntry(name); assert(dirEntry != NULL); JTreeNode* jbase = tree->GetRoot(); JNamedTreeNode* base = dynamic_cast<JNamedTreeNode*>(jbase); assert(base != NULL); GAddressBookTreeNode* book = new GAddressBookTreeNode(dirEntry, base, dirEntry->GetName()); assert(book != NULL); std::ifstream is(name); while (is.good()) { JString line = JReadLine(is); GAddressBookEntry* entry = new GAddressBookEntry(); assert( entry != NULL ); JString name; if (GetNextRecord(line, name, is)) { GetNextRecord(line, entry->fullname, is); if (GetNextRecord(line, entry->address, is)) { GetNextRecord(line, entry->fcc, is); GetNextRecord(line, entry->comment, is); itsAddresses->SetElement(name, entry, JPtrArrayT::kDelete); GAddressEntryTreeNode* aEntry = new GAddressEntryTreeNode(book, entry->fullname); assert(aEntry != NULL); GAddressItemTreeNode* item = new GAddressItemTreeNode(GAddressItemTreeNode::kName, aEntry, name, kJFalse); assert(item != NULL); JString address = entry->address; if (address.BeginsWith("(") && address.GetLength() > 2) { address = address.GetSubstring(2, address.GetLength() - 1); JPtrArray<JString> list(JPtrArrayT::kForgetAll); GParseNameList(address, list); const JSize count = list.GetElementCount(); for (JSize i = count; i >= 1; i--) { item = new GAddressItemTreeNode(GAddressItemTreeNode::kEMail, aEntry, *(list.NthElement(i)), kJFalse); assert(item != NULL); } list.DeleteAll(); } else { item = new GAddressItemTreeNode(GAddressItemTreeNode::kEMail, aEntry, address, kJFalse); } if (!entry->comment.IsEmpty()) { item = new GAddressItemTreeNode(GAddressItemTreeNode::kComment, aEntry, entry->comment, kJFalse); assert(item != NULL); } if (!entry->fcc.IsEmpty()) { item = new GAddressItemTreeNode(GAddressItemTreeNode::kFcc, aEntry, entry->fcc, kJFalse); assert(item != NULL); } book->InsertSorted(aEntry); continue; } } delete entry; } }
void CBCompileDocument::ConvertSelectionToFullPath ( JString* fileName ) const { (CBGetDocumentManager())->SetActiveListDocument(const_cast<CBCompileDocument*>(this)); if (JIsAbsolutePath(*fileName)) { return; } CBTextEditor* te = GetTextEditor(); const JString& text = te->GetText(); const JIndex caretChar = te->GetInsertionIndex(); JArray<JIndexRange> matchList; JStack<JIndex, JArray<JIndex> > dirStack; JIndex i=1; while (dirMarkerPattern.MatchFrom(text, i, &matchList)) { i = (matchList.GetElement(1)).last + 1; if (i >= caretChar) { break; } if (!(matchList.GetElement(3)).IsEmpty()) // Entering { dirStack.Push(i); } else // Leaving { assert( !(matchList.GetElement(4)).IsEmpty() ); JIndex j; dirStack.Pop(&j); } } JIndex startChar; if (dirStack.Peek(&startChar)) { JIndex endChar = startChar; if (text.GetCharacter(endChar) != '\'' && text.LocateNextSubstring("\'", &endChar)) { endChar--; JString testName = text.GetSubstring(startChar, endChar); testName = JCombinePathAndName(testName, *fileName); if (JFileExists(testName)) { *fileName = testName; return; } } } CBExecOutputDocument::ConvertSelectionToFullPath(fileName); }
JBoolean CBExecOutputDocument::ProcessFinished ( const JProcess::Finished& info ) { // Since the process has terminated, we know that it has written // everything to the pipe. When handle_input() no longer broadcasts, // we know we have read everything. do { itsReceivedDataFlag = kJFalse; JXApplication::CheckACEReactor(); } while (itsReceivedDataFlag); const pid_t pid = itsProcess->GetPID(); JProcess* p = itsProcess; itsProcess = NULL; jdelete p; delete itsRecordLink; itsRecordLink = NULL; delete itsDataLink; itsDataLink = NULL; CloseOutFD(); UpdateButtons(); CBTextEditor* te = GetTextEditor(); const JXTEBase::DisplayState state = te->SaveDisplayState(); te->SetCaretLocation(te->GetTextLength()+1); JBoolean stayOpen = kJTrue; int result; const JChildExitReason reason = info.GetReason(&result); if (info.Successful() || (reason == kJChildSignalled && result == SIGKILL)) { DataReverted(); te->ClearUndo(); if (!IsActive()) { stayOpen = kJFalse; } else { const JString reasonStr = JPrintChildExitReason(reason, result); te->Paste("\n"); te->Paste(reasonStr); te->Paste("\n"); DataReverted(); te->ClearUndo(); } } else { const JString reasonStr = JPrintChildExitReason(reason, result); te->Paste("\n"); te->Paste(reasonStr); te->Paste("\n"); if (reason != kJChildFinished) { #ifdef _J_OSX const JCharacter* path = "/cores/"; #else const JCharacter* path = itsPath; #endif const JString coreName = "core." + JString(pid, JString::kBase10); const JString coreFull = JCombinePathAndName(path, coreName); if (JFileExists(coreFull)) { te->Paste(JGetString("CoreLocation::CBExecOutputDocument")); te->SetCurrentFontBold(kJTrue); te->Paste(coreFull); te->SetCurrentFontBold(kJFalse); } else { const JCharacter* map[] = { "name", coreName }; const JString msg = JGetString("CoreName::CBExecOutputDocument", map, sizeof(map)); te->Paste(msg); } te->Paste("\n"); } DataReverted(); te->ClearUndo(); if (!IsActive() || GetWindow()->IsIconified()) // don't raise if active { Activate(); } GetDisplay()->Beep(); } if (state.hadSelection) { te->RestoreDisplayState(state); } return stayOpen; }
JBoolean JXSaveFileDialog::OKToDeactivate() { if (!JXCSFDialogBase::OKToDeactivate()) { return kJFalse; } else if (Cancelled()) { return kJTrue; } JXPathInput* pathInput = GetPathInput(); if (pathInput->HasFocus()) { GoToItsPath(); return kJFalse; } JXInputField* filterInput = GetFilterInput(); if (filterInput->HasFocus()) { AdjustFilter(); return kJFalse; } JXDirTable* fileBrowser = GetFileBrowser(); if (fileBrowser->HasFocus() && fileBrowser->GoToSelectedDirectory()) { return kJFalse; } const JString& fileName = itsFileNameInput->GetText(); if (fileName.IsEmpty()) { (JGetUserNotification())->ReportError("You need to enter a file name."); return kJFalse; } const JString& path = GetPath(); const JString fullName = path + fileName; const JBoolean fileExists = JFileExists(fullName); if (JDirectoryExists(fullName)) { (JGetUserNotification())->ReportError( "This name is already used for a directory."); return kJFalse; } else if (!JDirectoryWritable(path) && !fileExists) { (JGetUserNotification())->ReportError( "You are not allowed to write to this directory."); return kJFalse; } else if (!fileExists) { *itsFileName = fileName; return kJTrue; } else if (!JFileWritable(fullName)) { (JGetUserNotification())->ReportError( "You are not allowed to write to this file."); return kJFalse; } else if ((JGetUserNotification())->AskUserNo("That file already exists. Replace it?")) { *itsFileName = fileName; return kJTrue; } else { return kJFalse; } }
JBoolean SyGApplication::OpenDirectory ( const JString& pathName, SyGTreeDir** dir, JIndex* row, const JBoolean deiconify, const JBoolean reportError, const JBoolean forceNew, const JBoolean clearSelection ) { if (dir != NULL) { *dir = NULL; } if (row != NULL) { *row = 0; } JString fixedName, trueName; if (!JExpandHomeDirShortcut(pathName, &fixedName) || !JConvertToAbsolutePath(fixedName, NULL, &trueName)) { if (reportError) { JString msg = "\""; msg += pathName; msg += "\" does not exist."; (JGetUserNotification())->ReportError(msg); } return kJFalse; } // if file, select it after opening the window JString selectName; if (JFileExists(trueName) || !JDirectoryExists(trueName)) // broken link { JStripTrailingDirSeparator(&trueName); JString path; JSplitPathAndName(trueName, &path, &selectName); trueName = path; } // can't check this until after making sure that trueName is directory if (!JFSFileTreeNode::CanHaveChildren(trueName)) { if (reportError) { JString msg = "Unable to read contents of \""; msg += pathName; msg += "\""; (JGetUserNotification())->ReportError(msg); } return kJFalse; } // resolve all .. in path JIndex i; JString p, p1; while (trueName.LocateSubstring("..", &i)) { p = trueName.GetSubstring(1, i+1); if (!JGetTrueName(p, &p1)) { if (reportError) { JString msg = "\""; msg += p; msg += "\" does not exist."; (JGetUserNotification())->ReportError(msg); } return kJFalse; } trueName.ReplaceSubstring(1, i+1, p1); } // check if window is already open JString ancestor = trueName, n; JPtrArray<JString> pathList(JPtrArrayT::kDeleteAll); while (!JIsRootDirectory(ancestor)) { const JIndex count = itsWindowList->GetElementCount(); for (JIndex i=1; i<=count; i++) { const JString name = (itsWindowList->NthElement(i))->GetDirectory(); if (JSameDirEntry(name, ancestor)) { SyGTreeDir* childDir = itsWindowList->NthElement(i); childDir->Activate(); if (dir != NULL) { *dir = childDir; } JPoint cell; (childDir->GetTable())->SelectName(pathList, selectName, &cell, clearSelection); if (row != NULL) { *row = cell.y; } return kJTrue; } } if (forceNew) { break; } JStripTrailingDirSeparator(&ancestor); JSplitPathAndName(ancestor, &p, &n); ancestor = p; pathList.Prepend(n); } // create new window fixedName = trueName; JGetTrueName(fixedName, &trueName); SyGTreeDir* childDir = new SyGTreeDir(trueName); assert( childDir != NULL ); childDir->Activate(); JPoint cell; (childDir->GetTable())->SelectName(selectName, NULL, &cell); if (row != NULL) { *row = cell.y; } if (deiconify) { childDir->GetWindow()->Deiconify(); } itsWindowList->Append(childDir); if (dir != NULL) { *dir = childDir; } return kJTrue; }
void GenerateForm ( istream& input, const JString& formName, const JString& tagName, const JString& enclName, const JString& codePath, const JString& stringPath, const JString& codeSuffix, const JString& headerSuffix, JPtrArray<JString>* backupList ) { const JString codeFileName = codePath + formName + codeSuffix; const JString codeFileBakName = codeFileName + kBackupSuffix; const JString headerFileName = codePath + formName + headerSuffix; const JString headerFileBakName = headerFileName + kBackupSuffix; if (!JFileExists(codeFileName)) { cerr << codeFileName << " not found" << endl; return; } if (!JFileExists(headerFileName)) { cerr << headerFileName << " not found" << endl; return; } cout << "Generating: " << formName << ", " << tagName << endl; const JBoolean shouldBackup = ShouldBackupForm(formName, backupList); // copy code file contents before start delimiter JString tempCodeFileName; JError err = JCreateTempFile(codePath, NULL, &tempCodeFileName); if (!err.OK()) { cerr << "Unable to create temporary file in " << codePath << endl; cerr << " (" << err.GetMessage() << ')' << endl; return; } ifstream origCode(codeFileName); ofstream outputCode(tempCodeFileName); if (!outputCode.good()) { cerr << "Unable to open temporary file in " << codePath << endl; remove(tempCodeFileName); return; } if (!CopyBeforeCodeDelimiter(tagName, origCode, outputCode)) { cerr << "No starting delimiter in " << codeFileName << endl; outputCode.close(); remove(tempCodeFileName); return; } // generate code for each object in the form JPtrArray<JString> objTypes(JPtrArrayT::kDeleteAll), objNames(JPtrArrayT::kDeleteAll); GenerateCode(input, outputCode, stringPath, formName, tagName, enclName, &objTypes, &objNames); // copy code file contents after end delimiter JBoolean done = CopyAfterCodeDelimiter(tagName, origCode, outputCode); origCode.close(); outputCode.close(); if (!done) { cerr << "No ending delimiter in " << codeFileName << endl; remove(tempCodeFileName); return; } else if (shouldBackup && rename(codeFileName, codeFileBakName) != 0) { cerr << "Unable to rename original " << codeFileName << endl; remove(tempCodeFileName); return; } JEditVCS(codeFileName); rename(tempCodeFileName, codeFileName); // copy header file contents before start delimiter JString tempHeaderFileName; err = JCreateTempFile(codePath, NULL, &tempHeaderFileName); if (!err.OK()) { cerr << "Unable to create temporary file in " << codePath << endl; cerr << " (" << err.GetMessage() << ')' << endl; return; } ifstream origHeader(headerFileName); ofstream outputHeader(tempHeaderFileName); if (!outputHeader.good()) { cerr << "Unable to open temporary file in " << codePath << endl; remove(tempHeaderFileName); return; } if (!CopyBeforeCodeDelimiter(tagName, origHeader, outputHeader)) { cerr << "No starting delimiter in " << headerFileName << endl; outputHeader.close(); remove(tempHeaderFileName); return; } // generate instance variable for each object in the form GenerateHeader(outputHeader, objTypes, objNames); // copy header file contents after end delimiter done = CopyAfterCodeDelimiter(tagName, origHeader, outputHeader); origHeader.close(); outputHeader.close(); if (!done) { cerr << "No ending delimiter in " << headerFileName << endl; remove(tempHeaderFileName); return; } // check if header file actually changed JString origHeaderText, newHeaderText; JReadFile(headerFileName, &origHeaderText); JReadFile(tempHeaderFileName, &newHeaderText); if (newHeaderText != origHeaderText) { if (shouldBackup && rename(headerFileName, headerFileBakName) != 0) { cerr << "Unable to rename original " << headerFileName << endl; remove(tempHeaderFileName); return; } JEditVCS(headerFileName); rename(tempHeaderFileName, headerFileName); } else { remove(tempHeaderFileName); } }
JBoolean JXDocumentManager::FindFile ( const JCharacter* fileName, const JCharacter* currPath, JString* newFileName, const JBoolean askUser ) const { // if the file exists, we are done if (JFileExists(fileName)) { *newFileName = fileName; return kJTrue; } // search the directory tree below currPath JString path, name, newPath; JSplitPathAndName(fileName, &path, &name); if (JSearchSubdirs(currPath, name, kJTrue, kJTrue, &newPath)) { *newFileName = newPath + name; return kJTrue; } // check for known case of move/rename if (SearchFileMap(fileName, newFileName)) { return kJTrue; } // ask the user to find it if (askUser) { JString instrMsg = "Unable to locate "; instrMsg += fileName; instrMsg += "\n\nPlease find it."; while ((JGetChooseSaveFile())->ChooseFile("New name of file:", instrMsg, newFileName)) { JString newPath, newName; JSplitPathAndName(*newFileName, &newPath, &newName); if (newName != name) { JString warnMsg = name; warnMsg += " was requested.\n\nYou selected "; warnMsg += newName; warnMsg += ".\n\nAre you sure that this is correct?"; if (!(JGetUserNotification())->AskUserNo(warnMsg)) { continue; } } JString trueName; const JBoolean ok = JGetTrueName(*newFileName, &trueName); assert( ok ); FileMap map; map.oldName = new JString(fileName); assert( map.oldName != NULL ); map.newName = new JString(trueName); assert( map.newName != NULL ); itsFileMap->AppendElement(map); *newFileName = trueName; return kJTrue; } } newFileName->Clear(); return kJFalse; }
JError JXImage::CreateFromXPM ( JXDisplay* display, const JCharacter* fileName, JXImage** image ) { #ifdef _J_HAS_XPM JXColormap* colormap = display->GetColormap(); Pixmap image_pixmap = None; Pixmap mask_pixmap = None; XpmAttributes attr; attr.valuemask = XpmVisual | XpmColormap | XpmDepth | XpmExactColors | XpmCloseness | XpmColorKey | XpmAllocCloseColors | XpmReturnAllocPixels; attr.visual = colormap->GetVisual(); attr.colormap = colormap->GetXColormap(); attr.depth = display->GetDepth(); attr.color_key = XPM_COLOR; attr.alloc_pixels = NULL; attr.nalloc_pixels = 0; attr.alloc_close_colors = kJTrue; // so we can free all resulting pixels attr.exactColors = 1; attr.closeness = 0; const int xpmErr = XpmReadFileToPixmap(*display, display->GetRootWindow(), const_cast<JCharacter*>(fileName), &image_pixmap, &mask_pixmap, &attr); if (xpmErr == XpmOpenFailed && JFileExists(fileName)) { return JAccessDenied(fileName); } else if (xpmErr == XpmOpenFailed) { return JDirEntryDoesNotExist(fileName); } else if (xpmErr == XpmFileInvalid) { return FileIsNotXPM(fileName); } else if (xpmErr == XpmNoMemory) { return JNoProcessMemory(); } else if (xpmErr == XpmColorFailed || xpmErr == XpmColorError) { if (image_pixmap != None) { XFreePixmap(*display, image_pixmap); } if (mask_pixmap != None) { XFreePixmap(*display, mask_pixmap); } if (attr.alloc_pixels != NULL) { XFreeColors(*display, attr.colormap, attr.alloc_pixels, attr.nalloc_pixels, 0); } XpmFreeAttributes(&attr); return TooManyColors(); } // create image and mask *image = new JXImage(display, image_pixmap); assert( *image != NULL ); XFreePixmap(*display, image_pixmap); if (mask_pixmap != None) { JXImageMask* mask = new JXImageMask(display, mask_pixmap); assert( mask != NULL ); (**image).SetMask(mask); XFreePixmap(*display, mask_pixmap); } // free pixels so X has usage count of 1 XFreeColors(*display, attr.colormap, attr.alloc_pixels, attr.nalloc_pixels, 0); // clean up XpmFreeAttributes(&attr); return JNoError(); #else return XPMNotAvailable(); #endif }