Пример #1
0
JBoolean
jSearchVCSRoot
	(
	const JCharacter*	path,
	const JCharacter*	vcsDirName,
	JString*			vcsRoot
	)
{
	JString p = path, n;
	if (JFileExists(path) ||
		!JDirectoryExists(path))	// broken link
		{
		JSplitPathAndName(path, &p, &n);
		}

	do
		{
		n = JCombinePathAndName(p, vcsDirName);
		if (JDirectoryExists(n))
			{
			*vcsRoot = p;
			return kJTrue;
			}

		JSplitPathAndName(p, &p, &n);
		}
		while (!JIsRootDirectory(p));

	vcsRoot->Clear();
	return kJFalse;
}
Пример #2
0
JError
JCreateDirectory
	(
	const JCharacter*	dirName,
	const mode_t		mode
	)
{
	if (JDirectoryExists(dirName))
		{
		return JSetPermissions(dirName, mode);
		}

	JString path = dirName;
	JCleanPath(&path);
	JAppendDirSeparator(&path);

	JString dir;
	JIndex slashIndex = 2;
	while (path.LocateNextSubstring("/", &slashIndex))
		{
		dir = path.GetSubstring(1, slashIndex);
		if (!JDirectoryExists(dir))
			{
			const JError err = JMkDir(dir, mode);
			if (!err.OK())
				{
				return err;
				}
			}
		slashIndex++;	// move past the slash we found
		}

	return JNoError();
}
Пример #3
0
JVCSType
JGetVCSType
	(
	const JCharacter*	path,
	const JBoolean		deepInspection
	)
{
	JString p = path, n;
	if (JFileExists(path) ||
		!JDirectoryExists(path))	// broken link
		{
		JSplitPathAndName(path, &p, &n);
		}

	// can't read newer versions

	JString vcsDir = JCombinePathAndName(p, kSubversionDirName);
	vcsDir         = JCombinePathAndName(vcsDir, kSubversionFileName);
	if (JFileExists(vcsDir))
		{
		if (!deepInspection)
			{
			return kJSVNType;
			}

		JSize size;
		const JError err = JGetFileLength(vcsDir, &size);
		if (err.OK() && size > 10)
			{
			return kJSVNType;
			}
		}

	vcsDir = JCombinePathAndName(p, kCVSDirName);
	if (JDirectoryExists(vcsDir))
		{
		return kJCVSType;
		}

	vcsDir = JCombinePathAndName(p, kSCCSDirName);
	if (JDirectoryExists(vcsDir))
		{
		return kJSCCSType;
		}

	// check git & new svc last, since they need to search directory tree up to root

	if (JSearchGitRoot(p, &n))
	{
		return kJGitType;
	}
	else if (!deepInspection && jSearchVCSRoot(p, kSubversionDirName, &n))
	{
		return kJSVNType;
	}

	return kJUnknownVCSType;
}
JBoolean
JXGetNewDirDialog::OKToDeactivate()
{
	if (!JXGetStringDialog::OKToDeactivate())
		{
		return kJFalse;
		}
	else if (Cancelled())
		{
		return kJTrue;
		}

	const JString pathName = GetNewDirName();
	if (JDirectoryExists(pathName))
		{
		(JGetUserNotification())->ReportError(JGetString(kDirectoryExistsID));
		return kJFalse;
		}
	else if (JNameUsed(pathName))
		{
		(JGetUserNotification())->ReportError(JGetString(kNameUsedID));
		return kJFalse;
		}
	else
		{
		return kJTrue;
		}
}
Пример #5
0
JBoolean
GMApp::NewMailbox
	(
	const JCharacter*	filename,
	const JBoolean		openFile
	)
{
	JString path;
	JString name;
	JSplitPathAndName(filename, &path, &name);
	if (path.IsEmpty())
		{
		path = JGetCurrentDirectory();
		}
	if (!(JDirectoryExists(path) && JDirectoryReadable(path)))
		{
		JString notice = "You do not have write permissions in directory \"" + path + "\"";
		JGetUserNotification()->ReportError(notice);
		return kJFalse;
		}
	ofstream os(filename);
	if (!os.good())
		{
		JString notice = "Unable to create file \"" + path + name + "\"";
		JGetUserNotification()->ReportError(notice);
		return kJFalse;
		}
	os.close();
	if (openFile)
		{
		OpenMailbox(filename);
		}
	return kJTrue;
}
JBoolean
JDirInfo::ForceUpdate()
{
	if (JDirectoryExists(*itsCWD))
		{
		Broadcast(ContentsWillBeUpdated());

		const JError err = BuildInfo();
		if (err.OK())
			{
			return kJTrue;
			}
		}

	if (itsSwitchIfInvalidFlag)
		{
		JString path;
		if (!JGetHomeDirectory(&path) || !OKToCreate(path))
			{
			path = JGetRootDirectory();
			}
		GoTo(path);
		}
	else
		{
		itsIsValidFlag    = kJFalse;
		itsIsWritableFlag = kJFalse;
		itsDirEntries->CleanOut();
		itsVisEntries->CleanOut();
		itsAlphaEntries->CleanOut();
		}

	return kJFalse;
}
Пример #7
0
JBoolean
JDirectoryWritable
	(
	const JCharacter* dirName
	)
{
	return JI2B(JDirectoryExists(dirName) &&
				(getuid() == 0 || access(dirName, W_OK) == 0));
}
Пример #8
0
JBoolean
JCanEnterDirectory
	(
	const JCharacter* dirName
	)
{
	return JI2B(JDirectoryExists(dirName) &&
				(getuid() == 0 || access(dirName, X_OK) == 0));
}
JBoolean
JDirInfo::OKToCreate
	(
	const JCharacter* dirName
	)
{
	return JConvertToBoolean( JDirectoryExists(dirName) &&
							  JDirectoryReadable(dirName) &&
							  JCanEnterDirectory(dirName) );
}
Пример #10
0
JBoolean
JGetHomeDirectory
	(
	JString* homeDir
	)
{
	// try HOME environment variable

	char* envHomeDir = getenv("HOME");
	if (envHomeDir != NULL && JDirectoryExists(envHomeDir))
		{
		*homeDir = envHomeDir;
		JAppendDirSeparator(homeDir);
		return kJTrue;
		}

	// try password information

	char* envUserName = getenv("USER");

	struct passwd* pw;
	if (envUserName != NULL)
		{
		pw = getpwnam(envUserName);
		}
	else
		{
		pw = getpwuid( getuid() );
		}

	if (pw != NULL && JDirectoryExists(pw->pw_dir))
		{
		*homeDir = pw->pw_dir;
		JAppendDirSeparator(homeDir);
		return kJTrue;
		}

	// give up

	homeDir->Clear();
	return kJFalse;
}
Пример #11
0
JBoolean
SyGGetTrashDirectory
	(
	JString*		path,
	const JBoolean	reportErrors
	)
{
	if (!theTrashDir.IsEmpty())
		{
		*path = theTrashDir;
		return kJTrue;
		}

	if (!JGetPrefsDirectory(path))
		{
		if (reportErrors)
			{
			(JGetUserNotification())->ReportError(JGetString(kNoPrefsDirID));
			}
		return kJFalse;
		}

	*path = JCombinePathAndName(*path, kTrashDirName);

	JError err = JNoError();
	if (!JDirectoryExists(*path))
		{
		err = JCreateDirectory(*path, kTrashCanPerms);
		}
	else
		{
		err = JSetPermissions(*path, kTrashCanPerms);
		}

	if (err.OK())
		{
		theTrashDir       = *path;
		const JBoolean ok = JDirInfo::Create(theTrashDir, &theTrashDirInfo);
		assert( ok );
		return kJTrue;
		}
	else
		{
		path->Clear();
		if (reportErrors)
			{
			(JGetStringManager())->ReportError(kCreateTrashErrorID, err);
			}
		return kJFalse;
		}
}
Пример #12
0
JBoolean
SyGGetRecentFileDirectory
	(
	JString*		path,
	const JBoolean	reportErrors
	)
{
	if (!theRecentFileDir.IsEmpty())
		{
		*path = theRecentFileDir;
		return kJTrue;
		}

	if (!JGetPrefsDirectory(path))
		{
		if (reportErrors)
			{
			(JGetUserNotification())->ReportError(JGetString(kNoPrefsDirID));
			}
		return kJFalse;
		}

	*path = JCombinePathAndName(*path, kRecentFileDirName);

	JError err = JNoError();
	if (!JDirectoryExists(*path))
		{
		err = JCreateDirectory(*path, kRecentFileDirPerms);
		}
	else
		{
		err = JSetPermissions(*path, kRecentFileDirPerms);
		}

	if (err.OK())
		{
		theRecentFileDir = *path;
		return kJTrue;
		}
	else
		{
		path->Clear();
		if (reportErrors)
			{
			(JGetStringManager())->ReportError(kCreateRecentFileDirErrorID, err);
			}
		return kJFalse;
		}
}
Пример #13
0
JBoolean
JXPathInput::GetPath
	(
	JString* path
	)
	const
{
	const JString& text = GetText();
	return JI2B(!text.IsEmpty() &&
				(JIsAbsolutePath(text) || HasBasePath()) &&
				JConvertToAbsolutePath(text, itsBasePath, path) &&
				JDirectoryExists(*path) &&
				JDirectoryReadable(*path) &&
				JCanEnterDirectory(*path) &&
				(!itsRequireWriteFlag || JDirectoryWritable(*path)));
}
Пример #14
0
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;
}
JXGetNewDirDialog::JXGetNewDirDialog
	(
	JXDirector*			supervisor,
	const JCharacter*	windowTitle,
	const JCharacter*	prompt,
	const JCharacter*	initialName,
	const JCharacter*	basePath,
	const JBoolean		modal
	)
	:
	JXGetStringDialog(supervisor, windowTitle, prompt, initialName, modal),
	itsBasePath(basePath)
{
	assert( JDirectoryExists(basePath) );

	(GetInputField())->SetCharacterInWordFunction(JXChooseSaveFile::IsCharacterInWord);
}
Пример #16
0
JBoolean
JXPathInput::GetDroppedDirectory
	(
	const Time		time,
	const JBoolean	reportErrors,
	JString*		dirName
	)
{
	dirName->Clear();

	JXSelectionManager* selMgr = GetSelectionManager();

	Atom returnType;
	unsigned char* data;
	JSize dataLength;
	JXSelectionManager::DeleteMethod delMethod;
	if (selMgr->GetData(GetDNDManager()->GetDNDSelectionName(),
						time, selMgr->GetURLXAtom(),
						&returnType, &data, &dataLength, &delMethod))
		{
		if (returnType == selMgr->GetURLXAtom())
			{
			JPtrArray<JString> fileNameList(JPtrArrayT::kDeleteAll),
							   urlList(JPtrArrayT::kDeleteAll);
			JXUnpackFileNames((char*) data, dataLength, &fileNameList, &urlList);
			if (fileNameList.GetElementCount() == 1 &&
				(JDirectoryExists(*(fileNameList.FirstElement())) ||
				 JFileExists(*(fileNameList.FirstElement()))))
				{
				*dirName = *(fileNameList.FirstElement());

				JString homeDir;
				if (JGetHomeDirectory(&homeDir) &&
					dirName->BeginsWith(homeDir))
					{
					dirName->ReplaceSubstring(1, homeDir.GetLength(), "~" ACE_DIRECTORY_SEPARATOR_STR);
					}
				}
			JXReportUnreachableHosts(urlList);
			}

		selMgr->DeleteData(&data, delMethod);
		}

	return !dirName->IsEmpty();
}
Пример #17
0
void
JEditVCS
	(
	const JCharacter* fullName
	)
{
	if (JFileExists(fullName) && !JFileWritable(fullName))
		{
		JString path, name;
		JSplitPathAndName(fullName, &path, &name);

		JString vcsDir = JCombinePathAndName(path, kCVSDirName);
		if (JDirectoryExists(vcsDir))
			{
			const JString cmd = "cd " + path + "; cvs edit " + name;
			system(cmd);
			}
		}
}
Пример #18
0
void
GMApp::OpenMailbox
	(
	const JCharacter*	filename,
	const JBoolean		beep,
	const JBoolean		iconify
	)
{
	if (JDirectoryExists(filename))
		{
		const JCharacter* map[] =
			{
			"dir", filename
			};
		const JString msg = JGetString("NameIsDirectoryNotFile::GMApp", map, sizeof(map));
		JGetUserNotification()->ReportError(msg);
		return;
		}
		
	if (MailboxOpen(filename, !iconify))
		{
		return;
		}

	JString mailbox(filename);
	JBoolean locked = FileLocked(mailbox, kJFalse);
	GMessageTableDir* dir;

	if (!locked)
		{
		if (GLockFile(mailbox) && GMessageTableDir::Create(this, mailbox, &dir, iconify))
			{
			itsTableDirs->Append(dir);
			GUnlockFile(mailbox);
			Broadcast(MailboxOpened(mailbox));
			if (beep && GGetPrefsMgr()->IsBeepingOnNewMail())
				{
				GetCurrentDisplay()->Beep();
				}
			}
		}
}
Пример #19
0
JBoolean
JGetHomeDirectory
	(
	const JCharacter*	user,
	JString*			homeDir
	)
{
	struct passwd* pw = getpwnam(user);
	if (pw != NULL && JDirectoryExists(pw->pw_dir))
		{
		*homeDir = pw->pw_dir;
		JAppendDirSeparator(homeDir);
		return kJTrue;
		}
	else
		{
		homeDir->Clear();
		return kJFalse;
		}
}
Пример #20
0
void
SVNTabBase::OpenFiles()
{
	JPtrArray<JString> list(JPtrArrayT::kDeleteAll);
	GetSelectedFiles(&list);

	JPtrArray<JString> pathList(JPtrArrayT::kDeleteAll);

	const JSize count = list.GetElementCount();
	for (JIndex i=count; i>=1; i--)
		{
		JString* s = list.NthElement(i);
		if (JDirectoryExists(*s))
			{
			pathList.Append(s);
			list.RemoveElement(i);
			}
		}

	(JXGetWebBrowser())->ShowFileLocations(pathList);
	JXFSBindingManager::Exec(list);
}
Пример #21
0
JBoolean
JXFileInput::GetDroppedFileName
	(
	const Time		time,
	const JBoolean	reportErrors,
	JString*		fileName
	)
{
	fileName->Clear();

	JXSelectionManager* selMgr = GetSelectionManager();

	Atom returnType;
	unsigned char* data;
	JSize dataLength;
	JXSelectionManager::DeleteMethod delMethod;
	if (selMgr->GetData((GetDNDManager())->GetDNDSelectionName(),
						time, selMgr->GetURLXAtom(),
						&returnType, &data, &dataLength, &delMethod))
		{
		if (returnType == selMgr->GetURLXAtom())
			{
			JPtrArray<JString> fileNameList(JPtrArrayT::kDeleteAll),
							   urlList(JPtrArrayT::kDeleteAll);
			JXUnpackFileNames((char*) data, dataLength, &fileNameList, &urlList);
			if (fileNameList.GetElementCount() == 1 &&
				(JFileExists(*(fileNameList.FirstElement())) ||
				 JDirectoryExists(*(fileNameList.FirstElement()))))
				{
				*fileName = *(fileNameList.FirstElement());
				}
			JXReportUnreachableHosts(urlList);
			}

		selMgr->DeleteData(&data, delMethod);
		}

	return JNegate( fileName->IsEmpty() );
}
Пример #22
0
JBoolean
JGetVCSRepositoryPath
	(
	const JCharacter*	origPath,
	JString*			repoPath
	)
{
	JString path = origPath, name;
	if (JFileExists(origPath) ||
		!JDirectoryExists(origPath))	// broken link
		{
		JSplitPathAndName(origPath, &path, &name);
		}

	const JVCSType type = JGetVCSType(path);
	JBoolean found      = kJFalse;
	if (type == kJCVSType)
		{
		const JString cvsPath = JCombinePathAndName(path, kCVSDirName);

		JString fullName = JCombinePathAndName(cvsPath, "Root");
		JReadFile(fullName, repoPath);

		fullName = JCombinePathAndName(cvsPath, "Repository");
		JString repo;
		JReadFile(fullName, &repo);

		if (!repoPath->IsEmpty() && !repo.IsEmpty())
			{
			*repoPath = JCombinePathAndName(*repoPath, repo);
			found = kJTrue;
			}
		}
	else if (type == kJSVNType)
		{
		JString entriesFileName, data;
		entriesFileName = JCombinePathAndName(path, kSubversionDirName);
		entriesFileName = JCombinePathAndName(entriesFileName, kSubversionFileName);
		JReadFile(entriesFileName, &data);

		if (data.BeginsWith("<?xml"))
			{
			JIndexRange range;
			JArray<JIndexRange> matchList;
			if (svn4RepositoryPattern1.Match(data, &range) &&
				svn4RepositoryPattern2.MatchWithin(data, range, &matchList))
				{
				*repoPath = data.GetSubstring(matchList.GetElement(2));
				found = kJTrue;
				}
			}
		else
			{
			std::istrstream input(data, data.GetLength());

			const JString version = JReadLine(input);
			if (version == "8" || version == "9" || version == "10")
				{
				JIgnoreLine(input);		// ???
				JIgnoreLine(input);		// dir
				JIgnoreLine(input);		// latest update version

				*repoPath = JReadLine(input);
				found     = JI2B(input.good());
				}
			}
		}

	if (found)
		{
		if (!name.IsEmpty())
			{
			*repoPath = JCombinePathAndName(*repoPath, name);
			}
		return kJTrue;
		}
	else
		{
		repoPath->Clear();
		return kJFalse;
		}
}
Пример #23
0
void
CBFileNode::CreateFilesForTemplate
	(
	istream&			input,
	const JFileVersion	vers
	)
	const
{
	CBFileNodeBase::CreateFilesForTemplate(input, vers);

	JBoolean exists;
	input >> exists;
	if (exists)
		{
		JString relName, data;
		input >> relName >> data;

		JString path, name;
		JSplitPathAndName(relName, &path, &name);

		const CBProjectTree* projTree = dynamic_cast<const CBProjectTree*>(GetTree());
		assert( projTree != NULL );

		const JString& basePath = (projTree->GetProjectDoc())->GetFilePath();
		path = JCombinePathAndName(basePath, path);

		JUserNotification* un = JGetUserNotification();
		if (!JDirectoryExists(path))
			{
			const JError err = JCreateDirectory(path);
			if (!err.OK())
				{
				JString msg = "Unable to create the file ";
				msg += relName;
				msg += " from the template because:\n\n";
				msg += err.GetMessage();
				un->ReportError(msg);
				return;
				}
			}

		const JString fullName = JCombinePathAndName(path, name);
		if (JFileExists(fullName))
			{
			JString msg = fullName;
			msg.PrependCharacter('"');
			msg += "\" already exists.  Do you want to overwrite it?";
			if (!un->AskUserNo(msg))
				{
				return;
				}
			}

		ofstream output(fullName);
		if (output.good())
			{
			data.Print(output);
			}
		else
			{
			JString msg = "Unable to create the file ";
			msg += relName;
			msg += " from the template.";
			un->ReportError(msg);
			}
		}
}
Пример #24
0
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;
			}
		}
}
Пример #25
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;
}
int
main
	(
	int		argc,
	char*	argv[]
	)
{
	// parse the command line options

	JPtrArray<JString> inputFileList(JPtrArrayT::kDeleteAll);
	JString dataVarName, outputFileName, databaseFileName;
	JBoolean debug;
	GetOptions(argc, argv, &inputFileList,
			   &dataVarName, &outputFileName, &databaseFileName, &debug);

	const JSize inputCount = inputFileList.GetElementCount();

	// check mod times of input files
/*
	This doesn't work because compiling different versions of the program
	requires different sets of string files, none of which may have been
	modified in a long time.  The output file still needs to be re-built,
	however!

	time_t outputTime;
	if ((JGetModificationTime(outputFileName, &outputTime)).OK())
		{
		JBoolean changed = kJFalse;

		for (JIndex i=1; i<=inputCount; i++)
			{
			const JString* inputFileName = inputFileList.NthElement(i);
			time_t t;
			if (!(JGetModificationTime(*inputFileName, &t)).OK())
				{
				cerr << argv[0] << ":  " << *inputFileName << " does not exist" << endl;
				return 1;
				}
			else if (t >= outputTime)
				{
				changed = kJTrue;
				break;
				}
			}

		if (!changed)
			{
			return 0;
			}
		}
*/
	// process the input files

	JStringManager mgr;

	for (JIndex i=1; i<=inputCount; i++)
		{
		const JString* inputFileName = inputFileList.NthElement(i);
		if (JDirectoryExists(*inputFileName))
			{
			continue;
			}

		ifstream input(*inputFileName);
		if (!input.good())
			{
			cerr << argv[0] << ":  unable to open " << *inputFileName << endl;
			return 1;
			}
		mgr.MergeFile(input, debug);
		if (input.fail())
			{
			cerr << argv[0] << ":  error while reading " << *inputFileName << endl;
			return 1;
			}
		}

	// generate the output file

	std::ostringstream data1;
	mgr.WriteFile(data1);

	JString data1Str = data1.str();
	if (!databaseFileName.IsEmpty())
		{
		ofstream dbOutput(databaseFileName);
		data1Str.Print(dbOutput);
		}

	if (!outputFileName.IsEmpty())
		{
		JIndex i = 1;
		while (data1Str.LocateNextSubstring("\\", &i))
			{
			data1Str.ReplaceSubstring(i,i, "\\\\");
			i += 2;
			}
		i = 1;
		while (data1Str.LocateNextSubstring("\"", &i))
			{
			data1Str.ReplaceSubstring(i,i, "\\\"");
			i += 2;
			}
		i = 1;
		while (data1Str.LocateNextSubstring("\n", &i))
			{
			data1Str.ReplaceSubstring(i,i, "\\n");
			i += 2;
			}

		std::ostringstream data2;
		data2 << "#include <jTypes.h>" << endl;
		data2 << "static const JCharacter* ";
		dataVarName.Print(data2);
		data2 << "[] = {" << endl;

		// Visual C++ cannot handle file with more than 2048 characters on a line
		// and cannot compile string constant more than 2048 characters!

		const JSize l1 = data1Str.GetLength();
		for (i=0; i<l1; )
			{
			JSize l2 = JMin((JSize) 2040, l1 - i);
			while (l2 > 0 && data1Str.GetCharacter(i+l2) == '\\')
				{
				l2--;
				}
			assert( l2 > 0 );

			data2 << "\"";
			data2.write(((const char*) data1Str) + i, l2);
			data2 << "\"," << endl;

			i += l2;
			}

		data2 << "NULL };" << endl;

		// if the file won't change, don't re-write it

		const JString s2 = data2.str();
		if (JFileExists(outputFileName))
			{
			JString origData;
			JReadFile(outputFileName, &origData);
			if (origData == s2)
				{
				JUpdateCVSIgnore(outputFileName);
				return 0;
				}
			}

		// write file

		ofstream output(outputFileName);
		s2.Print(output);

		if (!output.good())
			{
			cerr << argv[0] << ":  unable to write to " << outputFileName << endl;
			return 1;
			}

		JUpdateCVSIgnore(outputFileName);
		}

	return 0;
}
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
JXSaveFileDialog::OKToDeactivate()
{
	if (!JXCSFDialogBase::OKToDeactivate())
		{
		return kJFalse;
		}
	else if (Cancelled())
		{
		return kJTrue;
		}

	JXPathInput* pathInput = GetPathInput();
	if (pathInput->HasFocus())
		{
		GoToItsPath();
		return kJFalse;
		}

	JXInputField* filterInput = GetFilterInput();
	if (filterInput->HasFocus())
		{
		AdjustFilter();
		return kJFalse;
		}

	JXDirTable* fileBrowser = GetFileBrowser();
	if (fileBrowser->HasFocus() && fileBrowser->GoToSelectedDirectory())
		{
		return kJFalse;
		}

	const JString& fileName = itsFileNameInput->GetText();
	if (fileName.IsEmpty())
		{
		(JGetUserNotification())->ReportError("You need to enter a file name.");
		return kJFalse;
		}

	const JString& path     = GetPath();
	const JString fullName  = path + fileName;

	const JBoolean fileExists = JFileExists(fullName);

	if (JDirectoryExists(fullName))
		{
		(JGetUserNotification())->ReportError(
			"This name is already used for a directory.");
		return kJFalse;
		}
	else if (!JDirectoryWritable(path) && !fileExists)
		{
		(JGetUserNotification())->ReportError(
			"You are not allowed to write to this directory.");
		return kJFalse;
		}
	else if (!fileExists)
		{
		*itsFileName = fileName;
		return kJTrue;
		}
	else if (!JFileWritable(fullName))
		{
		(JGetUserNotification())->ReportError(
			"You are not allowed to write to this file.");
		return kJFalse;
		}
	else if ((JGetUserNotification())->AskUserNo("That file already exists.  Replace it?"))
		{
		*itsFileName = fileName;
		return kJTrue;
		}
	else
		{
		return kJFalse;
		}
}
Пример #29
0
GMApp::GMApp
(
    int*		argc,
    char*		argv[],
    JBoolean*	displayAbout,
    JString*	prevVersStr
)
    :
    JXApplication(argc, argv, kAppSignature, kGMDefaultStringData),
    itsTableDirs(NULL),
    itsHasFileDirectory(kJFalse),
    itsOpenPrefsAfterAbout(kJFalse),
    itsPrefsNew(kJFalse),
    itsAboutDialog(NULL)
{
    *displayAbout = GMCreateGlobals(this);

    if (!*displayAbout)
    {
        *prevVersStr = (GGetPrefsMgr())->GetArrowVersionStr();
        if (*prevVersStr == GMGetVersionNumberStr())
        {
            prevVersStr->Clear();
        }
        else
        {
            *displayAbout = kJTrue;
            if (prevVersStr->BeginsWith("1") ||
                    prevVersStr->BeginsWith("0") ||
                    prevVersStr->BeginsWith("2.0b"))
            {
                itsOpenPrefsAfterAbout	= kJTrue;
            }
        }
    }
    else
    {
        itsPrefsNew				= kJTrue;
        itsOpenPrefsAfterAbout	= kJTrue;
        prevVersStr->Clear();
    }

    GMMDIServer* mdi = new GMMDIServer(this);
    assert(mdi != NULL);

    itsTableDirs = new JPtrArray<GMessageTableDir>(JPtrArrayT::kForgetAll);
    assert(itsTableDirs != NULL);

    itsEditDirs = new JPtrArray<GMessageEditDir>(JPtrArrayT::kForgetAll);
    assert(itsEditDirs != NULL);

    itsLockTasks = new JPtrArray<GLockFileTask>(JPtrArrayT::kForgetAll);
    assert(itsLockTasks != NULL);

    if (*displayAbout)
    {
        if (!(JGetUserNotification())->AcceptLicense())
        {
            exit(0);
        }
    }

    JString home;
    if (JGetHomeDirectory(&home))
    {
        JAppendDirSeparator(&home);
        home += kArrowFilesDir;
        if (!JDirectoryExists(home))
        {
            JError err = JCreateDirectory(home);
            if (err.OK())
            {
                itsFileDirectory	= home;
                itsHasFileDirectory	= kJTrue;
            }
        }
        else
        {
            if (JKillDirectory(home))
            {
                JCreateDirectory(home);
            }
            if (JDirectoryExists(home))
            {
                itsFileDirectory	= home;
                itsHasFileDirectory	= kJTrue;
            }
        }
    }

    JBoolean ok = OpenSession();

    if (*argc > 1)
    {
        mdi->HandleCmdLineOptions(*argc, argv);
    }
    else if (!ok)
    {
        OpenSystemMailbox();
    }

    OpenMailboxWindowIfNeeded();

    ListenTo(GGetPrefsMgr());

    /*	JString test("pulp");
    	JPtrArray<JString> names;
    	GParseNameList(test, names);
    	JPtrArray<JString> aliases;
    	aliases.SetCompareFunction(JCompareStringsCaseSensitive);
    	JSize i = 1;
    	while (i <= names.GetElementCount())
    		{
    		JString& name = *(names.NthElement(i));
    		JString alias;
    		JString fcc;
    		if (GGetAddressBookMgr()->NameIsAlias(name, alias, fcc))
    			{
    			JIndex findex;
    			if (!aliases.SearchSorted(&name, JOrderedSetT::kAnyMatch, &findex))
    				{
    				GParseNameList(alias, names);
    				aliases.InsertSorted(names.NthElement(i));
    				names.RemoveElement(i);
    				}
    			else
    				{
    				names.DeleteElement(i);
    				}
    			}
    		else
    			{
    			i++;
    			}
    		}
    	aliases.DeleteAll();
    	const JSize count	= names.GetElementCount();
    	for (JIndex i = 1; i <= count; i++)
    		{
    		cout << *(names.NthElement(i)) << endl;
    		}*/
}
Пример #30
0
JString
JGetClosestDirectory
	(
	const JCharacter*	origDirName,
	const JBoolean		requireWrite,
	const JCharacter*	basePath
	)
{
	assert( !JStringEmpty(origDirName) );

	JString workingDir;
	if (!JStringEmpty(basePath))
		{
		workingDir = basePath;
		JAppendDirSeparator(&workingDir);
		}
	else
		{
		workingDir = JGetCurrentDirectory();
		}

	JString dirName = origDirName;
	JString homeDir;
	JSize homeLength;
	if (origDirName[0] == '~' &&
		!JExpandHomeDirShortcut(origDirName, &dirName, &homeDir, &homeLength))
		{
		return JGetRootDirectory();
		}
	else if (JIsRelativePath(origDirName))
		{
		dirName.Prepend(workingDir);
		}

	assert( !JIsRelativePath(dirName) );

	JString newDir, junkName;
	while (!JDirectoryExists(dirName)   ||
		   !JCanEnterDirectory(dirName) ||
		   !JDirectoryReadable(dirName) ||
		   (requireWrite && !JDirectoryWritable(dirName)))
		{
		JStripTrailingDirSeparator(&dirName);
		if (JIsRootDirectory(dirName))
			{
			break;
			}
		JSplitPathAndName(dirName, &newDir, &junkName);
		dirName = newDir;
		}

	// convert back to partial path, if possible

	if (origDirName[0] == '~' &&
		dirName.BeginsWith(homeDir))
		{
		dirName.ReplaceSubstring(1, homeDir.GetLength(), origDirName, homeLength);
		}
	else if (JIsRelativePath(origDirName) &&
			 dirName.GetLength() > workingDir.GetLength() &&
			 dirName.BeginsWith(workingDir))
		{
		dirName.RemoveSubstring(1, workingDir.GetLength());
		}

	return dirName;
}