⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 etc_uty.cpp

📁 日本的开源编辑器源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//	$Id: etc_uty.cpp,v 1.58 2005/01/23 09:08:03 Administrator Exp $
/*!	@file
	@brief 共通関数群

	@author Norio Nakatani
	$Revision: 1.58 $
*/
/*
	Copyright (C) 1998-2001, Norio Nakatani
	Copyright (C) 2000-2001, jepro, genta
	Copyright (C) 2001, shoji masami, stonee, MIK, YAZAKI
	Copyright (C) 2002, genta, aroka, hor, MIK, 鬼
	Copyright (C) 2003, genta

	This source code is designed for sakura editor.
	Please contact the copyright holder to use this code for other purpose.
*/

#include <io.h>
#include <memory.h>		// Apr. 03, 2003 genta
#include "etc_uty.h"
#include "debug.h"
#include "CMemory.h"
#include "funccode.h"	//Stonee, 2001/02/23

#include "WINNETWK.H"	//Stonee, 2001/12/21
#include "sakura.hh"	//YAZAKI, 2001/12/11
#include "CEol.h"// 2002/2/3 aroka
#include "CBregexp.h"// 2002/2/3 aroka
#include "COsVersionInfo.h"
#include "my_icmp.h" // 2002/11/30 Moca 追加

#include "CShareData.h"
#include "CMRU.h"
#include "CMRUFolder.h"
#include "CMultiMonitor.h"	//	2004.05.01 genta
#include "Keycode.h"// novice 2004/10/10

//	CShareDataへ移動
/* 日付をフォーマット */
//const char* MyGetDateFormat( char* pszDest, int nDestLen, int nDateFormatType, const char* pszDateFormat )

/* 時刻をフォーマット */
//const char* MyGetTimeFormat( char* pszDest, int nDestLen, int nTimeFormatType, const char* pszTimeFormat )

int CALLBACK MYBrowseCallbackProc(
	HWND hwnd,
	UINT uMsg,
	LPARAM lParam,
	LPARAM lpData
)
{
	switch( uMsg ){
	case BFFM_INITIALIZED:
//		MYTRACE( "BFFM_INITIALIZED (char*)lpData = [%s]\n", (char*)lpData );
		::SendMessage( hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)lpData );
		break;
	case BFFM_SELCHANGED:
//		MYTRACE( "BFFM_SELCHANGED\n" );
		break;
	}
	return 0;

}




/* フォルダ選択ダイアログ */
BOOL SelectDir( HWND hWnd, const char* pszTitle, const char* pszInitFolder, char* strFolderName )
{
	BOOL	bRes;
	char	szInitFolder[MAX_PATH];

	strcpy( szInitFolder, pszInitFolder );
	/* フォルダの最後が半角かつ'\\'の場合は、取り除く "c:\\"等のルートは取り除かない*/
	CutLastYenFromDirectoryPath( szInitFolder );

	// SHBrowseForFolder()関数に渡す構造体
	BROWSEINFO bi;
	bi.hwndOwner = hWnd;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = strFolderName;
	bi.lpszTitle = pszTitle;
	bi.ulFlags = BIF_RETURNONLYFSDIRS/* | BIF_EDITBOX*//* | BIF_STATUSTEXT*/;
	bi.lpfn = MYBrowseCallbackProc;
	bi.lParam = (LPARAM)szInitFolder;
	bi.iImage = 0;
	// アイテムIDリストを返す
	// ITEMIDLISTはアイテムの一意を表す構造体
	ITEMIDLIST* pList = ::SHBrowseForFolder(&bi);
	if( NULL != pList ){
		// SHGetPathFromIDList()関数はアイテムIDリストの物理パスを探してくれる
		bRes = ::SHGetPathFromIDList( pList, strFolderName );
		// :SHBrowseForFolder()で取得したアイテムIDリストを削除
		::CoTaskMemFree( pList );
		if( bRes ){
			return TRUE;
		}else{
			return FALSE;
		}
	}
	return FALSE;
}




/* パス名に対するアイテムIDリストを作成する */
ITEMIDLIST* CreateItemIDList( const char* pszPath )
{
	ITEMIDLIST*		pIDL;
	IShellFolder*	pDesktopFolder;
	OLECHAR			ochPath[MAX_PATH + 1];
	ULONG			chEaten;			//文字列のサイズを受け取ります。
	ULONG			dwAttributes;		//属性を受け取ります。
	HRESULT			hRes;
	if( '\0' == pszPath[0] ){
		return NULL;
	}
	if( ::SHGetDesktopFolder( &pDesktopFolder ) != NOERROR ){
		return NULL;
	}
	//  これをしないとインターフェイスはダメなのです。
	::MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pszPath, -1, ochPath, MAX_PATH );
	//  実際にITEMIDLISTを取得します。
	hRes = pDesktopFolder->ParseDisplayName( NULL, NULL, ochPath, &chEaten, &pIDL, &dwAttributes);
	if( hRes != NOERROR ){
		pIDL = NULL;
	}
	pDesktopFolder->Release();
	return pIDL;
}




/* アイテムIDリストを削除する */
BOOL DeleteItemIDList( ITEMIDLIST* pIDL )
{
	IMalloc*	pMalloc;
	//  IMallocインターフェイスへのポインタを取得します。
	if( NOERROR != ::SHGetMalloc( &pMalloc ) ){
		return FALSE;
	}
	//  アイテムIDリストをリリースします。
	if( NULL != pIDL ){
		pMalloc->Free( pIDL );
	}
	pMalloc->Release();
	return TRUE;
}




/* 拡張子を調べる */
BOOL CheckEXT( const char* pszPath, const char* pszExt )
{
	char	szExt[_MAX_EXT];
	char*	pszWork;
	_splitpath( pszPath, NULL, NULL, NULL, szExt );
	pszWork = szExt;
	if( pszWork[0] == '.' ){
		pszWork++;
	}
	if( 0 == _stricmp( pszExt, pszWork ) ){
		return TRUE;
	}else{
		return FALSE;
	}
}

/*!
	空白を含むファイル名を考慮したトークンの分割
	
	先頭にある連続した区切り文字は無視する.
	
	@param pBuffer [in] 文字列バッファ(終端があること)
	@param nLen [in] 文字列の長さ
	@param pnOffset [in/out] オフセット
	@param pDelimiter [in] 区切り文字
	@return トークン

	@date 2004.02.15 みく 最適化
*/
TCHAR* my_strtok( TCHAR* pBuffer, int nLen, int* pnOffset, const TCHAR* pDelimiter )
{
	int i = *pnOffset;
	TCHAR* p;

	do {
		bool bFlag = false;	//ダブルコーテーションの中か?
		if( i >= nLen ) return NULL;
		p = &pBuffer[i];
		for( ; i < nLen; i++ )
		{
			if( pBuffer[i] == _T('"') ) bFlag = ! bFlag;
			if( ! bFlag )
			{
				if( _tcschr( pDelimiter, pBuffer[i] ) )
				{
					pBuffer[i++] = _T('\0');
					break;
				}
			}
		}
		*pnOffset = i;
	} while( ! *p );	//空のトークンなら次を探す
	return p;
}




/*! ヘルプファイルのフルパスを返す
 
    @param pszHelpFile [in] パスを格納するバッファ
    @param nMaxLen [in] バッファに格納可能な文字数:デフォルト値=_MAX_PATH
    
    @return パスを格納したバッファのポインタ
 
    @note 実行ファイルと同じ位置の sakura.hlp ファイルを返す。
        パスが UNC のときは _MAX_PATH に収まらない可能性がある。
        
 
    @date 2002/01/19 aroka ;nMaxLen 引数追加
*/
char* GetHelpFilePath( char* pszHelpFile, unsigned int nMaxLen )
{
//	int		i;
	unsigned long	lPathLen;
	char	szHelpFile[_MAX_PATH + 1];
//	int		nCharChars;
	char	szDrive[_MAX_DRIVE];
	char	szDir[_MAX_DIR];
	/* ヘルプファイルのファイルパス */
	lPathLen = ::GetModuleFileName(
		::GetModuleHandle( NULL ),
		szHelpFile, sizeof(szHelpFile)
	);
	if( lPathLen > nMaxLen ){
		*pszHelpFile = '\0';
		return pszHelpFile;
	}

	_splitpath( szHelpFile, szDrive, szDir, NULL, NULL );
	if( strlen(szDrive) + strlen(szDir) + strlen("sakura.hlp") > nMaxLen ){
		*pszHelpFile = '\0';
		return pszHelpFile;
	}
	strcpy( szHelpFile, szDrive );
	strcat( szHelpFile, szDir );
	strcat( szHelpFile, "sakura.hlp" );
	strncpy( pszHelpFile, szHelpFile, nMaxLen );
	return pszHelpFile;
}



# if 0
//	Aug. 18, 2002 genta
//	GetLongFileNameから呼び出されなくなったので不要
/* 相対パス→絶対パス */
BOOL GetAbsolutePath( const char* pszFilePathSrc, char* pszFilePathDes, BOOL bChangeCurrentFolder )
{
	char			szCurFolderOld[MAX_PATH];
	char			szCurFolder[MAX_PATH];
//	HANDLE			nFind;
//	WIN32_FIND_DATA	wfd;
	char			szPathSrc[MAX_PATH];
//	char			szPath2[MAX_PATH];
//	char			szPath3[MAX_PATH];
//	char			szPath4[MAX_PATH];
//	int				nPathSrcLen;
//	int				i;
	int				nCharChars;
//	int				nDirBgn;

	char			szDrive[_MAX_DRIVE];
	char			szDir[_MAX_DIR];
	char			szFname[_MAX_FNAME];
	char			szExt[_MAX_EXT];
	int				nFolderLen;
//	int				nDriveOrg;
	BOOL			bRet;
	bRet = TRUE;


	/* カレントフォルダの退避 */
	if( !bChangeCurrentFolder ){	/* カレントフォルダを変更するか */
		::GetCurrentDirectory( MAX_PATH, szCurFolderOld );
	}

	_splitpath( pszFilePathSrc, szDrive, szDir, szFname, szExt );
//	MYTRACE( "_splitpath 関数によるパス名の分解:\n" );
//	MYTRACE( " pszFilePathSrc    : %s\n", pszFilePathSrc );
//	MYTRACE( "  ドライブ    : %s\n", szDrive );
//	MYTRACE( "  ディレクトリ: %s\n", szDir );
//	MYTRACE( "  ファイル名  : %s\n", szFname );
//	MYTRACE( "  拡張子      : %s\n", szExt );
	_makepath( szCurFolder, szDrive, szDir, NULL, NULL );
//	MYTRACE( "  SetCurrentDirectory     : %s\n", szCurFolder );
	if( 0 < strlen( szCurFolder ) && 0 == ::SetCurrentDirectory( szCurFolder ) ){
		bRet =  FALSE;
		goto end_of_func;
	}
	::GetCurrentDirectory( MAX_PATH, szCurFolder );
//	MYTRACE( "  GetCurrentDirectory     : %s\n", szCurFolder );

	/* フォルダの最後が半角かつ'\\'の場合は、取り除く */
	nFolderLen = strlen( szCurFolder );
	if( 0 < nFolderLen ){
		nCharChars = &szCurFolder[nFolderLen] - CMemory::MemCharPrev( szCurFolder, nFolderLen, &szCurFolder[nFolderLen] );
//@@@ 2002.01.08 YAZAKI '/'も取り除くように変更
		if( 1 == nCharChars && ('\\' == szCurFolder[nFolderLen - 1] || '/' == szCurFolder[nFolderLen - 1])){
			szCurFolder[nFolderLen - 1] = '\0';
		}
	}
	wsprintf( szPathSrc, "%s\\%s%s", szCurFolder, szFname, szExt );
//	MYTRACE( "  絶対パス      : %s\n", szPathSrc );
	strcpy( pszFilePathDes, szPathSrc );
end_of_func:;
	/* カレントフォルダの復帰 */
	if( !bChangeCurrentFolder ){	/* カレントフォルダを変更するか */
		::SetCurrentDirectory( szCurFolderOld );
	}
	return bRet;

}
#endif



/* ロングファイル名を取得する */
BOOL GetLongFileName( const char* pszFilePathSrc, char* pszFilePathDes )
{
//	HANDLE			nFind;
//	WIN32_FIND_DATA	wfd;
//	char			szPathSrc[MAX_PATH];
//	char			szPath2[MAX_PATH];
//	char			szPath3[MAX_PATH];
//	int				nPathSrcLen;
//	int				i;
//	int				j;
//	int				nCharChars;
//	int				nDriveOrg;
	/* 相対パス→絶対パス */
	//	Aug. 18, 2002 genta 削除
	//	下で行っていることと機能が重複しているため.
	//	ここで作られたpszFilePathDesは全く使われていないので
	//	こちらを削除した.
	//	GetAbsolutePathを使うのはここだけなので,GetAbsolutePathも不要なはず.
	// if( FALSE == GetAbsolutePath( pszFilePathSrc, pszFilePathDes, TRUE) ){
	//	return FALSE;
	// }

	ITEMIDLIST* pIDL;
	/* パス名に対するアイテムIDリストを作成する */
	if( NULL == ( pIDL = CreateItemIDList( pszFilePathSrc ) ) ){
		//	May 9, 2000 genta
		char * name;
		int length;
		length = ::GetFullPathName( pszFilePathSrc, MAX_PATH, pszFilePathDes, &name );
//		::MessageBox( NULL, pszFilePathDes, "GetFullPathName", MB_OK );
		if( length <= 0 || MAX_PATH <= length ){
			::MessageBox( NULL, pszFilePathDes, "Too Long Path", MB_OK );
			return FALSE;
		}
	}
	else{
		// アイテムIDリストの物理パスを取得
		::SHGetPathFromIDList( pIDL, pszFilePathDes );

		/* アイテムIDリストを削除する */
		DeleteItemIDList( pIDL );
	}
//	::MessageBox( NULL, pszFilePathDes, pszFilePathSrc, MB_OK );
	return TRUE;

//-2000.1.6 自前の処理をやめた
//-
//-	nPathSrcLen = strlen( szPathSrc );
//-	if( 2 < nPathSrcLen
//-	 && '\\' == szPathSrc[0]
//-	 && '\\' == szPathSrc[1]
//-	){
//-		/* \\サーバ名\シェア名\... */
//-		i = 2 - 1;
//-		for( j = 0; j < 2; ++j ){
//-			++i;
//-			for( ; i < nPathSrcLen; ++i ){
//-				nCharChars = CMemory::MemCharNext( szPathSrc, nPathSrcLen, &szPathSrc[i] ) - &szPathSrc[i];
//-				if( 1 == nCharChars && '\\' == szPathSrc[i] ){
//-					break;
//-				}
//-				if( 2 == nCharChars ){
//-					++i;
//-				}
//-			}
//-		}
//-		nDriveOrg = i;
//-	}else{
//-		/* ドライブ名\... */
//-		nDriveOrg = 2;
//-	}
//-	strcpy( szPath2, "" );
//-	nFind = ::FindFirstFile( szPathSrc, (WIN32_FIND_DATA*)&wfd );
//-	if( INVALID_HANDLE_VALUE == nFind ){
//-		return FALSE;
//-	}
//-	::FindClose( nFind );
//-	while( 1 ){
//-			strcpy( szPath3, "\\" );
//-			strcat( szPath3, wfd.cFileName );
//-			strcat( szPath3, szPath2 );
//-			strcpy( szPath2, szPath3 );
//-		nPathSrcLen = strlen( szPathSrc );
//-		nCharChars = &szPathSrc[nPathSrcLen] - CMemory::MemCharPrev( szPathSrc, nPathSrcLen, &szPathSrc[nPathSrcLen] );
//-		for( i = nPathSrcLen - nCharChars; i >= 0; i-- ){
//-			if( 1 == nCharChars && '\\' == szPathSrc[i] ){
//-				if( 0 == strcmp( ".", wfd.cFileName ) ){
//-					strcpy( szPath3, &szPathSrc[i] );
//-					strcat( szPath3, szPath2 );
//-					strcpy( szPath2, szPath3 );
//-				}
//-				szPathSrc[i] = '\0';
//-				break;
//-			}
//-			nCharChars = &szPathSrc[i] - CMemory::MemCharPrev( szPathSrc, nPathSrcLen, &szPathSrc[i] );
//-			if( 2 == nCharChars ){
//-				i--;
//-			}
//-		}
//-		if( 0 > i ){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -