示例#1
0
JArray<JTEStyler::TokenData>*
JTEStyler::NewTokenStartList()
{
	JArray<TokenData>* list = new JArray<TokenData>(kListBlockSize);
	assert( list != NULL );
	list->SetSortOrder(JOrderedSetT::kSortAscending);
	list->SetCompareFunction(CompareTokenStarts);
	return list;
}
static JBoolean
jGetUserInfo
	(
	const uid_t uid,
	jUIDInfo*	info
	)
{
	if (theUserInfoMap.IsEmpty())
		{
		theUserInfoMap.SetCompareFunction(jCompareUIDs);
		theUserInfoMap.SetSortOrder(JOrderedSetT::kSortAscending);
		atexit(jCleanUserInfoMap);
		}

	const jUIDInfo target = { uid, NULL, NULL };
	JIndex i;
	if (theUserInfoMap.SearchSorted(target, JOrderedSetT::kAnyMatch, &i))
		{
		*info = theUserInfoMap.GetElement(i);
		}
	else
		{
		passwd* pwbuf = getpwuid(uid);
		if (pwbuf != NULL)
			{
			info->userName = new JString(pwbuf->pw_name);
			assert( info->userName != NULL );

			info->realName = new JString(pwbuf->pw_gecos);
			assert( info->realName != NULL );

			info->homeDirectory = new JString(pwbuf->pw_dir);
			assert( info->homeDirectory != NULL );

			info->shell = new JString(pwbuf->pw_shell);
			assert( info->shell != NULL );

			info->id = uid;
			const JBoolean inserted = theUserInfoMap.InsertSorted(*info, kJFalse);
			assert( inserted );
			}
		else
			{
			info->userName = info->realName = info->homeDirectory = info->shell = NULL;
			}
		}

	return JI2B( info->userName != NULL );
}
JBoolean
CBSymbolList::ClosestMatch
	(
	const JString&	prefixStr,
	JArray<JIndex>&	visibleList,
	JIndex*			index
	)
	const
{
	visibleList.SetCompareObject(ClosestMatchCompare(prefixStr, *itsSymbolList));
	visibleList.SetSortOrder(itsSymbolList->GetSortOrder());

	JBoolean found;
	*index = visibleList.SearchSorted1(0, JOrderedSetT::kFirstMatch, &found);
	if (*index > visibleList.GetElementCount())		// insert beyond end of list
		{
		*index = visibleList.GetElementCount();
		}

	return JConvertToBoolean( *index > 0 );
}
static JBoolean
jGetGroupInfo
	(
	const gid_t	gid,
	jGIDInfo*	info
	)
{
	if (groupInfoMap.IsEmpty())
		{
		groupInfoMap.SetCompareFunction(jCompareGIDs);
		groupInfoMap.SetSortOrder(JOrderedSetT::kSortAscending);
		}

	const jGIDInfo target = { gid, NULL };
	JIndex i;
	if (groupInfoMap.SearchSorted(target, JOrderedSetT::kAnyMatch, &i))
		{
		*info = groupInfoMap.GetElement(i);
		}
	else
		{
		group* grpbuf = getgrgid(gid);
		if (grpbuf != NULL)
			{
			info->groupName = new JString(grpbuf->gr_name);
			assert( info->groupName != NULL );

			info->id = gid;
			const JBoolean inserted = groupInfoMap.InsertSorted(*info, kJFalse);
			assert( inserted );
			}
		else
			{
			info->groupName = NULL;
			}
		}

	return JI2B( info->groupName != NULL );
}