CMSourceDirector::CMSourceDirector ( CMCommandDirector* commandDir, const JCharacter* fileOrFn, const Type type ) : JXWindowDirector(JXGetApplication()), itsType(type), itsSrcMainCmd(NULL), itsGetAssemblyCmd(NULL) { CMSourceViewDirectorX(commandDir); if (itsType == kAsmType && !JStringEmpty(fileOrFn)) { CMLocation loc; loc.SetFunctionName(fileOrFn); loc.SetMemoryAddress("0x0"); // not allowed to be null DisplayDisassembly(loc); } else if (itsType == kSourceType && JFileReadable(fileOrFn)) { DisplayFile(fileOrFn); } }
JColorIndex JXFileInput::GetTextColor ( const JCharacter* fileName, const JCharacter* basePath, const JBoolean requireRead, const JBoolean requireWrite, const JBoolean requireExec, const JColormap* colormap ) { if (JStringEmpty(fileName)) { return colormap->GetBlackColor(); } JString fullName; if ((!JIsRelativePath(fileName) || !JStringEmpty(basePath)) && JConvertToAbsolutePath(fileName, basePath, &fullName) && (!requireRead || JFileReadable(fullName)) && (!requireWrite || JFileWritable(fullName)) && (!requireExec || JFileExecutable(fullName))) { return colormap->GetBlackColor(); } else { return colormap->GetRedColor(); } }
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; } }
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 CMSourceDirector::DisplayFile ( const JCharacter* fileName, const JIndex lineNumber, const JBoolean markLine ) { assert( !JStringEmpty(fileName) ); if (!itsCurrentFile.IsEmpty() && JSameDirEntry(fileName, itsCurrentFile)) { DisplayLine(lineNumber, markLine); UpdateWindowTitle(NULL); } else if (JFileReadable(fileName)) { itsCurrentFile = fileName; JTextEditor::PlainTextFormat format; itsText->ReadPlainText(itsCurrentFile, &format); // Assembly must not end with newline, so we have to enforce this for // source code, too. const JString& text = itsText->GetText(); JIndex i = text.GetLength(); while (text.GetCharacter(i) == '\n') { i--; } if (i < text.GetLength()) { itsText->SetSelection(i+1, text.GetLength()); itsText->DeleteSelection(); } itsText->SetCaretLocation(1); DisplayLine(lineNumber, markLine); itsFileDisplay->SetText(itsCurrentFile); UpdateFileType(); UpdateWindowTitle(NULL); } }
void TestDirector::OpenTextFile ( const JCharacter* fileName ) { if (JFileReadable(fileName)) { TestTextEditDocument* doc = new TestTextEditDocument(this, fileName); assert( doc != NULL ); doc->Activate(); } else { JString msg = "You do not have permission to read \""; msg += fileName; msg += "\"."; (JGetUserNotification())->ReportError(msg); } }
void CBSearchTextDialog::LoadFileSet() { JString fullName; if (itsCSF->ChooseFile("", NULL, &fullName)) { if (itsCSF->ReplaceExisting()) { itsFileList->RemoveAllFiles(); } std::ifstream input(fullName); JString file; while (!input.eof() && !input.fail()) { file = JReadLine(input); if (JFileReadable(file)) { itsFileList->AddFile(file); } } } }
JBoolean MatchesCookie ( const JCharacter* cookie, const JDirEntry& entry ) { JString file = entry.GetFullName(); if (!JFileReadable(file)) { return kJFalse; } mode_t perms; JError err = JGetPermissions(file, &perms); if (!err.OK()) { perms = 0600; } ifstream is(file); is >> ws; JString line1 = JReadLine(is); is.close(); if (line1 == "") { return kJTrue; } JArray<JIndexRange> subList; JRegex regex; err = regex.SetPattern(cookie); JBoolean matched = regex.Match(line1, &subList); if (matched) { return kJTrue; } return kJFalse; }
void XDLink::SetProgram ( const JCharacter* fileName ) { Send("detach"); // StopDebugger(); // avoid broadcasting DebuggerRestarted // StartDebugger(); itsProgramConfigFileName.Clear(); itsSourcePathList->DeleteAll(); JString fullName; if (!JConvertToAbsolutePath(fileName, NULL, &fullName) || !JFileReadable(fullName)) { const JString error = JGetString("ConfigFileUnreadable::XDLink"); Broadcast(UserOutput(error, kJTrue)); return; } else if (CMMDIServer::IsBinary(fullName)) { const JString error = JGetString("ConfigFileIsBinary::XDLink"); Broadcast(UserOutput(error, kJTrue)); return; } JString line; if (!CMMDIServer::GetLanguage(fullName, &line) || JStringCompare(line, "php", kJFalse) != 0) { const JString error = JGetString("ConfigFileWrongLanguage::XDLink"); Broadcast(UserOutput(error, kJTrue)); return; } JString path, name, suffix; JSplitPathAndName(fullName, &path, &name); JSplitRootAndSuffix(name, &itsProgramName, &suffix); itsProgramConfigFileName = fullName; ifstream input(fullName); while (1) { line = JReadLine(input); line.TrimWhitespace(); if (line.BeginsWith("source-path:")) { line.RemoveSubstring(1, 12); line.TrimWhitespace(); name = JCombinePathAndName(path, line); itsSourcePathList->Append(name); } else if (!line.IsEmpty() && !line.BeginsWith("code-medic:")) { line.Prepend("Unknown option: "); line.AppendCharacter('\n'); Broadcast(UserOutput(line, kJTrue)); } if (!input.good()) { break; } } XDSetProgramTask* task = new XDSetProgramTask(); assert( task != NULL ); task->Go(); }
JBoolean GMApp::OpenSession() { JBoolean success = kJFalse; JString homeDir; if (JGetHomeDirectory(&homeDir)) { JAppendDirSeparator(&homeDir); JString session = homeDir + kStateFileName; if (JFileExists(session) && JFileReadable(session)) { JFileArray* fileArray; JError err = JFileArray::Create(session, kStateFileSignature, &fileArray); if (err.OK()) { JFileVersion version = fileArray->GetVersion(); if (0 < version && version <= kCurrentSessionVersion) { JFAID id = 1; JSize count; { std::string data; fileArray->GetElement(id, &data); std::istringstream is(data); is >> count; id.SetID(id.GetID() + 1); } if (count == 0) { delete fileArray; JRemoveFile(session); return kJFalse; } for (JSize i = 1; i <= count; i++) { JFileArray* embed; err = JFileArray::Create(fileArray, id, &embed); GMessageTableDir* dir; if (GMessageTableDir::Create(this, *embed, &dir, version)) { itsTableDirs->Append(dir); } id.SetID(id.GetID() + 1); delete embed; } { std::string data; fileArray->GetElement(id, &data); std::istringstream is(data); is >> count; id.SetID(id.GetID() + 1); } for (JSize i = 1; i <= count; i++) { std::string data; fileArray->GetElement(id, &data); std::istringstream is(data); GMessageEditDir* dir = new GMessageEditDir(JXGetApplication()); assert(dir != NULL); dir->ReadState(is, version); dir->Activate(); id.SetID(id.GetID() + 1); } { std::string data; fileArray->GetElement(id, &data); std::istringstream is(data); GGetInboxMgr()->ReadState(is); } success = kJTrue; }
void SyGTreeDir::BuildWindow ( const JCharacter* startPath ) { JXCurrentPathMenu* pathMenu = NULL; // begin JXLayout JXWindow* window = new JXWindow(this, 420,500, ""); assert( window != NULL ); JXMenuBar* menuBar = new JXMenuBar(window, JXWidget::kHElastic, JXWidget::kFixedTop, 0,0, 420,30); assert( menuBar != NULL ); itsToolBar = new JXToolBar(SyGGetPrefsMgr(), kSMainToolBarID, menuBar, 200,200, window, JXWidget::kHElastic, JXWidget::kVElastic, 0,30, 420,450); assert( itsToolBar != NULL ); itsPathInput = new SyGPathInput(window, JXWidget::kHElastic, JXWidget::kFixedBottom, 20,480, 340,20); assert( itsPathInput != NULL ); SyGTrashButton* trashButton = new SyGTrashButton(window, JXWidget::kFixedRight, JXWidget::kFixedBottom, 390,480, 30,20); assert( trashButton != NULL ); itsDragSrc = new SyGFolderDragSource(itsPathInput, &pathMenu, window, JXWidget::kFixedLeft, JXWidget::kFixedBottom, 0,480, 20,20); assert( itsDragSrc != NULL ); itsUpButton = new JXTextButton(JGetString("itsUpButton::SyGTreeDir::JXLayout"), window, JXWidget::kFixedRight, JXWidget::kFixedBottom, 360,480, 30,20); assert( itsUpButton != NULL ); // end JXLayout // folder setup JString prefsFile = JCombinePathAndName(startPath, kDirPrefsName); prefsFile += JGetUserName(); if (!JFileExists(prefsFile)) { const JString origPrefsFile = JCombinePathAndName(startPath, kOrigDirPrefsName); JRenameFile(origPrefsFile, prefsFile); } istream* input = NULL; const JString* prefs = NULL; std::string s; if (!JFileReadable(prefsFile) && (SyGGetApplication())->GetMountPointPrefs(startPath, &prefs)) { s.assign(prefs->GetCString(), prefs->GetLength()); input = new std::istringstream(s); } else { input = new ifstream(prefsFile); } assert( input != NULL ); JFileVersion vers = 0; JSize w, h; if (input->good()) { *input >> vers; if (vers <= kSyGCurrentDirSetupVersion) { window->ReadGeometry(*input); } else { delete input; input = NULL; } }
void ParseOptions ( const JSize argc, char* argv[], JString* fileName, JBoolean* printInfo, int* transparentColor, LaceOption* interlace, JBoolean* padColormap, JBoolean* blend, JFloat* alpha, JRGB* alphaColor, JString* blendOutput ) { if (argc == 1) { PrintHelp(); exit(0); } fileName->Clear(); *printInfo = kJFalse; *transparentColor = kTransparentColorNotSet; *interlace = kIgnoreInterlace; *padColormap = kJFalse; *blend = kJFalse; JIndex index = 1; while (index < argc) { if (strcmp(argv[index], "-h") == 0 || strcmp(argv[index], "--help") == 0) { PrintHelp(); exit(0); } else if (strcmp(argv[index], "-v") == 0 || strcmp(argv[index], "--version") == 0) { PrintVersion(); exit(0); } else if (strcmp(argv[index], "-i") == 0) { *printInfo = kJTrue; } else if (strcmp(argv[index], "-t") == 0) { JCheckForValues(1, &index, argc, argv); if (strcmp(argv[index], "none") == 0) { *transparentColor = kNoTransparentColor; } else if ('0' <= argv[index][0] && argv[index][0] <= '9') { *transparentColor = atoi(argv[index]); } else { cerr << argv[0] << ": -t requires a number or none" << endl; exit(1); } } else if (strcmp(argv[index], "-l") == 0) { JCheckForValues(1, &index, argc, argv); if (strcmp(argv[index], "on") == 0) { *interlace = kTurnInterlaceOn; } else if (strcmp(argv[index], "off") == 0) { *interlace = kTurnInterlaceOff; } else { cerr << argv[0] << ": -l requires either on or off" << endl; exit(1); } } else if (strcmp(argv[index], "-p") == 0) { *padColormap = kJTrue; } else if (strcmp(argv[index], "-b") == 0) { JCheckForValues(5, &index, argc, argv); *blend = kJTrue; *alpha = atof(argv[index]); alphaColor->red = atoi(argv[index+1]); alphaColor->green = atoi(argv[index+2]); alphaColor->blue = atoi(argv[index+3]); *blendOutput = argv[index+4]; index += 4; } else if (argv[index][0] == '-') { cerr << argv[0] << ": unknown option " << argv[index] << endl; exit(1); } else if (fileName->IsEmpty()) { if (!JFileReadable(argv[index])) { cerr << argv[0] << ": file is unreadable" << endl; exit(1); } if (!JFileWritable(argv[index])) { cerr << argv[0] << ": file is unwriteable" << endl; exit(1); } *fileName = argv[index]; } else { cerr << argv[0] << ": too many parameters" << endl; exit(1); } index++; } if (fileName->IsEmpty()) { cerr << argv[0] << ": no input file specified" << endl; exit(1); } if (argc == 2) { *printInfo = kJTrue; } }
const JCharacter* JFSBindingList::Revert() { const JCharacter* userMsg = ""; // toss everything itsBindingList->CleanOut(); itsOverriddenList->CleanOut(); delete itsUserDefault; itsUserDefault = NULL; delete itsSystemDefault; itsSystemDefault = NULL; // read system bindings ifstream sysInput(kGlobalBindingsFile); if (sysInput.good()) { Load(sysInput, kJTrue); } sysInput.close(); // read user bindings JPrefsFile* file = NULL; if (!itsSignalFileName.IsEmpty() && (JPrefsFile::Create(kUserExtensionBindingRoot, &file, JFileArray::kDeleteIfWaitTimeout)).OK()) { if (file->IsEmpty()) { JString origUserFile; if (JExpandHomeDirShortcut(kOrigUserExtensionBindingFile, &origUserFile) && JFileReadable(origUserFile)) { ifstream userInput(origUserFile); if (userInput.good()) { Load(userInput, kJFalse); userMsg = JGetString("UpgradeFromVersion1::JFSBindingList"); } } } else { for (JFileVersion vers = kCurrentBindingVersion; kJTrue; vers--) { if (file->IDValid(vers)) { std::string data; file->GetData(vers, &data); std::istringstream input(data); Load(input, kJFalse); break; } if (vers == 0) { break; // check *before* decrement since unsigned } } } delete file; } if (IsEmpty()) // nothing loaded { #ifdef _J_OSX const JCharacter* data = JGetString("DefaultBindingList-OSX::JFSBindingList"); #else const JCharacter* data = JGetString("DefaultBindingList::JFSBindingList"); #endif const std::string s(data, strlen(data)); std::istringstream input(s); Load(input, kJFalse); } if (!itsSignalFileName.IsEmpty()) { JGetModificationTime(itsSignalFileName, &itsSignalModTime); } // ensure that GetDefaultCommand() will work if (itsUserDefault == NULL && itsSystemDefault == NULL) { SetDefaultCommand(kDefaultCmd, kDefaultCmdType, kDefaultSingleFile); } return userMsg; }
void JXFileInput::AdjustStylesBeforeRecalc ( const JString& buffer, JRunArray<Font>* styles, JIndexRange* recalcRange, JIndexRange* redrawRange, const JBoolean deletion ) { const JColormap* colormap = GetColormap(); const JSize totalLength = buffer.GetLength(); JString fullName = buffer; if ((JIsRelativePath(buffer) && !HasBasePath()) || !JExpandHomeDirShortcut(buffer, &fullName)) { fullName.Clear(); } // Last clause because if JConvertToAbsolutePath() succeeds, we don't // want to further modify fullName. else if (JIsRelativePath(buffer) && !JConvertToAbsolutePath(buffer, itsBasePath, &fullName)) { if (HasBasePath()) { fullName = JCombinePathAndName(itsBasePath, buffer); } else { fullName.Clear(); } } JSize errLength; if (fullName.IsEmpty()) { errLength = totalLength; } else if (!JFileExists(fullName) || (itsRequireReadFlag && !JFileReadable(fullName)) || (itsRequireWriteFlag && !JFileWritable(fullName)) || (itsRequireExecFlag && !JFileExecutable(fullName))) { const JString closestDir = JGetClosestDirectory(fullName, kJFalse); if (fullName.BeginsWith(closestDir)) { errLength = fullName.GetLength() - closestDir.GetLength(); } else { errLength = totalLength; } } else { errLength = 0; } if (errLength > 0 && buffer.EndsWith(kThisDirSuffix)) { errLength++; // trailing . is trimmed } Font f = styles->GetFirstElement(); styles->RemoveAll(); if (errLength >= totalLength) { f.style.color = colormap->GetRedColor(); styles->AppendElements(f, totalLength); } else { f.style.color = colormap->GetBlackColor(); styles->AppendElements(f, totalLength - errLength); if (errLength > 0) { f.style.color = colormap->GetRedColor(); styles->AppendElements(f, errLength); } } *redrawRange += JIndexRange(1, totalLength); }