Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ttcomtester/teraterm/teraterm/teraterm.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

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