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 10255 - (hide annotations) (download) (as text)
Fri Sep 9 14:12:36 2022 UTC (19 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/teraterm.cpp
File MIME type: text/x-c++src
File size: 9052 byte(s)
RandomFileW() を追加

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

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