Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/teraterm.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10738 - (hide annotations) (download) (as text)
Sun Jun 4 12:28:20 2023 UTC (10 months, 1 week 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 doda 6806 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3 nmaya 9048 * (C) 2006- TeraTerm Project
4 doda 6806 * All rights reserved.
5     *
6 doda 6841 * Redistribution and use in source and binary forms, with or without
7     * modification, are permitted provided that the following conditions
8     * are met:
9 doda 6806 *
10 doda 6841 * 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 doda 6806 *
18 doda 6841 * 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 doda 6806 */
29 maya 3227
30     /* TERATERM.EXE, main */
31    
32 doda 8445 #include <stdio.h>
33 zmatsuo 7528 #include <crtdbg.h>
34 zmatsuo 8582 #include <windows.h>
35     #include <htmlhelp.h>
36 zmatsuo 10738 #include <locale.h>
37    
38 maya 3227 #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 doda 4414 #include "keyboard.h"
52 zmatsuo 7457 #include "dllutil.h"
53     #include "compat_win.h"
54 zmatsuo 7509 #include "dlglib.h"
55 zmatsuo 7528 #include "teraterml.h"
56 doda 8445 #include "sendmem.h"
57 zmatsuo 9124 #include "ttdebug.h"
58 zmatsuo 10148 #include "win32helper.h"
59     #include "asprintf.h"
60 zmatsuo 10349 #if ENABLE_GDIPLUS
61     #include "ttgdiplus.h"
62     #endif
63 maya 3227
64 zmatsuo 7656 #if defined(_DEBUG) && defined(_MSC_VER)
65 zmatsuo 7457 #define new ::new(_NORMAL_BLOCK, __FILE__, __LINE__)
66 maya 3227 #endif
67    
68 zmatsuo 7457 static BOOL AddFontFlag;
69 zmatsuo 10148 static wchar_t *TSpecialFont;
70 zmatsuo 7935 static CVTWindow* pVTWin;
71 zmatsuo 8582 static DWORD HtmlHelpCookie;
72 zmatsuo 7457
73 zmatsuo 10147 static void LoadSpecialFont(void)
74 zmatsuo 7457 {
75 zmatsuo 10148 wchar_t *mod_path;
76 zmatsuo 10147 if (IsExistFontW(L"Tera Special", SYMBOL_CHARSET, TRUE)) {
77 zmatsuo 8518 // ���������������������[�h������
78     return;
79     }
80 zmatsuo 7457
81 zmatsuo 10148 if (hGetModuleFileNameW(NULL, &mod_path) != 0) {
82 zmatsuo 8518 AddFontFlag = FALSE;
83     return;
84     }
85 zmatsuo 10148 *wcsrchr(mod_path, L'\\') = 0;
86     aswprintf(&TSpecialFont, L"%s\\TSPECIAL1.TTF", mod_path);
87     free(mod_path);
88 zmatsuo 7457
89 zmatsuo 8518 // teraterm.exe�������L�����t�H���g�������B
90     // remove�����������I��������OS������������
91 zmatsuo 9320 int r = 0;
92     if (pAddFontResourceExW != NULL) {
93     r = pAddFontResourceExW(TSpecialFont, FR_PRIVATE, NULL);
94     }
95 zmatsuo 8518 if (r == 0) {
96     // AddFontResourceEx() ���g����������
97     // �V�X�e���S�����g�����t�H���g������
98     // remove��������OS������������������
99 zmatsuo 9324 r = AddFontResourceW(TSpecialFont);
100 doda 6793 }
101 zmatsuo 8518 if (r != 0) {
102     AddFontFlag = TRUE;
103     }
104 maya 3227 }
105    
106 zmatsuo 10147 static void UnloadSpecialFont(void)
107 zmatsuo 7457 {
108 zmatsuo 8518 if (!AddFontFlag) {
109     return;
110 zmatsuo 7457 }
111 zmatsuo 9320 int r = 0;
112     if (pRemoveFontResourceExW != NULL) {
113     r = pRemoveFontResourceExW(TSpecialFont, FR_PRIVATE, NULL);
114     }
115 zmatsuo 8518 if (r == 0) {
116 zmatsuo 9324 RemoveFontResourceW(TSpecialFont);
117 zmatsuo 8518 }
118 zmatsuo 7457 }
119    
120 zmatsuo 10147 static void init(void)
121 zmatsuo 7457 {
122     DLLInit();
123     WinCompatInit();
124 zmatsuo 9124 DebugSetException();
125 zmatsuo 7509 LoadSpecialFont();
126 zmatsuo 9124 #if defined(DEBUG_OPEN_CONSOLE_AT_STARTUP)
127     DebugConsoleOpen();
128     #endif
129 zmatsuo 7457 }
130    
131 maya 3227 // Tera Term main engine
132 zmatsuo 7528 static BOOL OnIdle(LONG lCount)
133 maya 3227 {
134     static int Busy = 2;
135 zmatsuo 8857 int nx, ny;
136 maya 3227 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 zmatsuo 8857 int Change;
160 zmatsuo 9103 if (ProtoGetProtoFlag()) Change = ProtoDlgParse();
161 maya 3227 else {
162     switch (ActiveWin) {
163 doda 6435 case IdVT:
164 zmatsuo 7935 Change = pVTWin->Parse();
165 maya 3227 // 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 maya 3392 else {
179 maya 3227 Change = IdVT;
180 maya 3392 }
181 maya 3227 break;
182    
183     default:
184     Change = 0;
185     }
186    
187     switch (Change) {
188 maya 3392 case IdVT:
189     VTActivate();
190     break;
191     case IdTEK:
192 zmatsuo 7935 pVTWin->OpenTEK();
193 maya 3392 break;
194 maya 3227 }
195     }
196     }
197    
198 zmatsuo 8897 FLogWriteFile();
199 maya 3227
200 zmatsuo 8860 if (DDELog && AdvFlag) {
201     DDEAdv();
202     }
203 maya 3227
204     /* Talker */
205     switch (TalkStatus) {
206 maya 3392 case IdTalkFile:
207     FileSend();
208     break; /* file */
209 doda 8445 case IdTalkSendMem:
210     SendMemContinuously();
211     break;
212     default:
213     break;
214 maya 3227 }
215    
216     /* Receiver */
217 zmatsuo 8860 if (DDELog && DDEGetCount() > 0) {
218 maya 3227 // ���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 zmatsuo 8897 (cv.RRQ || (cv.OutBuffCount>0) || (cv.InBuffCount>0) || (cv.FlushLen>0) || FLogGetCount() > 0 || (DDEGetCount()>0)) ) {
231 maya 3227 Busy = 2;
232 maya 3392 }
233     else {
234 maya 3227 Busy--;
235 maya 3392 }
236 maya 3227
237     return (Busy>0);
238     }
239    
240 zmatsuo 7528 static HWND main_window;
241 zmatsuo 10147 HWND GetHWND(void)
242 zmatsuo 7528 {
243     return main_window;
244     }
245    
246 zmatsuo 7915 static HWND hModelessDlg;
247 zmatsuo 7528
248 zmatsuo 7915 void AddModelessHandle(HWND hWnd)
249 zmatsuo 7528 {
250 zmatsuo 7915 hModelessDlg = hWnd;
251 zmatsuo 7528 }
252    
253 zmatsuo 7915 void RemoveModelessHandle(HWND hWnd)
254 zmatsuo 7528 {
255 zmatsuo 7914 (void)hWnd;
256 zmatsuo 7915 hModelessDlg = 0;
257 zmatsuo 7528 }
258    
259 zmatsuo 7914 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 zmatsuo 7528 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst,
292     LPSTR lpszCmdLine, int nCmdShow)
293     {
294 zmatsuo 7914 (void)hPreInst;
295     (void)lpszCmdLine;
296     (void)nCmdShow;
297 zmatsuo 7528 #ifdef _DEBUG
298 zmatsuo 7656 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
299 zmatsuo 7528 #endif
300 doda 8445
301 zmatsuo 10255 srand((unsigned int)time(NULL));
302 zmatsuo 10738 setlocale(LC_ALL, "");
303 zmatsuo 10255
304 nmaya 10009 ts.TeraTermInstance = hInstance;
305 zmatsuo 10349 hInst = hInstance;
306 zmatsuo 9319 init();
307 zmatsuo 8582 _HtmlHelpW(NULL, NULL, HH_INITIALIZE, (DWORD_PTR)&HtmlHelpCookie);
308 zmatsuo 10349
309     #if ENABLE_GDIPLUS
310     GDIPInit();
311     #endif
312    
313 zmatsuo 7916 CVTWindow *m_pMainWnd = new CVTWindow(hInstance);
314 zmatsuo 7528 pVTWin = m_pMainWnd;
315     main_window = m_pMainWnd->m_hWnd;
316 zmatsuo 7589 // [Tera Term]�Z�N�V������DLG_SYSTEM_FONT�������������Z�b�g����
317 zmatsuo 10150 SetDialogFont(ts.DialogFontNameW, ts.DialogFontPoint, ts.DialogFontCharSet,
318     ts.UILanguageFileW, "Tera Term", "DLG_SYSTEM_FONT");
319 zmatsuo 7528
320 zmatsuo 7914 BOOL bIdle = TRUE; // idle������?
321     LONG lCount = 0;
322 zmatsuo 7528 MSG msg;
323 zmatsuo 7914 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 zmatsuo 7528 }
330 zmatsuo 7914
331     const BOOL continue_idle = OnIdle(lCount++);
332     if (!continue_idle) {
333     // FALSE��������������idle�������s�v
334     bIdle = FALSE;
335     break;
336     }
337 zmatsuo 7528 }
338    
339 zmatsuo 7914 // ���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 zmatsuo 7528
347 zmatsuo 7915 if (hModelessDlg == 0 ||
348     ::IsDialogMessage(hModelessDlg, &msg) == FALSE)
349 zmatsuo 7914 {
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 zmatsuo 7528 }
361 zmatsuo 7914
362     if (!message_processed) {
363     ::TranslateMessage(&msg);
364     ::DispatchMessage(&msg);
365     }
366 zmatsuo 7528 }
367    
368 zmatsuo 7914 // idle������������?
369     if (IsIdleMessage(&msg)) {
370     bIdle = TRUE;
371 zmatsuo 7528 lCount = 0;
372     }
373 zmatsuo 7914
374     if (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) == FALSE) {
375     // ���b�Z�[�W������������
376     break;
377     }
378 zmatsuo 7528 }
379 maya 3392 }
380 zmatsuo 7914 exit_message_loop:
381    
382 zmatsuo 7528 delete m_pMainWnd;
383     m_pMainWnd = NULL;
384    
385 zmatsuo 10349 #if ENABLE_GDIPLUS
386     GDIPUninit();
387     #endif
388    
389 zmatsuo 8582 _HtmlHelpW(NULL, NULL, HH_CLOSE_ALL, 0);
390     _HtmlHelpW(NULL, NULL, HH_UNINITIALIZE, HtmlHelpCookie);
391    
392 zmatsuo 10148 free(TSpecialFont);
393     TSpecialFont = NULL;
394 zmatsuo 7528 UnloadSpecialFont();
395     DLLExit();
396    
397 zmatsuo 7914 return (int)msg.wParam;
398 maya 3227 }

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