コード例 #1
0
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();
		}
}
コード例 #2
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;
		}
}
コード例 #3
0
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)));
}
コード例 #4
0
JBoolean
JProgramAvailable
	(
	const JCharacter*	programName,
	JString*			fixedName
	)
{
	if (JStringEmpty(programName) ||
		!JExpandHomeDirShortcut(programName, fixedName))
		{
		return kJFalse;
		}

	if (fixedName->GetFirstCharacter() == '/')
		{
		return JFileExecutable(*fixedName);
		}

	JString fullName = programName;
	if (fullName.Contains("/"))
		{
		const JString dir = JGetCurrentDirectory();
		fullName          = JCombinePathAndName(dir, fullName);
		return JFileExecutable(fullName);
		}

	// check each directory in the exec path list

	const JCharacter* cpath = getenv("PATH");

	JString path(cpath == NULL ? "" : cpath);
	if (theIncludeCWDOnPathFlag)
		{
		path.Prepend(".:");
		}

	if (path.IsEmpty())
		{
		return kJFalse;
		}

	JIndex colonIndex;
	while (path.LocateSubstring(":", &colonIndex))
		{
		if (colonIndex > 1)
			{
			const JString dir = path.GetSubstring(1, colonIndex-1);
			fullName          = JCombinePathAndName(dir, programName);
			if (JFileExists(fullName) && JFileExecutable(fullName))
				{
				if (dir == ".")
					{
					fixedName->Prepend("./");	// in case we added this to PATH
					}
				return kJTrue;
				}
			}

		path.RemoveSubstring(1, colonIndex);
		}

	if (path.IsEmpty())
		{
		return kJFalse;
		}

	fullName = JCombinePathAndName(path, programName);
	return JFileExecutable(fullName);
}
コード例 #5
0
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);
}