Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/teraterm/teraterm/teraterm.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10738 - (show annotations) (download) (as text)
Sun Jun 4 12:28:20 2023 UTC (11 months, 3 weeks ago) by zmatsuo
File MIME type: text/x-c++src
File size: 9244 byte(s)
setlocale(LC_ALL, "") を追加

- strftime() の %B は「6月」となる
  - ログフィアル名でstrftime()(wcsftime())を使用
  - 日本語の一般的な環境の場合
  - 修正前は %B は「June」だった

ticket #46476
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 /* TERATERM.EXE, main */
31
32 #include <stdio.h>
33 #include <crtdbg.h>
34 #include <windows.h>
35 #include <htmlhelp.h>
36 #include <locale.h>
37
38 #include "teraterm.h"
39 #include "tttypes.h"
40 #include "commlib.h"
41 #include "ttwinman.h"
42 #include "buffer.h"
43 #include "vtterm.h"
44 #include "vtwin.h"
45 #include "clipboar.h"
46 #include "filesys.h"
47 #include "telnet.h"
48 #include "tektypes.h"
49 #include "tekwin.h"
50 #include "ttdde.h"
51 #include "keyboard.h"
52 #include "dllutil.h"
53 #include "compat_win.h"
54 #include "dlglib.h"
55 #include "teraterml.h"
56 #include "sendmem.h"
57 #include "ttdebug.h"
58 #include "win32helper.h"
59 #include "asprintf.h"
60 #if ENABLE_GDIPLUS
61 #include "ttgdiplus.h"
62 #endif
63
64 #if defined(_DEBUG) && defined(_MSC_VER)
65 #define new ::new(_NORMAL_BLOCK, __FILE__, __LINE__)
66 #endif
67
68 static BOOL AddFontFlag;
69 static wchar_t *TSpecialFont;
70 static CVTWindow* pVTWin;
71 static DWORD HtmlHelpCookie;
72
73 static void LoadSpecialFont(void)
74 {
75 wchar_t *mod_path;
76 if (IsExistFontW(L"Tera Special", SYMBOL_CHARSET, TRUE)) {
77 // ���������������������[�h������
78 return;
79 }
80
81 if (hGetModuleFileNameW(NULL, &mod_path) != 0) {
82 AddFontFlag = FALSE;
83 return;
84 }
85 *wcsrchr(mod_path, L'\\') = 0;
86 aswprintf(&TSpecialFont, L"%s\\TSPECIAL1.TTF", mod_path);
87 free(mod_path);
88
89 // teraterm.exe�������L�����t�H���g�������B
90 // remove�����������I��������OS������������
91 int r = 0;
92 if (pAddFontResourceExW != NULL) {
93 r = pAddFontResourceExW(TSpecialFont, FR_PRIVATE, NULL);
94 }
95 if (r == 0) {
96 // AddFontResourceEx() ���g����������
97 // �V�X�e���S�����g�����t�H���g������
98 // remove��������OS������������������
99 r = AddFontResourceW(TSpecialFont);
100 }
101 if (r != 0) {
102 AddFontFlag = TRUE;
103 }
104 }
105
106 static void UnloadSpecialFont(void)
107 {
108 if (!AddFontFlag) {
109 return;
110 }
111 int r = 0;
112 if (pRemoveFontResourceExW != NULL) {
113 r = pRemoveFontResourceExW(TSpecialFont, FR_PRIVATE, NULL);
114 }
115 if (r == 0) {
116 RemoveFontResourceW(TSpecialFont);
117 }
118 }
119
120 static void init(void)
121 {
122 DLLInit();
123 WinCompatInit();
124 DebugSetException();
125 LoadSpecialFont();
126 #if defined(DEBUG_OPEN_CONSOLE_AT_STARTUP)
127 DebugConsoleOpen();
128 #endif
129 }
130
131 // Tera Term main engine
132 static BOOL OnIdle(LONG lCount)
133 {
134 static int Busy = 2;
135 int nx, ny;
136 BOOL Size;
137
138 if (lCount==0) Busy = 2;
139
140 if (cv.Ready)
141 {
142 /* Sender */
143 CommSend(&cv);
144
145 /* Parser */
146 if ((TelStatus==TelIdle) && cv.TelMode)
147 TelStatus = TelIAC;
148
149 if (TelStatus != TelIdle)
150 {
151 ParseTel(&Size,&nx,&ny);
152 if (Size) {
153 LockBuffer();
154 ChangeTerminalSize(nx,ny);
155 UnlockBuffer();
156 }
157 }
158 else {
159 int Change;
160 if (ProtoGetProtoFlag()) Change = ProtoDlgParse();
161 else {
162 switch (ActiveWin) {
163 case IdVT:
164 Change = pVTWin->Parse();
165 // TEK window���A�N�e�B�u���� pause ���g�����ACPU�g�p��100%������
166 // ���������b�������B(2006.2.6 yutaka)
167 // �����������������A�R���e�L�X�g�X�C�b�`�����������B(2006.3.20 yutaka)
168 Sleep(0);
169 break;
170
171 case IdTEK:
172 if (pTEKWin != NULL) {
173 Change = ((CTEKWindow*)pTEKWin)->Parse();
174 // TEK window���A�N�e�B�u���� pause ���g�����ACPU�g�p��100%������
175 // ���������b�������B(2006.2.6 yutaka)
176 Sleep(1);
177 }
178 else {
179 Change = IdVT;
180 }
181 break;
182
183 default:
184 Change = 0;
185 }
186
187 switch (Change) {
188 case IdVT:
189 VTActivate();
190 break;
191 case IdTEK:
192 pVTWin->OpenTEK();
193 break;
194 }
195 }
196 }
197
198 FLogWriteFile();
199
200 if (DDELog && AdvFlag) {
201 DDEAdv();
202 }
203
204 /* Talker */
205 switch (TalkStatus) {
206 case IdTalkFile:
207 FileSend();
208 break; /* file */
209 case IdTalkSendMem:
210 SendMemContinuously();
211 break;
212 default:
213 break;
214 }
215
216 /* Receiver */
217 if (DDELog && DDEGetCount() > 0) {
218 // ���O�o�b�t�@������DDE�N���C�A���g�����������������������A
219 // TCP�p�P�b�g�����M���s�������B
220 // �A���������M���s�����A���O�o�b�t�@�����E���h���r�������������M���f�[�^��
221 // �������������������\���������B(2007.6.14 yutaka)
222
223 } else {
224 CommReceive(&cv);
225 }
226
227 }
228
229 if (cv.Ready &&
230 (cv.RRQ || (cv.OutBuffCount>0) || (cv.InBuffCount>0) || (cv.FlushLen>0) || FLogGetCount() > 0 || (DDEGetCount()>0)) ) {
231 Busy = 2;
232 }
233 else {
234 Busy--;
235 }
236
237 return (Busy>0);
238 }
239
240 static HWND main_window;
241 HWND GetHWND(void)
242 {
243 return main_window;
244 }
245
246 static HWND hModelessDlg;
247
248 void AddModelessHandle(HWND hWnd)
249 {
250 hModelessDlg = hWnd;
251 }
252
253 void RemoveModelessHandle(HWND hWnd)
254 {
255 (void)hWnd;
256 hModelessDlg = 0;
257 }
258
259 static UINT nMsgLast;
260 static POINT ptCursorLast;
261
262 /**
263 * idle��������������������
264 */
265 static BOOL IsIdleMessage(const MSG* pMsg)
266 {
267 if (pMsg->message == WM_MOUSEMOVE ||
268 pMsg->message == WM_NCMOUSEMOVE)
269 {
270 if (pMsg->message == nMsgLast &&
271 pMsg->pt.x == ptCursorLast.x &&
272 pMsg->pt.y == ptCursorLast.y)
273 { // �������u��������idle������������
274 return FALSE;
275 }
276
277 ptCursorLast = pMsg->pt;
278 nMsgLast = pMsg->message;
279 return TRUE;
280 }
281
282 if (pMsg->message == WM_PAINT ||
283 pMsg->message == 0x0118/*WM_SYSTIMER*/)
284 {
285 return FALSE;
286 }
287
288 return TRUE;
289 }
290
291 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst,
292 LPSTR lpszCmdLine, int nCmdShow)
293 {
294 (void)hPreInst;
295 (void)lpszCmdLine;
296 (void)nCmdShow;
297 #ifdef _DEBUG
298 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
299 #endif
300
301 srand((unsigned int)time(NULL));
302 setlocale(LC_ALL, "");
303
304 ts.TeraTermInstance = hInstance;
305 hInst = hInstance;
306 init();
307 _HtmlHelpW(NULL, NULL, HH_INITIALIZE, (DWORD_PTR)&HtmlHelpCookie);
308
309 #if ENABLE_GDIPLUS
310 GDIPInit();
311 #endif
312
313 CVTWindow *m_pMainWnd = new CVTWindow(hInstance);
314 pVTWin = m_pMainWnd;
315 main_window = m_pMainWnd->m_hWnd;
316 // [Tera Term]�Z�N�V������DLG_SYSTEM_FONT�������������Z�b�g����
317 SetDialogFont(ts.DialogFontNameW, ts.DialogFontPoint, ts.DialogFontCharSet,
318 ts.UILanguageFileW, "Tera Term", "DLG_SYSTEM_FONT");
319
320 BOOL bIdle = TRUE; // idle������?
321 LONG lCount = 0;
322 MSG msg;
323 for (;;) {
324 // idle���������b�Z�[�W����������
325 while (bIdle) {
326 if (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) != FALSE) {
327 // ���b�Z�[�W����������
328 break;
329 }
330
331 const BOOL continue_idle = OnIdle(lCount++);
332 if (!continue_idle) {
333 // FALSE��������������idle�������s�v
334 bIdle = FALSE;
335 break;
336 }
337 }
338
339 // ���b�Z�[�W����������������������
340 for(;;) {
341 // ���b�Z�[�W���������������AGetMessage()���u���b�N��������������
342 if (::GetMessage(&msg, NULL, 0, 0) == FALSE) {
343 // WM_QUIT
344 goto exit_message_loop;
345 }
346
347 if (hModelessDlg == 0 ||
348 ::IsDialogMessage(hModelessDlg, &msg) == FALSE)
349 {
350 bool message_processed = false;
351
352 if (m_pMainWnd->m_hAccel != NULL) {
353 if (!MetaKey(ts.MetaKey)) {
354 // matakey����������������
355 if (::TranslateAccelerator(m_pMainWnd->m_hWnd , m_pMainWnd->m_hAccel, &msg)) {
356 // �A�N�Z�����[�^�[�L�[����������
357 message_processed = true;
358 }
359 }
360 }
361
362 if (!message_processed) {
363 ::TranslateMessage(&msg);
364 ::DispatchMessage(&msg);
365 }
366 }
367
368 // idle������������?
369 if (IsIdleMessage(&msg)) {
370 bIdle = TRUE;
371 lCount = 0;
372 }
373
374 if (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) == FALSE) {
375 // ���b�Z�[�W������������
376 break;
377 }
378 }
379 }
380 exit_message_loop:
381
382 delete m_pMainWnd;
383 m_pMainWnd = NULL;
384
385 #if ENABLE_GDIPLUS
386 GDIPUninit();
387 #endif
388
389 _HtmlHelpW(NULL, NULL, HH_CLOSE_ALL, 0);
390 _HtmlHelpW(NULL, NULL, HH_UNINITIALIZE, HtmlHelpCookie);
391
392 free(TSpecialFont);
393 TSpecialFont = NULL;
394 UnloadSpecialFont();
395 DLLExit();
396
397 return (int)msg.wParam;
398 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26