Beispiel #1
0
static void CommitPart(
	autoList_t *partFiles,
	char *wMode,
	void (*writeElement_x)(FILE *fp, uint element),
	sint (*compElement)(uint element1, uint element2),
	autoList_t *elements
	)
{
	rapidSort(elements, compElement);

	{
		char *partFile = makeTempPath("part");
		FILE *fp;
		uint element;
		uint index;

		addElement(partFiles, (uint)partFile);
		fp = fileOpen(partFile, wMode);

		foreach(elements, element, index)
			writeElement_x(fp, element);

		fileClose(fp);
		releaseAutoList(elements);
	}
}
Beispiel #2
0
 FileIndex::Pimpl::Pimpl(const FilePath& pFilePath, FileIndex::OPTIONS pOptions, bool pAtEnd) :
   path(&pFilePath),
   it(pAtEnd ?
     ts_recursive_directory_iterator() :
     ts_recursive_directory_iterator(path->name(), (pOptions & FileIndex::OPT_FOLLOW_SYMLINKS) != 0 ? ts_directory_options::follow_directory_symlink : ts_directory_options::none)
   ),
   options(pOptions),
   tempPath()
 {
   makeTempPath();
 }
CString CProcessStatus::makeTempPathShort(LPCTSTR lpszFileName, LPCTSTR lpszExtension)
{
	CString& sLong =  makeTempPath(lpszFileName, lpszExtension);

	int iResult = _taccess(sLong, 02); // ask for write permission

	if(-1 == iResult)
	{
		if(errno == EACCES)
		{
			CString sError(_T("Some process left this file open, so it can't be written to: "));
			sError += sLong;
			throw(sError);
		}
		else if (errno == ENOENT)
		{
			TRACE(_T("Creating %s for makeTempPath\n"), sLong);
			USES_CONVERSION;
			FILE* f = fopen(T2CA(sLong), "w"); // create it
			ASSERTX(f);
			fclose(f);
		}
		else
		{
			CString sError(_T("Unknown error trying to check the access permisions of the file: "));
			sError += sLong;
			throw(sError);
		}
	}
	ASSERTX(!_taccess(sLong, 02));

/*	// can't get a shortpath unless the file exists.  So we
	// need to make it exist if it doesn't already

	FILE*f = fopen(sLong, "r"); // does it exist?
	if(!f)
	{
		TRACE("Creating %s for makeTempPath\n", sLong);
		f = fopen(sLong, "w"); // create it
		ASSERTX(f);
	}
	fclose(f);
*/
//return sLong;
	TCHAR shortPath[1000];
	DWORD result = GetShortPathName( sLong, shortPath, 1000);
	ASSERTX(1000 > result);
	if(!result)
	{
		::checkForFileError(sLong, FALSE);
	}
	return CString(shortPath);
}
Beispiel #4
0
int main(int argc, char *argv[])
{
    installLogcatMessageHandler("ImageProcessor");
    QApplication a(argc, argv);
    SimpleCustomEvent::eventType();
#ifdef Q_OS_ANDROID
    registerNativeMethods();
#endif
    makeTempPath();
    Widget w;
#ifdef Q_OS_ANDROID
    g_listener = (QObject*)&w;
#endif
    QScreen *screen = a.primaryScreen();
    w.setMaximumSize(screen->size());
    w.show();

    return a.exec();
}
Beispiel #5
0
/*
	srcFile
		読み込み元ファイル

	destFile
		出力先ファイル
		srcFile と同じパスであっても良い。

	textMode
		真のとき -> テキストモード
		偽のとき -> バイナリーモード

	uint readElement(FILE *fp)
		1レコード読み込む。
		これ以上レコードが無いときは 0 を返すこと。

	void writeElement_x(FILE *fp, uint element)
		1レコード書き込む。
		必要であれば element を開放すること。

	sint compElement(uint element1, uint element2)
		element1 と element2 を比較した結果を strcmp() 的に返す。

	partSize
		メモリに一度期に読み込める「レコードの合計バイト数」の最大値の目安
		srcFile のシーク位置の変化をバイトに換算しているだけ。
		0 のときは常に1レコードずつになる。
		各パートのレコード数が partSize / 100 を超えないようにする。
*/
void MergeSort(
	char *srcFile,
	char *destFile,
	int textMode,
	uint (*readElement)(FILE *fp),
	void (*writeElement_x)(FILE *fp, uint element),
	sint (*compElement)(uint element1, uint element2),
	uint partSize
	)
{
	autoList_t *partFiles = newList();
	autoList_t *elements = NULL;
	char *rMode;
	char *wMode;
	FILE *fp;
	uint64 startPos = 0;

	if(textMode)
	{
		rMode = "rt";
		wMode = "wt";
	}
	else
	{
		rMode = "rb";
		wMode = "wb";
	}
	fp = fileOpen(srcFile, rMode);

	for(; ; )
	{
		uint element = readElement(fp);
		uint64 currPos;

		if(!element)
			break;

		if(!elements)
			elements = createAutoList(partSize / 100 + 1);

		addElement(elements, element);

		currPos = _ftelli64(fp);
		errorCase(currPos < 0);

		if(startPos + partSize <= currPos || partSize / 100 < getCount(elements))
		{
			CommitPart(partFiles, wMode, writeElement_x, compElement, elements);
			elements = NULL;
			startPos = currPos;

			// メモリのデフラグ?
			{
				char *wkFile = makeTempPath("work");

				writeLines_cx(wkFile, partFiles);
				partFiles = readLines(wkFile);

				removeFile(wkFile);
				memFree(wkFile);
			}
		}
	}
	if(elements)
		CommitPart(partFiles, wMode, writeElement_x, compElement, elements);

	fileClose(fp);

	while(2 < getCount(partFiles))
	{
		char *partFile1 = (char *)unaddElement(partFiles);
		char *partFile2 = (char *)unaddElement(partFiles);
		char *partFile3 = makeTempPath("part");

		MergePart(partFile1, partFile2, partFile3, rMode, wMode, readElement, writeElement_x, compElement);

		memFree(partFile1);
		memFree(partFile2);

		insertElement(partFiles, 0, (uint)partFile3);
	}
	switch(getCount(partFiles))
	{
	case 2:
		MergePart(getLine(partFiles, 0), getLine(partFiles, 1), destFile, rMode, wMode, readElement, writeElement_x, compElement);
		break;

	case 1:
		removeFileIfExist(destFile);
		moveFile(getLine(partFiles, 0), destFile);
		break;

	case 0:
		createFile(destFile);
		break;

	default:
		error();
	}
	releaseDim(partFiles, 1);
}