| 1 |
/* |
| 2 |
* Copyright (C) 1994-1998 T. Teranishi |
| 3 |
* (C) 2006- TeraTerm Project |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without |
| 7 |
* modification, are permitted provided that the following conditions |
| 8 |
* are met: |
| 9 |
* |
| 10 |
* 1. Redistributions of source code must retain the above copyright |
| 11 |
* notice, this list of conditions and the following disclaimer. |
| 12 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
* notice, this list of conditions and the following disclaimer in the |
| 14 |
* documentation and/or other materials provided with the distribution. |
| 15 |
* 3. The name of the author may not be used to endorse or promote products |
| 16 |
* derived from this software without specific prior written permission. |
| 17 |
* |
| 18 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
| 19 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 |
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
*/ |
| 29 |
|
| 30 |
/* useful routines */ |
| 31 |
|
| 32 |
#include <time.h> // for time_t |
| 33 |
|
| 34 |
#pragma once |
| 35 |
|
| 36 |
#include "i18n.h" |
| 37 |
#include "ttlib_static_dir.h" |
| 38 |
|
| 39 |
#ifdef __cplusplus |
| 40 |
extern "C" { |
| 41 |
#endif |
| 42 |
|
| 43 |
#if !defined(DllExport) |
| 44 |
#define DllExport __declspec(dllexport) |
| 45 |
#endif |
| 46 |
|
| 47 |
#if defined(_MSC_VER) && !defined(_Printf_format_string_) |
| 48 |
// ���`�������������������������������������`�������� |
| 49 |
#define _Printf_format_string_ |
| 50 |
#endif |
| 51 |
|
| 52 |
BOOL GetFileNamePos(const char *PathName, int *DirLen, int *FNPos); |
| 53 |
BOOL GetFileNamePosU8(const char *PathName, int *DirLen, int *FNPos); |
| 54 |
BOOL GetFileNamePosW(const wchar_t *PathName, size_t *DirLen, size_t *FNPos); |
| 55 |
DllExport BOOL ExtractFileName(PCHAR PathName, PCHAR FileName, int destlen); |
| 56 |
DllExport BOOL ExtractDirName(PCHAR PathName, PCHAR DirName); |
| 57 |
wchar_t *ExtractDirNameW(const wchar_t *PathName); |
| 58 |
wchar_t *ExtractFileNameW(const wchar_t *PathName); |
| 59 |
void FitFileName(PCHAR FileName, int destlen, const char *DefExt); |
| 60 |
void FitFileNameW(wchar_t *FileName, size_t destlen, const wchar_t *DefExt); |
| 61 |
void AppendSlash(PCHAR Path, int destlen); |
| 62 |
void AppendSlashW(wchar_t *Path, size_t destlen); |
| 63 |
void DeleteSlash(PCHAR Path); |
| 64 |
wchar_t *DeleteSlashW(const wchar_t *Path); |
| 65 |
void Str2Hex(PCHAR Str, PCHAR Hex, int Len, int MaxHexLen, BOOL ConvSP); |
| 66 |
BYTE ConvHexChar(BYTE b); |
| 67 |
int Hex2Str(PCHAR Hex, PCHAR Str, int MaxLen); |
| 68 |
int Hex2StrW(const wchar_t *Hex, wchar_t *Str, size_t MaxLen); |
| 69 |
BOOL DoesFileExist(const char *FName); |
| 70 |
BOOL DoesFolderExist(const char *FName); |
| 71 |
BOOL DoesFolderExistW(const wchar_t *FName); |
| 72 |
long GetFSize(const char *FName); |
| 73 |
unsigned long long GetFSize64H(HANDLE hFile); |
| 74 |
unsigned long long GetFSize64W(const wchar_t *FName); |
| 75 |
unsigned long long GetFSize64A(const char *FName); |
| 76 |
long GetFMtime(const char *FName); |
| 77 |
BOOL SetFMtime(const char *FName, DWORD mtime); |
| 78 |
void uint2str(UINT i, PCHAR Str, int destlen, int len); |
| 79 |
#ifdef WIN32 |
| 80 |
void QuoteFName(PCHAR FName); |
| 81 |
#endif |
| 82 |
BOOL isInvalidFileNameCharW(const wchar_t *FName); |
| 83 |
int isInvalidFileNameChar(const char *FName); |
| 84 |
#define deleteInvalidFileNameChar(name) replaceInvalidFileNameChar(name, 0) |
| 85 |
wchar_t *replaceInvalidFileNameCharW(const wchar_t *FName, wchar_t c); |
| 86 |
DllExport void replaceInvalidFileNameChar(PCHAR FName, unsigned char c); |
| 87 |
BOOL isInvalidStrftimeCharW(const wchar_t *format); |
| 88 |
int isInvalidStrftimeChar(PCHAR FName); |
| 89 |
void deleteInvalidStrftimeCharW(wchar_t *FName); |
| 90 |
void deleteInvalidStrftimeChar(PCHAR FName); |
| 91 |
void ParseStrftimeFileName(PCHAR FName, int destlen); |
| 92 |
#if 0 |
| 93 |
void ConvFName(const char *HomeDir, PCHAR Temp, int templen, const char *DefExt, PCHAR FName, int destlen); |
| 94 |
void ConvFNameW(const wchar_t *HomeDir, wchar_t *Temp, size_t templen, const wchar_t *DefExt, wchar_t *FName, size_t destlen); |
| 95 |
#endif |
| 96 |
void RestoreNewLine(PCHAR Text); |
| 97 |
size_t RestoreNewLineW(wchar_t *Text); |
| 98 |
BOOL GetNthString(PCHAR Source, int Nth, int Size, PCHAR Dest); |
| 99 |
void GetNthNum(PCHAR Source, int Nth, int *Num); |
| 100 |
int GetNthNum2(PCHAR Source, int Nth, int defval); |
| 101 |
void GetDownloadFolder(char *dest, int destlen); |
| 102 |
wchar_t *GetDownloadFolderW(void); |
| 103 |
wchar_t *GetDefaultFNameW(const wchar_t *home, const wchar_t *file); |
| 104 |
wchar_t *GetDefaultSetupFNameW(const wchar_t *home); |
| 105 |
BOOL GetNthStringW(const wchar_t *Source, int Nth, size_t Size, wchar_t *Dest); |
| 106 |
void GetNthNumW(const wchar_t *Source, int Nth, int *Num); |
| 107 |
int GetNthNum2W(const wchar_t *Source, int Nth, int defval); |
| 108 |
void GetUILanguageFileFull(const char *HomeDir, const char *UILanguageFileRel, |
| 109 |
char *UILanguageFileFull, size_t UILanguageFileFullLen); |
| 110 |
wchar_t *GetUILanguageFileFullW(const wchar_t *HomeDir, const wchar_t *UILanguageFileRel); |
| 111 |
void GetOnOffEntryInifile(char *entry, char *buf, int buflen); |
| 112 |
// __declspec(deprecated("Replace GetI18nStrWW()")) |
| 113 |
void get_lang_msg(const char *key, PCHAR buf, int buf_len, const char *def, const char *iniFile); |
| 114 |
// __declspec(deprecated("Replace GetI18nStrWW()")) |
| 115 |
void get_lang_msgW(const char *key, wchar_t *buf, int buf_len, const wchar_t *def, const char *iniFile); |
| 116 |
int get_lang_font(const char *key, HWND dlg, PLOGFONT logfont, HFONT *font, const char *iniFile); |
| 117 |
#if defined(_MSC_VER) |
| 118 |
DllExport void OutputDebugPrintf(_Printf_format_string_ const char *fmt, ...); |
| 119 |
void OutputDebugPrintfW(_Printf_format_string_ const wchar_t *fmt, ...); |
| 120 |
#elif defined(__GNUC__) |
| 121 |
DllExport void OutputDebugPrintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); |
| 122 |
void OutputDebugPrintfW(const wchar_t *fmt, ...); // __attribute__ ((format (wprintf, 1, 2))); |
| 123 |
#else |
| 124 |
DllExport void OutputDebugPrintf(const char *fmt, ...); |
| 125 |
void OutputDebugPrintfW(const wchar_t *fmt, ...); |
| 126 |
#endif |
| 127 |
void OutputDebugHexDump(const void *data, size_t len); |
| 128 |
BOOL IsWindowsVer(DWORD dwPlatformId, DWORD dwMajorVersion, DWORD dwMinorVersion); |
| 129 |
BOOL IsWindowsVerOrLater(DWORD dwMajorVersion, DWORD dwMinorVersion); |
| 130 |
DllExport DWORD get_OPENFILENAME_SIZEA(); |
| 131 |
DllExport DWORD get_OPENFILENAME_SIZEW(); |
| 132 |
DllExport BOOL IsWindows95(); |
| 133 |
DllExport BOOL IsWindowsMe(); |
| 134 |
DllExport BOOL IsWindowsNT4(); |
| 135 |
DllExport BOOL IsWindowsNTKernel(); |
| 136 |
DllExport BOOL IsWindows2000(); |
| 137 |
DllExport BOOL IsWindows2000OrLater(); |
| 138 |
BOOL IsWindowsXPOrLater(void); |
| 139 |
DllExport BOOL IsWindowsVistaOrLater(); |
| 140 |
DllExport BOOL IsWindows7OrLater(); |
| 141 |
DllExport BOOL HasMultiMonitorSupport(); |
| 142 |
DllExport BOOL HasDnsQuery(); |
| 143 |
DllExport BOOL HasBalloonTipSupport(); |
| 144 |
int KanjiCodeTranslate(int lang, int kcode); |
| 145 |
DllExport char *mctimelocal(char *format, BOOL utc_flag); |
| 146 |
char *strelapsed(DWORD start_time); |
| 147 |
|
| 148 |
void b64encode(PCHAR dst, int dsize, PCHAR src, int len); |
| 149 |
DllExport int b64decode(PCHAR dst, int dsize, PCHAR src); |
| 150 |
|
| 151 |
DllExport wchar_t * PASCAL GetParam(wchar_t *buff, size_t size, wchar_t *param); |
| 152 |
DllExport void PASCAL DequoteParam(wchar_t *dest, size_t dest_len, wchar_t *src); |
| 153 |
void PASCAL DeleteComment(PCHAR dest, int dest_size, PCHAR src); |
| 154 |
wchar_t *DeleteCommentW(const wchar_t *src); |
| 155 |
|
| 156 |
void split_buffer(char *buffer, int delimiter, char **head, char **body); |
| 157 |
BOOL GetPositionOnWindow( |
| 158 |
HWND hWnd, const POINT *point, |
| 159 |
BOOL *InWindow, BOOL *InClient, BOOL *InTitleBar); |
| 160 |
DllExport void GetMessageboxFont(LOGFONTA *logfont); |
| 161 |
void GetMessageboxFontW(LOGFONTW *logfont); |
| 162 |
void GetDesktopRect(HWND hWnd, RECT *rect); |
| 163 |
void CenterWindow(HWND hWnd, HWND hWndParent); |
| 164 |
void MoveWindowToDisplay(HWND hWnd); |
| 165 |
void MoveWindowToDisplayPoint(HWND hWnd, const POINT *p); |
| 166 |
|
| 167 |
#define CheckFlag(var, flag) (((var) & (flag)) != 0) |
| 168 |
|
| 169 |
int SetDlgTextsW(HWND hDlgWnd, const DlgTextInfo *infos, int infoCount, const wchar_t *UILanguageFileW); |
| 170 |
int SetDlgTexts(HWND hDlgWnd, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile); |
| 171 |
void SetDlgMenuTextsW(HMENU hMenu, const DlgTextInfo *infos, int infoCount, const wchar_t *UILanguageFile); |
| 172 |
void SetDlgMenuTexts(HMENU hMenu, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile); |
| 173 |
int GetMonitorDpiFromWindow(HWND hWnd); |
| 174 |
|
| 175 |
#define get_OPENFILENAME_SIZE() get_OPENFILENAME_SIZEA() |
| 176 |
|
| 177 |
/* |
| 178 |
* �V���A���|�[�g���A���������` |
| 179 |
*/ |
| 180 |
enum serial_port_conf { |
| 181 |
COM_DATABIT, |
| 182 |
COM_PARITY, |
| 183 |
COM_STOPBIT, |
| 184 |
COM_FLOWCTRL, |
| 185 |
}; |
| 186 |
|
| 187 |
/* |
| 188 |
* ttlib_static |
| 189 |
*/ |
| 190 |
typedef struct { |
| 191 |
const char *section; // �Z�N�V������ |
| 192 |
const char *title_key; // �^�C�g��(NULL�������Atitle_default �������g�p) |
| 193 |
const wchar_t *title_default; // lng �t�@�C�������������������������g�p |
| 194 |
const char *message_key; // ���b�Z�[�W |
| 195 |
const wchar_t *message_default; // lng �t�@�C�������������������������g�p |
| 196 |
UINT uType; // ���b�Z�[�W�{�b�N�X���^�C�v |
| 197 |
} TTMessageBoxInfoW; |
| 198 |
|
| 199 |
int TTMessageBoxA(HWND hWnd, const TTMessageBoxInfoW *info, const char *UILanguageFile, ...); |
| 200 |
int TTMessageBoxW(HWND hWnd, const TTMessageBoxInfoW *info, const wchar_t *UILanguageFile, ...); |
| 201 |
wchar_t *GetClipboardTextW(HWND hWnd, BOOL empty); |
| 202 |
char *GetClipboardTextA(HWND hWnd, BOOL empty); |
| 203 |
BOOL CBSetTextW(HWND hWnd, const wchar_t *str_w, size_t str_len); |
| 204 |
void TTInsertMenuItemA(HMENU hMenu, UINT targetItemID, UINT flags, UINT newItemID, const char *text, BOOL before); |
| 205 |
BOOL IsTextW(const wchar_t *str, size_t len); |
| 206 |
wchar_t *NormalizeLineBreakCR(const wchar_t *src, size_t *len); |
| 207 |
wchar_t *NormalizeLineBreakCRLF(const wchar_t *src_); |
| 208 |
BOOL IsRelativePathA(const char *path); |
| 209 |
BOOL IsRelativePathW(const wchar_t *path); |
| 210 |
DWORD TTWinExecA(const char *commandA); |
| 211 |
void CreateBakupFile(const wchar_t *fname, const wchar_t *prev_str); |
| 212 |
BOOL ConvertIniFileCharCode(const wchar_t *fname, const wchar_t *bak_str); |
| 213 |
wchar_t *MakeISO8601Str(time_t t); |
| 214 |
int KanjiCodeToISO8859Part(int kanjicode); |
| 215 |
void SaveBmpFromHDC(const wchar_t* fname, HDC hdc, int width, int height); |
| 216 |
wchar_t *RandomFileW(const wchar_t *filespec_src); |
| 217 |
void RandomFile(const char *filespec_src,char *filename, int destlen); |
| 218 |
int __ismbblead(BYTE b, int code_page); |
| 219 |
|
| 220 |
#ifdef __cplusplus |
| 221 |
} |
| 222 |
#endif |
| 223 |
|
| 224 |
#include "ttcommdlg.h" |