void JMemoryManager::ReadValue ( JBoolean* hasValue, unsigned char* value, const JCharacter* string ) { *hasValue = JConvertToBoolean(string != NULL); if (*hasValue && JStringCompare(string, "no", kJFalse) != 0) { const JCharacter* start = string; while ( isspace(*start) ) { ++start; } if (*start != '\0') // The string has a non-space value, so try to read as a number { JCharacter* end; unsigned char theValue = (unsigned char) strtol(start, &end, 0); if (*end == '\0') // We read the entire string, so the value must be good { *value = theValue; } } } }
JOrderedSetT::CompareResult SVNListBase::CompareLines::Compare ( JString* const & s1, JString* const & s2 ) const { const JString p1 = itsWidget->ExtractRelativePath(*s1); const JString p2 = itsWidget->ExtractRelativePath(*s2); const int r = JStringCompare(p1, p2, kJFalse); if (r > 0) { return JOrderedSetT::kFirstGreaterSecond; } else if (r < 0) { return JOrderedSetT::kFirstLessSecond; } else { return JOrderedSetT::kFirstEqualSecond; } }
JBoolean CBSymbolList::IsUniqueClassName ( const JCharacter* name, CBLanguage* lang ) const { const JSize symCount = itsSymbolList->GetElementCount(); const SymbolInfo* sym = itsSymbolList->GetCArray(); JBoolean found = kJFalse; for (JIndex i=0; i<symCount; i++) { if (IsClass(sym[i].type) && JStringCompare(*(sym[i].name), name, CBIsCaseSensitive(sym[i].lang)) == 0) { if (!found) { found = kJTrue; *lang = sym[i].lang; } else { return kJFalse; } } } return found; }
JOrderedSetT::CompareResult GPrefsMgr::CompareFileNames ( JString* const & n1, JString* const & n2 ) { JString s1(*n1); JString s2(*n2); JIndex index; if (s1.LocateLastSubstring("/",&index)) { s1.RemoveSubstring(1, index); } if (s2.LocateLastSubstring("/",&index)) { s2.RemoveSubstring(1, index); } const int r = JStringCompare(s1, s2, kJFalse); if (r > 0) { return JOrderedSetT::kFirstGreaterSecond; } else if (r < 0) { return JOrderedSetT::kFirstLessSecond; } else { return JOrderedSetT::kFirstEqualSecond; } }
JBoolean JXFontManager::BuildTrueTypeFontName ( const JCharacter* xName, const JSize size, const JFontStyle& style, JString* xFontStr ) const { xFontStr->Clear(); // NxM is not TrueType. Symbol is strange. if (nxmRegex.Match(xName) || JStringCompare(xName, "Symbol", kJFalse) == 0) { return kJFalse; } // name xFontStr->Append(xName); // size xFontStr->Append("-"); xFontStr->Append( JString(size, JString::kBase10) ); // regular or boldface if (style.bold) { xFontStr->Append(":weight=bold"); } else { xFontStr->Append(":weight=light"); } // regular or italic if (style.italic) { xFontStr->Append(":slant=oblique,italic"); } else { xFontStr->Append(":slant=roman"); } // success return kJTrue; }
JMMErrorPrinter::JMMErrorPrinter ( ) : JMMMonitor(), itsPrintErrorsFlag(kJTrue) { const JCharacter* printErrors = getenv("JMM_NO_PRINT_ERRORS"); if (printErrors != NULL && JStringCompare(printErrors, "yes", kJFalse) == 0) { itsPrintErrorsFlag = kJFalse; } }
JBoolean JStringManager::CanOverride ( const JCharacter* id ) { for (JIndex i=0; i<kNoOverrideIDCount; i++) { if (JStringCompare(id, kNoOverrideID[i]) == 0) { return kJFalse; } } return kJTrue; }
JOrderedSetT::CompareResult GMessageHeader::CompareDates ( GMessageHeader* const & h1, GMessageHeader* const & h2 ) { int r = h1->GetYear() - h2->GetYear(); if (r == 0) { if (h1->GetMonth() == h2->GetMonth()) { r = h1->GetDay() - h2->GetDay(); } else { JString month1 = h1->GetMonth(); JString month2 = h2->GetMonth(); JString months = "JanFebMarAprMayJunJulAugSepOctNovDec"; JIndex val1; JIndex val2; if (months.LocateSubstring(month1, &val1) && months.LocateSubstring(month2, &val2)) { r = val1 - val2; } } } if (r == 0) { r = JStringCompare(h1->GetTime(), h2->GetTime(), kJFalse); } if (r > 0) { return JOrderedSetT::kFirstGreaterSecond; } else if (r < 0) { return JOrderedSetT::kFirstLessSecond; } else { return JOrderedSetT::kFirstEqualSecond; } }
JOrderedSetT::CompareResult GMessageHeader::CompareSubject ( GMessageHeader* const & h1, GMessageHeader* const & h2 ) { const int r = JStringCompare(h1->GetBaseSubject(), h2->GetBaseSubject(), kJFalse); if (r > 0) { return JOrderedSetT::kFirstGreaterSecond; } else if (r < 0) { return JOrderedSetT::kFirstLessSecond; } else { return CompareDates(h1, h2); } }
JOrderedSetT::CompareResult CBStylerBase::CompareWords ( const WordStyle& w1, const WordStyle& w2 ) { const int result = JStringCompare(w1.key, w2.key, kJFalse); if (result < 0) { return JOrderedSetT::kFirstLessSecond; } else if (result == 0) { return JOrderedSetT::kFirstEqualSecond; } else { return JOrderedSetT::kFirstGreaterSecond; } }
JBoolean JIsMounted ( const JCharacter* path, JBoolean* writable, JBoolean* isTop, JString* device, JFileSystemType* fsType, JString* fsTypeString ) { struct stat stbuf1, stbuf2; if (stat(path, &stbuf1) != 0) { return kJFalse; } FILE* f = fopen(kMountedInfoName, "r"); if (f == NULL) { return kJFalse; } JBoolean isMounted = kJFalse; JString p; mnttab info; while (getmntent(f, &info) == 0) { if (strcmp(info.mnt_mountp, "/") != 0 && stat(info.mnt_mountp, &stbuf2) == 0 && stbuf1.st_dev == stbuf2.st_dev) { isMounted = kJTrue; if (writable != NULL) { *writable = JI2B(hasmntopt(&info, "ro") == NULL); } if (isTop != NULL) { *isTop = JI2B(stbuf1.st_ino == stbuf2.st_ino); } if (device != NULL) { *device = info.mnt_special; } if (fsType != NULL) { *fsType = kOtherFSType; if (JStringCompare(info.mnt_fstype, "vfat", kJFalse) == 0) { *fsType = kVFATType; } } if (fsTypeString != NULL) { *fsTypeString = info.mnt_fstype; } break; } } fclose(f); return isMounted; }
JMemoryManager::JMemoryManager() : itsMemoryTable(NULL), itsErrorPrinter(NULL), itsLink(NULL), itsErrorStream(NULL), itsExitStatsFileName(NULL), itsExitStatsStream(NULL), itsRecursionDepth(0), itsLastDeleteFile(kUnknownFile), itsLastDeleteLine(0), itsBroadcastErrorsFlag(kJFalse), itsPrintExitStatsFlag(kJFalse), itsPrintInternalStatsFlag(kJFalse), itsShredFlag(kJFalse), // Dummy initialization itsDeallocateGarbage(defaultDeallocateGarbage), itsTagSize(8), itsCheckDoubleAllocationFlag(kJFalse), itsDisallowDeleteNULLFlag(kJFalse) { // Instance() must set the flag assert(theConstructingFlag == kJTrue); const JCharacter* abortUnknownAlloc = getenv("JMM_ABORT_UNKNOWN_ALLOC"); if (abortUnknownAlloc != NULL && JStringCompare(abortUnknownAlloc, "yes", kJFalse) == 0) { theAbortUnknownAllocFlag = kJTrue; } const JCharacter* broadcastErrors = getenv("JMM_BROADCAST_ERRORS"); if (broadcastErrors != NULL && JStringCompare(broadcastErrors, "yes", kJFalse) == 0) { itsBroadcastErrorsFlag = kJTrue; } const JCharacter* printExitStats = getenv("JMM_PRINT_EXIT_STATS"); if (printExitStats != NULL && JStringCompare(printExitStats, "yes", kJFalse) == 0) { itsPrintExitStatsFlag = kJTrue; } const JCharacter* printInternalStats = getenv("JMM_PRINT_INTERNAL_STATS"); if (printInternalStats != NULL && JStringCompare(printInternalStats, "yes", kJFalse) == 0) { itsPrintInternalStatsFlag = kJTrue; } ReadValue(&theInitializeFlag, &theAllocateGarbage, getenv("JMM_INITIALIZE")); ReadValue(&itsShredFlag, &itsDeallocateGarbage, getenv("JMM_SHRED")); const JCharacter* checkDoubleAllocation = getenv("JMM_CHECK_DOUBLE_ALLOCATION"); if (checkDoubleAllocation != NULL && JStringCompare(checkDoubleAllocation, "yes", kJFalse) == 0) { itsCheckDoubleAllocationFlag = kJTrue; } const JCharacter* disallowDeleteNULL = getenv("JMM_DISALLOW_DELETE_NULL"); if (disallowDeleteNULL != NULL && JStringCompare(disallowDeleteNULL, "yes", kJFalse) == 0) { itsDisallowDeleteNULLFlag = kJTrue; } const JCharacter* recordAllocated = getenv("JMM_RECORD_ALLOCATED"); if (recordAllocated != NULL && JStringCompare(recordAllocated, "yes", kJFalse) == 0) { const JCharacter* tableType = getenv("JMM_TABLE_TYPE"); JCharacter* recordDeallocated = getenv("JMM_RECORD_DEALLOCATED"); JBoolean recordDeallocatedFlag = kJFalse; if (recordDeallocated != NULL && JStringCompare(recordDeallocated, "yes", kJFalse) == 0) { recordDeallocatedFlag = kJTrue; } if (tableType != NULL && JStringCompare(tableType, "array", kJFalse) == 0) { itsMemoryTable = new(__FILE__, __LINE__) JMMArrayTable(this, recordDeallocatedFlag); } else { itsMemoryTable = new(__FILE__, __LINE__) JMMHashTable(this, recordDeallocatedFlag); } assert(itsMemoryTable != NULL); } // JMM_PIPE done in Instance() atexit(::JMMHandleExit); }
JBoolean JGetUserMountPointList ( JMountPointList* list, JMountState* state ) { time_t t; if (state != NULL && (!(JGetModificationTime(_PATH_FSTAB, &t)).OK() || t == state->modTime)) { return kJFalse; } list->CleanOut(); if (state != NULL) { state->modTime = t; } endfsent(); const JBoolean isRoot = JI2B( getuid() == 0 ); if (isRoot) { ACE_stat stbuf; while (const fstab* info = getfsent()) { if (JIsRootDirectory(info->fs_file) || strcmp(info->fs_type, FSTAB_SW) == 0) // swap partition { continue; } const JMountType type = JGetUserMountPointType(info->fs_file, info->fs_spec, info->fs_vfstype); if (type == kJUnknownMountType || ACE_OS::stat(info->fs_file, &stbuf) != 0) { continue; } JFileSystemType fsType = kOtherFSType; if (options.Contains("vfat")) { fsType = kVFATType; } JFileSystemType fsType = kOtherFSType; if (JStringCompare(info->fs_vfstype, "vfat", kJFalse) == 0) { fsType = kVFATType; } JString* path = jnew JString(info->fs_file); assert( path != NULL ); JString* devicePath = jnew JString(info->fs_spec); assert( devicePath != NULL ); list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType)); } } endfsent(); return kJTrue; }
JBoolean JXDockWidget::Dock ( JXWindow* w, const JBoolean reportError ) { if (itsChildPartition != NULL) { return kJFalse; } const JRect geom = GetApertureGlobal(); JPoint minSize; if (w->Dock(this, (GetWindow())->GetXWindow(), geom, &minSize)) { if (itsWindowList == NULL) { itsWindowList = new JPtrArray<JXWindow>(JPtrArrayT::kForgetAll); assert( itsWindowList != NULL ); } const JSize count = itsWindowList->GetElementCount(); assert( count == itsTabGroup->GetTabCount() ); const JCharacter* title = JXFileDocument::SkipNeedsSavePrefix(w->GetTitle()); JIndex index = count+1; for (JIndex i=1; i<=count; i++) { const JCharacter* t = JXFileDocument::SkipNeedsSavePrefix((itsWindowList->NthElement(i))->GetTitle()); if (JStringCompare(title, t, kJFalse) < 0) { index = i; break; } } itsWindowList->InsertAtIndex(index, w); ListenTo(w); UpdateMinSize(); itsTabGroup->InsertTab(index, w->GetTitle()); // Can't call ShowTab() because window might be partially constructed, // so Activate() could blow up. JXSelectTabTask* task = new JXSelectTabTask(itsTabGroup, index); assert( task != NULL ); (JXGetApplication())->InstallUrgentTask(task); return kJTrue; } else { if (reportError) { (JGetUserNotification())->ReportError(JGetString(kWindowWillNotFitID)); } return kJFalse; } }
JBoolean JSearchSubdirs_private ( const JCharacter* startPath, const JCharacter* name, const JBoolean isFile, const JBoolean caseSensitive, JString* path, JString* newName, JProgressDisplay& pg, JBoolean* cancelled ) { // checking this way covers partial path cases like "X11/Xlib.h" const JString fullName = JCombinePathAndName(startPath, name); if (( isFile && JFileExists(fullName)) || (!isFile && JDirectoryExists(fullName))) { const JBoolean ok = JGetTrueName(startPath, path); assert( ok ); if (newName != NULL) { *newName = name; } return kJTrue; } JDirInfo* info; if (!JDirInfo::Create(startPath, &info)) { return kJFalse; } JBoolean found = kJFalse; const JSize count = info->GetEntryCount(); // check each entry (if case sensitive, the initial check is enough) if (!caseSensitive) { for (JIndex i=1; i<=count; i++) { const JDirEntry& entry = info->GetEntry(i); if ((( isFile && entry.IsFile()) || (!isFile && entry.IsDirectory())) && JStringCompare(name, entry.GetName(), caseSensitive) == 0) { const JBoolean ok = JGetTrueName(startPath, path); assert( ok ); if (newName != NULL) { *newName = entry.GetName(); } found = kJTrue; break; } if (!pg.IncrementProgress()) { *cancelled = kJTrue; break; } } } // recurse on each directory if (!found && !(*cancelled)) { for (JIndex i=1; i<=count; i++) { const JDirEntry& entry = info->GetEntry(i); if (entry.IsDirectory() && !entry.IsLink()) { const JString& newPath = entry.GetFullName(); if (JSearchSubdirs_private(newPath, name, isFile, caseSensitive, path, newName, pg, cancelled)) { found = kJTrue; break; } } if (*cancelled || (caseSensitive && !pg.IncrementProgress())) { *cancelled = kJTrue; break; } } } delete info; return found; }
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 JIsMounted ( const JCharacter* path, JBoolean* writable, JBoolean* isTop, JString* device, JFileSystemType* fsType, JString* fsTypeString ) { struct stat stbuf1, stbuf2; if (stat(path, &stbuf1) != 0) { return kJFalse; } JBoolean isMounted = kJFalse; struct statfs* info; const JSize count = getmntinfo(&info, MNT_WAIT); JString p; for (JIndex i=0; i<count; i++) { if (strcmp(info[i].f_mntonname, "/") != 0 && stat(info[i].f_mntonname, &stbuf2) == 0 && stbuf1.st_dev == stbuf2.st_dev) { isMounted = kJTrue; if (writable != NULL) { *writable = JNegate((info[i].f_flags & MNT_RDONLY) != 0); } if (isTop != NULL) { *isTop = JI2B(stbuf1.st_ino == stbuf2.st_ino); } if (device != NULL) { *device = info[i].f_mntfromname; } if (fsType != NULL) { *fsType = kOtherFSType; if (JStringCompare(info[i].f_fstypename, "vfat", kJFalse) == 0 || // UNIX JStringCompare(info[i].f_fstypename, "msdos", kJFalse) == 0) // OSX { *fsType = kVFATType; } } if (fsTypeString != NULL) { *fsTypeString = info[i].f_fstypename; } break; } } return isMounted; }
JBoolean JGetUserMountPointList ( JMountPointList* list, JMountState* state ) { time_t t; if (state != NULL && (!(JGetModificationTime(kAvailInfoName, &t)).OK() || t == state->modTime)) { return kJFalse; } list->CleanOut(); if (state != NULL) { state->modTime = t; } FILE* f = setmntent(kAvailInfoName, "r"); if (f == NULL) { return kJTrue; // did clear list } const JBoolean isRoot = JI2B( getuid() == 0 ); ACE_stat stbuf; while (const mntent* info = getmntent(f)) { if (!(isRoot || hasmntopt(info, "user") != NULL || hasmntopt(info, "users") != NULL || hasmntopt(info, "pamconsole") != NULL || (jUserOwnsDevice(info->mnt_fsname) && hasmntopt(info, "owner") != NULL)) || JIsRootDirectory(info->mnt_dir) || strcmp(info->mnt_type, MNTTYPE_SWAP) == 0) { continue; } const JMountType type = JGetUserMountPointType(info->mnt_dir, info->mnt_fsname, info->mnt_type); if (type == kJUnknownMountType || ACE_OS::stat(info->mnt_dir, &stbuf) != 0) { continue; } JFileSystemType fsType = kOtherFSType; if (JStringCompare(info->mnt_type, "vfat", kJFalse) == 0) { fsType = kVFATType; } JString* path = jnew JString(info->mnt_dir); assert( path != NULL ); JString* devicePath = jnew JString(info->mnt_fsname); assert( devicePath != NULL ); list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType)); } endmntent(f); return kJTrue; }
JBoolean JGetUserMountPointList ( JMountPointList* list, JMountState* state ) { time_t t; if (state != NULL && (!(JGetModificationTime(kAvailInfoName, &t)).OK() || t == state->modTime)) { return kJFalse; } list->CleanOut(); if (state != NULL) { state->modTime = t; } FILE* f = fopen(kAvailInfoName, "r"); if (f == NULL) { return kJTrue; // did clear list } const JBoolean isRoot = JI2B( getuid() == 0 ); if (isRoot) { ACE_stat stbuf; vfstab info; while (getvfsent(f, &info) == 0) { if (JIsRootDirectory(info.vfs_mountp) || strcmp(info.vfs_fstype, "swap") == 0) { continue; } const JMountType type = JGetUserMountPointType(info.vfs_mountp, info.vfs_special, info.vfs_fstype); if (type == kJUnknownMountType || ACE_OS::stat(info.vfs_mountp, &stbuf) != 0) { continue; } JFileSystemType fsType = kOtherFSType; if (JStringCompare(info.fs_vfstype, "vfat", kJFalse) == 0) { fsType = kVFATType; } JString* path = jnew JString(info.vfs_mountp); assert( path != NULL ); JString* devicePath = jnew JString(info.vfs_special); assert( devicePath != NULL ); list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType)); } } fclose(f); return kJTrue; }
JBoolean JIsMounted ( const JCharacter* path, JBoolean* writable, JBoolean* isTop, JString* device, JFileSystemType* fsType, JString* fsTypeString ) { struct stat stbuf1, stbuf2; if (stat(path, &stbuf1) != 0) { return kJFalse; } FILE* f = setmntent(kMountedInfoName, "r"); if (f == NULL) { return kJFalse; } JBoolean isMounted = kJFalse; JString p; while (const mntent* info = getmntent(f)) { if (strcmp(info->mnt_dir, "/") != 0 && stat(info->mnt_dir, &stbuf2) == 0 && stbuf1.st_dev == stbuf2.st_dev) { isMounted = kJTrue; if (writable != NULL) { *writable = JI2B(hasmntopt(info, MNTOPT_RO) == NULL); } if (isTop != NULL) { *isTop = JI2B(stbuf1.st_ino == stbuf2.st_ino); } if (device != NULL) { *device = info->mnt_fsname; } if (fsType != NULL) { *fsType = kOtherFSType; if (JStringCompare(info->mnt_type, "vfat", kJFalse) == 0) { *fsType = kVFATType; } } if (fsTypeString != NULL) { *fsTypeString = info->mnt_type; } break; } } endmntent(f); return isMounted; }
JBoolean JXTextMenuData::ParseNMShortcut ( JString* str, int* key, JXKeyModifiers* modifiers ) { JIndex i; JString keyStr(*str); modifiers->Clear(); // decode modifiers while (1) { JBoolean found = kJFalse; for (i=0; i<kNMModConvCount; i++) { if (keyStr.BeginsWith(kNMModConv[i].str) && keyStr.GetLength() > kNMModConv[i].strLength) { const JXModifierKey key = JXMenu::AdjustNMShortcutModifier(kNMModConv[i].key); if (!modifiers->Available(key)) { return kJFalse; } if (key != kNMModConv[i].key) { AdjustNMShortcutString(str, i, key); } keyStr.RemoveSubstring(1, kNMModConv[i].strLength); modifiers->SetState(key, kJTrue); found = kJTrue; break; } } if (!found) { break; } } // translate known name to single character for (i=0; i<kNMKeyConvCount; i++) { if (JStringCompare(keyStr, kNMKeyConv[i].str, kJFalse) == 0) { const int k = kNMKeyConv[i].key; if (0 < k && k <= (int) UCHAR_MAX) { const JCharacter s[2] = { k, '\0' }; keyStr = s; break; // extra processing below } else { *key = k; return kJTrue; } } } // check for single character const int c1 = (unsigned char) keyStr.GetFirstCharacter(); if (keyStr.GetLength() == 1) { if (!isalpha(c1) && !iscntrl(c1)) { // can't complain because of menu_strings file modifiers->SetState(kJXShiftKeyIndex, kJFalse); } *key = tolower(c1); return kJTrue; } // check for function key JSize fnIndex; if (c1 == 'F' && JString::ConvertToUInt(keyStr.GetCString()+1, &fnIndex) && 1 <= fnIndex && fnIndex <= 35) { *key = XK_F1 + fnIndex-1; return kJTrue; } // give up return kJFalse; }