Exemple #1
0
JBoolean
CBFileNode::ParseFiles
	(
	CBFileListTable*			parser,
	const JPtrArray<JString>&	allSuffixList,
	CBSymbolList*				symbolList,
	CBCTree*					cTree,
	CBJavaTree*					javaTree,
	CBPHPTree*					phpTree,
	JProgressDisplay&			pg
	)
	const
{
	JString fullName, trueName;
	if (GetFullName(&fullName) && JGetTrueName(fullName, &trueName))
		{
		if (!ParseFile(trueName, parser, allSuffixList, symbolList, cTree, javaTree, phpTree, pg))
			{
			return kJFalse;
			}

		const CBTextFileType type = (CBGetPrefsManager())->GetFileType(trueName);
		if ((CBGetDocumentManager())->GetComplementFile(trueName, type, &fullName,
														GetProjectDoc(), kJFalse) &&
			JGetTrueName(fullName, &trueName) &&
			!ParseFile(trueName, parser, allSuffixList, symbolList, cTree, javaTree, phpTree, pg))
			{
			return kJFalse;
			}
		}
	return CBFileNodeBase::ParseFiles(parser, allSuffixList, symbolList, cTree, javaTree, phpTree, pg);
}
void
CBFileListTable::ScanDirectory
	(
	const JString&				origPath,
	const JBoolean				recurse,
	const JPtrArray<JString>&	allSuffixList,
	CBSymbolList*				symbolList,
	CBCTree*					cTree,
	CBJavaTree*					javaTree,
	JProgressDisplay&			pg
	)
{
	JString path;
	JDirInfo* info;
	if (!JGetTrueName(origPath, &path) ||
		!JDirInfo::Create(path, &info))
		{
		return;
		}

	const JSize count = info->GetEntryCount();
	for (JIndex i=1; i<=count; i++)
		{
		const JDirEntry& entry = info->GetEntry(i);

		// If it's a directory, recurse.

		if (entry.IsDirectory() && recurse &&
			!entry.IsLink() && !JIsVCSDirectory(entry.GetName()))
			{
			ScanDirectory(entry.GetFullName(), recurse,
						  allSuffixList, symbolList,
						  cTree, javaTree,
						  pg);
			}

		// If it's a file ending in one of the suffixes, parse it.

		else if (entry.IsFile())
			{
			JString trueName = entry.GetFullName();
			time_t modTime   = entry.GetModTime();
			if (entry.IsWorkingLink())
				{
				const JBoolean ok = JGetTrueName(entry.GetFullName(), &trueName);
				assert( ok );
				const JError err = JGetModificationTime(trueName, &modTime);
				assert( err.OK() );
				}

			ParseFile(trueName, allSuffixList, modTime,
					  symbolList, cTree, javaTree);
			}

		pg.IncrementProgress();
		}

	delete info;
}
JBoolean
SVNWDManager::GetBrowser
	(
	const JCharacter*	path,
	SVNMainDirector**	dir
	)
{
	*dir = NULL;

	JString p1;
	JBoolean isURL = JIsURL(path);
	if (isURL)
		{
		p1 = path;
		JAppendDirSeparator(&p1);
		}
	else if (!JGetTrueName(path, &p1))
		{
		return kJFalse;
		}

	JPtrArray<JXWindowDirector> windowList(JPtrArrayT::kForgetAll);
	GetDirectors(&windowList);

	const JSize windowCount = windowList.GetElementCount();
	JString p2, p3;
	for (JIndex i=1; i<=windowCount; i++)
		{
		SVNMainDirector* d = dynamic_cast<SVNMainDirector*>(windowList.NthElement(i));
		if (d == NULL)
			{
			continue;
			}

		if (isURL && d->GetRepoPath(&p2))
			{
			JAppendDirSeparator(&p2);
			if (p1.BeginsWith(p2))
				{
				*dir = d;
				break;
				}
			}
		else if (!isURL && d->GetPath(&p3) &&
				 (JSameDirEntry(p1, p3) ||
				  (JGetTrueName(p3, &p2) && p1.BeginsWith(p2))))
			{
			*dir = d;
			break;
			}
		}

	return JI2B( *dir != NULL );
}
JBoolean
JTranslateLocalToRemote
	(
	const JCharacter*	localPathStr,
	JString*			host,
	JString*			remotePath
	)
{
	host->Clear();
	remotePath->Clear();

	JString localPath;
	FILE* f = setmntent(kMountedInfoName, "r");
	if (f == NULL || !JGetTrueName(localPathStr, &localPath))
		{
		return kJFalse;
		}

	JBoolean found = kJFalse;
	while (const mntent* info = getmntent(f))
		{
		if (jTranslateLocalToRemote1(localPath, info->mnt_fsname,
									 info->mnt_dir,
									 &found, host, remotePath))
			{
			break;		// localPath only on one partition
			}
		}

	endmntent(f);
	return found;
}
JBoolean
JTranslateLocalToRemote
	(
	const JCharacter*	localPathStr,
	JString*			host,
	JString*			remotePath
	)
{
	host->Clear();
	remotePath->Clear();

	JString localPath;
	FILE* f = fopen(kMountedInfoName, "r");
	if (f == NULL || !JGetTrueName(localPathStr, &localPath))
		{
		return kJFalse;
		}

	JBoolean found = kJFalse;
	mnttab info;
	while (getmntent(f, &info) == 0)
		{
		if (jTranslateLocalToRemote1(localPath, info.mnt_special,
									 info.mnt_mountp,
									 &found, host, remotePath))
			{
			break;		// localPath only on one partition
			}
		}

	fclose(f);
	return found;
}
JBoolean
JTranslateLocalToRemote
	(
	const JCharacter*	localPathStr,
	JString*			host,
	JString*			remotePath
	)
{
	host->Clear();
	remotePath->Clear();

	JString localPath;
	if (!JGetTrueName(localPathStr, &localPath))
		{
		return kJFalse;
		}

	struct statfs* info;
	const JSize count = getmntinfo(&info, MNT_WAIT);

	JBoolean found = kJFalse;
	for (JIndex i=0; i<count; i++)
		{
		if (jTranslateLocalToRemote1(localPath, info[i].f_mntfromname,
									 info[i].f_mntonname,
									 &found, host, remotePath))
			{
			break;		// localPath only on one partition
			}
		}

	return found;
}
JBoolean
JGetTrueName
	(
	const JCharacter*	name,
	JString*			trueName
	)
{
	trueName->Clear();

	if (!JNameUsed(name))
		{
		return kJFalse;
		}

	// check if it is a directory

	else if (JDirectoryExists(name))
		{
		const JString currPath = JGetCurrentDirectory();

		JError err = JChangeDirectory(name);
		if (!err.OK())
			{
			return kJFalse;
			}

		*trueName = JGetCurrentDirectory();

		err = JChangeDirectory(currPath);
		assert_ok( err );

		return kJTrue;
		}

	// it is a file, socket, fifo, etc.

	else
		{
		JString origPath, fileName;
		JSplitPathAndName(name, &origPath, &fileName);

		// get true directory

		JString truePath;
		if (!JGetTrueName(origPath, &truePath))
			{
			return kJFalse;
			}

		// resolve symbolic link

		JString target;
		if ((JGetSymbolicLinkTarget(name, &target)).OK())
			{
			if (JIsRelativePath(target))
				{
				target.Prepend(truePath);
				}
			return JGetTrueName(target, trueName);
			}
		else
			{
			*trueName = JCombinePathAndName(truePath, fileName);
			return kJTrue;
			}
		}
}
JBoolean
SyGApplication::OpenDirectory
	(
	const JString&	pathName,
	SyGTreeDir**	dir,
	JIndex*			row,
	const JBoolean	deiconify,
	const JBoolean	reportError,
	const JBoolean	forceNew,
	const JBoolean	clearSelection
	)
{
	if (dir != NULL)
		{
		*dir = NULL;
		}

	if (row != NULL)
		{
		*row = 0;
		}

	JString fixedName, trueName;
	if (!JExpandHomeDirShortcut(pathName, &fixedName) ||
		!JConvertToAbsolutePath(fixedName, NULL, &trueName))
		{
		if (reportError)
			{
			JString msg = "\"";
			msg += pathName;
			msg += "\" does not exist.";
			(JGetUserNotification())->ReportError(msg);
			}
		return kJFalse;
		}

	// if file, select it after opening the window

	JString selectName;
	if (JFileExists(trueName) ||
		!JDirectoryExists(trueName))	// broken link
		{
		JStripTrailingDirSeparator(&trueName);
		JString path;
		JSplitPathAndName(trueName, &path, &selectName);
		trueName = path;
		}

	// can't check this until after making sure that trueName is directory

	if (!JFSFileTreeNode::CanHaveChildren(trueName))
		{
		if (reportError)
			{
			JString msg = "Unable to read contents of \"";
			msg += pathName;
			msg += "\"";
			(JGetUserNotification())->ReportError(msg);
			}
		return kJFalse;
		}

	// resolve all .. in path

	JIndex i;
	JString p, p1;
	while (trueName.LocateSubstring("..", &i))
		{
		p = trueName.GetSubstring(1, i+1);
		if (!JGetTrueName(p, &p1))
			{
			if (reportError)
				{
				JString msg = "\"";
				msg += p;
				msg += "\" does not exist.";
				(JGetUserNotification())->ReportError(msg);
				}
			return kJFalse;
			}

		trueName.ReplaceSubstring(1, i+1, p1);
		}

	// check if window is already open

	JString ancestor = trueName, n;
	JPtrArray<JString> pathList(JPtrArrayT::kDeleteAll);
	while (!JIsRootDirectory(ancestor))
		{
		const JIndex count = itsWindowList->GetElementCount();
		for (JIndex i=1; i<=count; i++)
			{
			const JString name = (itsWindowList->NthElement(i))->GetDirectory();
			if (JSameDirEntry(name, ancestor))
				{
				SyGTreeDir* childDir = itsWindowList->NthElement(i);
				childDir->Activate();
				if (dir != NULL)
					{
					*dir = childDir;
					}

				JPoint cell;
				(childDir->GetTable())->SelectName(pathList, selectName, &cell, clearSelection);
				if (row != NULL)
					{
					*row = cell.y;
					}

				return kJTrue;
				}
			}

		if (forceNew)
			{
			break;
			}

		JStripTrailingDirSeparator(&ancestor);
		JSplitPathAndName(ancestor, &p, &n);
		ancestor = p;
		pathList.Prepend(n);
		}

	// create new window

	fixedName = trueName;
	JGetTrueName(fixedName, &trueName);

	SyGTreeDir* childDir = new SyGTreeDir(trueName);
	assert( childDir != NULL );

	childDir->Activate();

	JPoint cell;
	(childDir->GetTable())->SelectName(selectName, NULL, &cell);
	if (row != NULL)
		{
		*row = cell.y;
		}

	if (deiconify)
		{
		childDir->GetWindow()->Deiconify();
		}
	itsWindowList->Append(childDir);

	if (dir != NULL)
		{
		*dir = childDir;
		}
	return kJTrue;
}
JBoolean
JXDocumentManager::FindFile
	(
	const JCharacter*	fileName,
	const JCharacter*	currPath,
	JString*			newFileName,
	const JBoolean		askUser
	)
	const
{
	// if the file exists, we are done

	if (JFileExists(fileName))
		{
		*newFileName = fileName;
		return kJTrue;
		}

	// search the directory tree below currPath

	JString path, name, newPath;
	JSplitPathAndName(fileName, &path, &name);

	if (JSearchSubdirs(currPath, name, kJTrue, kJTrue, &newPath))
		{
		*newFileName = newPath + name;
		return kJTrue;
		}

	// check for known case of move/rename

	if (SearchFileMap(fileName, newFileName))
		{
		return kJTrue;
		}

	// ask the user to find it

	if (askUser)
		{
		JString instrMsg = "Unable to locate ";
		instrMsg += fileName;
		instrMsg += "\n\nPlease find it.";

		while ((JGetChooseSaveFile())->ChooseFile("New name of file:", instrMsg, newFileName))
			{
			JString newPath, newName;
			JSplitPathAndName(*newFileName, &newPath, &newName);
			if (newName != name)
				{
				JString warnMsg = name;
				warnMsg += " was requested.\n\nYou selected ";
				warnMsg += newName;
				warnMsg += ".\n\nAre you sure that this is correct?";
				if (!(JGetUserNotification())->AskUserNo(warnMsg))
					{
					continue;
					}
				}

			JString trueName;
			const JBoolean ok = JGetTrueName(*newFileName, &trueName);
			assert( ok );

			FileMap map;
			map.oldName = new JString(fileName);
			assert( map.oldName != NULL );
			map.newName = new JString(trueName);
			assert( map.newName != NULL );
			itsFileMap->AppendElement(map);

			*newFileName = trueName;
			return kJTrue;
			}
		}

	newFileName->Clear();
	return kJFalse;
}
Exemple #10
0
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;
}