void JXMenuData::InsertItem ( const JIndex index, const JBoolean isCheckbox, const JBoolean isRadio, const JCharacter* shortcuts, const JCharacter* id ) { BaseItemData itemData; itemData.isCheckbox = JConvertToBoolean(isCheckbox || isRadio); itemData.isRadio = isRadio; if (!JStringEmpty(shortcuts)) { itemData.shortcuts = new JString(shortcuts); assert( itemData.shortcuts != NULL ); } if (!JStringEmpty(id)) { itemData.id = new JString(id); assert( itemData.id != NULL ); } itsBaseItemData->InsertElementAtIndex(index, itemData); }
JColorIndex JXPathInput::GetTextColor ( const JCharacter* path, const JCharacter* base, const JBoolean requireWrite, const JColormap* colormap ) { if (JStringEmpty(path)) { return colormap->GetBlackColor(); } JString fullPath; if ((JIsAbsolutePath(path) || !JStringEmpty(base)) && JConvertToAbsolutePath(path, base, &fullPath) && JDirectoryReadable(fullPath) && JCanEnterDirectory(fullPath) && (!requireWrite || JDirectoryWritable(fullPath))) { return colormap->GetBlackColor(); } else { return colormap->GetRedColor(); } }
void JXMenuData::InsertItem ( const JIndex index, const JXMenu::ItemType type, const JCharacter* shortcuts, const JCharacter* id ) { BaseItemData itemData; itemData.type = type; if (!JStringEmpty(shortcuts)) { itemData.shortcuts = new JString(shortcuts); assert( itemData.shortcuts != NULL ); } if (!JStringEmpty(id)) { itemData.id = new JString(id); assert( itemData.id != NULL ); } itsBaseItemData->InsertElementAtIndex(index, itemData); }
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; }
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(); } }
JError JCreateTempFile ( const JCharacter* path, const JCharacter* prefix, JString* fullName ) { JString p; if (!JStringEmpty(path)) { p = path; } else if (!JGetTempDirectory(&p)) { return JDirEntryDoesNotExist("/tmp"); } if (!JStringEmpty(prefix)) { p = JCombinePathAndName(p, prefix); } else { p = JCombinePathAndName(p, "temp_file_"); } p += "XXXXXX"; char* s = p.AllocateCString(); jclear_errno(); int fd = mkstemp(s); if (fd != -1) { close(fd); *fullName = s; delete [] s; return JNoError(); } fullName->Clear(); delete [] s; // EINVAL counts as unexpected const int err = jerrno(); if (err == EEXIST) { return JAccessDenied(p); } else { return JUnexpectedError(err); } }
void JXMenuData::SetItemID ( const JIndex index, const JCharacter* id ) { BaseItemData itemData = itsBaseItemData->GetElement(index); if (!JStringEmpty(id)) { if (itemData.id == NULL) { itemData.id = new JString(id); assert( itemData.id != NULL ); itsBaseItemData->SetElement(index, itemData); } else { *(itemData.id) = id; } } else if (itemData.id != NULL) { delete (itemData.id); itemData.id = NULL; itsBaseItemData->SetElement(index, itemData); } }
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); } }
JBoolean JSplitPathAndName ( const JCharacter* fullName, JString* path, JString* name ) { assert( !JStringEmpty(fullName) ); JString pathAndName = fullName; assert( pathAndName.GetLastCharacter() != ACE_DIRECTORY_SEPARATOR_CHAR ); JIndex i; if (pathAndName.LocateLastSubstring(ACE_DIRECTORY_SEPARATOR_STR, &i)) { *path = pathAndName.GetSubstring(1,i); *name = pathAndName.GetSubstring(i+1, pathAndName.GetLength()); JCleanPath(path); return kJTrue; } else { *path = JGetCurrentDirectory(); *name = pathAndName; return kJFalse; } }
void SVNTabBase::ComparePrev ( const JCharacter* revStr ) { JString r = "PREV"; if (!JStringEmpty(revStr)) { JString s = revStr; JUInt rev; if (s.ConvertToUInt(&rev) && rev > 0) { r = JString(rev-1, JString::kBase10); r += ":"; r += JString(rev, JString::kBase10); } else { r += ":"; r += revStr; } } Compare(r, kJTrue); }
void JWebBrowser::ShowFileLocation ( const JCharacter* fileName ) { if (!JStringEmpty(itsShowFileLocationCmd)) { JString fullName = fileName; JStripTrailingDirSeparator(&fullName); JString path, name; JSplitPathAndName(fullName, &path, &name); const JCharacter* map[] = { kFileVarName, fullName, kPathVarName, path }; JString s = itsShowFileLocationCmd; if (!s.Contains("$")) { s += " '$"; s += kFileVarName; s += "'"; } (JGetStringManager())->Replace(&s, map, sizeof(map)); JSimpleProcess::Create(s, kJTrue); } }
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 JXGetStringDialog::BuildWindow ( const JCharacter* windowTitle, const JCharacter* prompt, const JCharacter* initialValue, const JBoolean password ) { // begin JXLayout JXWindow* window = new JXWindow(this, 310,110, ""); assert( window != NULL ); JXTextButton* okButton = new JXTextButton(JGetString("okButton::JXGetStringDialog::JXLayout"), window, JXWidget::kFixedRight, JXWidget::kFixedBottom, 190,80, 60,20); assert( okButton != NULL ); okButton->SetShortcuts(JGetString("okButton::JXGetStringDialog::shortcuts::JXLayout")); JXTextButton* cancelButton = new JXTextButton(JGetString("cancelButton::JXGetStringDialog::JXLayout"), window, JXWidget::kFixedLeft, JXWidget::kFixedBottom, 60,80, 60,20); assert( cancelButton != NULL ); cancelButton->SetShortcuts(JGetString("cancelButton::JXGetStringDialog::shortcuts::JXLayout")); itsInputField = new JXInputField(window, JXWidget::kHElastic, JXWidget::kFixedTop, 20,40, 270,20); assert( itsInputField != NULL ); JXStaticText* promptDisplay = new JXStaticText(JGetString("promptDisplay::JXGetStringDialog::JXLayout"), window, JXWidget::kHElastic, JXWidget::kFixedTop, 20,20, 270,20); assert( promptDisplay != NULL ); promptDisplay->SetToLabel(); // end JXLayout window->SetTitle(windowTitle); SetButtons(okButton, cancelButton); promptDisplay->SetText(prompt); if (password) { const JRect r = itsInputField->GetFrame(); delete itsInputField; itsInputField = new JXPasswordInput(window, JXWidget::kHElastic, JXWidget::kFixedTop, r.left, r.top, r.width(), r.height()); assert( itsInputField != NULL ); } else if (!JStringEmpty(initialValue)) { itsInputField->SetText(initialValue); } itsInputField->SetIsRequired(); }
JBoolean JGetTempDirectory ( JString* tempDir ) { // inside function to keep gcc 3.3.3 (cygwin) happy static JBoolean theTempPathInitFlag = kJFalse; static JString theTempPath; if (!theTempPathInitFlag) { char* path = getenv("TMPDIR"); if (!JStringEmpty(path) && JDirectoryWritable(path)) { theTempPath = path; } else if (P_tmpdir != NULL && JDirectoryWritable(P_tmpdir)) { theTempPath = P_tmpdir; } else { theTempPath = "/tmp/"; } JAppendDirSeparator(&theTempPath); theTempPathInitFlag = kJTrue; } *tempDir = theTempPath; return kJTrue; }
JBoolean JSearchSubdirs ( const JCharacter* startPath, const JCharacter* name, const JBoolean isFile, const JBoolean caseSensitive, JString* path, JString* newName, JProgressDisplay* userPG, JBoolean* userCancelled ) { assert( !JStringEmpty(startPath) ); assert( !JStringEmpty(name) && name[0] != '/' ); JLatentPG pg(100); if (userPG != NULL) { pg.SetPG(userPG, kJFalse); } JString msg = "Searching for \""; msg += name; msg += "\"..."; pg.VariableLengthProcessBeginning(msg, kJTrue, kJFalse); JBoolean cancelled = kJFalse; const JBoolean found = JSearchSubdirs_private(startPath, name, isFile, caseSensitive, path, newName, pg, &cancelled); if (!found) { path->Clear(); if (newName != NULL) { newName->Clear(); } } pg.ProcessFinished(); if (userCancelled != NULL) { *userCancelled = cancelled; } return found; }
JString JGetUniqueDirEntryName ( const JCharacter* path, const JCharacter* namePrefix, const JCharacter* nameSuffix, const JIndex startIndex ) { assert( !JStringEmpty(namePrefix) ); JString fullPath; if (JStringEmpty(path)) { if (!JGetTempDirectory(&fullPath)) { fullPath = JGetCurrentDirectory(); } } else { const JBoolean ok = JConvertToAbsolutePath(path, NULL, &fullPath); assert( ok ); } assert( JDirectoryExists(fullPath) ); const JString prefix = JCombinePathAndName(fullPath, namePrefix); JString name; for (JIndex i=startIndex; i<=kJIndexMax; i++) { name = prefix; if (i > 1) { name += JString(i, JString::kBase10); } if (!JStringEmpty(nameSuffix)) { name += nameSuffix; } if (!JNameUsed(name)) { break; } } return name; }
JVariableList::MatchResult JVariableList::FindUniqueVarName ( const JCharacter* prefix, JIndex* index, JString* maxPrefix ) const { assert( !JStringEmpty(prefix) ); const JSize count = GetElementCount(); JArray<JIndex> matchList; for (JIndex i=1; i<=count; i++) { const JString& name = GetVariableName(i); if (name == prefix) { *index = i; *maxPrefix = name; return kSingleMatch; } else if (JStringBeginsWith(name, name.GetLength(), prefix)) { matchList.AppendElement(i); } } const JSize matchCount = matchList.GetElementCount(); if (matchCount == 0) { *index = 0; maxPrefix->Clear(); return kNoMatch; } else if (matchCount == 1) { *index = matchList.GetElement(1); *maxPrefix = GetVariableName(*index); return kSingleMatch; } else { *maxPrefix = GetVariableName( matchList.GetElement(1) ); for (JIndex i=2; i<=matchCount; i++) { const JString& varName = GetVariableName( matchList.GetElement(i) ); const JSize matchLength = JCalcMatchLength(*maxPrefix, varName); const JSize prefixLength = maxPrefix->GetLength(); if (matchLength < prefixLength) { maxPrefix->RemoveSubstring(matchLength+1, prefixLength); } } *index = 0; return kMultipleMatch; } }
void JXSearchTextDialog::SetSearchTextHelpName ( const JCharacter* name ) { itsSearchTextHelpName = (JStringEmpty(name) ? kJXSearchTextHelpName : name); }
void JXFileHistoryMenu::AddFile ( const JCharacter* origPath, const JCharacter* name ) { if (JStringEmpty(origPath) || JStringEmpty(name)) { return; } JString path = origPath; path.PrependCharacter(' '); path.AppendCharacter(' '); AddItem(name, path); }
JBoolean JIsRootDirectory ( const JCharacter* dirName ) { assert( !JStringEmpty(dirName) ); return JI2B( dirName[0] == '/' && dirName[1] == '\0' ); }
JBoolean JIsRelativePath ( const JCharacter* path ) { assert( !JStringEmpty(path) ); return JI2B( path[0] != '/' && path[0] != '~' ); }
void CMSourceDirector::DisplayDisassembly ( const CMLocation& loc ) { const JString& fnName = loc.GetFunctionName(); const JString& addr = loc.GetMemoryAddress(); assert( !JStringEmpty(fnName) ); assert( !JStringEmpty(addr) ); if (fnName == itsCurrentFn) { JIndex i; if (dynamic_cast<CMLineAddressTable*>(itsTable)->FindAddressLineNumber(addr, &i)) { DisplayLine(i); } else { itsTable->SetCurrentLine(0); } UpdateWindowTitle(NULL); } else { itsCurrentFn = fnName; if (itsGetAssemblyCmd == NULL) { itsGetAssemblyCmd = (CMGetLink())->CreateGetAssembly(this); } if (itsGetAssemblyCmd != NULL) { itsAsmLocation = loc; itsGetAssemblyCmd->Send(); } UpdateWindowTitle(NULL); } }
JString JCombinePathAndName ( const JCharacter* path, const JCharacter* name ) { assert( !JStringEmpty(path) ); assert( !JStringEmpty(name) ); JString file = path; if (file.GetLastCharacter() != ACE_DIRECTORY_SEPARATOR_CHAR && name[0] != ACE_DIRECTORY_SEPARATOR_CHAR) { file.AppendCharacter(ACE_DIRECTORY_SEPARATOR_CHAR); } file += name; JCleanPath(&file); return file; }
void CBSearchFilterHistoryMenu::AddFilter ( const JCharacter* filter, const JBoolean invert ) { if (!JStringEmpty(filter)) { AddItem(filter, invert ? kInvertFlag : ""); } }
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 JConvertToAbsolutePath ( const JCharacter* path, const JCharacter* base, // can be NULL JString* result ) { assert( !JStringEmpty(path) && result != NULL ); JBoolean ok = kJTrue; if (path[0] == '/') { *result = path; } else if (path[0] == '~') { ok = JExpandHomeDirShortcut(path, result); } else if (!JStringEmpty(base)) { *result = JCombinePathAndName(base, path); } else { const JString currDir = JGetCurrentDirectory(); *result = JCombinePathAndName(currDir, path); } if (ok) { return JNameUsed(*result); } else { result->Clear(); return kJFalse; } }
void CBCPreprocessor::DefineMacro ( const JCharacter* name, const JCharacter* value ) { assert( !JStringEmpty(name) && value != NULL ); MacroInfo info(new JString(name), new JString(value)); assert( info.name != NULL && info.value != NULL ); itsMacroList->InsertSorted(info); }
XFontStruct* #endif JXFontManager::GetNewFont ( const JCharacter* name, const JCharacter* charSet, const JSize size, const JFontStyle& style ) const { #ifdef _J_USE_XFT double raw_size = size; XftFont* font = XftFontOpen(*itsDisplay, DefaultScreen((Display*)*itsDisplay), XFT_FAMILY, XftTypeString, name, XFT_SIZE, XftTypeDouble, raw_size, XFT_WEIGHT, XftTypeInteger, style.bold ? XFT_WEIGHT_BOLD : XFT_WEIGHT_MEDIUM, XFT_SLANT, XftTypeInteger, style.italic ? XFT_SLANT_ITALIC : XFT_SLANT_ROMAN, 0); return font; #else const JCharacter* italicStr = kObliqueStr; // try oblique before italic JBoolean iso = JStringEmpty(charSet); XFontStruct* xfont = NULL; while (1) { JString xFontStr = BuildFontName(name, charSet, size, style, italicStr, iso); xfont = XLoadQueryFont(*itsDisplay, xFontStr); if (xfont != NULL) { break; } if (strcmp(italicStr, kObliqueStr) == 0 && style.italic) { italicStr = kItalicStr; } else if (iso) { iso = kJFalse; italicStr = kObliqueStr; } else { break; // give up and return NULL } } return xfont; #endif }
void JXTextMenuData::SetNMShortcut ( const JIndex index, const JCharacter* str ) { TextItemData itemData = itsTextItemData->GetElement(index); const JBoolean strEmpty = JStringEmpty(str); JBoolean changed = kJFalse; if (!strEmpty && itemData.nmShortcut == NULL) { itemData.nmShortcut = new JString(str); assert( itemData.nmShortcut != NULL ); itsTextItemData->SetElement(index, itemData); changed = kJTrue; } else if (!strEmpty) { *(itemData.nmShortcut) = str; changed = kJTrue; } else if (itemData.nmShortcut != NULL) { delete itemData.nmShortcut; itemData.nmShortcut = NULL; itsTextItemData->SetElement(index, itemData); changed = kJTrue; } if (changed) { itsNeedGeomRecalcFlag = kJTrue; JXWindow* window = itsMenu->GetWindow(); window->ClearMenuShortcut(itsMenu, index); int key; JXKeyModifiers modifiers(itsMenu->GetDisplay()); if (itemData.nmShortcut != NULL && ParseNMShortcut(itemData.nmShortcut, &key, &modifiers) && !window->InstallMenuShortcut(itsMenu, index, key, modifiers)) { SetNMShortcut(index, NULL); // don't display if not registered } } }
CMVarNode::CMVarNode ( JTreeNode* parent, const JCharacter* name, const JCharacter* value ) : JNamedTreeNode(NULL, JStringEmpty(name) ? " " : name, kJFalse), itsShouldListenToLinkFlag(kJFalse), itsValue(value) { VarTreeNodeX(); if (parent != NULL) { parent->Append(this); if (parent->IsRoot() && !JStringEmpty(name)) { CMInitVarNodeTask* task = new CMInitVarNodeTask(this); assert( task != NULL ); task->Go(); } } }